### Question:
BasicAuthHttpHeaderProvider implements HttpHeadersProvider { @Override public HttpHeaders getHeaders(Instance instance) { String username = getMetadataValue(instance, USERNAME_KEYS); String password = getMetadataValue(instance, PASSWORD_KEYS); if (!(StringUtils.hasText(username) && StringUtils.hasText(password))) { String registeredName = instance.getRegistration().getName(); InstanceCredentials credentials = this.serviceMap.get(registeredName); if (credentials != null) { username = credentials.getUserName(); password = credentials.getUserPassword(); } else { username = this.defaultUserName; password = this.defaultPassword; } } HttpHeaders headers = new HttpHeaders(); if (StringUtils.hasText(username) && StringUtils.hasText(password)) { headers.set(HttpHeaders.AUTHORIZATION, encode(username, password)); } return headers; } BasicAuthHttpHeaderProvider(@Nullable String defaultUserName, @Nullable String defaultPassword,
			Map<String, InstanceCredentials> serviceMap);  BasicAuthHttpHeaderProvider(); @Override HttpHeaders getHeaders(Instance instance);  }### Answer:
@Test public void test_auth_header() { Registration registration = Registration.create("foo", "http: .metadata("user.password", "drowssap").build(); Instance instance = Instance.create(InstanceId.of("id")).register(registration); assertThat(this.headersProvider.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)) .containsOnly("Basic dGVzdDpkcm93c3NhcA=="); }
@Test public void test_auth_header_with_dashes() { Registration registration = Registration.create("foo", "http: .metadata("user-password", "drowssap").build(); Instance instance = Instance.create(InstanceId.of("id")).register(registration); assertThat(this.headersProvider.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)) .containsOnly("Basic dGVzdDpkcm93c3NhcA=="); }
@Test public void test_auth_header_no_separator() { Registration registration = Registration.create("foo", "http: .metadata("userpassword", "drowssap").build(); Instance instance = Instance.create(InstanceId.of("id")).register(registration); assertThat(this.headersProvider.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)) .containsOnly("Basic dGVzdDpkcm93c3NhcA=="); }
@Test public void test_no_header() { Registration registration = Registration.create("foo", "http: Instance instance = Instance.create(InstanceId.of("id")).register(registration); assertThat(this.headersProvider.getHeaders(instance)).isEmpty(); }
@Test public void test_auth_instance_enabled_use_default_creds() { Registration registration = Registration.create("foo", "http: Instance instance = Instance.create(InstanceId.of("id")).register(registration); assertThat(this.headersProviderEnableInstanceAuth.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)) .containsOnly("Basic Y2xpZW50OmNsaWVudA=="); }
@Test public void test_auth_instance_enabled_use_service_specific_creds() { Registration registration = Registration.create("foo", "http: Instance instance = Instance.create(InstanceId.of("id")).register(registration); assertThat(this.headersProviderEnableInstanceAuth.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)) .containsOnly("Basic YWRtaW46YWRtaW4="); }
@Test public void test_auth_instance_enabled_use_metadata_over_props() { Registration registration = Registration.create("foo", "http: .metadata("userpassword", "drowssap").name("xyz-server").build(); Instance instance = Instance.create(InstanceId.of("id")).register(registration); assertThat(this.headersProviderEnableInstanceAuth.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)) .containsOnly("Basic dGVzdDpkcm93c3NhcA=="); }