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 <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2017-01-02 11:20:22 +01:00
parent 0d24e5d5f9
commit 02359c79fd
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
3 changed files with 45 additions and 20 deletions

View File

@ -76,3 +76,11 @@ Feature: auth
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"
# 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"

View File

@ -1,4 +1,5 @@
<?php
/**
*
@ -116,15 +117,13 @@ 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, [
$response = $client->get($loginUrl, [
'cookies' => $this->cookieJar,
]
);
]);
$this->extracRequestTokenFromResponse($response);
// Login and extract new token
@ -134,6 +133,7 @@ trait Auth {
'body' => [
'user' => 'user0',
'password' => '123456',
'remember_login' => $remember ? '1' : '0',
'requesttoken' => $this->requestToken,
],
'cookies' => $this->cookieJar,
@ -142,4 +142,18 @@ trait Auth {
$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();
}
}

View File

@ -24,7 +24,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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();
}
}