Api And Auth Management Tests
OpenFrame Documentation
Get the most out of OpenFrame · Book 30 minutes with Conrad, 25 years in IT. He'll show you what Mingo and Fae can take off your list.
OpenFrame Documentation
Api And Auth Management Tests is an end-to-end test slice supplied by the OpenFrame OSS Library through the com.openframe.oss:openframe-test-service-core artifact. It is run by this repository's OpenFrame test service and verifies security-sensitive user-facing workflows against a live tenant: API-key lifecycle management, access-token refresh and logout, password-reset confirmation, and tenant ownership transfer.
The module contains four JUnit 5 test classes. It drives HTTP-facing test APIs, authenticates using real cookie sessions, and validates observable responses, status codes, and persisted state. The tests deliberately create isolated resources and clean them up so that repeated executions leave the tenant usable.
| Area | Test class | Primary assertions |
|---|---|---|
| API-key lifecycle | ApiKeysTest | Creation, read operations, partial update, enablement, regeneration, deletion, and cleanup |
| Session tokens | AuthTokensTest | Refresh behavior and logout invalidation, with and without an explicit tenant identifier |
| Password reset | ResetPasswordTest | Reset-token retrieval, confirmation, authenticated result, and invalid-token rejection |
| User ownership | UserTest | User reads, ownership authorization, ownership handoff and rollback, and deleted-target rejection |
The module tests contracts exposed by the platform rather than reimplementing authentication or authorization logic. Its collaborators include ApiKeyApi, AuthApi, UserApi, InvitationApi, TenantApi, the configured test user, authentication flows, Redis test access, and test data generators.
flowchart LR
Runner["JUnit 5 Test Runner"] --> ApiKeys["API Key Tests"]
Runner --> Tokens["Auth Token Tests"]
Runner --> Reset["Password Reset Tests"]
Runner --> Users["User Ownership Tests"]
ApiKeys --> ApiKeyApi["API Key Test Client"]
Tokens --> AuthApi["Authentication Test Client"]
Tokens --> TenantApi["Tenant Discovery Test Client"]
Reset --> UserApi["User Test Client"]
Reset --> Redis["Reset Token Store"]
Users --> UserApi
Users --> InvitationApi["Invitation Test Client"]
Users --> AuthFlow["Authentication Flow"]
ApiKeyApi --> Platform["OpenFrame Tenant APIs"]
AuthApi --> Platform
TenantApi --> Platform
UserApi --> Platform
InvitationApi --> Platform
AuthFlow --> Platform
The execution surface is the tenant API layer. The suite relies on response DTOs and raw-response methods where it must assert error status codes, while normal paths use typed helpers. Redis is accessed only by the password-reset scenario to obtain the reset token created for the test user.
Api And Auth Management Tests uses ordered JUnit methods when later cases must observe state made by an earlier case:
ApiKeysTest carries one generated API key from creation through mutation, regeneration, and deletion.UserTest records the initial owner, provisions an isolated administrator, optionally transfers ownership away and back, then deletes the temporary account.Precondition helpers use JUnit assumptions to skip dependent cases when their setup state is unavailable, avoiding misleading follow-on failures. Tests that can run independently, including token refresh, logout, and password-reset cases, are not ordered.
Each stateful class provides an AfterAll safeguard:
Ownership transfer is additionally guarded by PipelineContext.hasRegisteredTenant(). The actual handoff and restoration run only for a pipeline-registered tenant because the operation temporarily demotes the suite's owner session.
flowchart TD
Start["Start Ordered Test Class"] --> Setup["Create or Locate Test State"]
Setup --> TestCase["Execute Current Assertion"]
TestCase --> Next{"More Ordered Cases?"}
Next -->|"Yes"| TestCase
Next -->|"No"| Cleanup["Run AfterAll Safeguards"]
Cleanup --> Finish["Leave Tenant in Usable State"]
ApiKeysTest creates an API key with a run-specific name, description, and no initial traffic. It asserts that the returned identifier begins with ak_ and that the one-time disclosed full credential begins with the generated identifier followed by .sk_.
The class then validates the entire lifecycle for that key only:
stateDiagram-v2
[*] --> Created
Created --> Listed
Listed --> Updated
Updated --> Disabled
Disabled --> Enabled
Enabled --> Regenerated
Regenerated --> Deleted
Deleted --> [*]
This sequence protects important key-management invariants: credentials are disclosed only at issuance or regeneration, regeneration invalidates the former identifier, and disabled keys remain manageable and visible to their owner.
AuthTokensTest logs in the configured user through AuthFlow, then exercises refresh and logout through both tenant-aware and tenant-less helper overloads.
For refresh, it asserts that the returned cookie map differs from the original session, installs those cookies using AuthHelper, and confirms that the me response remains authenticated. For logout, it asserts the cookie map equals the known cleared-cookie representation and confirms that attempting refresh with the prior cookies receives HTTP 401.
sequenceDiagram
participant Test as "Auth Token Test"
participant Flow as "Authentication Flow"
participant Auth as "Authentication API"
participant User as "User API"
Test->>Flow: Log in configured user
Flow-->>Test: Session cookies
Test->>Auth: Refresh session cookies
Auth-->>Test: Replacement cookies
Test->>User: Request current user with replacements
User-->>Test: Authenticated response
Test->>Auth: Log out session
Auth-->>Test: Cleared cookies
Test->>Auth: Attempt refresh using old cookies
Auth-->>Test: HTTP 401
ResetPasswordTest starts a password reset for the configured user, retrieves the generated token from the test Redis helper, and submits a generated confirmation request. The test updates the in-memory user's password to the confirmed value and requires the subsequent current-user response to be authenticated.
A negative test submits a confirmation request containing the literal invalid token value and compares the typed error response with the canonical invalid-token response generated by AuthGenerator.
The Redis lookup is an intentional test-only observation point. Production password-reset behavior is still exercised through the user-facing reset and confirmation APIs.
UserTest verifies that listed users have essential populated properties, then checks that fetching a listed user returns the same record. The historical owner-deletion assertion is retained but disabled until the associated deletion behavior is implemented.
The active ownership sequence validates both authorization and lifecycle rules:
OWNER;USER_NOT_FOUND behavior;OWNER and ADMIN respectively;flowchart TD
Owner["Active Tenant Owner"] --> CreateAdmin["Create Temporary Administrator"]
CreateAdmin --> VerifyAdmin["Verify Administrator Cannot Transfer"]
VerifyAdmin --> TransferOut["Owner Transfers Ownership"]
TransferOut --> NewOwner["Temporary User Becomes Owner"]
NewOwner --> FreshLogin["Authenticate as New Owner"]
FreshLogin --> TransferBack["Transfer Ownership Back"]
TransferBack --> DeleteAdmin["Delete Temporary Administrator"]
DeleteAdmin --> RejectDeleted["Reject Deleted Transfer Target"]
The classes use JUnit tags to support targeted runs:
| Tag | Meaning in this module |
|---|---|
oss |
Open-source tenant coverage for API-key, token, and user tests |
api-keys |
API-key management scenario |
users |
User and ownership scenario |
feature |
Primary feature behavior |
read |
Listing and retrieval behavior |
negative |
Error and refusal behavior |
token |
Refresh-token behavior |
logout |
Logout and revoked-session behavior |
reset |
Password-reset behavior |
needs-registered-tenant |
Ownership mutation that only runs in a pipeline-registered tenant |
This module is library code from OpenFrame OSS Library, pinned by this repository at version 7.0.11. The repository assembles and deploys the API, authorization server, gateway, and related services against which the test artifact is run. In the deployment configuration, the gateway forwards /sas/** requests to the authorization server and /api/** requests to the API service; the tests validate behavior across those boundaries through their test API clients.
The module does not expose a production endpoint. It provides acceptance coverage for the platform's API-key management, authenticated-session, password-reset, invitation, and user-management capabilities.
ApiKeysTest and UserTest; changing method order without changing state handling can invalidate later assertions.