14
14
import java .util .List ;
15
15
import org .apache .commons .io .IOUtils ;
16
16
import org .apache .http .HttpRequest ;
17
+ import org .apache .http .client .methods .HttpGet ;
17
18
import org .apache .http .client .methods .HttpHead ;
18
19
import org .apache .http .client .methods .HttpPost ;
19
20
import org .apache .http .client .methods .HttpRequestBase ;
20
21
import org .apache .http .impl .client .HttpClientBuilder ;
21
22
import org .junit .jupiter .api .BeforeAll ;
22
23
import org .junit .jupiter .api .Test ;
24
+ import org .jvnet .hudson .test .Issue ;
23
25
import org .jvnet .hudson .test .JenkinsRule ;
24
26
import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
25
27
import org .mockito .ArgumentCaptor ;
@@ -50,7 +52,8 @@ static void init(JenkinsRule rule) {
50
52
51
53
@ Test
52
54
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 );
54
57
BitbucketBuildStatus status = new BitbucketBuildStatus ();
55
58
status .setName (RandomStringUtils .randomAlphanumeric (300 ));
56
59
status .setState (Status .INPROGRESS );
@@ -90,6 +93,8 @@ void verify_checkPathExists_given_a_path() throws Exception {
90
93
assertThat (request ).isNotNull ()
91
94
.isInstanceOfSatisfying (HttpHead .class , head -> {
92
95
assertThat (head .getURI ())
96
+ .hasScheme ("https" )
97
+ .hasHost ("acme.bitbucket.org" )
93
98
.hasPath ("/rest/api/1.0/projects/amuniz/repos/test-repos/browse/folder/Jenkinsfile" )
94
99
.hasQuery ("at=feature/pipeline" );
95
100
});
@@ -103,7 +108,10 @@ void verify_checkPathExists_given_file() throws Exception {
103
108
HttpRequestBase request = extractRequest (client );
104
109
assertThat (request ).isNotNull ()
105
110
.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" ));
107
115
}
108
116
109
117
@ Test
@@ -135,11 +143,45 @@ void disableCookieManager() throws Exception {
135
143
136
144
@ Test
137
145
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" );
139
148
140
149
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" ;
142
151
client .getMirroredRepository (url );
143
152
verify (authenticator , never ()).configureRequest (any (HttpRequest .class ));
144
153
}
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
+
145
187
}
0 commit comments