diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index 13bf42fbd..e048a6216 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -20,37 +20,10 @@ trait ProjectCustom 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' => $email, - 'password' => $password, - 'name' => $name, - ]); - - $this->assertEquals(201, $root['headers']['status-code']); - - $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', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', ], [ 'name' => 'Demo Project Team', @@ -63,7 +36,7 @@ trait ProjectCustom $project = $this->client->call(Client::METHOD_POST, '/projects', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', ], [ 'name' => 'Demo Project', @@ -85,7 +58,7 @@ trait ProjectCustom $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$uid'] . '/keys', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', ], [ 'name' => 'Demo Project Key', diff --git a/tests/e2e/Scopes/Scope.php b/tests/e2e/Scopes/Scope.php index 60937da0b..d9b6881cd 100644 --- a/tests/e2e/Scopes/Scope.php +++ b/tests/e2e/Scopes/Scope.php @@ -52,4 +52,104 @@ abstract class Scope extends TestCase * @return array */ abstract public function getProject():array; -} + + /** + * @var array + */ + protected static $root = []; + + /** + * @return array + */ + public function getRoot(): array + { + if((self::$root)) { + return self::$root; + } + + $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' => $email, + 'password' => $password, + 'name' => $name, + ]); + + $this->assertEquals(201, $root['headers']['status-code']); + + $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']; + + self::$root = [ + '$uid' => $root['body']['$uid'], + 'name' => $root['body']['name'], + 'session' => $session, + ]; + + return self::$root; + } + + /** + * @var array + */ + protected static $user = []; + + /** + * @return array + */ + public function getUser(): array + { + if(isset(self::$user[$this->getProject()['$uid']])) { + return self::$user[$this->getProject()['$uid']]; + } + + $email = uniqid().'user@localhost.test'; + $password = 'password'; + $name = 'User Name'; + + $user = $this->client->call(Client::METHOD_POST, '/account', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'email' => $email, + 'password' => $password, + 'name' => $name, + ]); + + $this->assertEquals(201, $user['headers']['status-code']); + + $session = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'email' => $email, + 'password' => $password, + ]); + + $session = $this->client->parseCookie($session['headers']['set-cookie'])['a_session_'.$this->getProject()['$uid']]; + + self::$user[$this->getProject()['$uid']] = [ + '$uid' => $user['body']['$uid'], + 'name' => $user['body']['name'], + 'session' => $session, + ]; + + return self::$user[$this->getProject()['$uid']]; + } +} \ No newline at end of file diff --git a/tests/e2e/Scopes/SideClient.php b/tests/e2e/Scopes/SideClient.php index 2e442ef7a..0a2654d9f 100644 --- a/tests/e2e/Scopes/SideClient.php +++ b/tests/e2e/Scopes/SideClient.php @@ -6,6 +6,9 @@ trait SideClient { public function getHeaders():array { - return []; + return [ + 'origin' => 'http://localhost', + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $this->getUser()['session'], + ]; } } diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 77d60c72b..d0b1973df 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -15,11 +15,11 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_POST, '/account', [ + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => $password, 'name' => $name, @@ -37,11 +37,11 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/account', [ + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => $password, 'name' => $name, @@ -68,11 +68,11 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => $password, ]); @@ -85,33 +85,33 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email.'x', 'password' => $password, ]); $this->assertEquals($response['headers']['status-code'], 401); - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => $password.'x', ]); $this->assertEquals($response['headers']['status-code'], 401); - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => '', 'password' => '', ]); @@ -136,12 +136,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ + $response = $this->client->call(Client::METHOD_GET, '/account', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ])); $this->assertEquals($response['headers']['status-code'], 200); $this->assertNotEmpty($response['body']); @@ -157,16 +157,14 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', + $response = $this->client->call(Client::METHOD_GET, '/account', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', 'content-type' => 'application/json', 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session.'xx', 'x-appwrite-project' => $this->getProject()['$uid'], @@ -187,12 +185,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ + $response = $this->client->call(Client::METHOD_GET, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ])); $this->assertEquals($response['headers']['status-code'], 200); $this->assertIsArray($response['body']); @@ -202,11 +200,11 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ + $response = $this->client->call(Client::METHOD_GET, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); @@ -224,12 +222,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ])); $this->assertEquals($response['headers']['status-code'], 200); $this->assertIsArray($response['body']); @@ -263,11 +261,11 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); @@ -285,12 +283,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/account/logs', [ + $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ])); $this->assertEquals($response['headers']['status-code'], 200); $this->assertIsArray($response['body']); @@ -350,11 +348,11 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/account/logs', [ + $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); @@ -375,12 +373,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/name', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ 'name' => $newName ]); @@ -396,30 +394,30 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/name', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/name', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ ]); $this->assertEquals($response['headers']['status-code'], 400); - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/name', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ 'name' => 'ocSRq1d3QphHivJyUmYY7WMnrxyjdk5YvVwcDqx2zS0coxESN8RmsQwLWw5Whnf0WbVohuFWTRAaoKgCOO0Y0M7LwgFnZmi8881Y7' ]); @@ -442,12 +440,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ 'password' => 'new-password', 'old-password' => $password, ]); @@ -461,11 +459,11 @@ trait AccountBase $this->assertEquals($response['body']['email'], $email); $this->assertEquals($response['body']['name'], 'New Name'); - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => 'new-password', ]); @@ -475,20 +473,20 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); - $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -509,12 +507,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/email', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ 'email' => $newEmail, 'password' => 'new-password', ]); @@ -531,20 +529,20 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/email', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); - $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/email', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ ]); $this->assertEquals($response['headers']['status-code'], 400); @@ -565,12 +563,12 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ]), [ 'prefs' => [ 'key1' => 'value1', 'key2' => 'value2', @@ -587,11 +585,11 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ + $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); @@ -610,11 +608,11 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => $password, ]); @@ -627,27 +625,27 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, 'x-appwrite-project' => $this->getProject()['$uid'], + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, ]); $this->assertEquals($response['headers']['status-code'], 200); - $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionNewUid, [ + $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionNewUid, array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, + ])); $this->assertEquals($response['headers']['status-code'], 204); - $response = $this->client->call(Client::METHOD_GET, '/account', [ + $response = $this->client->call(Client::METHOD_GET, '/account', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ])); $this->assertEquals($response['headers']['status-code'], 200); @@ -657,8 +655,8 @@ trait AccountBase $response = $this->client->call(Client::METHOD_GET, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, 'x-appwrite-project' => $this->getProject()['$uid'], + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $sessionNew, ]); $this->assertEquals($response['headers']['status-code'], 401); @@ -677,11 +675,11 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => $password, ]); @@ -733,24 +731,23 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, + ])); $this->assertEquals($response['headers']['status-code'], 204); /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ + $response = $this->client->call(Client::METHOD_GET, '/account', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', - 'cookie' => 'a_session_'.$this->getProject()['$uid'].'=' . $session, 'x-appwrite-project' => $this->getProject()['$uid'], - ]); + ])); $this->assertEquals($response['headers']['status-code'], 401); @@ -760,11 +757,11 @@ trait AccountBase $email = (isset($data['email'])) ? $data['email'] : ''; $password = (isset($data['password'])) ? $data['password'] : ''; - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'password' => $password, ]); @@ -785,11 +782,11 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'url' => 'http://localhost/recovery', ]); @@ -810,33 +807,33 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'url' => 'localhost/recovery', ]); $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => $email, 'url' => 'http://remotehost/recovery', ]); $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'email' => 'not-found@localhost.test', 'url' => 'http://localhost/recovery', ]); @@ -860,11 +857,11 @@ trait AccountBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'userId' => $uid, 'token' => $recovery, 'password-a' => $newPassowrd, @@ -876,11 +873,11 @@ trait AccountBase /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'userId' => 'ewewe', 'token' => $recovery, 'password-a' => $newPassowrd, @@ -889,11 +886,11 @@ trait AccountBase $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'userId' => $uid, 'token' => 'sdasdasdasd', 'password-a' => $newPassowrd, @@ -902,11 +899,11 @@ trait AccountBase $this->assertEquals(401, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ + $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ + ]), [ 'userId' => $uid, 'token' => $recovery, 'password-a' => $newPassowrd.'x', diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php new file mode 100644 index 000000000..a32111d13 --- /dev/null +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -0,0 +1,196 @@ +client->call(Client::METHOD_POST, '/storage/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'files' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), + 'read' => ['*'], + 'write' => ['*'], + 'folderId' => 'xyz', + ]); + + $this->assertEquals($file['headers']['status-code'], 201); + $this->assertNotEmpty($file['body'][0]['$uid']); + $this->assertEquals('files', $file['body'][0]['$collection']); + $this->assertIsInt($file['body'][0]['dateCreated']); + $this->assertEquals('logo.png', $file['body'][0]['name']); + $this->assertEquals('image/png', $file['body'][0]['mimeType']); + $this->assertEquals(47218, $file['body'][0]['sizeOriginal']); + $this->assertEquals(54944, $file['body'][0]['sizeActual']); + $this->assertEquals('gzip', $file['body'][0]['algorithm']); + $this->assertEquals('1', $file['body'][0]['fileOpenSSLVersion']); + $this->assertEquals('aes-128-gcm', $file['body'][0]['fileOpenSSLCipher']); + $this->assertNotEmpty($file['body'][0]['fileOpenSSLTag']); + $this->assertNotEmpty($file['body'][0]['fileOpenSSLIV']); + + /** + * Test for FAILURE + */ + return ['fileId' => $file['body'][0]['$uid']]; + } + + /** + * @depends testCreateFile + */ + public function testGetFile(array $data):array + { + /** + * Test for SUCCESS + */ + $file1 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals($file1['headers']['status-code'], 200); + $this->assertNotEmpty($file1['body']['$uid']); + $this->assertIsInt($file1['body']['dateCreated']); + $this->assertEquals('logo.png', $file1['body']['name']); + $this->assertEquals('image/png', $file1['body']['mimeType']); + $this->assertEquals(47218, $file1['body']['sizeOriginal']); + //$this->assertEquals(54944, $file1['body']['sizeActual']); + //$this->assertEquals('gzip', $file1['body']['algorithm']); + //$this->assertEquals('1', $file1['body']['fileOpenSSLVersion']); + //$this->assertEquals('aes-128-gcm', $file1['body']['fileOpenSSLCipher']); + //$this->assertNotEmpty($file1['body']['fileOpenSSLTag']); + //$this->assertNotEmpty($file1['body']['fileOpenSSLIV']); + $this->assertIsArray($file1['body']['$permissions']['read']); + $this->assertIsArray($file1['body']['$permissions']['write']); + $this->assertCount(1, $file1['body']['$permissions']['read']); + $this->assertCount(1, $file1['body']['$permissions']['write']); + + $file2 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/preview', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $file2['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $file2['headers']['content-type']); + $this->assertNotEmpty($file2['body']); + + $file3 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/download', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $file3['headers']['status-code']); + $this->assertEquals('attachment; filename="logo.png"', $file3['headers']['content-disposition']); + $this->assertEquals('image/png; charset=UTF-8', $file3['headers']['content-type']); + $this->assertNotEmpty($file3['body']); + + $file4 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/view', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $file4['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $file4['headers']['content-type']); + $this->assertNotEmpty($file4['body']); + + /** + * Test for FAILURE + */ + + return $data; + } + + /** + * @depends testGetFile + */ + public function testListFiles(array $data):array + { + /** + * Test for SUCCESS + */ + $files = $this->client->call(Client::METHOD_GET, '/storage/files', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $files['headers']['status-code']); + $this->assertGreaterThan(0, $files['body']['sum']); + $this->assertGreaterThan(0, count($files['body']['files'])); + + /** + * Test for FAILURE + */ + + return $data; + } + + /** + * @depends testListFiles + */ + public function testUpdateFile(array $data):array + { + /** + * Test for SUCCESS + */ + $file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['fileId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'read' => ['*'], + 'write' => ['*'], + ]); + + $this->assertEquals(200, $file['headers']['status-code']); + $this->assertNotEmpty($file['body']['$uid']); + $this->assertIsInt($file['body']['dateCreated']); + $this->assertEquals('logo.png', $file['body']['name']); + $this->assertEquals('image/png', $file['body']['mimeType']); + $this->assertEquals(47218, $file['body']['sizeOriginal']); + //$this->assertEquals(54944, $file['body']['sizeActual']); + //$this->assertEquals('gzip', $file['body']['algorithm']); + //$this->assertEquals('1', $file['body']['fileOpenSSLVersion']); + //$this->assertEquals('aes-128-gcm', $file['body']['fileOpenSSLCipher']); + //$this->assertNotEmpty($file['body']['fileOpenSSLTag']); + //$this->assertNotEmpty($file['body']['fileOpenSSLIV']); + $this->assertIsArray($file['body']['$permissions']['read']); + $this->assertIsArray($file['body']['$permissions']['write']); + $this->assertCount(1, $file['body']['$permissions']['read']); + $this->assertCount(1, $file['body']['$permissions']['write']); + + /** + * Test for FAILURE + */ + + return $data; + } + + /** + * @depends testUpdateFile + */ + public function testDeleteFile(array $data):array + { + /** + * Test for SUCCESS + */ + $file = $this->client->call(Client::METHOD_DELETE, '/storage/files/' . $data['fileId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(204, $file['headers']['status-code']); + $this->assertEmpty($file['body']); + + /** + * Test for FAILURE + */ + + return $data; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php new file mode 100644 index 000000000..b2c958296 --- /dev/null +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -0,0 +1,14 @@ +client->call(Client::METHOD_POST, '/storage/files', [ 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], ], [ 'files' => new CURLFile(realpath(__DIR__ . '/../resources/logo.png'), 'image/png', 'logo.png'), 'read' => ['*'], @@ -50,10 +49,10 @@ class ProjectStorafeTest extends BaseProjects */ public function testFileReadSuccess(array $data): array { - $file1 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'], [ - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); + $file1 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); $this->assertEquals($file1['headers']['status-code'], 200); $this->assertNotEmpty($file1['body']['$uid']); @@ -72,29 +71,29 @@ class ProjectStorafeTest extends BaseProjects $this->assertCount(1, $file1['body']['$permissions']['read']); $this->assertCount(1, $file1['body']['$permissions']['write']); - $file2 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/preview', [ - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); + $file2 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/preview', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); $this->assertEquals(200, $file2['headers']['status-code']); $this->assertEquals('image/png; charset=UTF-8', $file2['headers']['content-type']); $this->assertNotEmpty($file2['body']); - $file3 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/download', [ - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); + $file3 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/download', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); $this->assertEquals(200, $file3['headers']['status-code']); $this->assertEquals('attachment; filename="logo.png"', $file3['headers']['content-disposition']); $this->assertEquals('image/png; charset=UTF-8', $file3['headers']['content-type']); $this->assertNotEmpty($file3['body']); - $file4 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/view', [ - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); + $file4 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/view', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); $this->assertEquals(200, $file4['headers']['status-code']); $this->assertEquals('image/png; charset=UTF-8', $file4['headers']['content-type']); @@ -108,10 +107,10 @@ class ProjectStorafeTest extends BaseProjects */ public function testFileListSuccess(array $data): array { - $files = $this->client->call(Client::METHOD_GET, '/storage/files', [ - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); + $files = $this->client->call(Client::METHOD_GET, '/storage/files', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); $this->assertEquals(200, $files['headers']['status-code']); $this->assertEquals(1, $files['body']['sum']); @@ -125,10 +124,10 @@ class ProjectStorafeTest extends BaseProjects */ public function testFileUpdateSuccess(array $data): array { - $file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['fileId'], [ - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ], [ + $file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['fileId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ 'read' => ['*'], 'write' => ['*'], ]); @@ -158,10 +157,10 @@ class ProjectStorafeTest extends BaseProjects */ public function testFileDeleteSuccess(array $data): array { - $file = $this->client->call(Client::METHOD_DELETE, '/storage/files/' . $data['fileId'], [ - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); + $file = $this->client->call(Client::METHOD_DELETE, '/storage/files/' . $data['fileId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); $this->assertEquals(204, $file['headers']['status-code']); $this->assertEmpty($file['body']);