diff --git a/tests/acceptance/TestHelpers/SettingsHelper.php b/tests/acceptance/TestHelpers/SettingsHelper.php index 2d42a6edbbc..f870301c5f1 100644 --- a/tests/acceptance/TestHelpers/SettingsHelper.php +++ b/tests/acceptance/TestHelpers/SettingsHelper.php @@ -224,6 +224,36 @@ class SettingsHelper { ); } + /** + * @param string $baseUrl + * @param string|null $user + * @param string|null $password + * @param string $accountUuid + * @param array $headers + * + * @return ResponseInterface + * + * @throws GuzzleException + * @throws Exception + */ + public static function getPermissionsList( + string $baseUrl, + ?string $user, + ?string $password, + string $accountUuid, + array $headers = [], + ): ResponseInterface { + $fullUrl = self::buildFullUrl($baseUrl, "permissions-list"); + $body = json_encode(["account_uuid" => $accountUuid], JSON_THROW_ON_ERROR); + return HttpRequestHelper::post( + $fullUrl, + $user, + $password, + $headers, + $body, + ); + } + /** * @param string $baseUrl * @param string|null $user diff --git a/tests/acceptance/bootstrap/VaultContext.php b/tests/acceptance/bootstrap/VaultContext.php index d17df97364b..d2aefeb55a6 100644 --- a/tests/acceptance/bootstrap/VaultContext.php +++ b/tests/acceptance/bootstrap/VaultContext.php @@ -26,8 +26,12 @@ use Behat\Behat\Context\Context; use Behat\Behat\Hook\Scope\BeforeScenarioScope; use GuzzleHttp\Exception\GuzzleException; use PHPUnit\Framework\Assert; +use Psr\Http\Message\ResponseInterface; use TestHelpers\BehatHelper; +use TestHelpers\GraphHelper; +use TestHelpers\HttpRequestHelper; use TestHelpers\KeycloakHelper; +use TestHelpers\SettingsHelper; require_once 'bootstrap.php'; @@ -120,4 +124,79 @@ class VaultContext implements Context { "Expected acr value to be $acr but got $actualAcr", ); } + + /** + * @param string $user + * + * @return ResponseInterface + * @throws GuzzleException + */ + private function getPermissionsList(string $user): ResponseInterface { + $password = $this->featureContext->getPasswordForUser($user); + $headers = []; + $authUser = $user; + if (KeycloakHelper::isTestingWithKeycloak()) { + $this->authenticateKeycloakUserIfNeeded($user); + $accessToken = $this->featureContext->getOcisUserToken($user)['token']['accessToken']; + $headers['Authorization'] = 'Bearer ' . $accessToken; + $authUser = null; + $password = null; + } + $userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id'); + return SettingsHelper::getPermissionsList( + $this->featureContext->getBaseUrl(), + $authUser, + $password, + $userId, + $headers, + ); + } + + /** + * Authenticates a Keycloak-backed user directly via the OIDC token endpoint (no browser, + * no MFA/vault-mode UI setup) so that the user's oCIS account (and id) is provisioned even + * for roles that don't have vault UI elements to interact with, e.g. User Light. + * + * @param string $user + * + * @return void + * @throws GuzzleException + * @throws JsonException + */ + private function authenticateKeycloakUserIfNeeded(string $user): void { + if ($this->featureContext->getAttributeOfCreatedUser($user, 'id')) { + return; + } + $userAttribute = $this->featureContext->getCreatedKeycloakUsers()[strtolower($user)]; + $tokenData = KeycloakHelper::setAccessTokenForKeycloakOcisUser($userAttribute); + $this->featureContext->setOcisUserToken($userAttribute, $tokenData); + + $response = HttpRequestHelper::get( + GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'me'), + null, + null, + ['Authorization' => 'Bearer ' . $tokenData['access_token']], + ); + $userAttribute['id'] = $this->featureContext->getJsonDecodedResponse($response)['id']; + $this->featureContext->addUserToCreatedUsersList( + $user, + $userAttribute['password'], + $userAttribute['displayName'], + $userAttribute['email'], + $userAttribute['id'], + ); + } + + /** + * @When /^user "([^"]*)" gets the permissions list using the settings API$/ + * + * @param string $user + * + * @return void + * @throws GuzzleException + * @throws JsonException + */ + public function userGetsPermissionsList(string $user): void { + $this->featureContext->setResponse($this->getPermissionsList($user)); + } } diff --git a/tests/acceptance/features/apiVault/vault.feature b/tests/acceptance/features/apiVault/vault.feature index 5c468556dc5..ad60348f956 100644 --- a/tests/acceptance/features/apiVault/vault.feature +++ b/tests/acceptance/features/apiVault/vault.feature @@ -1130,3 +1130,59 @@ Feature: vault | permissions-role | | Viewer | | File Editor | + + + Scenario Outline: users with role Admin, Space Admin or User should have access to vault + Given the administrator has assigned the role "" to user "Alice" using the Graph API + When user "Alice" gets the permissions list using the settings API + Then the HTTP status code should be "201" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["permissions"], + "properties": { + "permissions": { + "type": "array", + "minItems": , + "maxItems": , + "uniqueItems": true, + "contains": { + "const": "VaultMode.ReadWriteEnabled.own" + } + } + } + } + """ + Examples: + | user-role | permission-count | + | Admin | 33 | + | Space Admin | 27 | + | User | 20 | + + + Scenario: user with role User Light should not have access to vault + Given the administrator has assigned the role "User Light" to user "Alice" using the Graph API + When user "Alice" gets the permissions list using the settings API + Then the HTTP status code should be "201" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["permissions"], + "properties": { + "permissions": { + "type": "array", + "minItems": 13, + "maxItems": 13, + "uniqueItems": true, + "not": { + "contains": { + "const": "VaultMode.ReadWriteEnabled.own" + } + } + } + } + } + """ +