Merge branch '1.9.x' into appwrite-embeddings

This commit is contained in:
ArnabChatterjee20k authored and GitHub committed 2026-06-01 12:50:59 +05:30
commit 8ac3dba7cc
17 files changed
+159 -108

No files matched your search

+6 -6
View File
@@ -761,11 +761,11 @@ jobs:
run: |
docker tag ${{ env.IMAGE }}:before ${{ env.IMAGE }}
docker compose up -d --wait --no-build
for attempt in $(seq 1 5); do
if curl -fsS http://localhost/v1/health; then
for attempt in $(seq 1 10); do
if curl -fsS http://localhost/v1/health/version; then
break
fi
if [ "$attempt" -eq 5 ]; then
if [ "$attempt" -eq 10 ]; then
exit 1
fi
sleep 1
@@ -825,11 +825,11 @@ jobs:
run: |
docker tag ${{ env.IMAGE }}:after ${{ env.IMAGE }}
docker compose up -d --wait --no-build
for attempt in $(seq 1 5); do
if curl -fsS http://localhost/v1/health; then
for attempt in $(seq 1 10); do
if curl -fsS http://localhost/v1/health/version; then
break
fi
if [ "$attempt" -eq 5 ]; then
if [ "$attempt" -eq 10 ]; then
exit 1
fi
sleep 1
@@ -117,19 +117,23 @@ class PublicHostname extends Validator
*/
public static function resolve(string $hostname): array
{
$ipv4 = @\gethostbynamel($hostname) ?: [];
$ipv4 = [];
$ipv6 = [];
$records = @\dns_get_record($hostname, DNS_AAAA);
$records = @\dns_get_record($hostname, DNS_A | DNS_AAAA);
if (\is_array($records)) {
foreach ($records as $record) {
if (!empty($record['ip'])) {
$ipv4[] = $record['ip'];
}
if (!empty($record['ipv6'])) {
$ipv6[] = $record['ipv6'];
}
}
}
return \array_values(\array_unique(\array_merge($ipv4, $ipv6)));
return \array_values(\array_unique([...$ipv4, ...$ipv6]));
}
/**
@@ -81,7 +81,7 @@ class Create extends Base
))
->param('functionId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Function ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject'])
->param('name', '', new Text(128), 'Function name. Max length: 128 chars.')
->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', enum: new Enum(name: 'FunctionRuntime'))
->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', enum: new Enum(name: 'Runtime'))
->param('execute', [], new Roles(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 64 characters long.', true)
->param('events', [], new ArrayList(new FunctionEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true)
->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true)
@@ -73,7 +73,7 @@ class Update extends Base
))
->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function ID.', false, ['dbForProject'])
->param('name', '', new Text(128), 'Function name. Max length: 128 chars.')
->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', true, enum: new Enum(name: 'FunctionRuntime'))
->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', true, enum: new Enum(name: 'Runtime'))
->param('execute', [], new Roles(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 64 characters long.', true)
->param('events', [], new ArrayList(new FunctionEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true)
->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true)
@@ -51,7 +51,7 @@ class XList extends Base
)
]
))
->param('runtimes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('runtimes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of runtimes allowed for filtering function templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' runtimes are allowed.', true, enum: new Enum(name: 'FunctionRuntime'))
->param('runtimes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('runtimes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of runtimes allowed for filtering function templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' runtimes are allowed.', true, enum: new Enum(name: 'Runtime'))
->param('useCases', [], new ArrayList(new WhiteList(FunctionUseCases::getAll()), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of use cases allowed for filtering function templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' use cases are allowed.', true, enum: new Enum(name: 'FunctionTemplateUseCase'))
->param('limit', 25, new Range(1, 5000), 'Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000.', true)
->param('offset', 0, new Range(0, 5000), 'Offset the list of returned templates. Maximum offset is 5000.', true)
@@ -298,6 +298,9 @@ class Builds extends Action
$templateRootDirectory = $template->getAttribute('rootDirectory', '');
$templateRootDirectory = \trim($templateRootDirectory, '/');
while (\str_starts_with($templateRootDirectory, './')) {
$templateRootDirectory = \substr($templateRootDirectory, 2);
}
if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) {
throw new \Exception('Invalid template root directory');
}
@@ -423,6 +426,9 @@ class Builds extends Action
$templateRootDirectory = $template->getAttribute('rootDirectory', '');
$templateRootDirectory = \trim($templateRootDirectory, '/');
while (\str_starts_with($templateRootDirectory, './')) {
$templateRootDirectory = \substr($templateRootDirectory, 2);
}
if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) {
throw new \Exception('Invalid template root directory');
}
@@ -59,7 +59,7 @@ class Create extends Action
->param('endpoint', '', new URL(), 'Source Appwrite endpoint')
->param('projectId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Source Project ID', false, ['dbForProject'])
->param('apiKey', '', new Text(512), 'Source API Key')
->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'MigrationOnDuplicate'))
->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'OnDuplicate'))
->inject('response')
->inject('dbForProject')
->inject('project')
@@ -70,7 +70,7 @@ class Create extends Action
->param('fileId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'File ID.', false, ['dbForProject'])
->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.')
->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true)
->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'MigrationOnDuplicate'))
->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'OnDuplicate'))
->inject('response')
->inject('dbForProject')
->inject('dbForPlatform')
@@ -69,7 +69,7 @@ class Create extends Action
->param('fileId', '', new UID(), 'File ID.')
->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.')
->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true)
->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'MigrationOnDuplicate'))
->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'OnDuplicate'))
->inject('response')
->inject('dbForProject')
->inject('dbForPlatform')
@@ -23,6 +23,9 @@ class Get extends Action
public function __construct()
{
$policies = $this->getPolicies();
$policyIds = \array_keys($policies);
$this
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/project/policies/:policyId')
@@ -40,31 +43,11 @@ class Get extends Action
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: [
Response::MODEL_POLICY_PASSWORD_DICTIONARY,
Response::MODEL_POLICY_PASSWORD_HISTORY,
Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA,
Response::MODEL_POLICY_SESSION_ALERT,
Response::MODEL_POLICY_SESSION_DURATION,
Response::MODEL_POLICY_SESSION_INVALIDATION,
Response::MODEL_POLICY_SESSION_LIMIT,
Response::MODEL_POLICY_USER_LIMIT,
Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
],
model: \array_values($policies),
)
]
))
->param('policyId', '', new WhiteList([
'password-dictionary',
'password-history',
'password-personal-data',
'session-alert',
'session-duration',
'session-invalidation',
'session-limit',
'user-limit',
'membership-privacy',
], true), 'Policy ID. Can be one of: password-dictionary, password-history, password-personal-data, session-alert, session-duration, session-invalidation, session-limit, user-limit, membership-privacy.', enum: new Enum(name: 'ProjectPolicyId'))
->param('policyId', '', new WhiteList($policyIds, true), 'Policy ID. Can be one of: ' . \implode(', ', $policyIds) . '.', enum: new Enum(name: 'ProjectPolicyId'))
->inject('response')
->inject('project')
->callback($this->action(...));
@@ -75,9 +58,43 @@ class Get extends Action
Response $response,
Document $project,
): void {
$resolved = $this->resolvePolicy($policyId, $project);
if ($resolved === null) {
throw new \LogicException('Unknown policy ID: ' . $policyId);
}
[$policy, $model] = $resolved;
$response->dynamic($policy, $model);
}
/**
* @return array<string, string>
*/
protected function getPolicies(): array
{
return [
'password-dictionary' => Response::MODEL_POLICY_PASSWORD_DICTIONARY,
'password-history' => Response::MODEL_POLICY_PASSWORD_HISTORY,
'password-personal-data' => Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA,
'session-alert' => Response::MODEL_POLICY_SESSION_ALERT,
'session-duration' => Response::MODEL_POLICY_SESSION_DURATION,
'session-invalidation' => Response::MODEL_POLICY_SESSION_INVALIDATION,
'session-limit' => Response::MODEL_POLICY_SESSION_LIMIT,
'user-limit' => Response::MODEL_POLICY_USER_LIMIT,
'membership-privacy' => Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
];
}
/**
* @return ?array<mixed>
*/
protected function resolvePolicy(string $policyId, Document $project): ?array
{
$auths = $project->getAttribute('auths', []);
[$policy, $model] = match ($policyId) {
return match ($policyId) {
'password-dictionary' => [
new Document([
'$id' => 'password-dictionary',
@@ -145,9 +162,7 @@ class Get extends Action
]),
Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
],
default => throw new \LogicException('Unknown policy ID: ' . $policyId),
default => null,
};
$response->dynamic($policy, $model);
}
}
@@ -71,9 +71,30 @@ class XList extends Action
throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage());
}
$policies = $this->getPolicies($project);
$total = $includeTotal ? \count($policies) : 0;
$grouped = Query::groupByType($queries);
$offset = $grouped['offset'] ?? 0;
$limit = $grouped['limit'] ?? null;
$policies = \array_slice($policies, $offset, $limit);
$response->dynamic(new Document([
'policies' => $policies,
'total' => $total,
]), Response::MODEL_POLICY_LIST);
}
/**
* @return array<Document>
*/
protected function getPolicies(Document $project): array
{
$auths = $project->getAttribute('auths', []);
$policies = [
return [
new Document([
'$id' => 'password-dictionary',
'enabled' => $auths['passwordDictionary'] ?? false,
@@ -115,18 +136,5 @@ class XList extends Action
'userMFA' => $auths['membershipsMfa'] ?? false,
]),
];
$total = $includeTotal ? \count($policies) : 0;
$grouped = Query::groupByType($queries);
$offset = $grouped['offset'] ?? 0;
$limit = $grouped['limit'] ?? null;
$policies = \array_slice($policies, $offset, $limit);
$response->dynamic(new Document([
'policies' => $policies,
'total' => $total,
]), Response::MODEL_POLICY_LIST);
}
}
@@ -68,7 +68,7 @@ class Create extends Action
->param('domain', null, new ValidatorDomain(), 'Domain name.')
->param('url', null, new URL(), 'Target URL of redirection')
->param('statusCode', null, new WhiteList([301, 302, 307, 308]), 'Status code of redirection', enum: new Enum(
name: 'RedirectStatusCode',
name: 'StatusCode',
map: [
'301' => 'MovedPermanently',
'302' => 'Found',
@@ -64,7 +64,7 @@ class Create extends Base
))
->param('siteId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Site ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject'])
->param('name', '', new Text(128), 'Site name. Max length: 128 chars.')
->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'SiteFramework'))
->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'Framework'))
->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true)
->param('logging', true, new Boolean(), 'When disabled, request logs will exclude logs and errors, and site responses will be slightly faster.', true)
->param('timeout', 30, new Range(1, (int) System::getEnv('_APP_SITES_TIMEOUT', 30)), 'Maximum request time in seconds.', true)
@@ -72,8 +72,8 @@ class Create extends Base
->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true)
->param('startCommand', '', new Text(8192, 0), 'Custom start command. Leave empty to use default.', true)
->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true)
->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', enum: new Enum(name: 'SiteBuildRuntime'))
->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'SiteAdapter'))
->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', enum: new Enum(name: 'BuildRuntime'))
->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'Adapter'))
->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true)
->param('fallbackFile', '', new Text(255, 0), 'Fallback file for single page application sites.', true)
->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true)
@@ -68,7 +68,7 @@ class Update extends Base
))
->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site ID.', false, ['dbForProject'])
->param('name', '', new Text(128), 'Site name. Max length: 128 chars.')
->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'SiteFramework'))
->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'Framework'))
->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true)
->param('logging', true, new Boolean(), 'When disabled, request logs will exclude logs and errors, and site responses will be slightly faster.', true)
->param('timeout', 30, new Range(1, (int) System::getEnv('_APP_SITES_TIMEOUT', 30)), 'Maximum request time in seconds.', true)
@@ -76,8 +76,8 @@ class Update extends Base
->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true)
->param('startCommand', '', new Text(8192, 0), 'Custom start command. Leave empty to use default.', true)
->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true)
->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true, enum: new Enum(name: 'SiteBuildRuntime'))
->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'SiteAdapter'))
->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true, enum: new Enum(name: 'BuildRuntime'))
->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'Adapter'))
->param('fallbackFile', '', new Text(255, 0), 'Fallback file for single page application sites.', true)
->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true)
->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true)
@@ -50,7 +50,7 @@ class XList extends Base
)
]
))
->param('frameworks', [], new ArrayList(new WhiteList(\array_keys(Config::getParam('frameworks')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of frameworks allowed for filtering site templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' frameworks are allowed.', true, enum: new Enum(name: 'SiteFramework'))
->param('frameworks', [], new ArrayList(new WhiteList(\array_keys(Config::getParam('frameworks')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of frameworks allowed for filtering site templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' frameworks are allowed.', true, enum: new Enum(name: 'Framework'))
->param('useCases', [], new ArrayList(new WhiteList(SiteUseCases::getAll()), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of use cases allowed for filtering site templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' use cases are allowed.', true, enum: new Enum(name: 'SiteTemplateUseCase'))
->param('limit', 25, new Range(1, 5000), 'Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000.', true)
->param('offset', 0, new Range(0, 5000), 'Offset the list of returned templates. Maximum offset is 5000.', true)
@@ -17,23 +17,31 @@ class PolicyList extends Model
'example' => 9,
])
->addRule('policies', [
'type' => [
Response::MODEL_POLICY_PASSWORD_DICTIONARY,
Response::MODEL_POLICY_PASSWORD_HISTORY,
Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA,
Response::MODEL_POLICY_SESSION_ALERT,
Response::MODEL_POLICY_SESSION_DURATION,
Response::MODEL_POLICY_SESSION_INVALIDATION,
Response::MODEL_POLICY_SESSION_LIMIT,
Response::MODEL_POLICY_USER_LIMIT,
Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
],
'type' => $this->getPolicyModels(),
'description' => 'List of policies.',
'default' => [],
'array' => true,
]);
}
/**
* @return array<string>
*/
protected function getPolicyModels(): array
{
return [
Response::MODEL_POLICY_PASSWORD_DICTIONARY,
Response::MODEL_POLICY_PASSWORD_HISTORY,
Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA,
Response::MODEL_POLICY_SESSION_ALERT,
Response::MODEL_POLICY_SESSION_DURATION,
Response::MODEL_POLICY_SESSION_INVALIDATION,
Response::MODEL_POLICY_SESSION_LIMIT,
Response::MODEL_POLICY_USER_LIMIT,
Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
];
}
public function getName(): string
{
return 'Policies List';
+43 -33
View File
@@ -7,13 +7,12 @@ use Utopia\Database\Query;
trait PoliciesBase
{
// =========================================================================
// Get Policy
// =========================================================================
public function testGetPolicy(): void
/**
* @return array<string, array<string>>
*/
protected function getExpectedPolicies(): array
{
$expectedFields = [
return [
'password-dictionary' => ['enabled'],
'password-history' => ['total'],
'password-personal-data' => ['enabled'],
@@ -24,8 +23,15 @@ trait PoliciesBase
'user-limit' => ['total'],
'membership-privacy' => ['userId', 'userEmail', 'userPhone', 'userName', 'userMFA'],
];
}
foreach ($expectedFields as $policyId => $fields) {
// =========================================================================
// Get Policy
// =========================================================================
public function testGetPolicy(): void
{
foreach ($this->getExpectedPolicies() as $policyId => $fields) {
$response = $this->getPolicy($policyId);
$this->assertSame(200, $response['headers']['status-code']);
@@ -125,25 +131,25 @@ trait PoliciesBase
{
$response = $this->listPolicies();
$expected = $this->getExpectedPolicies();
$this->assertSame(200, $response['headers']['status-code']);
$this->assertArrayHasKey('policies', $response['body']);
$this->assertArrayHasKey('total', $response['body']);
$this->assertIsArray($response['body']['policies']);
$this->assertIsInt($response['body']['total']);
$this->assertSame(9, $response['body']['total']);
$this->assertCount(9, $response['body']['policies']);
// Unpaginated list: total reflects exactly what was returned.
$this->assertSame($response['body']['total'], \count($response['body']['policies']));
// At least the known policies are present; downstream may add more.
$this->assertGreaterThanOrEqual(\count($expected), $response['body']['total']);
$policyIds = \array_column($response['body']['policies'], '$id');
$this->assertContains('password-dictionary', $policyIds);
$this->assertContains('password-history', $policyIds);
$this->assertContains('password-personal-data', $policyIds);
$this->assertContains('session-alert', $policyIds);
$this->assertContains('session-duration', $policyIds);
$this->assertContains('session-invalidation', $policyIds);
$this->assertContains('session-limit', $policyIds);
$this->assertContains('user-limit', $policyIds);
$this->assertContains('membership-privacy', $policyIds);
foreach (\array_keys($expected) as $policyId) {
$this->assertContains($policyId, $policyIds);
}
}
public function testListPoliciesResponseModel(): void
@@ -161,19 +167,13 @@ trait PoliciesBase
$byId[$policy['$id']] = $policy;
}
$this->assertArrayHasKey('enabled', $byId['password-dictionary']);
$this->assertArrayHasKey('total', $byId['password-history']);
$this->assertArrayHasKey('enabled', $byId['password-personal-data']);
$this->assertArrayHasKey('enabled', $byId['session-alert']);
$this->assertArrayHasKey('duration', $byId['session-duration']);
$this->assertArrayHasKey('enabled', $byId['session-invalidation']);
$this->assertArrayHasKey('total', $byId['session-limit']);
$this->assertArrayHasKey('total', $byId['user-limit']);
$this->assertArrayHasKey('userId', $byId['membership-privacy']);
$this->assertArrayHasKey('userEmail', $byId['membership-privacy']);
$this->assertArrayHasKey('userPhone', $byId['membership-privacy']);
$this->assertArrayHasKey('userName', $byId['membership-privacy']);
$this->assertArrayHasKey('userMFA', $byId['membership-privacy']);
foreach ($this->getExpectedPolicies() as $policyId => $fields) {
$this->assertArrayHasKey($policyId, $byId);
foreach ($fields as $field) {
$this->assertArrayHasKey($field, $byId[$policyId]);
}
}
}
public function testListPoliciesReflectsUpdates(): void
@@ -226,7 +226,15 @@ trait PoliciesBase
$this->assertSame(200, $response['headers']['status-code']);
$this->assertSame(0, $response['body']['total']);
$this->assertCount(9, $response['body']['policies']);
// total=false skips the count but still returns every policy; downstream may add more.
$this->assertGreaterThanOrEqual(\count($this->getExpectedPolicies()), \count($response['body']['policies']));
$policyIds = \array_column($response['body']['policies'], '$id');
foreach (\array_keys($this->getExpectedPolicies()) as $policyId) {
$this->assertContains($policyId, $policyIds);
}
}
public function testListPoliciesWithLimit(): void
@@ -237,7 +245,9 @@ trait PoliciesBase
$this->assertSame(200, $response['headers']['status-code']);
$this->assertCount(1, $response['body']['policies']);
$this->assertSame(9, $response['body']['total']);
// limit caps the page, not the total; downstream may add more policies.
$this->assertGreaterThanOrEqual(\count($this->getExpectedPolicies()), $response['body']['total']);
}
public function testListPoliciesWithOffset(): void