Skip to content

Commit 5907d2a

Browse files
committed
Use persona terminology and decouple identity setup from actions
- Rename "role" to "persona" in feature file and step definitions - Replace hardcoded Keycloak usernames with World parameter keys - Add Given step for persona setup, decoupled from When action - Split into "tries to retrieve" (no status check) and "retrieves" (asserts 200) - Add generic "Then the http response code is {int}" step in common - Remove section comments from feature file Issue: ZENKO-5202
1 parent 5e43726 commit 5907d2a

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

tests/ctst/common/common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ Then('the API should {string} with {string}', function (this: Zenko, result: str
427427
}
428428
});
429429

430+
Then('the http response code is {int}', function (this: Zenko, expectedStatus: number) {
431+
const response = this.getSaved<{ statusCode: number }>('lastHttpResponse');
432+
assert.strictEqual(response.statusCode, expectedStatus,
433+
`Expected status ${expectedStatus} but got ${response.statusCode}`);
434+
});
435+
430436
Then('the operation finished without error', function (this: Zenko) {
431437
this.useSavedIdentity();
432438
assert.strictEqual(!!this.getResult().err, false);

tests/ctst/features/reporting/StorageUsageReporting.feature

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@ Feature: Storage Usage Reporting API
22
The storage usage reporting API allows authorized Keycloak users to retrieve
33
aggregated storage usage metrics across all accounts and locations.
44

5-
# Permission tests
65
@2.14.0
76
@PreMerge
87
@StorageUsageReporting
9-
Scenario Outline: Storage usage report access control per role
10-
When the user retrieves the storage usage report as "<role>"
11-
Then the storage usage report http response code is <expectedStatus>
8+
Scenario Outline: Storage usage report access control per persona
9+
Given an identity with the "<persona>" keycloak persona
10+
When the user tries to retrieve the storage usage report
11+
Then the http response code is <expectedStatus>
1212

1313
Examples:
14-
| role | expectedStatus |
15-
| storage_manager | 200 |
16-
| data_consumer | 403 |
14+
| persona | expectedStatus |
15+
| StorageManagerUsername | 200 |
16+
| DataConsumerUsername | 403 |
1717

18-
# Content tests
1918
@2.14.0
2019
@PreMerge
2120
@StorageUsageReporting
2221
Scenario: Storage usage report has a valid structure
23-
When the user retrieves the storage usage report as "storage_manager"
24-
Then the storage usage report http response code is 200
25-
And the storage usage report response has a valid structure
22+
Given an identity with the "StorageManagerUsername" keycloak persona
23+
When the user retrieves the storage usage report
24+
Then the storage usage report response has a valid structure
2625

2726
@2.14.0
2827
@PreMerge
2928
@StorageUsageReporting
3029
Scenario: Storage usage report contains multiple accounts
31-
Given 2 additional accounts
32-
When the user retrieves the storage usage report as "storage_manager"
33-
Then the storage usage report http response code is 200
34-
And the storage usage report contains the additional accounts
30+
Given an identity with the "StorageManagerUsername" keycloak persona
31+
And 2 additional accounts
32+
When the user retrieves the storage usage report
33+
Then the storage usage report contains the additional accounts
3534

3635
@2.14.0
3736
@PreMerge
3837
@StorageUsageReporting
3938
@PrepareStorageUsageReportingScenarios
4039
Scenario Outline: Storage usage report returns accurate metrics
4140
Given the environment is set up with bucket created, test data uploaded, and count-items ran
42-
When the user retrieves the storage usage report as "storage_manager"
43-
Then the storage usage report http response code is 200
44-
And the report contains the test account with location "<locationName>"
41+
And an identity with the "StorageManagerUsername" keycloak persona
42+
When the user retrieves the storage usage report
43+
Then the report contains the test account with location "<locationName>"
4544
And the report shows 3 objects and 600 bytes
4645

4746
Examples:

tests/ctst/steps/reporting/storageUsageReporting.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { When, Then } from '@cucumber/cucumber';
1+
import { Given, When, Then } from '@cucumber/cucumber';
22
import { strict as assert } from 'assert';
33
import Zenko from '../../world/Zenko';
44
import { IdentityEnum } from 'cli-testing';
@@ -14,26 +14,37 @@ interface ReportingUsageResponse {
1414
accounts: Record<string, Record<string, LocationUsage>>;
1515
}
1616

17-
When('the user retrieves the storage usage report as {string}', async function (this: Zenko, role: string) {
18-
const result = await this.managementAPIRequest(
17+
Given('an identity with the {string} keycloak persona', function (this: Zenko, persona: string) {
18+
const username = (this.parameters as Record<string, string>)[persona] || persona;
19+
this.addToSaved('keycloakPersona', username);
20+
});
21+
22+
async function fetchStorageUsageReport(world: Zenko) {
23+
const persona = world.getSaved<string>('keycloakPersona');
24+
const result = await world.managementAPIRequest(
1925
'GET',
20-
`/instance/${this.parameters.InstanceID}/reporting/usage`,
26+
`/instance/${world.parameters.InstanceID}/reporting/usage`,
2127
{},
2228
{},
23-
role,
29+
persona,
2430
);
25-
this.addToSaved('reportingResponse', result);
31+
world.addToSaved('lastHttpResponse', result);
32+
return result;
33+
}
34+
35+
When('the user tries to retrieve the storage usage report', async function (this: Zenko) {
36+
await fetchStorageUsageReport(this);
2637
});
2738

28-
Then('the storage usage report http response code is {int}', function (this: Zenko, expectedStatus: number) {
29-
const response = this.getSaved<{ statusCode: number }>('reportingResponse');
30-
assert.strictEqual(response.statusCode, expectedStatus,
31-
`Expected status ${expectedStatus} but got ${response.statusCode}`);
39+
When('the user retrieves the storage usage report', async function (this: Zenko) {
40+
const result = await fetchStorageUsageReport(this);
41+
assert.strictEqual(result.statusCode, 200,
42+
`Expected status 200 but got ${result.statusCode}`);
3243
});
3344

3445
Then('the storage usage report response has a valid structure', function (this: Zenko) {
3546
const response = this.getSaved<{ statusCode: number; data: ReportingUsageResponse }>(
36-
'reportingResponse');
47+
'lastHttpResponse');
3748
const data = response.data;
3849
assert.strictEqual(typeof data.isTruncated, 'boolean',
3950
'isTruncated should be a boolean');
@@ -45,7 +56,7 @@ Then('the storage usage report response has a valid structure', function (this:
4556

4657
Then('the storage usage report contains the additional accounts', async function (this: Zenko) {
4758
const response = this.getSaved<{ statusCode: number; data: ReportingUsageResponse }>(
48-
'reportingResponse');
59+
'lastHttpResponse');
4960
const accountNames = this.getSavedIdentities()
5061
.filter(id => id.identityType === IdentityEnum.ACCOUNT)
5162
.map(id => id.accountName);
@@ -57,7 +68,7 @@ Then('the storage usage report contains the additional accounts', async function
5768

5869
Then('the report contains the test account with location {string}', async function (this: Zenko, locationName: string) {
5970
const response = this.getSaved<{ statusCode: number; data: ReportingUsageResponse }>(
60-
'reportingResponse');
71+
'lastHttpResponse');
6172
const accountName = this.getSaved<string>('accountName');
6273

6374
assert.ok(accountName in response.data.accounts,

0 commit comments

Comments
 (0)