Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix oauth2 tests
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jun 8, 2023
commit 808819a4d0f87ba294b95e894b6db66872662208
68 changes: 44 additions & 24 deletions apps/oauth2/tests/Controller/OauthApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,21 @@ public function testGetTokenInvalidAppToken() {

$client = new Client();
$client->setClientIdentifier('clientId');
$client->setSecret('clientSecret');
$client->setSecret('encryptedClientSecret');
$this->clientMapper->method('getByUid')
->with(42)
->willReturn($client);

$this->crypto->method('decrypt')
->with(
'encryptedToken',
'validrefresh'
)->willReturn('decryptedToken');
$this->crypto
->method('decrypt')
->with($this->callback(function (string $text) {
return $text === 'encryptedClientSecret' || $text === 'encryptedToken';
}))
->willReturnCallback(function (string $text) {
return $text === 'encryptedClientSecret'
? 'clientSecret'
: ($text === 'encryptedToken' ? 'decryptedToken' : '');
});

$this->tokenProvider->method('getTokenById')
->with(1337)
Expand All @@ -237,16 +242,21 @@ public function testGetTokenValidAppToken() {

$client = new Client();
$client->setClientIdentifier('clientId');
$client->setSecret('clientSecret');
$client->setSecret('encryptedClientSecret');
$this->clientMapper->method('getByUid')
->with(42)
->willReturn($client);

$this->crypto->method('decrypt')
->with(
'encryptedToken',
'validrefresh'
)->willReturn('decryptedToken');
$this->crypto
->method('decrypt')
->with($this->callback(function (string $text) {
return $text === 'encryptedClientSecret' || $text === 'encryptedToken';
}))
->willReturnCallback(function (string $text) {
return $text === 'encryptedClientSecret'
? 'clientSecret'
: ($text === 'encryptedToken' ? 'decryptedToken' : '');
});

$appToken = new PublicKeyToken();
$appToken->setUid('userId');
Expand Down Expand Up @@ -329,16 +339,21 @@ public function testGetTokenValidAppTokenBasicAuth() {

$client = new Client();
$client->setClientIdentifier('clientId');
$client->setSecret('clientSecret');
$client->setSecret('encryptedClientSecret');
$this->clientMapper->method('getByUid')
->with(42)
->willReturn($client);

$this->crypto->method('decrypt')
->with(
'encryptedToken',
'validrefresh'
)->willReturn('decryptedToken');
$this->crypto
->method('decrypt')
->with($this->callback(function (string $text) {
return $text === 'encryptedClientSecret' || $text === 'encryptedToken';
}))
->willReturnCallback(function (string $text) {
return $text === 'encryptedClientSecret'
? 'clientSecret'
: ($text === 'encryptedToken' ? 'decryptedToken' : '');
});

$appToken = new PublicKeyToken();
$appToken->setUid('userId');
Expand Down Expand Up @@ -424,16 +439,21 @@ public function testGetTokenExpiredAppToken() {

$client = new Client();
$client->setClientIdentifier('clientId');
$client->setSecret('clientSecret');
$client->setSecret('encryptedClientSecret');
$this->clientMapper->method('getByUid')
->with(42)
->willReturn($client);

$this->crypto->method('decrypt')
->with(
'encryptedToken',
'validrefresh'
)->willReturn('decryptedToken');
$this->crypto
->method('decrypt')
->with($this->callback(function (string $text) {
return $text === 'encryptedClientSecret' || $text === 'encryptedToken';
}))
->willReturnCallback(function (string $text) {
return $text === 'encryptedClientSecret'
? 'clientSecret'
: ($text === 'encryptedToken' ? 'decryptedToken' : '');
});

$appToken = new PublicKeyToken();
$appToken->setUid('userId');
Expand Down
10 changes: 9 additions & 1 deletion apps/oauth2/tests/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IURLGenerator;
use OCP\Security\ICrypto;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class AdminTest extends TestCase {
Expand All @@ -48,7 +50,13 @@ protected function setUp(): void {
$this->initialState = $this->createMock(IInitialState::class);
$this->clientMapper = $this->createMock(ClientMapper::class);

$this->admin = new Admin($this->initialState, $this->clientMapper, $this->createMock(IURLGenerator::class));
$this->admin = new Admin(
$this->initialState,
$this->clientMapper,
$this->createMock(IURLGenerator::class),
$this->createMock(ICrypto::class),
$this->createMock(LoggerInterface::class)
);
}

public function testGetForm() {
Expand Down