diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 8b5c09316a..283c76a34b 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -314,138 +314,138 @@ trait AccountBase return $data; } - // /** - // * @depends testCreateAccountSession - // */ - // public function testGetAccountLogs($data): array - // { - // sleep(10); - // $session = $data['session'] ?? ''; - // $sessionId = $data['sessionId'] ?? ''; - // $userId = $data['id'] ?? ''; - // /** - // * Test for SUCCESS - // */ - // $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, - // ])); + /** + * @depends testCreateAccountSession + */ + public function testGetAccountLogs($data): array + { + sleep(10); + $session = $data['session'] ?? ''; + $sessionId = $data['sessionId'] ?? ''; + $userId = $data['id'] ?? ''; + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); - // $this->assertEquals($response['headers']['status-code'], 200); - // $this->assertIsArray($response['body']['logs']); - // $this->assertNotEmpty($response['body']['logs']); - // $this->assertCount(3, $response['body']['logs']); - // $this->assertIsNumeric($response['body']['total']); - // $this->assertContains($response['body']['logs'][1]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); - // $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); - // $this->assertIsNumeric($response['body']['logs'][1]['time']); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']['logs']); + $this->assertNotEmpty($response['body']['logs']); + $this->assertCount(3, $response['body']['logs']); + $this->assertIsNumeric($response['body']['total']); + $this->assertContains($response['body']['logs'][1]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); + $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); + $this->assertIsNumeric($response['body']['logs'][1]['time']); - // $this->assertEquals('Windows', $response['body']['logs'][1]['osName']); - // $this->assertEquals('WIN', $response['body']['logs'][1]['osCode']); - // $this->assertEquals('10', $response['body']['logs'][1]['osVersion']); + $this->assertEquals('Windows', $response['body']['logs'][1]['osName']); + $this->assertEquals('WIN', $response['body']['logs'][1]['osCode']); + $this->assertEquals('10', $response['body']['logs'][1]['osVersion']); - // $this->assertEquals('browser', $response['body']['logs'][1]['clientType']); - // $this->assertEquals('Chrome', $response['body']['logs'][1]['clientName']); - // $this->assertEquals('CH', $response['body']['logs'][1]['clientCode']); - // $this->assertEquals('70.0', $response['body']['logs'][1]['clientVersion']); - // $this->assertEquals('Blink', $response['body']['logs'][1]['clientEngine']); + $this->assertEquals('browser', $response['body']['logs'][1]['clientType']); + $this->assertEquals('Chrome', $response['body']['logs'][1]['clientName']); + $this->assertEquals('CH', $response['body']['logs'][1]['clientCode']); + $this->assertEquals('70.0', $response['body']['logs'][1]['clientVersion']); + $this->assertEquals('Blink', $response['body']['logs'][1]['clientEngine']); - // $this->assertEquals('desktop', $response['body']['logs'][1]['deviceName']); - // $this->assertEquals('', $response['body']['logs'][1]['deviceBrand']); - // $this->assertEquals('', $response['body']['logs'][1]['deviceModel']); - // $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); + $this->assertEquals('desktop', $response['body']['logs'][1]['deviceName']); + $this->assertEquals('', $response['body']['logs'][1]['deviceBrand']); + $this->assertEquals('', $response['body']['logs'][1]['deviceModel']); + $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); - // $this->assertEquals('--', $response['body']['logs'][1]['countryCode']); - // $this->assertEquals('Unknown', $response['body']['logs'][1]['countryName']); + $this->assertEquals('--', $response['body']['logs'][1]['countryCode']); + $this->assertEquals('Unknown', $response['body']['logs'][1]['countryName']); - // $this->assertContains($response['body']['logs'][2]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); - // $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); - // $this->assertIsNumeric($response['body']['logs'][2]['time']); + $this->assertContains($response['body']['logs'][2]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); + $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); + $this->assertIsNumeric($response['body']['logs'][2]['time']); - // $this->assertEquals('Windows', $response['body']['logs'][2]['osName']); - // $this->assertEquals('WIN', $response['body']['logs'][2]['osCode']); - // $this->assertEquals('10', $response['body']['logs'][2]['osVersion']); + $this->assertEquals('Windows', $response['body']['logs'][2]['osName']); + $this->assertEquals('WIN', $response['body']['logs'][2]['osCode']); + $this->assertEquals('10', $response['body']['logs'][2]['osVersion']); - // $this->assertEquals('browser', $response['body']['logs'][2]['clientType']); - // $this->assertEquals('Chrome', $response['body']['logs'][2]['clientName']); - // $this->assertEquals('CH', $response['body']['logs'][2]['clientCode']); - // $this->assertEquals('70.0', $response['body']['logs'][2]['clientVersion']); - // $this->assertEquals('Blink', $response['body']['logs'][2]['clientEngine']); + $this->assertEquals('browser', $response['body']['logs'][2]['clientType']); + $this->assertEquals('Chrome', $response['body']['logs'][2]['clientName']); + $this->assertEquals('CH', $response['body']['logs'][2]['clientCode']); + $this->assertEquals('70.0', $response['body']['logs'][2]['clientVersion']); + $this->assertEquals('Blink', $response['body']['logs'][2]['clientEngine']); - // $this->assertEquals('desktop', $response['body']['logs'][2]['deviceName']); - // $this->assertEquals('', $response['body']['logs'][2]['deviceBrand']); - // $this->assertEquals('', $response['body']['logs'][2]['deviceModel']); - // $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); + $this->assertEquals('desktop', $response['body']['logs'][2]['deviceName']); + $this->assertEquals('', $response['body']['logs'][2]['deviceBrand']); + $this->assertEquals('', $response['body']['logs'][2]['deviceModel']); + $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); - // $this->assertEquals('--', $response['body']['logs'][2]['countryCode']); - // $this->assertEquals('Unknown', $response['body']['logs'][2]['countryName']); + $this->assertEquals('--', $response['body']['logs'][2]['countryCode']); + $this->assertEquals('Unknown', $response['body']['logs'][2]['countryName']); - // $responseLimit = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, - // ]), [ - // 'limit' => 1 - // ]); + $responseLimit = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'limit' => 1 + ]); - // $this->assertEquals($responseLimit['headers']['status-code'], 200); - // $this->assertIsArray($responseLimit['body']['logs']); - // $this->assertNotEmpty($responseLimit['body']['logs']); - // $this->assertCount(1, $responseLimit['body']['logs']); - // $this->assertIsNumeric($responseLimit['body']['total']); + $this->assertEquals($responseLimit['headers']['status-code'], 200); + $this->assertIsArray($responseLimit['body']['logs']); + $this->assertNotEmpty($responseLimit['body']['logs']); + $this->assertCount(1, $responseLimit['body']['logs']); + $this->assertIsNumeric($responseLimit['body']['total']); - // $this->assertEquals($response['body']['logs'][0], $responseLimit['body']['logs'][0]); + $this->assertEquals($response['body']['logs'][0], $responseLimit['body']['logs'][0]); - // $responseOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, - // ]), [ - // 'offset' => 1 - // ]); + $responseOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'offset' => 1 + ]); - // $this->assertEquals($responseOffset['headers']['status-code'], 200); - // $this->assertIsArray($responseOffset['body']['logs']); - // $this->assertNotEmpty($responseOffset['body']['logs']); - // $this->assertCount(2, $responseOffset['body']['logs']); - // $this->assertIsNumeric($responseOffset['body']['total']); + $this->assertEquals($responseOffset['headers']['status-code'], 200); + $this->assertIsArray($responseOffset['body']['logs']); + $this->assertNotEmpty($responseOffset['body']['logs']); + $this->assertCount(2, $responseOffset['body']['logs']); + $this->assertIsNumeric($responseOffset['body']['total']); - // $this->assertEquals($response['body']['logs'][1], $responseOffset['body']['logs'][0]); + $this->assertEquals($response['body']['logs'][1], $responseOffset['body']['logs'][0]); - // $responseLimitOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, - // ]), [ - // 'limit' => 1, - // 'offset' => 1 - // ]); + $responseLimitOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'limit' => 1, + 'offset' => 1 + ]); - // $this->assertEquals($responseLimitOffset['headers']['status-code'], 200); - // $this->assertIsArray($responseLimitOffset['body']['logs']); - // $this->assertNotEmpty($responseLimitOffset['body']['logs']); - // $this->assertCount(1, $responseLimitOffset['body']['logs']); - // $this->assertIsNumeric($responseLimitOffset['body']['total']); + $this->assertEquals($responseLimitOffset['headers']['status-code'], 200); + $this->assertIsArray($responseLimitOffset['body']['logs']); + $this->assertNotEmpty($responseLimitOffset['body']['logs']); + $this->assertCount(1, $responseLimitOffset['body']['logs']); + $this->assertIsNumeric($responseLimitOffset['body']['total']); - // $this->assertEquals($response['body']['logs'][1], $responseLimitOffset['body']['logs'][0]); - // /** - // * Test for FAILURE - // */ - // $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ])); + $this->assertEquals($response['body']['logs'][1], $responseLimitOffset['body']['logs'][0]); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ])); - // $this->assertEquals($response['headers']['status-code'], 401); + $this->assertEquals($response['headers']['status-code'], 401); - // return $data; - // } + return $data; + } // TODO Add tests for OAuth2 session creation