Skip to content

Commit

Permalink
Fix "Invalid cookie header" warnings (#791)
Browse files Browse the repository at this point in the history
Co-authored-by: Günter Grodotzki <gunter@grodotzki.com>
  • Loading branch information
rickard-n and lifeofguenter authored Jan 16, 2024
1 parent a7656fc commit dea7dcd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ private CloseableHttpClient getHttpClient(final HttpRequestBase request) {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
httpClientBuilder.useSystemProperties();
httpClientBuilder.setRetryHandler(new StandardHttpRequestRetryHandler());
httpClientBuilder.disableCookieManagement();

RequestConfig.Builder requestConfig = RequestConfig.custom();
String connectTimeout = System.getProperty("http.connect.timeout", "10");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import java.util.List;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.WithoutJenkins;
import org.mockito.MockedStatic;

import static com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.API_BROWSE_PATH;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -23,6 +26,10 @@
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class BitbucketServerAPIClientTest {

Expand Down Expand Up @@ -82,4 +89,16 @@ public void sortRepositoriesByName() throws Exception {
assertThat(names, is(List.of("another-repo", "dogs-repo", "test-repos")));
}

@Test
public void disableCookieManager() throws Exception {
try(MockedStatic<HttpClientBuilder> staticHttpClientBuilder = mockStatic(HttpClientBuilder.class)) {
HttpClientBuilder httpClientBuilder = mock(HttpClientBuilder.class);
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
staticHttpClientBuilder.when(HttpClientBuilder::create).thenReturn(httpClientBuilder);
when(httpClientBuilder.build()).thenReturn(httpClient);
BitbucketApi client = BitbucketIntegrationClientFactory.getClient("localhost", "amuniz", "test-repos");
client.getRepositories();
verify(httpClientBuilder).disableCookieManagement();
}
}
}

0 comments on commit dea7dcd

Please sign in to comment.