From cb94e17183dc23a8ef859752ba7184ce378e404e Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 11 Jul 2020 16:26:04 +0300 Subject: [PATCH] New tests for API keys --- .../Projects/ProjectsConsoleClientTest.php | 182 ++++++++---------- 1 file changed, 75 insertions(+), 107 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 2371fb67d9..6c1a00ffc2 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -589,126 +589,94 @@ class ProjectsConsoleClientTest extends Scope return $data; } - // /** - // * @depends testCreateProjectKey - // */ - // public function testUpdateProjectWebhook($data): array - // { - // $id = (isset($data['projectId'])) ? $data['projectId'] : ''; - // $webhookId = (isset($data['webhookId'])) ? $data['webhookId'] : ''; + /** + * @depends testCreateProjectKey + */ + public function testUpdateProjectKey($data): array + { + $id = (isset($data['projectId'])) ? $data['projectId'] : ''; + $keyId = (isset($data['keyId'])) ? $data['keyId'] : ''; - // $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'name' => 'Webhook Test Update', - // 'events' => ['account.delete', 'account.sessions.delete', 'storage.files.create'], - // 'url' => 'https://appwrite.io/new', - // 'security' => false, - // 'httpUser' => '', - // 'httpPass' => '', - // ]); + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'name' => 'Key Test Update', + 'scopes' => ['users.read', 'users.write', 'collections.read'], + ]); - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertNotEmpty($response['body']['$id']); - // $this->assertEquals($webhookId, $response['body']['$id']); - // $this->assertEquals('Webhook Test Update', $response['body']['name']); - // $this->assertContains('account.delete', $response['body']['events']); - // $this->assertContains('account.sessions.delete', $response['body']['events']); - // $this->assertContains('storage.files.create', $response['body']['events']); - // $this->assertCount(3, $response['body']['events']); - // $this->assertEquals('https://appwrite.io/new', $response['body']['url']); - // $this->assertIsBool($response['body']['security']); - // $this->assertEquals(false, $response['body']['security']); - // $this->assertEquals('', $response['body']['httpUser']); - // // $this->assertEquals('', $response['body']['httpPass']); // TODO add after encrypt refactor + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals($keyId, $response['body']['$id']); + $this->assertEquals('Key Test Update', $response['body']['name']); + $this->assertContains('users.read', $response['body']['scopes']); + $this->assertContains('users.write', $response['body']['scopes']); + $this->assertContains('collections.read', $response['body']['scopes']); + $this->assertCount(3, $response['body']['scopes']); - // $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), []); + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertNotEmpty($response['body']['$id']); - // $this->assertEquals($webhookId, $response['body']['$id']); - // $this->assertEquals('Webhook Test Update', $response['body']['name']); - // $this->assertContains('account.delete', $response['body']['events']); - // $this->assertContains('account.sessions.delete', $response['body']['events']); - // $this->assertContains('storage.files.create', $response['body']['events']); - // $this->assertCount(3, $response['body']['events']); - // $this->assertEquals('https://appwrite.io/new', $response['body']['url']); - // $this->assertIsBool($response['body']['security']); - // $this->assertEquals(false, $response['body']['security']); - // $this->assertEquals('', $response['body']['httpUser']); - // // $this->assertEquals('', $response['body']['httpPass']); // TODO add after encrypt refactor + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals($keyId, $response['body']['$id']); + $this->assertEquals('Key Test Update', $response['body']['name']); + $this->assertContains('users.read', $response['body']['scopes']); + $this->assertContains('users.write', $response['body']['scopes']); + $this->assertContains('collections.read', $response['body']['scopes']); + $this->assertCount(3, $response['body']['scopes']); - // /** - // * Test for FAILURE - // */ - // $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'name' => 'Webhook Test Update', - // 'events' => ['account.delete', 'account.sessions.delete', 'storage.files.create', 'unknown'], - // 'url' => 'https://appwrite.io/new', - // 'security' => false, - // 'httpUser' => '', - // 'httpPass' => '', - // ]); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'name' => 'Key Test Update', + 'scopes' => ['users.read', 'users.write', 'collections.read', 'unknown'], + ]); - // $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); - // $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'name' => 'Webhook Test Update', - // 'events' => ['account.delete', 'account.sessions.delete', 'storage.files.create'], - // 'url' => 'appwrite.io/new', - // 'security' => false, - // 'httpUser' => '', - // 'httpPass' => '', - // ]); + return $data; + } - // $this->assertEquals(400, $response['headers']['status-code']); + /** + * @depends testCreateProjectKey + */ + public function testDeleteProjectKey($data): array + { + $id = (isset($data['projectId'])) ? $data['projectId'] : ''; + $keyId = (isset($data['keyId'])) ? $data['keyId'] : ''; - // return $data; - // } + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); - // /** - // * @depends testCreateProjectKey - // */ - // public function testDeleteProjectWebhook($data): array - // { - // $id = (isset($data['projectId'])) ? $data['projectId'] : ''; - // $webhookId = (isset($data['webhookId'])) ? $data['webhookId'] : ''; + $this->assertEquals(204, $response['headers']['status-code']); + $this->assertEmpty($response['body']); - // $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), []); + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); - // $this->assertEquals(204, $response['headers']['status-code']); - // $this->assertEmpty($response['body']); - - // $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), []); - - // $this->assertEquals(404, $response['headers']['status-code']); + $this->assertEquals(404, $response['headers']['status-code']); - // /** - // * Test for FAILURE - // */ - // $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/webhooks/error', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), []); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/error', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); - // $this->assertEquals(404, $response['headers']['status-code']); + $this->assertEquals(404, $response['headers']['status-code']); - // return $data; - // } + return $data; + } } \ No newline at end of file