|
15 | 15 | import org.elasticsearch.xpack.core.security.authc.Authentication;
|
16 | 16 | import org.elasticsearch.xpack.core.security.authc.Authentication.AuthenticationType;
|
17 | 17 | import org.elasticsearch.xpack.core.security.authc.Authentication.RealmRef;
|
| 18 | +import org.elasticsearch.xpack.core.security.authc.AuthenticationField; |
18 | 19 | import org.elasticsearch.xpack.core.security.user.SystemUser;
|
19 | 20 | import org.elasticsearch.xpack.core.security.user.User;
|
20 | 21 | import org.junit.Before;
|
21 | 22 |
|
| 23 | +import java.io.EOFException; |
22 | 24 | import java.io.IOException;
|
| 25 | +import java.io.UncheckedIOException; |
23 | 26 | import java.util.concurrent.atomic.AtomicReference;
|
24 | 27 |
|
| 28 | +import static org.hamcrest.Matchers.instanceOf; |
| 29 | + |
25 | 30 | public class SecurityContextTests extends ESTestCase {
|
26 | 31 |
|
27 | 32 | private Settings settings;
|
@@ -51,6 +56,14 @@ public void testGetAuthenticationAndUser() throws IOException {
|
51 | 56 | assertEquals(user, securityContext.getUser());
|
52 | 57 | }
|
53 | 58 |
|
| 59 | + public void testGetAuthenticationDoesNotSwallowIOException() { |
| 60 | + threadContext.putHeader(AuthenticationField.AUTHENTICATION_KEY, ""); // an intentionally corrupt header |
| 61 | + final SecurityContext securityContext = new SecurityContext(Settings.EMPTY, threadContext); |
| 62 | + final UncheckedIOException e = expectThrows(UncheckedIOException.class, securityContext::getAuthentication); |
| 63 | + assertNotNull(e.getCause()); |
| 64 | + assertThat(e.getCause(), instanceOf(EOFException.class)); |
| 65 | + } |
| 66 | + |
54 | 67 | public void testSetUser() {
|
55 | 68 | final User user = new User("test");
|
56 | 69 | assertNull(securityContext.getAuthentication());
|
|
0 commit comments