From a2f9e7ef990b87012be3e38baab7ee70a2885022 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 11 Jan 2020 23:53:57 +0200 Subject: [PATCH] Updated tests --- app/app.php | 6 +- app/config/roles.php | 12 +- app/controllers/api/account.php | 6 +- app/controllers/api/auth.php | 4 +- docker-compose.yml | 3 +- tests/e2e/AccountBase.php | 154 +++++++++++++------------- tests/e2e/AccountCustomServerTest.php | 30 ++++- tests/e2e/Client.php | 4 + tests/e2e/Scopes/ProjectCustom.php | 47 ++++---- tests/old/AccountTest.php | 2 +- 10 files changed, 153 insertions(+), 115 deletions(-) diff --git a/app/app.php b/app/app.php index a1afaedc1..773af7289 100644 --- a/app/app.php +++ b/app/app.php @@ -120,10 +120,10 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ $scope = $route->getLabel('scope', 'none'); // Allowed scope for chosen route $scopes = $roles[$role]['scopes']; // Allowed scopes for user role - + // Check if given key match project API keys $key = $project->search('secret', $request->getHeader('X-Appwrite-Key', ''), $project->getAttribute('keys', [])); - + /* * Try app auth when we have project key and no user * Mock user to app and grant API key scopes in addition to default app scopes @@ -138,7 +138,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ ]); $role = Auth::USER_ROLE_APP; - $scopes = array_merge($roles[$role]['scopes'], $key->getAttribute('scopes', [])); + $scopes = $key->getAttribute('scopes', []); Authorization::disable(); // Cancel security segmentation for API keys. } diff --git a/app/config/roles.php b/app/config/roles.php index 9ea6b5eed..c30570e36 100644 --- a/app/config/roles.php +++ b/app/config/roles.php @@ -28,6 +28,12 @@ $logged = [ ]; $admins = [ + 'teams.read', + 'teams.write', + 'documents.read', + 'documents.write', + 'files.read', + 'files.write', 'users.read', 'users.write', 'collections.read', @@ -61,15 +67,15 @@ return [ ], ROLE_ADMIN => [ 'label' => 'Admin', - 'scopes' => array_merge($logged, $admins, []), + 'scopes' => array_merge($admins, []), ], ROLE_DEVELOPER => [ 'label' => 'Developer', - 'scopes' => array_merge($logged, $admins, []), + 'scopes' => array_merge($admins, []), ], ROLE_OWNER => [ 'label' => 'Owner', - 'scopes' => array_merge($logged, $admins, []), + 'scopes' => array_merge($admins, []), ], ROLE_APP => [ 'label' => 'Application', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 850b24a1d..4fae49c57 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -392,7 +392,7 @@ $utopia->post('/v1/account/sessions') $utopia->get('/v1/account/sessions/oauth/:provider') ->desc('Create Account Session with OAuth') - ->label('error', __DIR__.'/../views/general/error.phtml') + ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('scope', 'public') ->label('sdk.namespace', 'account') ->label('sdk.method', 'createAccountSessionOAuth') @@ -434,7 +434,7 @@ $utopia->get('/v1/account/sessions/oauth/:provider') $utopia->get('/v1/account/sessions/oauth/callback/:provider/:projectId') ->desc('OAuth Callback') - ->label('error', __DIR__.'/../views/general/error.phtml') + ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('scope', 'public') ->label('abuse-limit', 50) ->label('abuse-key', 'ip:{ip}') @@ -452,7 +452,7 @@ $utopia->get('/v1/account/sessions/oauth/callback/:provider/:projectId') $utopia->get('/v1/account/sessions/oauth/:provider/redirect') ->desc('OAuth Redirect') - ->label('error', __DIR__.'/../views/general/error.phtml') + ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('webhook', 'account.sessions.create') ->label('scope', 'public') ->label('abuse-limit', 50) diff --git a/app/controllers/api/auth.php b/app/controllers/api/auth.php index b303e0181..23704a6c6 100644 --- a/app/controllers/api/auth.php +++ b/app/controllers/api/auth.php @@ -431,7 +431,7 @@ $utopia->get('/v1/auth/login/oauth/:provider') $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId') ->desc('OAuth Callback') - ->label('error', __DIR__.'/../views/general/error.phtml') + ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('scope', 'auth') ->label('abuse-limit', 50) ->label('abuse-key', 'ip:{ip}') @@ -449,7 +449,7 @@ $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId') $utopia->get('/v1/auth/login/oauth/:provider/redirect') ->desc('OAuth Redirect') - ->label('error', __DIR__.'/../views/general/error.phtml') + ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('webhook', 'auth.oauth') ->label('scope', 'auth') ->label('abuse-limit', 50) diff --git a/docker-compose.yml b/docker-compose.yml index 28620ee05..1eb523a09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -118,11 +118,12 @@ services: - RESQUE_WEB_HTTP_BASIC_AUTH_PASSWORD=password maildev: + image: djfarrelly/maildev + restart: unless-stopped ports: - '1080:80' networks: - appwrite - image: djfarrelly/maildev networks: appwrite: diff --git a/tests/e2e/AccountBase.php b/tests/e2e/AccountBase.php index bae6bea2d..aa856dd1d 100644 --- a/tests/e2e/AccountBase.php +++ b/tests/e2e/AccountBase.php @@ -9,7 +9,7 @@ trait AccountBase public function testCreateAccount():array { $email = uniqid().'user@localhost.test'; - $password = 'passwrod'; + $password = 'password'; $name = 'User Name'; /** @@ -18,7 +18,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => $password, @@ -40,7 +40,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => $password, @@ -71,24 +71,24 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => $password, ]); - $sessionUid = $response['body']['$uid']; - $session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - $this->assertEquals($response['headers']['status-code'], 201); + $sessionUid = $response['body']['$uid']; + $session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_'.$this->getProject()['$uid']]; + /** * Test for FAILURE */ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email.'x', 'password' => $password, @@ -99,7 +99,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => $password.'x', @@ -110,7 +110,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => '', 'password' => '', @@ -139,8 +139,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -160,7 +160,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -168,8 +168,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session.'xx', - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session.'xx', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -190,8 +190,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -205,7 +205,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -227,8 +227,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -266,7 +266,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -288,8 +288,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account/logs', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -353,7 +353,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account/logs', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -378,8 +378,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'name' => $newName ]); @@ -399,7 +399,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -407,8 +407,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ ]); @@ -417,8 +417,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'name' => 'ocSRq1d3QphHivJyUmYY7WMnrxyjdk5YvVwcDqx2zS0coxESN8RmsQwLWw5Whnf0WbVohuFWTRAaoKgCOO0Y0M7LwgFnZmi8881Y7' ]); @@ -445,8 +445,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'password' => 'new-password', 'old-password' => $password, @@ -464,7 +464,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => 'new-password', @@ -478,7 +478,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -486,8 +486,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ ]); @@ -512,8 +512,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $newEmail, 'password' => 'new-password', @@ -534,7 +534,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -542,8 +542,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ ]); @@ -568,8 +568,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'prefs' => [ 'key1' => 'value1', @@ -590,7 +590,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -613,22 +613,22 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => $password, ]); $sessionNewUid = $response['body']['$uid']; - $sessionNew = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; + $sessionNew = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_'.$this->getProject()['$uid']]; $this->assertEquals($response['headers']['status-code'], 201); $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -636,8 +636,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionNewUid, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 204); @@ -645,8 +645,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -657,8 +657,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -680,21 +680,21 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => $password, ]); - $sessionNew = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; + $sessionNew = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_'.$this->getProject()['$uid']]; $this->assertEquals($response['headers']['status-code'], 201); $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -702,8 +702,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/current', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 204); @@ -714,8 +714,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -736,8 +736,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 204); @@ -748,8 +748,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + 'x-appwrite-project' => $this->getProject()['$uid'], ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -763,13 +763,13 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'password' => $password, ]); - $data['session'] = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; + $data['session'] = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_'.$this->getProject()['$uid']]; return $data; } @@ -788,7 +788,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'reset' => 'http://localhost/recovery', @@ -813,7 +813,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'reset' => 'localhost/recovery', @@ -824,7 +824,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => $email, 'reset' => 'http://remotehost/recovery', @@ -835,7 +835,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'email' => 'not-found@localhost.test', 'reset' => 'http://localhost/recovery', @@ -863,7 +863,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'userId' => $uid, 'token' => $recovery, @@ -879,7 +879,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'userId' => 'ewewe', 'token' => $recovery, @@ -892,7 +892,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'userId' => $uid, 'token' => 'sdasdasdasd', @@ -905,7 +905,7 @@ trait AccountBase $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'userId' => $uid, 'token' => $recovery, diff --git a/tests/e2e/AccountCustomServerTest.php b/tests/e2e/AccountCustomServerTest.php index 0614d3178..fdb7ccdf4 100644 --- a/tests/e2e/AccountCustomServerTest.php +++ b/tests/e2e/AccountCustomServerTest.php @@ -2,8 +2,36 @@ namespace Tests\E2E; +use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; +use Tests\E2E\Scopes\SideServer; -class AccountServerClientTest extends Scope +class AccountCustomServerTest extends Scope { + use ProjectCustom; + use SideServer; + + public function testCreateAccount():array + { + $email = uniqid().'user@localhost.test'; + $password = 'password'; + $name = 'User Name'; + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_POST, '/account', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'X-Appwrite-Key' => $this->getProject()['apiKey'], + ], [ + 'email' => $email, + 'password' => $password, + 'name' => $name, + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + return []; + } } \ No newline at end of file diff --git a/tests/e2e/Client.php b/tests/e2e/Client.php index 9f4d4bf25..4511f78c9 100644 --- a/tests/e2e/Client.php +++ b/tests/e2e/Client.php @@ -234,6 +234,10 @@ class Client $responseHeaders['status-code'] = $responseStatus; + if($responseStatus === 500) { + echo 'Server error(!): '.json_encode($responseBody)."\n"; + } + return [ 'headers' => $responseHeaders, 'body' => $responseBody diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index 873e1353b..c8c95cea1 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -6,43 +6,46 @@ use Tests\E2E\Client; trait ProjectCustom { - /** - * @var string - */ - protected $rootEmail = ''; - - /** - * @var string - */ - protected $rootPassword = ''; - /** * @var array */ - protected $project = []; + protected static $project = []; /** * @return array */ public function getProject(): array { - if(!empty($this->project)) { - return $this->project; + if(!empty(self::$project)) { + return self::$project; } + $email = uniqid().'user@localhost.test'; + $password = 'password'; + $name = 'User Name'; + $root = $this->client->call(Client::METHOD_POST, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => 'console', ], [ - 'email' => $this->rootEmail, - 'password' => $this->rootEmail, - 'name' => 'Demo User', + 'email' => $email, + 'password' => $password, + 'name' => $name, ]); $this->assertEquals(201, $root['headers']['status-code']); - $session = $this->client->parseCookie($root['headers']['set-cookie'])['a_session_console']; + $session = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], [ + 'email' => $email, + 'password' => $password, + ]); + + $session = $this->client->parseCookie($session['headers']['set-cookie'])['a_session_console']; $team = $this->client->call(Client::METHOD_POST, '/teams', [ 'origin' => 'http://localhost', @@ -87,9 +90,7 @@ trait ProjectCustom ], [ 'name' => 'Demo Project Key', 'scopes' => [ - 'account', - '', - '', + 'files.read', ], ]); @@ -106,14 +107,12 @@ trait ProjectCustom // 'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a_session_' . $project['body']['$uid']], // ]; - $this->project = [ + self::$project = [ '$uid' => $project['body']['$uid'], 'name' => $project['body']['name'], 'apiKey' => $key['body']['secret'], ]; - var_dump('init project'); - - return $this->project; + return self::$project; } } diff --git a/tests/old/AccountTest.php b/tests/old/AccountTest.php index c60026127..f9a16c9be 100644 --- a/tests/old/AccountTest.php +++ b/tests/old/AccountTest.php @@ -19,7 +19,7 @@ class AccountTest extends Base public function testCreateAccount():array { $email = uniqid().'user@localhost.test'; - $password = 'passwrod'; + $password = 'password'; $name = 'User Name'; /**