Skip to content

Conversation

@JanZachmann
Copy link
Contributor

Summary

Add comprehensive unit tests for AuthorizationService to validate role-based access control logic.

Tests Added (12)

FleetAdministrator Role

  • ✅ Valid tenant succeeds
  • ✅ Invalid tenant fails
  • ✅ Multiple tenants including valid succeeds

FleetOperator Role

  • ✅ Matching fleet succeeds
  • ✅ Non-matching fleet fails
  • ✅ Multiple fleets including match succeeds
  • ✅ Without fleet_list in claims fails
  • ✅ Invalid tenant fails

FleetObserver Role

  • ✅ Valid tenant still fails (role has no access)

Missing Claims

  • ✅ Without tenant_list fails
  • ✅ Without roles fails

Token Verification

  • ✅ Invalid SSO token fails

Implementation Details

  • Uses mockall to mock SingleSignOnProvider and DeviceServiceClient
  • Tests organized in nested modules by role type
  • Helper function create_claims() for test data
  • All edge cases covered per authorization rules

Test Results

cargo test --features mock services::auth::authorization::tests

All 12 tests pass ✅

Impact

  • Total backend tests: 28 → 40 (+12)
  • Coverage: Comprehensive authorization logic validation
  • Phase: 1.1 of backend test plan

Checklist

  • All tests pass
  • Code formatted with cargo fmt
  • Clippy passes
  • BACKEND_TEST_CONCEPT.md updated

Signed-off-by: Jan Zachmann 50990105+JanZachmann@users.noreply.github.com

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
- Implemented auth.spec.ts, device.spec.ts, network.spec.ts
- Added centrifugo fixture helper
- Fixed Centrifugo subscription in App.vue
- Improved test scripts for argument forwarding
- Configured playwright to ignore HTTPS errors
- Added jsonwebtoken for test token generation

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Add comprehensive unit tests for AuthorizationService covering:
- FleetAdministrator role with valid/invalid tenants
- FleetOperator role with matching/non-matching fleets
- FleetObserver role rejection
- Missing claims (roles, tenant_list, fleet_list) handling
- Invalid SSO token verification

Tests use mockall to mock SingleSignOnProvider and DeviceServiceClient.

12 tests added, bringing total backend tests from 28 to 40.

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant