mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
tests: add tests for email injection
This commit is contained in:
@@ -10,11 +10,9 @@ use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
|
||||
trait AccountBase
|
||||
{
|
||||
public function testCreateAccount(): array
|
||||
public function testCreateAccount($name = 'User Name', $password = 'password', $email = null): array
|
||||
{
|
||||
$email = uniqid() . 'user@localhost.test';
|
||||
$password = 'password';
|
||||
$name = 'User Name';
|
||||
$email ??= uniqid() . 'user@localhost.test';
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
@@ -1554,4 +1552,63 @@ trait AccountBase
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testAccountEmailInjections()
|
||||
{
|
||||
$account = $this->testCreateAccount(name: '<html>test</html>');
|
||||
$data = $this->testCreateAccountSession($account);
|
||||
[
|
||||
'session' => $session,
|
||||
'email' => $email
|
||||
] = $data;
|
||||
|
||||
/**
|
||||
* Verification
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/verification', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
||||
|
||||
]), [
|
||||
'url' => 'http://localhost/verification',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$lastEmail = $this->getLastEmail();
|
||||
$this->assertStringNotContainsString('<html>test</html>', $lastEmail['html']);
|
||||
|
||||
/**
|
||||
* Recovery
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'email' => $email,
|
||||
'url' => 'http://localhost/recovery',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$lastEmail = $this->getLastEmail();
|
||||
$this->assertStringNotContainsString('<html>test</html>', $lastEmail['html']);
|
||||
|
||||
/**
|
||||
* Magic URL
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => $account['id'],
|
||||
'email' => $email
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$lastEmail = $this->getLastEmail();
|
||||
$this->assertStringNotContainsString('<html>test</html>', $lastEmail['html']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Tests\E2E\Services\Teams;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Tests\E2E\Services\Teams;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user