Skip to content

Commit 441929e

Browse files
committed
[JENKINS-64418] Add exponential backoff to BitBucket rate limit retry loop
Add unit test for server API client
1 parent a34562f commit 441929e

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

src/test/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClientTest.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import java.util.List;
1515
import org.apache.commons.io.IOUtils;
1616
import org.apache.http.HttpRequest;
17+
import org.apache.http.client.methods.HttpGet;
1718
import org.apache.http.client.methods.HttpHead;
1819
import org.apache.http.client.methods.HttpPost;
1920
import org.apache.http.client.methods.HttpRequestBase;
2021
import org.apache.http.impl.client.HttpClientBuilder;
2122
import org.junit.jupiter.api.BeforeAll;
2223
import org.junit.jupiter.api.Test;
24+
import org.jvnet.hudson.test.Issue;
2325
import org.jvnet.hudson.test.JenkinsRule;
2426
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
2527
import org.mockito.ArgumentCaptor;
@@ -50,7 +52,8 @@ static void init(JenkinsRule rule) {
5052

5153
@Test
5254
void verify_status_notitication_name_max_length() throws Exception {
53-
BitbucketApi client = BitbucketIntegrationClientFactory.getApiMockClient("https://acme.bitbucket.org");
55+
String serverURL = "https://acme.bitbucket.org";
56+
BitbucketApi client = BitbucketIntegrationClientFactory.getApiMockClient(serverURL);
5457
BitbucketBuildStatus status = new BitbucketBuildStatus();
5558
status.setName(RandomStringUtils.randomAlphanumeric(300));
5659
status.setState(Status.INPROGRESS);
@@ -90,6 +93,8 @@ void verify_checkPathExists_given_a_path() throws Exception {
9093
assertThat(request).isNotNull()
9194
.isInstanceOfSatisfying(HttpHead.class, head -> {
9295
assertThat(head.getURI())
96+
.hasScheme("https")
97+
.hasHost("acme.bitbucket.org")
9398
.hasPath("/rest/api/1.0/projects/amuniz/repos/test-repos/browse/folder/Jenkinsfile")
9499
.hasQuery("at=feature/pipeline");
95100
});
@@ -103,7 +108,10 @@ void verify_checkPathExists_given_file() throws Exception {
103108
HttpRequestBase request = extractRequest(client);
104109
assertThat(request).isNotNull()
105110
.isInstanceOfSatisfying(HttpHead.class, head ->
106-
assertThat(head.getURI()).hasPath("/rest/api/1.0/projects/amuniz/repos/test-repos/browse/Jenkinsfile"));
111+
assertThat(head.getURI())
112+
.hasScheme("https")
113+
.hasHost("acme.bitbucket.org")
114+
.hasPath("/rest/api/1.0/projects/amuniz/repos/test-repos/browse/Jenkinsfile"));
107115
}
108116

109117
@Test
@@ -135,11 +143,45 @@ void disableCookieManager() throws Exception {
135143

136144
@Test
137145
void verify_mirroredRepository_does_not_authenticate_request() throws Exception {
138-
BitbucketServerAPIClient client = (BitbucketServerAPIClient) BitbucketIntegrationClientFactory.getClient("localhost", "amuniz", "test-repos");
146+
String serverURL = "https://acme.bitbucket.org";
147+
BitbucketServerAPIClient client = (BitbucketServerAPIClient) BitbucketIntegrationClientFactory.getClient(serverURL, "amuniz", "test-repos");
139148

140149
BitbucketAuthenticator authenticator = extractAuthenticator(client);
141-
String url = "https://localhost/rest/mirroring/latest/upstreamServers/1/repos/1?jwt=TOKEN";
150+
String url = serverURL + "/rest/mirroring/latest/upstreamServers/1/repos/1?jwt=TOKEN";
142151
client.getMirroredRepository(url);
143152
verify(authenticator, never()).configureRequest(any(HttpRequest.class));
144153
}
154+
155+
@Issue("JENKINS-64418")
156+
@Test
157+
void verify_getBranch_request_URL() throws Exception {
158+
String serverURL = "https://acme.bitbucket.org";
159+
BitbucketServerAPIClient client = (BitbucketServerAPIClient) BitbucketIntegrationClientFactory.getClient(serverURL, "amuniz", "test-repos");
160+
161+
client.getBranch("feature/BB-1");
162+
HttpRequestBase request = extractRequest(client);
163+
assertThat(request).isNotNull()
164+
.isInstanceOfSatisfying(HttpGet.class, head ->
165+
assertThat(head.getURI())
166+
.hasScheme("https")
167+
.hasHost("acme.bitbucket.org")
168+
.hasPath("/rest/api/1.0/projects/amuniz/repos/test-repos/branches"));
169+
}
170+
171+
@Issue("JENKINS-64418")
172+
@Test
173+
void verify_getTag_request_URL() throws Exception {
174+
String serverURL = "https://acme.bitbucket.org";
175+
BitbucketServerAPIClient client = (BitbucketServerAPIClient) BitbucketIntegrationClientFactory.getClient(serverURL, "amuniz", "test-repos");
176+
177+
client.getTag("v0.0.0");
178+
HttpRequestBase request = extractRequest(client);
179+
assertThat(request).isNotNull()
180+
.isInstanceOfSatisfying(HttpGet.class, head ->
181+
assertThat(head.getURI())
182+
.hasScheme("https")
183+
.hasHost("acme.bitbucket.org")
184+
.hasPath("/rest/api/1.0/projects/amuniz/repos/test-repos/tags"));
185+
}
186+
145187
}

0 commit comments

Comments
 (0)