Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds a test‐only Pbkdf2PasswordEncoder bean and verifies it in integration tests.
- Define a
PasswordEncoderConfigurationclass to register aPbkdf2PasswordEncoderfor tests - Update the
@CommerceApiTestmeta‐annotation to include the new configuration - Add a new test in
CommerceApiApp_specsto assert thePasswordEncoderbean type
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/test/java/test/commerce/api/PasswordEncoderConfiguration.java | Introduce a test configuration class providing a password encoder bean |
| src/test/java/test/commerce/api/CommerceApiTest.java | Extend the custom test annotation to load the new config |
| src/test/java/test/commerce/CommerceApiApp_specs.java | Add a test to verify the PasswordEncoder bean is available |
Comments suppressed due to low confidence (1)
src/test/java/test/commerce/CommerceApiApp_specs.java:12
- This test uses @SpringBootTest directly against CommerceApiApp, so it won’t load the PasswordEncoderConfiguration. Either switch to @CommerceApiTest or include PasswordEncoderConfiguration in the classes list.
@SpringBootTest(classes = CommerceApiApp.class)
Comment on lines
+3
to
+8
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Primary; | ||
| import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; | ||
|
|
||
| import static org.springframework.security.crypto.password.Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256; | ||
|
|
There was a problem hiding this comment.
The class is not annotated with @configuration or @TestConfiguration, so its @bean method won’t be picked up. Add @TestConfiguration to register the bean in the test context.
Suggested change
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Primary; | |
| import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; | |
| import static org.springframework.security.crypto.password.Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.boot.test.context.TestConfiguration; | |
| import org.springframework.context.annotation.Primary; | |
| import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; | |
| import static org.springframework.security.crypto.password.Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256; | |
| @TestConfiguration |
Comment on lines
10
to
14
|
|
||
| @Bean | ||
| @Primary | ||
| Pbkdf2PasswordEncoder testPasswordEncoder() { | ||
| return new Pbkdf2PasswordEncoder("", 16, 10, PBKDF2WithHmacSHA256); |
There was a problem hiding this comment.
[nitpick] Extract the magic numbers (salt length 16 and iteration count 10) into named constants or add comments to clarify their purpose.
Suggested change
| @Bean | |
| @Primary | |
| Pbkdf2PasswordEncoder testPasswordEncoder() { | |
| return new Pbkdf2PasswordEncoder("", 16, 10, PBKDF2WithHmacSHA256); | |
| private static final int SALT_LENGTH = 16; // Length of the salt in bytes | |
| private static final int ITERATION_COUNT = 10; // Number of hash iterations | |
| @Bean | |
| @Primary | |
| Pbkdf2PasswordEncoder testPasswordEncoder() { | |
| return new Pbkdf2PasswordEncoder("", SALT_LENGTH, ITERATION_COUNT, PBKDF2WithHmacSHA256); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.