20
20
import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
21
21
import static com .github .tomakehurst .wiremock .client .WireMock .urlMatching ;
22
22
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
23
+ import static org .assertj .core .api .AssertionsForInterfaceTypes .assertThat ;
23
24
import static org .junit .jupiter .api .Assertions .assertEquals ;
24
25
import static org .junit .jupiter .api .Assertions .assertIterableEquals ;
25
- import static org .junit .jupiter .api .Assertions .assertThrows ;
26
26
import static org .mockito .ArgumentMatchers .anyString ;
27
27
28
28
import com .fasterxml .jackson .core .JsonProcessingException ;
32
32
import com .netflix .spinnaker .clouddriver .docker .registry .api .v2 .auth .DockerBearerToken ;
33
33
import com .netflix .spinnaker .clouddriver .docker .registry .api .v2 .auth .DockerBearerTokenService ;
34
34
import com .netflix .spinnaker .kork .retrofit .ErrorHandlingExecutorCallAdapterFactory ;
35
- import com .netflix .spinnaker .kork .retrofit .exceptions .SpinnakerHttpException ;
36
35
import java .util .Arrays ;
37
36
import java .util .Map ;
38
37
import okhttp3 .OkHttpClient ;
@@ -116,7 +115,7 @@ private static <T> T buildService(Class<T> type, String baseUrl) {
116
115
@ Test
117
116
public void getTagsWithoutNextLink () {
118
117
wmDockerRegistry .stubFor (
119
- WireMock .get (urlMatching ("/v2/library/nginx/tags/list" ))
118
+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list\\ ?n=5 " ))
120
119
.willReturn (
121
120
aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsResponseString )));
122
121
@@ -128,7 +127,7 @@ public void getTagsWithoutNextLink() {
128
127
@ Test
129
128
public void getTagsWithNextLink () {
130
129
wmDockerRegistry .stubFor (
131
- WireMock .get (urlMatching ("/v2/library/nginx/tags/list" ))
130
+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list\\ ?n=5 " ))
132
131
.willReturn (
133
132
aResponse ()
134
133
.withStatus (HttpStatus .OK .value ())
@@ -147,7 +146,7 @@ public void getTagsWithNextLink() {
147
146
"</v2/library/nginx/tags/list1>; rel=\" next\" " )
148
147
.withBody (tagsSecondResponseString )));
149
148
wmDockerRegistry .stubFor (
150
- WireMock .get (urlMatching ("/v2/library/nginx/tags/list1" ))
149
+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list1\\ ?n=5 " ))
151
150
.willReturn (
152
151
aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsThirdResponseString )));
153
152
@@ -190,12 +189,8 @@ public void getTagsWithNextLinkEncryptedAndEncoded() {
190
189
String tagsListEndPointMinusQueryParams = "/v2/library/nginx/tags/list" ;
191
190
String expectedEncodedParam = "Md1Woj%2FNOhjepFq7kPAr%2FEw%2FYxfcJoH9N52%2Blo3qAQ%3D%3D" ;
192
191
193
- // notice %252F, %253D which are double encoded characters of /(or %2F) and =(or %3D)
194
- String doubleEncodedParam =
195
- "Md1Woj%252FNOhjepFq7kPAr%252FEw%252FYxfcJoH9N52%252Blo3qAQ%253D%253D" ;
196
-
197
192
wmDockerRegistry .stubFor (
198
- WireMock .get (urlMatching (tagsListEndPointMinusQueryParams ))
193
+ WireMock .get (urlMatching (tagsListEndPointMinusQueryParams + " \\ ?n=5" ))
199
194
.willReturn (
200
195
aResponse ()
201
196
.withStatus (HttpStatus .OK .value ())
@@ -211,26 +206,13 @@ public void getTagsWithNextLinkEncryptedAndEncoded() {
211
206
.willReturn (
212
207
aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsSecondResponseString )));
213
208
214
- wmDockerRegistry .stubFor (
215
- WireMock .get (
216
- urlMatching (
217
- tagsListEndPointMinusQueryParams + "\\ ?last=" + doubleEncodedParam + "&n=5" ))
218
- .willReturn (aResponse ().withStatus (405 ).withBody ("Method Not Allowed" )));
219
-
220
- // TODO: Fix this issue of retrofit2 encoding the already encoded query parameter
221
- assertThrows (
222
- SpinnakerHttpException .class ,
223
- () -> dockerRegistryClient .getTags ("library/nginx" ),
224
- "Status: 405, Method: GET, Message: Method Not Allowed" );
209
+ DockerRegistryTags dockerRegistryTags = dockerRegistryClient .getTags ("library/nginx" );
210
+ assertThat (dockerRegistryTags .getTags ()).hasSize (10 );
225
211
226
- wmDockerRegistry .verify (1 , getRequestedFor (urlMatching (tagsListEndPointMinusQueryParams )));
227
212
wmDockerRegistry .verify (
228
- 1 ,
229
- getRequestedFor (
230
- urlMatching (
231
- tagsListEndPointMinusQueryParams + "\\ ?last=" + doubleEncodedParam + "&n=5" )));
213
+ 1 , getRequestedFor (urlMatching (tagsListEndPointMinusQueryParams + "\\ ?n=5" )));
232
214
wmDockerRegistry .verify (
233
- 0 ,
215
+ 1 ,
234
216
getRequestedFor (
235
217
urlMatching (
236
218
tagsListEndPointMinusQueryParams + "\\ ?last=" + expectedEncodedParam + "&n=5" )));
0 commit comments