-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from owncloud/feature/azure-ad-hack
Azure AD: Use access token payload instead of user info endpoint
- Loading branch information
Showing
7 changed files
with
81 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,13 @@ class ClientTest extends TestCase { | |
*/ | ||
private $config; | ||
|
||
public function providesGetUserInfoData(): array { | ||
return [ | ||
'access-token' => [true], | ||
'user-info-endpoint' => [false], | ||
]; | ||
} | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
$this->config = $this->createMock(IConfig::class); | ||
|
@@ -125,4 +132,43 @@ public function testCtorInsecure(): void { | |
self::assertEquals(false, $this->client->getVerifyHost()); | ||
self::assertEquals(false, $this->client->getVerifyPeer()); | ||
} | ||
|
||
/** | ||
* @dataProvider providesGetUserInfoData | ||
* @param $useAccessTokenPayloadForUserInfo | ||
*/ | ||
public function testGetUserInfo($useAccessTokenPayloadForUserInfo): void { | ||
$this->config->method('getSystemValue')->willReturnCallback(static function ($key) use ($useAccessTokenPayloadForUserInfo) { | ||
if ($key === 'openid-connect') { | ||
return [ | ||
'provider-url' => '$providerUrl', | ||
'client-id' => 'client-id', | ||
'client-secret' => 'secret', | ||
'use-access-token-payload-for-user-info' => $useAccessTokenPayloadForUserInfo | ||
]; | ||
} | ||
throw new \InvalidArgumentException("Unexpected key: $key"); | ||
}); | ||
|
||
$this->client = $this->getMockBuilder(Client::class) | ||
->setConstructorArgs([$this->config, $this->urlGenerator, $this->session]) | ||
->onlyMethods(['requestUserInfo', 'getAccessTokenPayload']) | ||
->getMock(); | ||
if ($useAccessTokenPayloadForUserInfo) { | ||
$this->client->expects(self::never())->method('requestUserInfo'); | ||
$this->client->expects(self::once())->method('getAccessTokenPayload')->willReturn([ | ||
'preferred_username' => '[email protected]' | ||
]); | ||
} else { | ||
$this->client->expects(self::never())->method('getAccessTokenPayload'); | ||
$this->client->expects(self::once())->method('requestUserInfo')->willReturn([ | ||
'preferred_username' => '[email protected]' | ||
]); | ||
} | ||
|
||
$info = $this->client->getUserInfo(); | ||
self::assertEquals([ | ||
'preferred_username' => '[email protected]' | ||
], $info); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,7 @@ public function testLoginNoUserInfo(): void { | |
|
||
public function testLoginUnknownUser(): void { | ||
$this->client->method('getOpenIdConfig')->willReturn([]); | ||
$this->client->method('requestUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->client->method('getUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->userLookup->method('lookupUser')->willThrowException(new LoginException('User foo is not known.')); | ||
$this->expectException(LoginException::class); | ||
$this->expectExceptionMessage('User foo is not known.'); | ||
|
@@ -127,7 +127,7 @@ public function testLoginUnknownUser(): void { | |
|
||
public function testLoginCreateSessionFailed(): void { | ||
$this->client->method('getOpenIdConfig')->willReturn([]); | ||
$this->client->method('requestUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->client->method('getUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$user = $this->createMock(IUser::class); | ||
$this->userLookup->method('lookupUser')->willReturn($user); | ||
$this->userSession->method('createSessionToken')->willReturn(false); | ||
|
@@ -138,7 +138,7 @@ public function testLoginCreateSessionFailed(): void { | |
|
||
public function testLoginCreateSuccess(): void { | ||
$this->client->method('getOpenIdConfig')->willReturn([]); | ||
$this->client->method('requestUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->client->method('getUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->client->method('getIdToken')->willReturn('id'); | ||
$this->client->method('getAccessToken')->willReturn('access'); | ||
$this->client->method('getRefreshToken')->willReturn('refresh'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ public function testInvalidTokenWithIntrospectionNotActive(): void { | |
public function testValidTokenWithIntrospection(): void { | ||
$this->client->method('getOpenIdConfig')->willReturn(['use-token-introspection-endpoint' => true]); | ||
$this->client->method('introspectToken')->willReturn((object)['active' => true, 'exp' => \time() + 3600]); | ||
$this->client->method('requestUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->client->method('getUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->cacheFactory->method('create')->willReturn(new ArrayCache()); | ||
$user = $this->createMock(IUser::class); | ||
$this->lookupService->expects(self::once())->method('lookupUser')->willReturn($user); | ||
|
@@ -141,7 +141,7 @@ public function testValidTokenWithJWT(): void { | |
$this->client->method('getOpenIdConfig')->willReturn(['use-token-introspection-endpoint' => false]); | ||
$this->client->method('verifyJWTsignature')->willReturn(true); | ||
$this->client->method('getAccessTokenPayload')->willReturn((object)['exp' => \time() + 3600]); | ||
$this->client->method('requestUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->client->method('getUserInfo')->willReturn((object)['email' => '[email protected]']); | ||
$this->cacheFactory->method('create')->willReturn(new ArrayCache()); | ||
$user = $this->createMock(IUser::class); | ||
$this->lookupService->expects(self::once())->method('lookupUser')->willReturn($user); | ||
|