Skip to content

Commit 76b55d5

Browse files
authored
Merge pull request #11575 from owncloud/tests/unified-roles
[test-only][full-ci] add tests on cli command for listing unified roles
1 parent 7d844d5 commit 76b55d5

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

tests/acceptance/bootstrap/CliContext.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ public function theAdministratorChecksTheBackupConsistencyUsingTheCli(): void {
138138
$this->featureContext->setResponse(CliHelper::runCommand($body));
139139
}
140140

141+
/**
142+
* @When the administrator lists all the unified roles using the CLI
143+
*
144+
* @return void
145+
*/
146+
public function theAdministratorListsAllTheUnifiedRolesUsingTheCli(): void {
147+
$command = "graph list-unified-roles";
148+
$body = [
149+
"command" => $command,
150+
];
151+
$this->featureContext->setResponse(CliHelper::runCommand($body));
152+
}
153+
141154
/**
142155
* @When the administrator creates auth-app token for user :user with expiration time :expirationTime using the auth-app CLI
143156
* @When the administrator tries to create auth-app token for user :user with expiration time :expirationTime using the auth-app CLI
@@ -344,6 +357,62 @@ public function theCommandOutputShouldContain(string $shouldOrNot, string $outpu
344357
}
345358
}
346359

360+
/**
361+
* @Then the command output should include the following roles:
362+
*
363+
* @param TableNode $table
364+
*
365+
* @return void
366+
* @throws Exception
367+
*/
368+
public function theCommandOutputShouldIncludeTheFollowingRoles(TableNode $table): void {
369+
$this->featureContext->verifyTableNodeColumns(
370+
$table,
371+
['LABEL', 'ENABLED', 'DESCRIPTION'],
372+
);
373+
374+
$expectedRoles = $table->getColumnsHash();
375+
$response = $this->featureContext->getResponse();
376+
$decodedResponse = $this->featureContext->getJsonDecodedResponse($response);
377+
378+
// Regex pattern to extract LABEL, ENABLED, and DESCRIPTION
379+
$pattern = '/│\s*\d+\s*│\s*([^\|]+?)\s*│\s*([a-f0-9\-]{36})\s*│\s*(enabled|disabled)\s*│\s*(.*?)\s*│/i';
380+
preg_match_all($pattern, $decodedResponse['message'], $matches, PREG_SET_ORDER);
381+
382+
$actualRoles = [];
383+
foreach ($matches as $match) {
384+
$actualRoles[] = [
385+
'LABEL' => trim($match[1]),
386+
'ENABLED' => trim($match[3]),
387+
'DESCRIPTION' => trim($match[4]),
388+
];
389+
}
390+
391+
// Compare expected roles with actual roles by LABEL and assert equality
392+
foreach ($expectedRoles as $expected) {
393+
$label = $expected['LABEL'];
394+
$actual = null;
395+
foreach ($actualRoles as $role) {
396+
if ($role['LABEL'] === $label) {
397+
$actual = $role;
398+
break;
399+
}
400+
}
401+
402+
Assert::assertNotNull(
403+
$actual,
404+
"Role with LABEL '$label' not found in command output.",
405+
);
406+
407+
Assert::assertEquals(
408+
$expected,
409+
$actual,
410+
"Mismatch for LABEL '$label':\nExpected: " . json_encode($expected) .
411+
"\nActual: " . json_encode($actual),
412+
);
413+
}
414+
}
415+
347416
/**
348417
* @When the administrator lists all the upload sessions
349418
* @When the administrator lists all the upload sessions with flag :flag
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@env-config
2+
Feature: List unified roles
3+
As an administrator
4+
I want to list all available unified roles
5+
So that I can check which roles exist, their permissions, and their status
6+
7+
@issue-11254
8+
Scenario: List unified roles with expected fields
9+
When the administrator lists all the unified roles using the CLI
10+
Then the command should be successful
11+
And the command output should include the following roles:
12+
| LABEL | ENABLED | DESCRIPTION |
13+
| Viewer | enabled | View and download. |
14+
| ViewerListGrants | disabled | View, download and show all invited people. |
15+
| SpaceViewer | enabled | View and download. |
16+
| Editor | enabled | View, download, upload, edit, add and delete. |
17+
| EditorListGrants | disabled | View, download, upload, edit, add, delete and show all invited people. |
18+
| EditorListGrantsWithVersions | disabled | View, download, upload, edit, delete and show all invited people, show all versions. |
19+
| SpaceEditor | enabled | View, download, upload, edit, add, delete including the history. |
20+
| SpaceEditorWithoutVersions | disabled | View, download, upload, edit, add and delete. |
21+
| SpaceEditorWithoutTrashbin | disabled | View, download, upload, edit, add and delete. |
22+
| FileEditor | enabled | View, download and edit. |
23+
| FileEditorListGrants | disabled | View, download, edit and show all invited people. |
24+
| FileEditorListGrantsWithVersions | disabled | View, download, edit and show all invited people, show all versions. |
25+
| EditorLite | enabled | View, download and upload. |
26+
| Manager | enabled | View, download, upload, edit, add, delete and manage members. |
27+
| SecureViewer | disabled | View only documents, images and PDFs. Watermarks will be applied. |
28+
| Denied | disabled | Deny all access. |

0 commit comments

Comments
 (0)