test: e2e universal token
This commit is contained in:
parent
e41fab769f
commit
0332d35d9e
2 changed files with 88 additions and 0 deletions
|
@ -982,6 +982,66 @@ class AccountCustomClientTest extends Scope
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetAccountSessions
|
||||
* @depends testGetAccountLogs
|
||||
*/
|
||||
public function testExchangeUniversalToken(array $data): array
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_POST, '/users/' . $data['id'] . '/tokens', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]);
|
||||
|
||||
$userId = $response['body']['userId'];
|
||||
$secret = $response['body']['secret'];
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/token', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'userId' => $userId,
|
||||
'secret' => $secret,
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertNotEmpty($response['body']['userId']);
|
||||
$this->assertNotEmpty($response['body']['expire']);
|
||||
$this->assertNotEmpty($response['body']['secret']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
// Invalid userId
|
||||
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/token', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'userId' => ID::custom('ewewe'),
|
||||
'secret' => $secret,
|
||||
]);
|
||||
|
||||
$this->assertEquals(401, $response['headers']['status-code']);
|
||||
|
||||
// Invalid secret
|
||||
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/token', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'userId' => $userId,
|
||||
'secret' => '123456',
|
||||
]);
|
||||
|
||||
$this->assertEquals(401, $response['headers']['status-code']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testUpdatePhone
|
||||
*/
|
||||
|
|
|
@ -229,6 +229,34 @@ trait UsersBase
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateAccount
|
||||
*/
|
||||
public function testCreateUniversalToken(array $data): void
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$token = $this->client->call(Client::METHOD_POST, '/users/' . $data['userId'] . '/tokens', array_merge([
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($token['headers']['status-code'], 201);
|
||||
$this->assertEquals($token['body']['userId'], $data['userId']);
|
||||
$this->assertNotEmpty($token['body']['secret']);
|
||||
$this->assertNotEmpty($token['body']['expire']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$token = $this->client->call(Client::METHOD_POST, '/users/invalid/tokens', array_merge([
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($token['headers']['status-code'], 404);
|
||||
$this->assertEmpty($token['body']['secret']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all optional parameters of createUser (email, phone, anonymous..)
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue