[tests-only] test: add test cases for vault user access (#12860)

test: add test cases for vault user access
This commit is contained in:
isha authored and GitHub committed 2026-09-04 12:00:32 +05:45
1 parent d2f5c3316e
commit f92f0af3bb
3 files changed
+165

No files matched your search

@@ -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
@@ -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));
}
}
@@ -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 "<user-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": <permission-count>,
"maxItems": <permission-count>,
"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"
}
}
}
}
}
"""