229 lines
No EOL
8.3 KiB
PHP
229 lines
No EOL
8.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\E2E\Services\Account;
|
|
|
|
use Tests\E2E\Client;
|
|
use Tests\E2E\Scopes\Scope;
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
use Tests\E2E\Scopes\SideClient;
|
|
|
|
class AccountCustomClientTest extends Scope
|
|
{
|
|
use AccountBase;
|
|
use ProjectCustom;
|
|
use SideClient;
|
|
|
|
public function testCreateOAuth2AccountSession():array
|
|
{
|
|
$provider = 'mock';
|
|
$appId = '1';
|
|
$secret = '123456';
|
|
|
|
/**
|
|
* Test for SUCCESS
|
|
*/
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$this->getProject()['$id'].'/oauth2', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => 'console',
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
]), [
|
|
'provider' => $provider,
|
|
'appId' => $appId,
|
|
'secret' => $secret,
|
|
]);
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
]), [
|
|
'success' => 'http://localhost/v1/mock/tests/general/oauth2/success',
|
|
'failure' => 'http://localhost/v1/mock/tests/general/oauth2/failure',
|
|
]);
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
$this->assertEquals('success', $response['body']['result']);
|
|
|
|
return [];
|
|
}
|
|
|
|
public function testBlockedAccount():array
|
|
{
|
|
$email = uniqid().'user@localhost.test';
|
|
$password = 'password';
|
|
$name = 'User Name (blocked)';
|
|
|
|
/**
|
|
* Test for SUCCESS
|
|
*/
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
]), [
|
|
'email' => $email,
|
|
'password' => $password,
|
|
'name' => $name,
|
|
]);
|
|
|
|
$id = $response['body']['$id'];
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
]), [
|
|
'email' => $email,
|
|
'password' => $password,
|
|
]);
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
$sessionId = $response['body']['$id'];
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', 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);
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/users/' . $id . '/status', [
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
], [
|
|
'status' => 2,
|
|
]);
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', 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'], 401);
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
]), [
|
|
'email' => $email,
|
|
'password' => $password,
|
|
]);
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
return [];
|
|
}
|
|
|
|
public function testCreateJWT():array
|
|
{
|
|
$email = uniqid().'user@localhost.test';
|
|
$password = 'password';
|
|
$name = 'User Name (JWT)';
|
|
|
|
/**
|
|
* Test for SUCCESS
|
|
*/
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
]), [
|
|
'email' => $email,
|
|
'password' => $password,
|
|
'name' => $name,
|
|
]);
|
|
|
|
$id = $response['body']['$id'];
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
]), [
|
|
'email' => $email,
|
|
'password' => $password,
|
|
]);
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
$sessionId = $response['body']['$id'];
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', 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);
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/jwt', 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'], 201);
|
|
$this->assertNotEmpty($response['body']['jwt']);
|
|
$this->assertIsString($response['body']['jwt']);
|
|
|
|
$jwt = $response['body']['jwt'];
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
'x-appwrite-jwt' => 'wrong-token',
|
|
]));
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
'x-appwrite-jwt' => $jwt,
|
|
]));
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionId, 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'], 204);
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
'origin' => 'http://localhost',
|
|
'content-type' => 'application/json',
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
'x-appwrite-jwt' => $jwt,
|
|
]));
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
return [];
|
|
}
|
|
} |