|
11 | 11 | import org.elasticsearch.action.ActionListener; |
12 | 12 | import org.elasticsearch.action.support.PlainActionFuture; |
13 | 13 | import org.elasticsearch.common.settings.SecureString; |
| 14 | +import org.elasticsearch.common.settings.Setting; |
14 | 15 | import org.elasticsearch.common.settings.Settings; |
15 | 16 | import org.elasticsearch.common.util.concurrent.ThreadContext; |
16 | 17 | import org.elasticsearch.env.Environment; |
@@ -62,13 +63,67 @@ public void testConnectionFactoryReturnsCorrectLDAPConnectionOptionsWithDefaultS |
62 | 63 | assertThat(options.getSSLSocketVerifier(), is(instanceOf(HostNameSSLSocketVerifier.class))); |
63 | 64 | } |
64 | 65 |
|
| 66 | + public void testSessionFactoryWithResponseTimeout() throws Exception { |
| 67 | + final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("ldap", "response_settings"); |
| 68 | + final Path pathHome = createTempDir(); |
| 69 | + { |
| 70 | + Settings settings = Settings.builder() |
| 71 | + .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_RESPONSE_SETTING), "10s") |
| 72 | + .put("path.home", pathHome) |
| 73 | + .build(); |
| 74 | + |
| 75 | + final Environment environment = TestEnvironment.newEnvironment(settings); |
| 76 | + RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings)); |
| 77 | + LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(settings, environment), logger); |
| 78 | + assertThat(options.getResponseTimeoutMillis(), is(equalTo(10000L))); |
| 79 | + } |
| 80 | + { |
| 81 | + Settings settings = Settings.builder() |
| 82 | + .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_READ_SETTING), "7s") |
| 83 | + .put("path.home", pathHome) |
| 84 | + .build(); |
| 85 | + |
| 86 | + final Environment environment = TestEnvironment.newEnvironment(settings); |
| 87 | + RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings)); |
| 88 | + LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(settings, environment), logger); |
| 89 | + assertThat(options.getResponseTimeoutMillis(), is(equalTo(7000L))); |
| 90 | + assertSettingDeprecationsAndWarnings(new Setting<?>[]{SessionFactorySettings.TIMEOUT_TCP_READ_SETTING.apply("ldap") |
| 91 | + .getConcreteSettingForNamespace("response_settings")}); |
| 92 | + } |
| 93 | + { |
| 94 | + Settings settings = Settings.builder() |
| 95 | + .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_RESPONSE_SETTING), "11s") |
| 96 | + .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_READ_SETTING), "6s") |
| 97 | + .put("path.home", pathHome) |
| 98 | + .build(); |
| 99 | + |
| 100 | + final Environment environment = TestEnvironment.newEnvironment(settings); |
| 101 | + RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings)); |
| 102 | + IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> SessionFactory.connectionOptions(realmConfig |
| 103 | + , new SSLService(settings, environment), logger)); |
| 104 | + assertThat(ex.getMessage(), is("[xpack.security.authc.realms.ldap.response_settings.timeout.tcp_read] and [xpack.security" + |
| 105 | + ".authc.realms.ldap.response_settings.timeout.response] may not be used at the same time")); |
| 106 | + } |
| 107 | + { |
| 108 | + Settings settings = Settings.builder() |
| 109 | + .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_LDAP_SETTING), "750ms") |
| 110 | + .put("path.home", pathHome) |
| 111 | + .build(); |
| 112 | + |
| 113 | + final Environment environment = TestEnvironment.newEnvironment(settings); |
| 114 | + RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings)); |
| 115 | + LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(settings, environment), logger); |
| 116 | + assertThat(options.getResponseTimeoutMillis(), is(equalTo(750L))); |
| 117 | + } |
| 118 | + } |
| 119 | + |
65 | 120 | public void testConnectionFactoryReturnsCorrectLDAPConnectionOptions() throws Exception { |
66 | 121 | final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("ldap", "conn_settings"); |
67 | 122 | final Path pathHome = createTempDir(); |
68 | 123 | Settings settings = getSettingsBuilder() |
69 | 124 | .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_CONNECTION_SETTING), "10ms") |
70 | 125 | .put(getFullSettingKey(realmId, SessionFactorySettings.HOSTNAME_VERIFICATION_SETTING), "false") |
71 | | - .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_READ_SETTING), "20ms") |
| 126 | + .put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_RESPONSE_SETTING), "20ms") |
72 | 127 | .put(getFullSettingKey(realmId, SessionFactorySettings.FOLLOW_REFERRALS_SETTING), "false") |
73 | 128 | .put("path.home", pathHome) |
74 | 129 | .build(); |
|
0 commit comments