Skip to content

Commit

Permalink
Fix incorrect log warning when exporting monitoring via HTTP without …
Browse files Browse the repository at this point in the history
…authentication (#57279)
  • Loading branch information
danhermann authored May 28, 2020
1 parent 24ab3a1 commit 4235c5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,15 @@ public static List<String> loadSettings(Settings settings) {
* @throws SettingsException if the username is missing, but a password is supplied
*/
@Nullable
private static CredentialsProvider createCredentialsProvider(final Config config) {
// visible for testing
static CredentialsProvider createCredentialsProvider(final Config config) {
final String username = AUTH_USERNAME_SETTING.getConcreteSettingForNamespace(config.name()).get(config.settings());

if (Strings.isNullOrEmpty(username)) {
// nothing to configure; default situation for most users
return null;
}

final String deprecatedPassword = AUTH_PASSWORD_SETTING.getConcreteSettingForNamespace(config.name()).get(config.settings());
final SecureString securePassword = SECURE_AUTH_PASSWORDS.get(config.name());
final String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.monitoring.exporter.http;

import org.apache.http.client.CredentialsProvider;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
Expand Down Expand Up @@ -356,6 +357,17 @@ public void testCreateRestClient() throws IOException {
}
}

public void testCreateCredentialsProviderWithoutSecurity() {
final Settings.Builder builder = Settings.builder()
.put("xpack.monitoring.exporters._http.type", "http")
.put("xpack.monitoring.exporters._http.host", "http://localhost:9200");

final Config config = createConfig(builder.build());
CredentialsProvider provider = HttpExporter.createCredentialsProvider(config);

assertNull(provider);
}

public void testCreateSnifferDisabledByDefault() {
final Config config = createConfig(Settings.EMPTY);
final RestClient client = mock(RestClient.class);
Expand Down

0 comments on commit 4235c5e

Please sign in to comment.