]> source.dussan.org Git - nextcloud-server.git/commitdiff
Extend tests 32375/head
authorJoas Schilling <coding@schilljs.com>
Mon, 16 May 2022 08:33:30 +0000 (10:33 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 16 May 2022 08:33:30 +0000 (10:33 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
tests/Core/Controller/ClientFlowLoginControllerTest.php
tests/Core/Controller/ClientFlowLoginV2ControllerTest.php

index dae42474f41bd5a74043461e4892e5888873e997..dfd3e629dcd4ae0501ca9e572a2a0d794081f591 100644 (file)
@@ -134,15 +134,15 @@ class ClientFlowLoginControllerTest extends TestCase {
 
        public function testShowAuthPickerPageWithOcsHeader() {
                $this->request
-                       ->expects($this->at(0))
                        ->method('getHeader')
-                       ->with('USER_AGENT')
-                       ->willReturn('Mac OS X Sync Client');
-               $this->request
-                       ->expects($this->at(1))
-                       ->method('getHeader')
-                       ->with('OCS-APIREQUEST')
-                       ->willReturn('true');
+                       ->withConsecutive(
+                               ['USER_AGENT'],
+                               ['OCS-APIREQUEST']
+                       )
+                       ->willReturnMap([
+                               ['USER_AGENT', 'Mac OS X Sync Client'],
+                               ['OCS-APIREQUEST', 'true'],
+                       ]);
                $this->random
                        ->expects($this->once())
                        ->method('generate')
@@ -196,10 +196,15 @@ class ClientFlowLoginControllerTest extends TestCase {
 
        public function testShowAuthPickerPageWithOauth() {
                $this->request
-                       ->expects($this->at(0))
                        ->method('getHeader')
-                       ->with('USER_AGENT')
-                       ->willReturn('Mac OS X Sync Client');
+                       ->withConsecutive(
+                               ['USER_AGENT'],
+                               ['OCS-APIREQUEST']
+                       )
+                       ->willReturnMap([
+                               ['USER_AGENT', 'Mac OS X Sync Client'],
+                               ['OCS-APIREQUEST', 'false'],
+                       ]);
                $client = new Client();
                $client->setName('My external service');
                $client->setRedirectUri('https://example.com/redirect.php');
@@ -413,23 +418,21 @@ class ClientFlowLoginControllerTest extends TestCase {
         */
        public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $redirectUrl) {
                $this->session
-                       ->expects($this->at(0))
                        ->method('get')
-                       ->with('client.flow.state.token')
-                       ->willReturn('MyStateToken');
-               $this->session
-                       ->expects($this->at(1))
-                       ->method('remove')
-                       ->with('client.flow.state.token');
-               $this->session
-                       ->expects($this->at(3))
-                       ->method('get')
-                       ->with('oauth.state')
-                       ->willReturn('MyOauthState');
+                       ->withConsecutive(
+                               ['client.flow.state.token'],
+                               ['oauth.state']
+                       )
+                       ->willReturnMap([
+                               ['client.flow.state.token', 'MyStateToken'],
+                               ['oauth.state', 'MyOauthState'],
+                       ]);
                $this->session
-                       ->expects($this->at(4))
                        ->method('remove')
-                       ->with('oauth.state');
+                       ->withConsecutive(
+                               ['client.flow.state.token'],
+                               ['oauth.state']
+                       );
                $this->session
                        ->expects($this->once())
                        ->method('getId')
@@ -450,15 +453,15 @@ class ClientFlowLoginControllerTest extends TestCase {
                        ->with($myToken, 'SessionId')
                        ->willReturn('MyPassword');
                $this->random
-                       ->expects($this->at(0))
                        ->method('generate')
-                       ->with(72)
-                       ->willReturn('MyGeneratedToken');
-               $this->random
-                       ->expects($this->at(1))
-                       ->method('generate')
-                       ->with(128)
-                       ->willReturn('MyAccessCode');
+                       ->withConsecutive(
+                               [72],
+                               [128]
+                       )
+                       ->willReturnMap([
+                               [72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS, 'MyGeneratedToken'],
+                               [128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS, 'MyAccessCode'],
+                       ]);
                $user = $this->createMock(IUser::class);
                $user
                        ->expects($this->once())
index 1e35dc71c3f0b68214463fd3b7cf813dfd671c1b..53d5f392ac647fb8448495e07d06e3712238a50d 100644 (file)
@@ -36,6 +36,8 @@ use OCP\IL10N;
 use OCP\IRequest;
 use OCP\ISession;
 use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserSession;
 use OCP\Security\ISecureRandom;
 use PHPUnit\Framework\MockObject\MockObject;
 use Test\TestCase;
@@ -50,6 +52,8 @@ class ClientFlowLoginV2ControllerTest extends TestCase {
        private $urlGenerator;
        /** @var ISession|MockObject */
        private $session;
+       /** @var IUserSession|MockObject */
+       private $userSession;
        /** @var ISecureRandom|MockObject */
        private $random;
        /** @var Defaults|MockObject */
@@ -66,6 +70,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase {
                $this->loginFlowV2Service = $this->createMock(LoginFlowV2Service::class);
                $this->urlGenerator = $this->createMock(IURLGenerator::class);
                $this->session = $this->createMock(ISession::class);
+               $this->userSession = $this->createMock(IUserSession::class);
                $this->random = $this->createMock(ISecureRandom::class);
                $this->defaults = $this->createMock(Defaults::class);
                $this->l = $this->createMock(IL10N::class);
@@ -75,6 +80,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase {
                        $this->loginFlowV2Service,
                        $this->urlGenerator,
                        $this->session,
+                       $this->userSession,
                        $this->random,
                        $this->defaults,
                        'user',
@@ -224,6 +230,14 @@ class ClientFlowLoginV2ControllerTest extends TestCase {
                                return null;
                        });
 
+               $user = $this->createMock(IUser::class);
+               $user->method('getUID')
+                       ->willReturn('uid');
+               $user->method('getDisplayName')
+                       ->willReturn('display name');
+               $this->userSession->method('getUser')
+                       ->willReturn($user);
+
                $flow = new LoginFlowV2();
                $this->loginFlowV2Service->method('getByLoginToken')
                        ->with('loginToken')