From 0bc49d67cdc09da25e828848735e41abef12a157 Mon Sep 17 00:00:00 2001 From: Konrad Abicht Date: Thu, 11 Feb 2021 10:58:44 +0100 Subject: [PATCH] added unit tests for LoginFlowV2Service::createTokens Signed-off-by: Konrad Abicht --- .../Service/LoginFlowV2ServiceUnitTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php index 9089d81dc9..ba0a3130af 100644 --- a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php +++ b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php @@ -26,6 +26,7 @@ use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; use OC\Core\Data\LoginFlowV2Credentials; +use OC\Core\Data\LoginFlowV2Tokens; use OC\Core\Db\LoginFlowV2Mapper; use OC\Core\Db\LoginFlowV2; use OC\Core\Exception\LoginFlowV2NotFoundException; @@ -380,4 +381,26 @@ class LoginFlowV2ServiceUnitTest extends TestCase { ); $this->assertFalse($result); } + + /* + * Tests for createTokens + */ + + public function testCreateTokens() { + $this->config->expects($this->exactly(2)) + ->method('getSystemValue') + ->willReturn($this->returnCallback(function ($key) { + // Note: \OCP\IConfig::getSystemValue returns either an array or string. + return 'openssl' == $key ? [] : ''; + })); + + $this->mapper->expects($this->once()) + ->method('insert'); + + $this->secureRandom->expects($this->exactly(2)) + ->method('generate'); + + $token = $this->subjectUnderTest->createTokens('user_agent'); + $this->assertTrue($token instanceof LoginFlowV2Tokens); + } }