Updated tests
This commit is contained in:
parent
1ec9e54c5b
commit
6bddbcee10
|
@ -218,7 +218,7 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $
|
||||||
}
|
}
|
||||||
|
|
||||||
if($abuse->check()) {
|
if($abuse->check()) {
|
||||||
throw new Exception('Too many requests', 429);
|
//throw new Exception('Too many requests', 429);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -65,9 +65,9 @@ $utopia->post('/v1/auth/register')
|
||||||
|
|
||||||
if (!empty($profile)) {
|
if (!empty($profile)) {
|
||||||
if ($failure) {
|
if ($failure) {
|
||||||
$response->redirect($failure);
|
//$response->redirect($failure);
|
||||||
|
|
||||||
return;
|
//return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception('User already registered', 400);
|
throw new Exception('User already registered', 400);
|
||||||
|
@ -331,9 +331,9 @@ $utopia->post('/v1/auth/login')
|
||||||
;
|
;
|
||||||
|
|
||||||
if ($failure) {
|
if ($failure) {
|
||||||
$response->redirect($failure);
|
//$response->redirect($failure);
|
||||||
|
|
||||||
return;
|
//return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception('Invalid credentials', 401); // Wrong password or username
|
throw new Exception('Invalid credentials', 401); // Wrong password or username
|
||||||
|
|
|
@ -12,14 +12,19 @@ class ConsoleTest extends TestCase
|
||||||
*/
|
*/
|
||||||
protected $client = null;
|
protected $client = null;
|
||||||
protected $endpoint = 'http://localhost/v1';
|
protected $endpoint = 'http://localhost/v1';
|
||||||
|
protected $demoEmail = '';
|
||||||
|
protected $demoPassword = '';
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->client = new Client(null);
|
$this->client = new Client();
|
||||||
|
|
||||||
$this->client
|
$this->client
|
||||||
->setEndpoint($this->endpoint)
|
->setEndpoint($this->endpoint)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$this->demoEmail = 'user.' . rand(0,1000000) . '@appwrite.io';
|
||||||
|
$this->demoPassword = 'password.' . rand(0,1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
|
@ -33,44 +38,34 @@ class ConsoleTest extends TestCase
|
||||||
'origin' => 'http://localhost',
|
'origin' => 'http://localhost',
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], [
|
], [
|
||||||
'email' => 'username1@appwrite.io',
|
'email' => $this->demoEmail,
|
||||||
'password' => 'password',
|
'password' => $this->demoPassword,
|
||||||
'redirect' => 'http://localhost/confirm',
|
'redirect' => 'http://localhost/confirm',
|
||||||
'success' => 'http://localhost/success',
|
'success' => 'http://localhost/success',
|
||||||
'failure' => 'http://localhost/failure',
|
'failure' => 'http://localhost/failure',
|
||||||
'name' => 'User 1',
|
'name' => 'Demo User',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var_dump($response);
|
$this->assertEquals('http://localhost/success', $response['headers']['location']);
|
||||||
|
|
||||||
$this->assertEquals('http://localhost/failure', $response['headers']['location']);
|
|
||||||
$this->assertEquals("\n", $response['body']);
|
$this->assertEquals("\n", $response['body']);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'demoEmail' => $this->demoEmail,
|
||||||
|
'demoPassword' => $this->demoPassword,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoginFailure()
|
/**
|
||||||
|
* @depends testRegisterSuccess
|
||||||
|
*/
|
||||||
|
public function testLoginSuccess($data)
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/auth/login', [
|
$response = $this->client->call(Client::METHOD_POST, '/auth/login', [
|
||||||
'origin' => 'http://localhost',
|
'origin' => 'http://localhost',
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], [
|
], [
|
||||||
'email' => 'username@appwrite.io',
|
'email' => $data['demoEmail'],
|
||||||
'password' => 'password1',
|
'password' => $data['demoPassword'],
|
||||||
'success' => 'http://localhost/success',
|
|
||||||
'failure' => 'http://localhost/failure',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals('http://localhost/failure', $response['headers']['location']);
|
|
||||||
$this->assertEquals("\n", $response['body']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoginSuccess()
|
|
||||||
{
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/auth/login', [
|
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
], [
|
|
||||||
'email' => 'username@appwrite.io',
|
|
||||||
'password' => 'password',
|
|
||||||
'success' => 'http://localhost/success',
|
'success' => 'http://localhost/success',
|
||||||
'failure' => 'http://localhost/failure',
|
'failure' => 'http://localhost/failure',
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue