diff --git a/app/controllers/auth.php b/app/controllers/auth.php index a4bbc4bc76..639e4dc2c7 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 . '?message=User already registered'); - //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 @@ -390,7 +390,7 @@ $utopia->delete('/v1/auth/logout') ->label('scope', 'account') ->label('sdk.namespace', 'auth') ->label('sdk.method', 'logout') - ->label('sdk.description', 'Use this endpoint to log out the currently logged in user from his account. When succeed this endpoint will delete the user session and remove the session secret cookie.') + ->label('sdk.description', 'Use this endpoint to log out the currently logged in user from his account. When succeed this endpoint will delete the user session and remove the session secret cookie from the user client.') ->label('abuse-limit', 100) ->action( function () use ($response, $request, $user, $projectDB, $audit, $webhook) { diff --git a/docker-compose.yml b/docker-compose.yml index 82a9ba660a..02ca1956be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,10 +32,7 @@ services: - _APP_INFLUXDB_PORT=8086 - _APP_STATSD_HOST=telegraf - _APP_STATSD_PORT=8125 - #- _APP_CONSOLE_WHITELIST_EMAILS=user1@example.com,user2@example.com - #- _APP_CONSOLE_WHITELIST_IPS=192.1.1.100,192.1.1.101 - #- _APP_CONSOLE_WHITELIST_DOMAINS=appwrite.io,example.com - + mariadb: image: appwrite/mariadb:1.0.0 # fix issues when upgrading using: mysql_upgrade -u root -p restart: unless-stopped diff --git a/tests/e2e/Client.php b/tests/e2e/Client.php index 95d5e74810..ac5e81a98f 100644 --- a/tests/e2e/Client.php +++ b/tests/e2e/Client.php @@ -224,12 +224,29 @@ class Client curl_close($ch); + $responseHeaders['status-code'] = $responseStatus; + return [ 'headers' => $responseHeaders, 'body' => $responseBody ]; } + /** + * Parse Cookie String + * + * @param string $cookie + * @return array + */ + public function parseCookie($cookie) + { + $cookies = []; + + parse_str(strtr($cookie, array('&' => '%26', '+' => '%2B', ';' => '&')), $cookies); + + return $cookies; + } + /** * Flatten params array to PHP multiple format * diff --git a/tests/e2e/ConsoleTest.php b/tests/e2e/ConsoleTest.php index 0da51a8789..8012647232 100644 --- a/tests/e2e/ConsoleTest.php +++ b/tests/e2e/ConsoleTest.php @@ -70,9 +70,37 @@ class ConsoleTest extends TestCase 'failure' => 'http://localhost/failure', ]); - var_dump(); + $session = $this->client->parseCookie($response['headers']['set-cookie'])['a-session-console']; +var_dump($response['headers']); + $this->assertEquals('http://localhost/success', $response['headers']['location']); + $this->assertEquals("\n", $response['body']); + return ['session' => $session]; + } + + /** + * @depends testLoginSuccess + */ + public function testLogoutSuccess($data) + { + $response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a-session-console=' . $data['session'], + ], []); + + var_dump($response); $this->assertEquals('http://localhost/success', $response['headers']['location']); $this->assertEquals("\n", $response['body']); } + + // public function testLogoutFailure() + // { + // $response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // ], []); + + // $this->assertEquals('401', $response['body']['code']); + // } } \ No newline at end of file