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:
parent
0d24e5d5f9
commit
02359c79fd
3 changed files with 45 additions and 20 deletions
|
@ -75,4 +75,12 @@ Feature: auth
|
||||||
Scenario: using OCS with browser session
|
Scenario: using OCS with browser session
|
||||||
Given a new browser session is started
|
Given a new browser session is started
|
||||||
When requesting "/ocs/v1.php/apps/files_sharing/api/v1/remote_shares" with "GET" using browser session
|
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"
|
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"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
*
|
*
|
||||||
|
@ -47,7 +48,7 @@ trait Auth {
|
||||||
try {
|
try {
|
||||||
if ($useCookies) {
|
if ($useCookies) {
|
||||||
$request = $this->client->createRequest($method, $fullUrl, [
|
$request = $this->client->createRequest($method, $fullUrl, [
|
||||||
'cookies' => $this->cookieJar,
|
'cookies' => $this->cookieJar,
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$request = $this->client->createRequest($method, $fullUrl);
|
$request = $this->client->createRequest($method, $fullUrl);
|
||||||
|
@ -116,30 +117,43 @@ trait Auth {
|
||||||
/**
|
/**
|
||||||
* @Given a new browser session is started
|
* @Given a new browser session is started
|
||||||
*/
|
*/
|
||||||
public function aNewBrowserSessionIsStarted() {
|
public function aNewBrowserSessionIsStarted($remember = false) {
|
||||||
$loginUrl = substr($this->baseUrl, 0, -5) . '/login';
|
$loginUrl = substr($this->baseUrl, 0, -5) . '/login';
|
||||||
// Request a new session and extract CSRF token
|
// Request a new session and extract CSRF token
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$response = $client->get(
|
$response = $client->get($loginUrl, [
|
||||||
$loginUrl, [
|
'cookies' => $this->cookieJar,
|
||||||
'cookies' => $this->cookieJar,
|
]);
|
||||||
]
|
|
||||||
);
|
|
||||||
$this->extracRequestTokenFromResponse($response);
|
$this->extracRequestTokenFromResponse($response);
|
||||||
|
|
||||||
// Login and extract new token
|
// Login and extract new token
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$response = $client->post(
|
$response = $client->post(
|
||||||
$loginUrl, [
|
$loginUrl, [
|
||||||
'body' => [
|
'body' => [
|
||||||
'user' => 'user0',
|
'user' => 'user0',
|
||||||
'password' => '123456',
|
'password' => '123456',
|
||||||
'requesttoken' => $this->requestToken,
|
'remember_login' => $remember ? '1' : '0',
|
||||||
],
|
'requesttoken' => $this->requestToken,
|
||||||
'cookies' => $this->cookieJar,
|
],
|
||||||
|
'cookies' => $this->cookieJar,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->extracRequestTokenFromResponse($response);
|
$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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Cookie\CookieJar;
|
||||||
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use GuzzleHttp\Message\ResponseInterface;
|
use GuzzleHttp\Message\ResponseInterface;
|
||||||
|
|
||||||
require __DIR__ . '/../../vendor/autoload.php';
|
require __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
@ -48,7 +51,7 @@ trait BasicStructure {
|
||||||
/** @var ResponseInterface */
|
/** @var ResponseInterface */
|
||||||
private $response = null;
|
private $response = null;
|
||||||
|
|
||||||
/** @var \GuzzleHttp\Cookie\CookieJar */
|
/** @var CookieJar */
|
||||||
private $cookieJar;
|
private $cookieJar;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
|
@ -63,7 +66,7 @@ trait BasicStructure {
|
||||||
$this->localBaseUrl = $this->baseUrl;
|
$this->localBaseUrl = $this->baseUrl;
|
||||||
$this->remoteBaseUrl = $this->baseUrl;
|
$this->remoteBaseUrl = $this->baseUrl;
|
||||||
$this->currentServer = 'LOCAL';
|
$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
|
// in case of ci deployment we take the server url from the environment
|
||||||
$testServerUrl = getenv('TEST_SERVER_URL');
|
$testServerUrl = getenv('TEST_SERVER_URL');
|
||||||
|
@ -174,7 +177,7 @@ trait BasicStructure {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->response = $client->send($client->createRequest($verb, $fullUrl, $options));
|
$this->response = $client->send($client->createRequest($verb, $fullUrl, $options));
|
||||||
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
} catch (ClientException $ex) {
|
||||||
$this->response = $ex->getResponse();
|
$this->response = $ex->getResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +207,7 @@ trait BasicStructure {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->response = $client->send($client->createRequest($verb, $fullUrl, $options));
|
$this->response = $client->send($client->createRequest($verb, $fullUrl, $options));
|
||||||
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
} catch (ClientException $ex) {
|
||||||
$this->response = $ex->getResponse();
|
$this->response = $ex->getResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,7 +301,7 @@ trait BasicStructure {
|
||||||
$request->addHeader('requesttoken', $this->requestToken);
|
$request->addHeader('requesttoken', $this->requestToken);
|
||||||
try {
|
try {
|
||||||
$this->response = $client->send($request);
|
$this->response = $client->send($request);
|
||||||
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
$this->response = $e->getResponse();
|
$this->response = $e->getResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,7 +324,7 @@ trait BasicStructure {
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
$this->response = $client->send($request);
|
$this->response = $client->send($request);
|
||||||
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
$this->response = $e->getResponse();
|
$this->response = $e->getResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue