1
0
Fork 0
mirror of synced 2024-09-28 23:41:23 +12:00

Updated tests

This commit is contained in:
Eldad Fux 2020-01-11 23:53:57 +02:00
parent f5f074eb86
commit a2f9e7ef99
10 changed files with 153 additions and 115 deletions

View file

@ -120,10 +120,10 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
$scope = $route->getLabel('scope', 'none'); // Allowed scope for chosen route $scope = $route->getLabel('scope', 'none'); // Allowed scope for chosen route
$scopes = $roles[$role]['scopes']; // Allowed scopes for user role $scopes = $roles[$role]['scopes']; // Allowed scopes for user role
// Check if given key match project API keys // Check if given key match project API keys
$key = $project->search('secret', $request->getHeader('X-Appwrite-Key', ''), $project->getAttribute('keys', [])); $key = $project->search('secret', $request->getHeader('X-Appwrite-Key', ''), $project->getAttribute('keys', []));
/* /*
* Try app auth when we have project key and no user * 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 * 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; $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. Authorization::disable(); // Cancel security segmentation for API keys.
} }

View file

@ -28,6 +28,12 @@ $logged = [
]; ];
$admins = [ $admins = [
'teams.read',
'teams.write',
'documents.read',
'documents.write',
'files.read',
'files.write',
'users.read', 'users.read',
'users.write', 'users.write',
'collections.read', 'collections.read',
@ -61,15 +67,15 @@ return [
], ],
ROLE_ADMIN => [ ROLE_ADMIN => [
'label' => 'Admin', 'label' => 'Admin',
'scopes' => array_merge($logged, $admins, []), 'scopes' => array_merge($admins, []),
], ],
ROLE_DEVELOPER => [ ROLE_DEVELOPER => [
'label' => 'Developer', 'label' => 'Developer',
'scopes' => array_merge($logged, $admins, []), 'scopes' => array_merge($admins, []),
], ],
ROLE_OWNER => [ ROLE_OWNER => [
'label' => 'Owner', 'label' => 'Owner',
'scopes' => array_merge($logged, $admins, []), 'scopes' => array_merge($admins, []),
], ],
ROLE_APP => [ ROLE_APP => [
'label' => 'Application', 'label' => 'Application',

View file

@ -392,7 +392,7 @@ $utopia->post('/v1/account/sessions')
$utopia->get('/v1/account/sessions/oauth/:provider') $utopia->get('/v1/account/sessions/oauth/:provider')
->desc('Create Account Session with OAuth') ->desc('Create Account Session with OAuth')
->label('error', __DIR__.'/../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
->label('sdk.method', 'createAccountSessionOAuth') ->label('sdk.method', 'createAccountSessionOAuth')
@ -434,7 +434,7 @@ $utopia->get('/v1/account/sessions/oauth/:provider')
$utopia->get('/v1/account/sessions/oauth/callback/:provider/:projectId') $utopia->get('/v1/account/sessions/oauth/callback/:provider/:projectId')
->desc('OAuth Callback') ->desc('OAuth Callback')
->label('error', __DIR__.'/../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('scope', 'public') ->label('scope', 'public')
->label('abuse-limit', 50) ->label('abuse-limit', 50)
->label('abuse-key', 'ip:{ip}') ->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') $utopia->get('/v1/account/sessions/oauth/:provider/redirect')
->desc('OAuth Redirect') ->desc('OAuth Redirect')
->label('error', __DIR__.'/../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('webhook', 'account.sessions.create') ->label('webhook', 'account.sessions.create')
->label('scope', 'public') ->label('scope', 'public')
->label('abuse-limit', 50) ->label('abuse-limit', 50)

View file

@ -431,7 +431,7 @@ $utopia->get('/v1/auth/login/oauth/:provider')
$utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId') $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId')
->desc('OAuth Callback') ->desc('OAuth Callback')
->label('error', __DIR__.'/../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('scope', 'auth') ->label('scope', 'auth')
->label('abuse-limit', 50) ->label('abuse-limit', 50)
->label('abuse-key', 'ip:{ip}') ->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') $utopia->get('/v1/auth/login/oauth/:provider/redirect')
->desc('OAuth Redirect') ->desc('OAuth Redirect')
->label('error', __DIR__.'/../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('webhook', 'auth.oauth') ->label('webhook', 'auth.oauth')
->label('scope', 'auth') ->label('scope', 'auth')
->label('abuse-limit', 50) ->label('abuse-limit', 50)

View file

@ -118,11 +118,12 @@ services:
- RESQUE_WEB_HTTP_BASIC_AUTH_PASSWORD=password - RESQUE_WEB_HTTP_BASIC_AUTH_PASSWORD=password
maildev: maildev:
image: djfarrelly/maildev
restart: unless-stopped
ports: ports:
- '1080:80' - '1080:80'
networks: networks:
- appwrite - appwrite
image: djfarrelly/maildev
networks: networks:
appwrite: appwrite:

View file

@ -9,7 +9,7 @@ trait AccountBase
public function testCreateAccount():array public function testCreateAccount():array
{ {
$email = uniqid().'user@localhost.test'; $email = uniqid().'user@localhost.test';
$password = 'passwrod'; $password = 'password';
$name = 'User Name'; $name = 'User Name';
/** /**
@ -18,7 +18,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account', [ $response = $this->client->call(Client::METHOD_POST, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => $password, 'password' => $password,
@ -40,7 +40,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account', [ $response = $this->client->call(Client::METHOD_POST, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => $password, 'password' => $password,
@ -71,24 +71,24 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => $password, 'password' => $password,
]); ]);
$sessionUid = $response['body']['$uid'];
$session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console'];
$this->assertEquals($response['headers']['status-code'], 201); $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 * Test for FAILURE
*/ */
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email.'x', 'email' => $email.'x',
'password' => $password, 'password' => $password,
@ -99,7 +99,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => $password.'x', 'password' => $password.'x',
@ -110,7 +110,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => '', 'email' => '',
'password' => '', 'password' => '',
@ -139,8 +139,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
@ -160,7 +160,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -168,8 +168,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session.'xx', 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session.'xx',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -190,8 +190,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
@ -205,7 +205,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -227,8 +227,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
@ -266,7 +266,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -288,8 +288,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account/logs', [ $response = $this->client->call(Client::METHOD_GET, '/account/logs', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
@ -353,7 +353,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account/logs', [ $response = $this->client->call(Client::METHOD_GET, '/account/logs', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -378,8 +378,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'name' => $newName 'name' => $newName
]); ]);
@ -399,7 +399,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -407,8 +407,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
]); ]);
@ -417,8 +417,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'name' => 'ocSRq1d3QphHivJyUmYY7WMnrxyjdk5YvVwcDqx2zS0coxESN8RmsQwLWw5Whnf0WbVohuFWTRAaoKgCOO0Y0M7LwgFnZmi8881Y7' 'name' => 'ocSRq1d3QphHivJyUmYY7WMnrxyjdk5YvVwcDqx2zS0coxESN8RmsQwLWw5Whnf0WbVohuFWTRAaoKgCOO0Y0M7LwgFnZmi8881Y7'
]); ]);
@ -445,8 +445,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'password' => 'new-password', 'password' => 'new-password',
'old-password' => $password, 'old-password' => $password,
@ -464,7 +464,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => 'new-password', 'password' => 'new-password',
@ -478,7 +478,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -486,8 +486,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
]); ]);
@ -512,8 +512,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $newEmail, 'email' => $newEmail,
'password' => 'new-password', 'password' => 'new-password',
@ -534,7 +534,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -542,8 +542,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
]); ]);
@ -568,8 +568,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'prefs' => [ 'prefs' => [
'key1' => 'value1', 'key1' => 'value1',
@ -590,7 +590,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -613,22 +613,22 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => $password, 'password' => $password,
]); ]);
$sessionNewUid = $response['body']['$uid']; $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); $this->assertEquals($response['headers']['status-code'], 201);
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $sessionNew, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
@ -636,8 +636,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionNewUid, [ $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionNewUid, [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 204); $this->assertEquals($response['headers']['status-code'], 204);
@ -645,8 +645,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
@ -657,8 +657,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $sessionNew, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -680,21 +680,21 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => $password, '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); $this->assertEquals($response['headers']['status-code'], 201);
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $sessionNew, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
@ -702,8 +702,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/current', [ $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/current', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $sessionNew, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 204); $this->assertEquals($response['headers']['status-code'], 204);
@ -714,8 +714,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $sessionNew, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -736,8 +736,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions', [ $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 204); $this->assertEquals($response['headers']['status-code'], 204);
@ -748,8 +748,8 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_GET, '/account', [ $response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session, 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session,
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
]); ]);
$this->assertEquals($response['headers']['status-code'], 401); $this->assertEquals($response['headers']['status-code'], 401);
@ -763,13 +763,13 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'password' => $password, '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; return $data;
} }
@ -788,7 +788,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'reset' => 'http://localhost/recovery', 'reset' => 'http://localhost/recovery',
@ -813,7 +813,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'reset' => 'localhost/recovery', 'reset' => 'localhost/recovery',
@ -824,7 +824,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => $email, 'email' => $email,
'reset' => 'http://remotehost/recovery', 'reset' => 'http://remotehost/recovery',
@ -835,7 +835,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'email' => 'not-found@localhost.test', 'email' => 'not-found@localhost.test',
'reset' => 'http://localhost/recovery', 'reset' => 'http://localhost/recovery',
@ -863,7 +863,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'userId' => $uid, 'userId' => $uid,
'token' => $recovery, 'token' => $recovery,
@ -879,7 +879,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'userId' => 'ewewe', 'userId' => 'ewewe',
'token' => $recovery, 'token' => $recovery,
@ -892,7 +892,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'userId' => $uid, 'userId' => $uid,
'token' => 'sdasdasdasd', 'token' => 'sdasdasdasd',
@ -905,7 +905,7 @@ trait AccountBase
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => $this->getProject()['$uid'],
], [ ], [
'userId' => $uid, 'userId' => $uid,
'token' => $recovery, 'token' => $recovery,

View file

@ -2,8 +2,36 @@
namespace Tests\E2E; namespace Tests\E2E;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope; 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 [];
}
} }

