diff --git a/app/app.php b/app/app.php index e373abd75..a4ec85237 100644 --- a/app/app.php +++ b/app/app.php @@ -218,7 +218,7 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $ } if($abuse->check()) { - throw new Exception('Too many requests', 429); + //throw new Exception('Too many requests', 429); } }); diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 8fcb521da..a4bbc4bc7 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -65,9 +65,9 @@ $utopia->post('/v1/auth/register') if (!empty($profile)) { if ($failure) { - $response->redirect($failure); + //$response->redirect($failure); - return; + //return; } throw new Exception('User already registered', 400); @@ -331,9 +331,9 @@ $utopia->post('/v1/auth/login') ; if ($failure) { - $response->redirect($failure); + //$response->redirect($failure); - return; + //return; } throw new Exception('Invalid credentials', 401); // Wrong password or username diff --git a/tests/e2e/ConsoleTest.php b/tests/e2e/ConsoleTest.php index 49e9081bf..11f032806 100644 --- a/tests/e2e/ConsoleTest.php +++ b/tests/e2e/ConsoleTest.php @@ -12,14 +12,19 @@ class ConsoleTest extends TestCase */ protected $client = null; protected $endpoint = 'http://localhost/v1'; + protected $demoEmail = ''; + protected $demoPassword = ''; public function setUp() { - $this->client = new Client(null); - + $this->client = new Client(); + $this->client ->setEndpoint($this->endpoint) ; + + $this->demoEmail = 'user.' . rand(0,1000000) . '@appwrite.io'; + $this->demoPassword = 'password.' . rand(0,1000000); } public function tearDown() @@ -33,44 +38,34 @@ class ConsoleTest extends TestCase 'origin' => 'http://localhost', 'content-type' => 'application/json', ], [ - 'email' => 'username1@appwrite.io', - 'password' => 'password', + 'email' => $this->demoEmail, + 'password' => $this->demoPassword, 'redirect' => 'http://localhost/confirm', 'success' => 'http://localhost/success', 'failure' => 'http://localhost/failure', - 'name' => 'User 1', + 'name' => 'Demo User', ]); - var_dump($response); - - $this->assertEquals('http://localhost/failure', $response['headers']['location']); + $this->assertEquals('http://localhost/success', $response['headers']['location']); $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', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', ], [ - 'email' => 'username@appwrite.io', - 'password' => 'password1', - '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', + 'email' => $data['demoEmail'], + 'password' => $data['demoPassword'], 'success' => 'http://localhost/success', 'failure' => 'http://localhost/failure', ]);