appwrite/tests/e2e/Services/Teams/TeamsCustomClientTest.php

175 lines
6.6 KiB
PHP
Raw Normal View History

2020-01-16 14:06:28 +00:00
<?php
namespace Tests\E2E\Services\Teams;
2024-07-22 13:37:28 +00:00
use Tests\E2E\Client;
2020-01-16 14:06:28 +00:00
use Tests\E2E\Scopes\ProjectCustom;
2024-03-06 17:34:21 +00:00
use Tests\E2E\Scopes\Scope;
2020-01-16 14:06:28 +00:00
use Tests\E2E\Scopes\SideClient;
use Utopia\Console;
2020-01-16 14:06:28 +00:00
class TeamsCustomClientTest extends Scope
{
use TeamsBase;
use TeamsBaseClient;
use ProjectCustom;
use SideClient;
2024-07-22 13:37:28 +00:00
2024-11-06 15:35:31 +00:00
/**
* @depends testGetTeamMemberships
*/
2024-11-07 10:13:20 +00:00
public function testGetMembershipPrivacy($data)
2024-11-06 15:35:31 +00:00
{
$teamUid = $data['teamUid'] ?? '';
$projectId = $this->getProject()['$id'];
2024-11-06 20:15:31 +00:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/auth/memberships-privacy', array_merge([
2024-11-06 15:35:31 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
2024-11-06 20:15:31 +00:00
'userName' => false,
'userEmail' => false,
'mfa' => false,
2024-11-06 15:35:31 +00:00
]);
$this->assertEquals(200, $response['headers']['status-code']);
/**
* Test that sensitive fields are hidden
*/
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['total']);
$this->assertNotEmpty($response['body']['memberships'][0]['$id']);
// Assert that sensitive fields are not present
$this->assertEmpty($response['body']['memberships'][0]['userName']);
$this->assertEmpty($response['body']['memberships'][0]['userEmail']);
$this->assertFalse($response['body']['memberships'][0]['mfa']);
/**
* Update project settings to show sensitive fields
*/
2024-11-06 20:15:31 +00:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/auth/memberships-privacy', array_merge([
2024-11-06 15:35:31 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
2024-11-06 20:15:31 +00:00
'userName' => true,
'userEmail' => true,
'mfa' => true,
2024-11-06 15:35:31 +00:00
]);
$this->assertEquals(200, $response['headers']['status-code']);
/**
* Test that sensitive fields are shown
*/
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['total']);
$this->assertNotEmpty($response['body']['memberships'][0]['$id']);
// Assert that sensitive fields are present
2024-11-06 16:54:02 +00:00
$this->assertNotEmpty($response['body']['memberships'][0]['userName']);
$this->assertNotEmpty($response['body']['memberships'][0]['userEmail']);
$this->assertArrayHasKey('mfa', $response['body']['memberships'][0]);
2024-11-13 09:45:50 +00:00
/**
* Update project settings to show only MFA
*/
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $this->getProject()['$id'] . '/auth/memberships-privacy', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
'userName' => false,
'userEmail' => false,
'mfa' => true,
]);
$this->assertEquals(200, $response['headers']['status-code']);
/**
* Test that sensitive fields are not shown
*/
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['total']);
$this->assertNotEmpty($response['body']['memberships'][0]['$id']);
// Assert that sensitive fields are present
$this->assertEmpty($response['body']['memberships'][0]['userName']);
$this->assertEmpty($response['body']['memberships'][0]['userEmail']);
$this->assertArrayHasKey('mfa', $response['body']['memberships'][0]);
2024-11-06 15:35:31 +00:00
}
2024-07-22 13:37:28 +00:00
/**
* @depends testUpdateTeamMembership
*/
public function testTeamsInviteHTMLInjection($data): array
{
$teamUid = $data['teamUid'] ?? '';
$email = uniqid() . 'friend@localhost.test';
$name = 'Friend User';
$password = 'password';
// Create a user account before we create a invite so we can check if the user has permissions when it shouldn't
$user = $this->client->call(Client::METHOD_POST, '/account', [
'content-type' => 'application/json',
'x-appwrite-project' => 'console'], [
'userId' => 'unique()',
'email' => $email,
'password' => $password,
'name' => $name,
], false);
$this->assertEquals(201, $user['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'email' => $email,
'name' => $name,
'roles' => ['admin', 'editor'],
'url' => 'http://localhost:5000/join-us\"></a><h1>INJECTED</h1>'
]);
$this->assertEquals(201, $response['headers']['status-code']);
$email = $this->getLastEmail();
2025-03-29 11:49:46 +00:00
Console::log(json_encode([
'testTeamsInviteHTMLInjection' => $email
], JSON_PRETTY_PRINT));
2024-07-22 13:37:28 +00:00
$encoded = 'http://localhost:5000/join-us\&quot;&gt;&lt;/a&gt;&lt;h1&gt;INJECTED&lt;/h1&gt;?';
$this->assertStringNotContainsString('<h1>INJECTED</h1>', $email['html']);
$this->assertStringContainsString($encoded, $email['html']);
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid . '/memberships/'.$response['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(204, $response['headers']['status-code']);
return $data;
}
2022-05-23 14:54:50 +00:00
}