|
6 | 6 |
|
7 | 7 | package org.elasticsearch.xpack.security.authc.kerberos; |
8 | 8 |
|
| 9 | +import org.elasticsearch.action.ActionListener; |
9 | 10 | import org.elasticsearch.action.support.PlainActionFuture; |
10 | 11 | import org.elasticsearch.common.collect.Tuple; |
11 | 12 | import org.elasticsearch.common.settings.SecureString; |
12 | 13 | import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException; |
13 | 14 | import org.elasticsearch.env.Environment; |
14 | 15 | import org.elasticsearch.env.TestEnvironment; |
15 | 16 | import org.elasticsearch.xpack.core.security.authc.kerberos.KerberosRealmSettings; |
16 | | -import org.elasticsearch.xpack.security.authc.kerberos.KerberosTicketValidator; |
17 | 17 | import org.ietf.jgss.GSSException; |
18 | 18 |
|
19 | 19 | import java.io.IOException; |
|
25 | 25 | import javax.security.auth.login.LoginException; |
26 | 26 |
|
27 | 27 | import static org.hamcrest.Matchers.equalTo; |
| 28 | +import static org.hamcrest.Matchers.instanceOf; |
28 | 29 | import static org.hamcrest.Matchers.is; |
29 | 30 | import static org.hamcrest.Matchers.notNullValue; |
30 | 31 | import static org.hamcrest.Matchers.nullValue; |
@@ -57,10 +58,23 @@ public void testInvalidKerbTicketFailsValidation() throws Exception { |
57 | 58 |
|
58 | 59 | final Environment env = TestEnvironment.newEnvironment(globalSettings); |
59 | 60 | final Path keytabPath = env.configFile().resolve(KerberosRealmSettings.HTTP_SERVICE_KEYTAB_PATH.get(settings)); |
60 | | - final PlainActionFuture<Tuple<String, String>> future = new PlainActionFuture<>(); |
61 | | - kerberosTicketValidator.validateTicket(Base64.getDecoder().decode(base64KerbToken), keytabPath, true, future); |
62 | | - final GSSException gssException = expectThrows(GSSException.class, () -> unwrapExpectedExceptionFromFutureAndThrow(future)); |
63 | | - assertThat(gssException.getMajor(), equalTo(GSSException.DEFECTIVE_TOKEN)); |
| 61 | + kerberosTicketValidator.validateTicket(Base64.getDecoder().decode(base64KerbToken), keytabPath, true, |
| 62 | + new ActionListener<Tuple<String, String>>() { |
| 63 | + boolean exceptionHandled = false; |
| 64 | + |
| 65 | + @Override |
| 66 | + public void onResponse(Tuple<String, String> response) { |
| 67 | + fail("expected exception to be thrown of type GSSException"); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void onFailure(Exception e) { |
| 72 | + assertThat(exceptionHandled, is(false)); |
| 73 | + assertThat(e, instanceOf(GSSException.class)); |
| 74 | + assertThat(((GSSException) e).getMajor(), equalTo(GSSException.DEFECTIVE_TOKEN)); |
| 75 | + exceptionHandled = true; |
| 76 | + } |
| 77 | + }); |
64 | 78 | } |
65 | 79 |
|
66 | 80 | public void testWhenKeyTabWithInvalidContentFailsValidation() |
|
0 commit comments