-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fix exception from empty basic auth header token #8109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @zeeshanadnan! I have left one comment inline.
In addition please add a test to BasicAuthenticationFilterTests
.
This can be very similar to the existing test invalidBase64IsIgnored
.
...a/org/springframework/security/web/authentication/www/BasicAuthenticationConverterTests.java
Outdated
Show resolved
Hide resolved
@eleftherias updated the PR with the requested changes. Also in case of empty basic auth token filter chain should not proceed. Changed it too. Any further code improvements and comments is highly appreciated. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zeeshanadnan.
I have left one more comment.
@@ -111,4 +112,12 @@ public void convertWhenEmptyPassword() { | |||
assertThat(authentication.getName()).isEqualTo("rod"); | |||
assertThat(authentication.getCredentials()).isEqualTo(""); | |||
} | |||
|
|||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the expected exception to the @Test
annotation.
For an example see
Lines 94 to 100 in 7411f25
@Test(expected = BadCredentialsException.class) | |
public void testWhenInvalidBase64ThenError() { | |
MockHttpServletRequest request = new MockHttpServletRequest(); | |
request.addHeader("Authorization", "Basic NOT_VALID_BASE64"); | |
converter.convert(request); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the convention of using AssertJ in new tests. So used assertThatThrownBy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @zeeshanadnan.
I have one more suggestion and then we should be ready to merge this into master.
@@ -424,4 +424,20 @@ public void doFilterWhenTokenAndFilterCharsetDoNotMatchThenUnauthorized() throws | |||
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull(); | |||
} | |||
|
|||
@Test | |||
public void requestWhenEmptyBasicAuthorizationHeaderTokenThenIgnored() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the test name, since the header is not ignored, but rather returns unauthorized.
public void requestWhenEmptyBasicAuthorizationHeaderTokenThenIgnored() throws Exception { | |
public void requestWhenEmptyBasicAuthorizationHeaderTokenThenUnauthorized() throws Exception { |
Thank for the PR @zeeshanadnan! This is now merged into master. |
fixes gh-7976