diff options
author | Konrad Abicht <hi@inspirito.de> | 2021-02-11 09:49:39 +0100 |
---|---|---|
committer | Konrad Abicht <hi@inspirito.de> | 2021-02-11 09:49:39 +0100 |
commit | f29748a5e11bc1a86e47ce97dd00f6aaff183c36 (patch) | |
tree | ac5c4d531ac38456d2c4c0e9516693ea1bdc8678 | |
parent | b0a2278a7ec0309ff70ac5e5254c41030f4d1880 (diff) | |
download | nextcloud-server-f29748a5e11bc1a86e47ce97dd00f6aaff183c36.tar.gz nextcloud-server-f29748a5e11bc1a86e47ce97dd00f6aaff183c36.zip |
added unit tests for LoginFlowV2Service::getByLoginToken
Signed-off-by: Konrad Abicht <hi@inspirito.de>
-rw-r--r-- | tests/Core/Service/LoginFlowV2ServiceUnitTest.php | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php index ed87380897c..511c9be3271 100644 --- a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php +++ b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php @@ -74,8 +74,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { * * Code was moved to separate function to keep setUp function small and clear. */ - private function setupSubjectUnderTest(): void - { + private function setupSubjectUnderTest(): void { $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor()->getMock(); @@ -115,7 +114,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { // Create the private and public key $res = openssl_pkey_new([ 'digest_alg' => 'md5', // take fast algorithm for testing purposes - 'private_key_bits' => 4096, + 'private_key_bits' => 512, 'private_key_type' => OPENSSL_KEYTYPE_RSA, ]); @@ -142,7 +141,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { /* * Cannot be mocked, because functions like getLoginName are magic functions. - * To be able to call it, we have to use the real class here. + * To be able to set internal properties, we have to use the real class here. */ $loginFlowV2 = new LoginFlowV2(); $loginFlowV2->setLoginName('test'); @@ -184,7 +183,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { /* * Cannot be mocked, because functions like getLoginName are magic functions. - * To be able to call it, we have to use the real class here. + * To be able to set internal properties, we have to use the real class here. */ $loginFlowV2 = new LoginFlowV2(); $loginFlowV2->setLoginName('test_login'); @@ -212,4 +211,37 @@ class LoginFlowV2ServiceUnitTest extends TestCase { $credentials->jsonSerialize() ); } + + /* + * Tests for getByLoginToken + */ + + public function testGetByLoginToken() { + $loginFlowV2 = new LoginFlowV2(); + $loginFlowV2->setLoginName('test_login'); + $loginFlowV2->setServer('test_server'); + $loginFlowV2->setAppPassword('test'); + + $this->mapper->expects($this->once()) + ->method('getByLoginToken') + ->willReturn($loginFlowV2); + + $result = $this->subjectUnderTest->getByLoginToken('test_token'); + + $this->assertTrue($result instanceof LoginFlowV2); + $this->assertEquals('test_server', $result->getServer()); + $this->assertEquals('test_login', $result->getLoginName()); + $this->assertEquals('test', $result->getAppPassword()); + } + + public function testGetByLoginTokenLoginTokenInvalid() { + $this->expectException(LoginFlowV2NotFoundException::class); + $this->expectExceptionMessage('Login token invalid'); + + $this->mapper->expects($this->once()) + ->method('getByLoginToken') + ->willThrowException(new DoesNotExistException('')); + + $this->subjectUnderTest->getByLoginToken('test_token'); + } } |