View file

@ -234,6 +234,10 @@ class Client
$responseHeaders['status-code'] = $responseStatus; $responseHeaders['status-code'] = $responseStatus;
if($responseStatus === 500) {
echo 'Server error(!): '.json_encode($responseBody)."\n";
}
return [ return [
'headers' => $responseHeaders, 'headers' => $responseHeaders,
'body' => $responseBody 'body' => $responseBody

View file

@ -6,43 +6,46 @@ use Tests\E2E\Client;
trait ProjectCustom trait ProjectCustom
{ {
/**
* @var string
*/
protected $rootEmail = '';
/**
* @var string
*/
protected $rootPassword = '';
/** /**
* @var array * @var array
*/ */
protected $project = []; protected static $project = [];
/** /**
* @return array * @return array
*/ */
public function getProject(): array public function getProject(): array
{ {
if(!empty($this->project)) { if(!empty(self::$project)) {
return $this->project; return self::$project;
} }
$email = uniqid().'user@localhost.test';
$password = 'password';
$name = 'User Name';
$root = $this->client->call(Client::METHOD_POST, '/account', [ $root = $this->client->call(Client::METHOD_POST, '/account', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => 'console', 'x-appwrite-project' => 'console',
], [ ], [
'email' => $this->rootEmail, 'email' => $email,
'password' => $this->rootEmail, 'password' => $password,
'name' => 'Demo User', 'name' => $name,
]); ]);
$this->assertEquals(201, $root['headers']['status-code']); $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', [ $team = $this->client->call(Client::METHOD_POST, '/teams', [
'origin' => 'http://localhost', 'origin' => 'http://localhost',
@ -87,9 +90,7 @@ trait ProjectCustom
], [ ], [
'name' => 'Demo Project Key', 'name' => 'Demo Project Key',
'scopes' => [ 'scopes' => [
'account', 'files.read',
'',
'',
], ],
]); ]);
@ -106,14 +107,12 @@ trait ProjectCustom
// 'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a_session_' . $project['body']['$uid']], // 'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a_session_' . $project['body']['$uid']],
// ]; // ];
$this->project = [ self::$project = [
'$uid' => $project['body']['$uid'], '$uid' => $project['body']['$uid'],
'name' => $project['body']['name'], 'name' => $project['body']['name'],
'apiKey' => $key['body']['secret'], 'apiKey' => $key['body']['secret'],
]; ];
var_dump('init project'); return self::$project;
return $this->project;
} }
} }

View file

@ -19,7 +19,7 @@ class AccountTest extends Base
public function testCreateAccount():array public function testCreateAccount():array
{ {
$email = uniqid().'user@localhost.test'; $email = uniqid().'user@localhost.test';
$password = 'passwrod'; $password = 'password';
$name = 'User Name'; $name = 'User Name';
/** /**