Add missing tests for JobController, JwtTokenProvider, JwtAuthenticationFilter, and EncryptionService#25
Conversation
…nticationFilter, and EncryptionService Agent-Logs-Url: https://github.com/MaximumTrainer/OpenDataMask/sessions/58805c8b-a639-40f3-94b0-c345d1bedbc3 Co-authored-by: MaximumTrainer <1376575+MaximumTrainer@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds new backend test coverage for previously untested security, crypto, and controller components to improve correctness and prevent regressions.
Changes:
- Introduces unit tests for
JwtTokenProvidertoken generation, parsing, and validation behavior. - Adds unit tests for
JwtAuthenticationFilterto verifySecurityContextbehavior for Bearer/invalid/missing headers. - Adds
@WebMvcTestcoverage forJobControllerendpoints and unit tests forEncryptionServiceAES round-trips and edge cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| backend/src/test/kotlin/com/opendatamask/security/JwtTokenProviderTest.kt | Unit tests around JWT token lifecycle (generate/parse/validate). |
| backend/src/test/kotlin/com/opendatamask/security/JwtAuthenticationFilterTest.kt | Unit tests verifying filter authentication behavior and chain continuation. |
| backend/src/test/kotlin/com/opendatamask/controller/JobControllerTest.kt | MVC slice tests for job listing/details/logs/cancel endpoints. |
| backend/src/test/kotlin/com/opendatamask/config/EncryptionServiceTest.kt | Crypto round-trip + IV uniqueness + edge case tests for encryption/decryption. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @WebMvcTest( | ||
| JobController::class, | ||
| excludeAutoConfiguration = [SecurityAutoConfiguration::class, SecurityFilterAutoConfiguration::class] | ||
| ) | ||
| @ActiveProfiles("test") | ||
| class JobControllerTest { |
There was a problem hiding this comment.
JobController defines a POST /api/workspaces/{workspaceId}/jobs endpoint (createAndRunJob) returning 201, but this test class only covers list/get/logs/cancel. Either add a WebMvc test for the create endpoint (including setting an AuthenticationPrincipal and stubbing userRepository.findByUsername, plus verifying jobService.createJob and jobService.runJob are invoked) or update the PR description/claim about covering all endpoints.
| class EncryptionServiceTest { | ||
|
|
||
| private lateinit var encryptionService: EncryptionService | ||
|
|
||
| @BeforeEach | ||
| fun setup() { | ||
| encryptionService = EncryptionService("0123456789abcdef") | ||
| } |
There was a problem hiding this comment.
These tests may not affect your reported coverage metrics: backend/build.gradle.kts config excludes **/config/** from JaCoCo classDirectories, and EncryptionService lives under com.opendatamask.config. If the goal is to raise coverage for EncryptionService in CI reports, consider removing that exclusion or moving EncryptionService out of the excluded package.
|
@copilot apply changes based on the comments in this thread |
… coverage Agent-Logs-Url: https://github.com/MaximumTrainer/OpenDataMask/sessions/190eb898-bd59-4574-9240-605c65c31c00 Co-authored-by: MaximumTrainer <1376575+MaximumTrainer@users.noreply.github.com>
Done in commit
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Four backend components had zero test coverage:
JobController,JwtTokenProvider,JwtAuthenticationFilter, andEncryptionService.New test files
JobControllerTest—@WebMvcTestcovering all 6 endpoints: list, get (200 + 404), logs, cancel, and create-and-run (POST returning 201). The create endpoint test uses a nested@TestConfiguration @EnableWebSecuritywith a permissiveSecurityFilterChainand@WithMockUserto properly resolve@AuthenticationPrincipal; stubsuserRepository.findByUsername,jobService.createJob, andjobService.runJob, and verifies both service methods are invoked.JwtTokenProviderTest— token generation, subject extraction, and validation against valid/expired/tampered tokensJwtAuthenticationFilterTest— filter behavior for valid ****** (setsSecurityContext), invalid token, missing header, and non-******EncryptionServiceTest— AES-CBC round-trip, random IV uniqueness, and edge cases (empty string, special chars, unicode)All tests follow existing patterns:
@WebMvcTest+excludeAutoConfigurationfor controllers,@ExtendWith(MockitoExtension::class)for unit tests, JUnit 5Assertions.*throughout.Build configuration
build.gradle.ktsJaCoCo exclusions: replaced the blanket**/config/**exclusion with per-class exclusions forSecurityConfig,GlobalExceptionHandler, andStartupSecurityValidator, soEncryptionService(which lives incom.opendatamask.config) is now included in coverage reports.