From c2cd5fc5d345a61b6cc251d2974f199f4e8c04f8 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 9 Nov 2017 00:29:34 +0100 Subject: [PATCH 1/2] Fix flow Signed-off-by: Mario Danic --- core/Controller/ClientFlowLoginController.php | 11 +++++++++- .../ClientFlowLoginControllerTest.php | 20 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/Controller/ClientFlowLoginController.php b/core/Controller/ClientFlowLoginController.php index 81ba8009b2488..47bbbce640e36 100644 --- a/core/Controller/ClientFlowLoginController.php +++ b/core/Controller/ClientFlowLoginController.php @@ -307,7 +307,16 @@ public function generateAppPassword($stateToken, ); $this->session->remove('oauth.state'); } else { - $redirectUri = 'nc://login/server:' . $this->request->getServerHost() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token); + $serverPostfix = ''; + + if (strpos($this->request->getRequestUri(), '/index.php') !== false) { + $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php')); + } else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) { + $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow')); + } + + $serverPath = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . $serverPostfix; + $redirectUri = 'nc://login/server:' . $serverPath . '&user:' . urlencode($loginName) . '&password:' . urlencode($token); } return new Http\RedirectResponse($redirectUri); diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index 99388e2c4417e..d2dec68573758 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -158,6 +158,10 @@ public function testShowAuthPickerPageWithOcsHeader() { ->expects($this->once()) ->method('getName') ->willReturn('ExampleCloud'); + $this->request + ->expects($this->once()) + ->method('getServerProtocol') + ->willReturn('http'); $this->request ->expects($this->once()) ->method('getServerHost') @@ -214,6 +218,10 @@ public function testShowAuthPickerPageWithOauth() { ->expects($this->once()) ->method('getName') ->willReturn('ExampleCloud'); + $this->request + ->expects($this->once()) + ->method('getServerProtocol') + ->willReturn('http'); $this->request ->expects($this->once()) ->method('getServerHost') @@ -423,12 +431,16 @@ public function testGeneratePasswordWithPassword() { IToken::PERMANENT_TOKEN, IToken::DO_NOT_REMEMBER ); + $this->request + ->expects($this->once()) + ->method('getServerProtocol') + ->willReturn('http'); $this->request ->expects($this->once()) ->method('getServerHost') ->willReturn('example.com'); - $expected = new Http\RedirectResponse('nc://login/server:example.com&user:MyLoginName&password:MyGeneratedToken'); + $expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } @@ -571,12 +583,16 @@ public function testGeneratePasswordWithoutPassword() { IToken::PERMANENT_TOKEN, IToken::DO_NOT_REMEMBER ); + $this->request + ->expects($this->once()) + ->method('getServerProtocol') + ->willReturn('http'); $this->request ->expects($this->once()) ->method('getServerHost') ->willReturn('example.com'); - $expected = new Http\RedirectResponse('nc://login/server:example.com&user:MyLoginName&password:MyGeneratedToken'); + $expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } } From 555fe7047f3140bcc5a46a961a160f59d25662d2 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 8 Dec 2017 13:29:33 +0100 Subject: [PATCH 2/2] fix tests Signed-off-by: Bjoern Schiessle --- tests/Core/Controller/ClientFlowLoginControllerTest.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index d2dec68573758..216738632233e 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -158,10 +158,6 @@ public function testShowAuthPickerPageWithOcsHeader() { ->expects($this->once()) ->method('getName') ->willReturn('ExampleCloud'); - $this->request - ->expects($this->once()) - ->method('getServerProtocol') - ->willReturn('http'); $this->request ->expects($this->once()) ->method('getServerHost') @@ -218,10 +214,6 @@ public function testShowAuthPickerPageWithOauth() { ->expects($this->once()) ->method('getName') ->willReturn('ExampleCloud'); - $this->request - ->expects($this->once()) - ->method('getServerProtocol') - ->willReturn('http'); $this->request ->expects($this->once()) ->method('getServerHost')