This PR addresses critical security concerns around admin API key management and adds comprehensive test coverage for leaderboard functionality and the complete enrollment-to-milestone student journey.
feat: add admin API key rotation and comprehensive test coverage
Security improvements:
- Implement admin API key rotation system with 1-hour transition window
- Add key versioning and rotation history tracking
- Implement 90-day rotation alert for security compliance
- Add key revocation capability
Testing improvements:
- Add comprehensive Leaderboard component unit tests
* Verify top 10 scholars render with correct rank, address, and LRN balance
* Highlight current user in leaderboard
* Test pagination controls
* Verify loading skeleton display
* Test truncated address display
* Verify reputation rank badge coloring (gold/silver/bronze)
- Add complete enrollment-to-milestone E2E test
* Student wallet connection → course enrollment → lesson navigation
* Milestone evidence submission with verification
* Admin approval workflow
* LRN token balance verification
* Leaderboard rank update verification
Database:
- Migration 017: admin_api_keys and admin_key_rotation_history tables
Files added:
- /server/src/db/migrations/017_admin_api_keys.sql
- /server/src/db/migrations/017_admin_api_keys.undo.sql
- /server/src/services/admin-key-rotation.service.ts
- /server/src/controllers/admin-key-rotation.controller.ts
- /server/src/routes/admin-key-rotation.routes.ts
- /src/pages/Leaderboard.test.tsx
- /e2e/enrollment-to-milestone.spec.ts
The admin API key was static with no rotation mechanism, creating a catastrophic single point of failure. A compromised key would grant unlimited access to all critical contract functions (minting, approvals, upgrades).
Implemented a comprehensive key rotation system:
Key Rotation Endpoints:
POST /api/admin/rotate-key- Rotate admin API key with reason trackingGET /api/admin/keys/active- List active API keysGET /api/admin/keys/rotation-status- Check if rotation is needed (90-day alert)POST /api/admin/keys/revoke- Revoke compromised keys immediately
Features:
- 1-hour transition window: Both old and new keys valid during rotation
- Rotation history tracking: Audit trail of all key rotations with timestamps
- 90-day rotation alerts: Automated notifications if key not rotated
- Key versioning: Track multiple generations of keys per admin
- Revocation support: Immediately invalidate compromised keys
Database Schema:
admin_api_keys:
- id (PK)
- admin_address
- key_hash (SHA256)
- key_name
- is_active
- last_rotated_at
- created_at
- revoked_at
- rotation_reason
admin_key_rotation_history:
- id (PK)
- admin_address
- old_key_hash
- new_key_hash
- rotation_reason
- rotated_by
- carried_out_atLeaderboard page had no unit test coverage, risking regressions in ranking display and user experience.
Added comprehensive unit test suite covering:
Test Cases:
- ✅ Top 10 scholars render with correct rank, address, and LRN balance
- ✅ Current user is highlighted with "You" badge when in top 10
- ✅ User's rank displayed in footer
- ✅ LRN balance formatted correctly
- ✅ Addresses truncated appropriately
- ✅ Reputation rank badges show correct tier colors:
- Rank 1: Gold (bg-yellow-500)
- Rank 2: Silver (bg-slate-300)
- Rank 3: Bronze (bg-amber-600)
- Rank 4+: Neutral (bg-white/10)
- ✅ Pagination controls functional
- ✅ Loading skeleton displayed during fetch
- ✅ Completed milestones count shown
File: src/pages/Leaderboard.test.tsx
No E2E test coverage for the critical student learning journey:
- Wallet connection
- Course enrollment
- Lesson/milestone navigation
- Evidence submission
- Admin approval
- Reward verification
- Leaderboard rank update
Added comprehensive E2E spec with two test scenarios:
Scenario 1: Complete Flow (enrollment-to-milestone.spec.ts)
- ✅ Navigate to courses page
- ✅ Connect wallet (Freighter mock)
- ✅ Find and enroll in course
- ✅ View course details and milestones
- ✅ Submit milestone evidence
- ✅ Switch to admin wallet
- ✅ Approve milestone from admin dashboard
- ✅ Verify LRN balance increased (100 tokens per milestone)
- ✅ Verify reputation rank updated in leaderboard
- ✅ Verify "You" badge shows in leaderboard
Scenario 2: Multiple Milestones
- Enroll in course
- Submit multiple consecutive milestone evidences
- Verify all submissions are pending review
Features:
- Full API mocking for enrollment, milestone, and leaderboard endpoints
- Admin wallet switching simulation
- Balance and ranking verification
- Network wait handling for realistic conditions
npm run test -- Leaderboard.test.tsxnpx playwright test e2e/enrollment-to-milestone.spec.tsnpm run test
npx playwright test# Run the new migration
npm run db:migrate
# Verify migration
npm run db:migrate:verify
# To rollback (if needed)
npm run db:migrate:rollback- Research Soroban multi-signature capabilities
- Assess feasibility of requiring 2-of-3 admin threshold for critical operations
- Define admin roles (viewer, approver, admin)
- Implement authorization layer in contracts
- Add key rotation playbook for operations
- Create runbook for key compromise response
- Document key storage best practices
- Add monitoring alerts for rotation overdue
- Milestone approval rejection flow
- Evidence validation and rejection
- Course completion and certification
- LRN burn and token economics
- Peer review process
None. This is a purely additive change with new endpoints and tables.
- Security audit finding: Static admin key with no rotation
- Test coverage gap: Leaderboard functionality
- Unreliable E2E: Student learning journey critical path
- Database migrations created and tested
- Admin key rotation service implemented
- API endpoints documented with OpenAPI
- Unit tests for Leaderboard added
- E2E test for enrollment-to-milestone added
- No breaking changes
- Security review ready