2020import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
2121import static com .github .tomakehurst .wiremock .client .WireMock .urlMatching ;
2222import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
23+ import static org .assertj .core .api .AssertionsForInterfaceTypes .assertThat ;
2324import static org .junit .jupiter .api .Assertions .assertEquals ;
2425import static org .junit .jupiter .api .Assertions .assertIterableEquals ;
25- import static org .junit .jupiter .api .Assertions .assertThrows ;
2626import static org .mockito .ArgumentMatchers .anyString ;
2727
2828import com .fasterxml .jackson .core .JsonProcessingException ;
3232import com .netflix .spinnaker .clouddriver .docker .registry .api .v2 .auth .DockerBearerToken ;
3333import com .netflix .spinnaker .clouddriver .docker .registry .api .v2 .auth .DockerBearerTokenService ;
3434import com .netflix .spinnaker .kork .retrofit .ErrorHandlingExecutorCallAdapterFactory ;
35- import com .netflix .spinnaker .kork .retrofit .exceptions .SpinnakerHttpException ;
3635import java .util .Arrays ;
3736import java .util .Map ;
3837import okhttp3 .OkHttpClient ;
@@ -116,7 +115,7 @@ private static <T> T buildService(Class<T> type, String baseUrl) {
116115 @ Test
117116 public void getTagsWithoutNextLink () {
118117 wmDockerRegistry .stubFor (
119- WireMock .get (urlMatching ("/v2/library/nginx/tags/list" ))
118+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list\\ ?n=5 " ))
120119 .willReturn (
121120 aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsResponseString )));
122121
@@ -128,7 +127,7 @@ public void getTagsWithoutNextLink() {
128127 @ Test
129128 public void getTagsWithNextLink () {
130129 wmDockerRegistry .stubFor (
131- WireMock .get (urlMatching ("/v2/library/nginx/tags/list" ))
130+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list\\ ?n=5 " ))
132131 .willReturn (
133132 aResponse ()
134133 .withStatus (HttpStatus .OK .value ())
@@ -147,7 +146,7 @@ public void getTagsWithNextLink() {
147146 "</v2/library/nginx/tags/list1>; rel=\" next\" " )
148147 .withBody (tagsSecondResponseString )));
149148 wmDockerRegistry .stubFor (
150- WireMock .get (urlMatching ("/v2/library/nginx/tags/list1" ))
149+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list1\\ ?n=5 " ))
151150 .willReturn (
152151 aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsThirdResponseString )));
153152
@@ -190,12 +189,8 @@ public void getTagsWithNextLinkEncryptedAndEncoded() {
190189 String tagsListEndPointMinusQueryParams = "/v2/library/nginx/tags/list" ;
191190 String expectedEncodedParam = "Md1Woj%2FNOhjepFq7kPAr%2FEw%2FYxfcJoH9N52%2Blo3qAQ%3D%3D" ;
192191
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-
197192 wmDockerRegistry .stubFor (
198- WireMock .get (urlMatching (tagsListEndPointMinusQueryParams ))
193+ WireMock .get (urlMatching (tagsListEndPointMinusQueryParams + " \\ ?n=5" ))
199194 .willReturn (
200195 aResponse ()
201196 .withStatus (HttpStatus .OK .value ())
@@ -211,26 +206,13 @@ public void getTagsWithNextLinkEncryptedAndEncoded() {
211206 .willReturn (
212207 aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsSecondResponseString )));
213208
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 );
225211
226- wmDockerRegistry .verify (1 , getRequestedFor (urlMatching (tagsListEndPointMinusQueryParams )));
227212 wmDockerRegistry .verify (
228- 1 ,
229- getRequestedFor (
230- urlMatching (
231- tagsListEndPointMinusQueryParams + "\\ ?last=" + doubleEncodedParam + "&n=5" )));
213+ 1 , getRequestedFor (urlMatching (tagsListEndPointMinusQueryParams + "\\ ?n=5" )));
232214 wmDockerRegistry .verify (
233- 0 ,
215+ 1 ,
234216 getRequestedFor (
235217 urlMatching (
236218 tagsListEndPointMinusQueryParams + "\\ ?last=" + expectedEncodedParam + "&n=5" )));
0 commit comments