Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit a1077a4

Browse files
committed
Added missing check in UserAuthorizationService.authenticateUserWithUsernameAndPassword
1 parent 25b1811 commit a1077a4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/main/java/de/filefighter/rest/domain/user/business/UserAuthorizationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public UserAuthorizationService(UserRepository userRepository, UserDtoService us
2929
}
3030

3131
public User authenticateUserWithUsernameAndPassword(String base64encodedUserAndPassword) {
32-
String decodedUsernameAndPassword = "";
32+
String decodedUsernameAndPassword;
3333
try {
3434
byte[] decodedValue = Base64.getDecoder().decode(base64encodedUserAndPassword);
3535
decodedUsernameAndPassword = new String(decodedValue, StandardCharsets.UTF_8);

src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ class UserAuthorizationServiceUnitTest {
2626
void authenticateUserWithUsernameAndPasswordThrows() {
2727
String matchesButIsNotSupportedEncoding = "���"; //funny enough sonar doesnt like this. who cares.
2828
String matchesButUserWasNotFound = "dXNlcjpwYXNzd29yZA==";
29+
String onlyContainsUsername = "dXNlcm5hbWU=";
2930

3031
RuntimeException ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () ->
3132
userAuthorizationService.authenticateUserWithUsernameAndPassword(matchesButIsNotSupportedEncoding));
3233
assertEquals("Request didnt meet formal requirements. Found unsupported character in header.", ex.getMessage());
3334

35+
ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () ->
36+
userAuthorizationService.authenticateUserWithUsernameAndPassword(onlyContainsUsername));
37+
assertEquals("Request didnt meet formal requirements. Credentials didnt meet formal requirements.", ex.getMessage());
38+
3439
when(userRepositoryMock.findByLowercaseUsernameAndPassword("user", "password")).thenReturn(null);
3540

3641
ex = assertThrows(UserNotAuthenticatedException.class, () ->

0 commit comments

Comments
 (0)