Skip to content

Commit

Permalink
Merge pull request #5 from ids-basecamp/fix/multiple-auth-header
Browse files Browse the repository at this point in the history
bugfix: disallow multiple auth headers
  • Loading branch information
augustocmleal authored Apr 3, 2024
2 parents 5809490 + 23e26e2 commit 8b985cd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public boolean isAuthenticated(Map<String, List<String>> headers) {
}

private boolean checkApiKeyValid(List<String> apiKeys) {
return apiKeys.stream().anyMatch(hardCodedApiKey::equalsIgnoreCase);
return apiKeys.size() == 1 && apiKeys.stream().allMatch(hardCodedApiKey::equalsIgnoreCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void isAuthorized_notAuthorized() {
}

@Test
void isAuthorized_multipleValues_oneAuthorized() {
void isAuthorized_multipleValues_oneAuthorized_shouldReturnFalse(){
var map = Map.of("x-api-key", List.of("invalid_api_key", TEST_API_KEY));
assertThat(service.isAuthenticated(map)).isTrue();
assertThat(service.isAuthenticated(map)).isFalse();
}
}

0 comments on commit 8b985cd

Please sign in to comment.