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