diff --git a/clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentials.java b/clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentials.java index 2251338f620..c45ce796991 100644 --- a/clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentials.java +++ b/clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentials.java @@ -17,6 +17,7 @@ package com.netflix.spinnaker.clouddriver.artifacts.bitbucket; +import static org.springframework.http.HttpHeaders.ACCEPT; import static org.springframework.http.HttpHeaders.AUTHORIZATION; import com.google.common.collect.ImmutableList; @@ -28,6 +29,7 @@ import java.util.Optional; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; @NonnullByDefault @Slf4j @@ -48,6 +50,7 @@ protected Headers getHeaders(BitbucketArtifactAccount account) { Optional token = account.getTokenAsString(); if (token.isPresent()) { headers.set(AUTHORIZATION, "Bearer " + token.get()); + headers.set(ACCEPT, MediaType.APPLICATION_JSON_VALUE); log.info("Loaded credentials for Bitbucket Artifact Account {}", account.getName()); return headers.build(); } diff --git a/clouddriver-artifacts/src/test/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentialsTest.java b/clouddriver-artifacts/src/test/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentialsTest.java index 24325c34911..6b01923ffc5 100644 --- a/clouddriver-artifacts/src/test/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentialsTest.java +++ b/clouddriver-artifacts/src/test/java/com/netflix/spinnaker/clouddriver/artifacts/bitbucket/BitbucketArtifactCredentialsTest.java @@ -18,6 +18,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.*; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.http.HttpHeaders.ACCEPT; import static org.springframework.http.HttpHeaders.AUTHORIZATION; import com.github.tomakehurst.wiremock.WireMockServer; @@ -33,6 +34,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junitpioneer.jupiter.TempDirectory; +import org.springframework.http.MediaType; import ru.lanwen.wiremock.ext.WiremockResolver; @ExtendWith({WiremockResolver.class, TempDirectory.class}) @@ -47,7 +49,12 @@ void downloadWithToken(@WiremockResolver.Wiremock WireMockServer server) throws BitbucketArtifactAccount account = BitbucketArtifactAccount.builder().name("my-bitbucket-account").token("abc").build(); - runTestCase(server, account, m -> m.withHeader(AUTHORIZATION, equalTo("Bearer abc"))); + runTestCase( + server, + account, + m -> + m.withHeader(AUTHORIZATION, equalTo("Bearer abc")) + .withHeader(ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))); } @Test @@ -63,7 +70,12 @@ void downloadWithTokenFromFile( .tokenFile(authFile.toAbsolutePath().toString()) .build(); - runTestCase(server, account, m -> m.withHeader(AUTHORIZATION, equalTo("Bearer zzz"))); + runTestCase( + server, + account, + m -> + m.withHeader(AUTHORIZATION, equalTo("Bearer zzz")) + .withHeader(ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))); } @Test @@ -79,11 +91,21 @@ void downloadWithTokenFromFileWithReloadHeaders( .tokenFile(authFile.toAbsolutePath().toString()) .build(); - runTestCase(server, account, m -> m.withHeader(AUTHORIZATION, equalTo("Bearer zzz"))); + runTestCase( + server, + account, + m -> + m.withHeader(AUTHORIZATION, equalTo("Bearer zzz")) + .withHeader(ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))); Files.write(authFile, "aaa".getBytes()); - runTestCase(server, account, m -> m.withHeader(AUTHORIZATION, equalTo("Bearer aaa"))); + runTestCase( + server, + account, + m -> + m.withHeader(AUTHORIZATION, equalTo("Bearer aaa")) + .withHeader(ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))); } @Test