1
0
Fork 0
mirror of synced 2024-06-23 08:40:58 +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
$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.
}

View file

@ -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',

View file

@ -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)

View file

@ -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)

View file

@ -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:

View file

@ -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,

View file

@ -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 [];
}
}

View file

@ -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

View file

@ -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;
}
}

View file

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