Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] Backport extend assign role test coverage #5744

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/acceptance/features/apiGraph/assignRole.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ Feature: assign role
| Space Admin | 401 |
| User | 401 |
| Guest | 401 |


Scenario Outline: assign role to the user with setting api and list role with graph api
Given user "Alice" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "<userRole>" using the settings api
When the administrator retrieves the assigned role of user "Alice" using the Graph API
Then the HTTP status code should be "200"
And the Graph API response should have the role "<userRole>"
Examples:
| userRole |
| Admin |
| Space Admin |
| User |
| Guest |
42 changes: 28 additions & 14 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1887,20 +1887,7 @@ public function theAdministratorHasGivenTheRoleUsingTheGraphApi(string $role, st
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id') ?? $user;

if (empty($this->appEntity)) {
$applicationEntity = (
$this->featureContext->getJsonDecodedResponse(
GraphHelper::getApplications(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
)
)
)['value'][0];
$this->appEntity["id"] = $applicationEntity["id"];
foreach ($applicationEntity["appRoles"] as $value) {
$this->appEntity["appRoles"][$value['displayName']] = $value['id'];
}
$this->setApplicationEntity();
}

$response = GraphHelper::assignRole(
Expand Down Expand Up @@ -1942,16 +1929,43 @@ public function userRetrievesAssignedRoleUsingTheGraphApi(string $user): void {
);
}

/**
* set application Entity in global variable
*
* @return void
* @throws GuzzleException
*/
public function setApplicationEntity(): void {
$applicationEntity = (
$this->featureContext->getJsonDecodedResponse(
GraphHelper::getApplications(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
)
)
)['value'][0];
$this->appEntity["id"] = $applicationEntity["id"];
foreach ($applicationEntity["appRoles"] as $value) {
$this->appEntity["appRoles"][$value['displayName']] = $value['id'];
}
}

/**
* @Then /^the Graph API response should have the role "([^"]*)"$/
*
* @param string $role
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theGraphApiResponseShouldHaveTheRole(string $role): void {
$response = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['value'][0];
if (empty($this->appEntity)) {
$this->setApplicationEntity();
}
Assert::assertEquals(
$this->appEntity["appRoles"][$role],
$response['appRoleId'],
Expand Down