From 02359c79fdf9a46a3cd6eaf01ca60c406e96fd48 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 2 Jan 2017 11:20:22 +0100 Subject: [PATCH] Test remember-me login This adds a simple integration test that ensures that remembered login works when the session cookies vanish. Signed-off-by: Christoph Wurst --- build/integration/features/auth.feature | 10 ++++- build/integration/features/bootstrap/Auth.php | 40 +++++++++++++------ .../features/bootstrap/BasicStructure.php | 15 ++++--- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/build/integration/features/auth.feature b/build/integration/features/auth.feature index 43aa618bd00..a3af28f25c8 100644 --- a/build/integration/features/auth.feature +++ b/build/integration/features/auth.feature @@ -75,4 +75,12 @@ Feature: auth Scenario: using OCS with browser session Given a new browser session is started When requesting "/ocs/v1.php/apps/files_sharing/api/v1/remote_shares" with "GET" using browser session - Then the OCS status code should be "100" \ No newline at end of file + Then the OCS status code should be "100" + + # REMEMBER ME + Scenario: remember login + Given a new remembered browser session is started + When the session cookie expires + And requesting "/index.php/apps/files" with "GET" using browser session + Then the HTTP status code should be "200" + diff --git a/build/integration/features/bootstrap/Auth.php b/build/integration/features/bootstrap/Auth.php index f4b1a3e5b47..61cad0dc145 100644 --- a/build/integration/features/bootstrap/Auth.php +++ b/build/integration/features/bootstrap/Auth.php @@ -1,4 +1,5 @@ client->createRequest($method, $fullUrl, [ - 'cookies' => $this->cookieJar, + 'cookies' => $this->cookieJar, ]); } else { $request = $this->client->createRequest($method, $fullUrl); @@ -116,30 +117,43 @@ trait Auth { /** * @Given a new browser session is started */ - public function aNewBrowserSessionIsStarted() { + public function aNewBrowserSessionIsStarted($remember = false) { $loginUrl = substr($this->baseUrl, 0, -5) . '/login'; // Request a new session and extract CSRF token $client = new Client(); - $response = $client->get( - $loginUrl, [ - 'cookies' => $this->cookieJar, - ] - ); + $response = $client->get($loginUrl, [ + 'cookies' => $this->cookieJar, + ]); $this->extracRequestTokenFromResponse($response); // Login and extract new token $client = new Client(); $response = $client->post( $loginUrl, [ - 'body' => [ - 'user' => 'user0', - 'password' => '123456', - 'requesttoken' => $this->requestToken, - ], - 'cookies' => $this->cookieJar, + 'body' => [ + 'user' => 'user0', + 'password' => '123456', + 'remember_login' => $remember ? '1' : '0', + 'requesttoken' => $this->requestToken, + ], + 'cookies' => $this->cookieJar, ] ); $this->extracRequestTokenFromResponse($response); } + /** + * @Given a new remembered browser session is started + */ + public function aNewRememberedBrowserSessionIsStarted() { + $this->aNewBrowserSessionIsStarted(true); + } + + /** + * @When the session cookie expires + */ + public function whenTheSessionCookieExpires() { + $this->cookieJar->clearSessionCookies(); + } + } diff --git a/build/integration/features/bootstrap/BasicStructure.php b/build/integration/features/bootstrap/BasicStructure.php index 24428b6c9d9..8e1fcf86ba1 100644 --- a/build/integration/features/bootstrap/BasicStructure.php +++ b/build/integration/features/bootstrap/BasicStructure.php @@ -24,7 +24,10 @@ * along with this program. If not, see . * */ + use GuzzleHttp\Client; +use GuzzleHttp\Cookie\CookieJar; +use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Message\ResponseInterface; require __DIR__ . '/../../vendor/autoload.php'; @@ -48,7 +51,7 @@ trait BasicStructure { /** @var ResponseInterface */ private $response = null; - /** @var \GuzzleHttp\Cookie\CookieJar */ + /** @var CookieJar */ private $cookieJar; /** @var string */ @@ -63,7 +66,7 @@ trait BasicStructure { $this->localBaseUrl = $this->baseUrl; $this->remoteBaseUrl = $this->baseUrl; $this->currentServer = 'LOCAL'; - $this->cookieJar = new \GuzzleHttp\Cookie\CookieJar(); + $this->cookieJar = new CookieJar(); // in case of ci deployment we take the server url from the environment $testServerUrl = getenv('TEST_SERVER_URL'); @@ -174,7 +177,7 @@ trait BasicStructure { try { $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); - } catch (\GuzzleHttp\Exception\ClientException $ex) { + } catch (ClientException $ex) { $this->response = $ex->getResponse(); } } @@ -204,7 +207,7 @@ trait BasicStructure { try { $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); - } catch (\GuzzleHttp\Exception\ClientException $ex) { + } catch (ClientException $ex) { $this->response = $ex->getResponse(); } } @@ -298,7 +301,7 @@ trait BasicStructure { $request->addHeader('requesttoken', $this->requestToken); try { $this->response = $client->send($request); - } catch (\GuzzleHttp\Exception\ClientException $e) { + } catch (ClientException $e) { $this->response = $e->getResponse(); } } @@ -321,7 +324,7 @@ trait BasicStructure { ); try { $this->response = $client->send($request); - } catch (\GuzzleHttp\Exception\ClientException $e) { + } catch (ClientException $e) { $this->response = $e->getResponse(); } }