mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
New tests for API keys
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user