Skip to content

Commit

Permalink
Merge pull request #6040 from owncloud/change-user-role
Browse files Browse the repository at this point in the history
[full-ci] [tests-only] Change user role
  • Loading branch information
grgprarup authored May 24, 2023
2 parents 971ba4e + 8d06acf commit 768044c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/acceptance/features/apiGraph/changeRole.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@api
Feature: change role
As an admin
I want to change the role of user
So that I can manage the role of user

Background:
Given user "Alice" has been created with default attributes and without skeleton files


Scenario Outline: admin user changes the role of another user with different roles
Given user "Brian" has been created with default attributes and without skeleton files
And the administrator has assigned the role "Admin" to user "Alice" using the Graph API
And the administrator has assigned the role "<userRole>" to user "Brian" using the Graph API
When user "Alice" changes the role of user "Brian" to role "<newRole>" using the Graph API
Then the HTTP status code should be "201"
And user "Brian" should have the role "<newRole>"
Examples:
| userRole | newRole |
| Admin | Admin |
| Admin | Space Admin |
| Admin | User |
| Admin | Guest |
| Space Admin | Admin |
| Space Admin | Space Admin |
| Space Admin | User |
| Space Admin | Guest |
| User | Admin |
| User | Space Admin |
| User | User |
| User | Guest |
| Guest | Admin |
| Guest | Space Admin |
| Guest | User |
| Guest | Guest |


Scenario Outline: admin user tries to change his/her own role
Given the administrator has assigned the role "Admin" to user "Alice" using the Graph API
When user "Alice" tries to change the role of user "Alice" to role "<newRole>" using the Graph API
Then the HTTP status code should be "403"
And user "Alice" should have the role "Admin"
Examples:
| newRole |
| Space Admin |
| User |
| Guest |
| Admin |
33 changes: 33 additions & 0 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2510,4 +2510,37 @@ public function userShouldNotHaveAnyRoleAssigned(string $user): void {
. "\nExpected user '$user' to have no roles assigned but got '" . json_encode($jsonDecodedResponse) . "'"
);
}

/**
* @When user :user changes the role of user :ofUser to role :role using the Graph API
* @When user :user tries to change the role of user :ofUser to role :role using the Graph API
*
* @param string $user
* @param string $ofUser
* @param string $role
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function userChangesTheRoleOfUserToRoleUsingTheGraphApi(string $user, string $ofUser, string $role): void {
$userId = $this->featureContext->getAttributeOfCreatedUser($ofUser, 'id') ?? $ofUser;
$credentials = $this->getAdminOrUserCredentials($user);
if (empty($this->appEntity)) {
$this->setApplicationEntity();
}

$this->featureContext->setResponse(
GraphHelper::assignRole(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password'],
$this->appEntity["appRoles"][$role],
$this->appEntity["id"],
$userId
)
);
}
}

0 comments on commit 768044c

Please sign in to comment.