17
17
package com .netflix .spinnaker .clouddriver .docker .registry .api .v2 .client ;
18
18
19
19
import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
20
+ import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
20
21
import static com .github .tomakehurst .wiremock .client .WireMock .urlMatching ;
21
22
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
23
+ import static org .assertj .core .api .AssertionsForInterfaceTypes .assertThat ;
22
24
import static org .junit .jupiter .api .Assertions .assertEquals ;
23
25
import static org .junit .jupiter .api .Assertions .assertIterableEquals ;
24
26
import static org .mockito .ArgumentMatchers .anyString ;
29
31
import com .github .tomakehurst .wiremock .junit5 .WireMockExtension ;
30
32
import com .netflix .spinnaker .clouddriver .docker .registry .api .v2 .auth .DockerBearerToken ;
31
33
import com .netflix .spinnaker .clouddriver .docker .registry .api .v2 .auth .DockerBearerTokenService ;
32
- import com .netflix .spinnaker .config .DefaultServiceClientProvider ;
33
- import com .netflix .spinnaker .config .okhttp3 .DefaultOkHttpClientBuilderProvider ;
34
- import com .netflix .spinnaker .config .okhttp3 .OkHttpClientProvider ;
35
- import com .netflix .spinnaker .kork .client .ServiceClientProvider ;
36
34
import com .netflix .spinnaker .kork .retrofit .ErrorHandlingExecutorCallAdapterFactory ;
37
- import com .netflix .spinnaker .kork .retrofit .Retrofit2ServiceFactory ;
38
- import com .netflix .spinnaker .kork .retrofit .Retrofit2ServiceFactoryAutoConfiguration ;
39
- import com .netflix .spinnaker .okhttp .OkHttpClientConfigurationProperties ;
40
35
import java .util .Arrays ;
41
36
import java .util .Map ;
42
37
import okhttp3 .OkHttpClient ;
43
38
import org .junit .jupiter .api .BeforeEach ;
44
39
import org .junit .jupiter .api .Test ;
45
40
import org .junit .jupiter .api .extension .RegisterExtension ;
46
41
import org .mockito .Mockito ;
47
- import org .springframework .beans .factory .annotation .Autowired ;
48
42
import org .springframework .boot .test .context .SpringBootTest ;
49
43
import org .springframework .boot .test .mock .mockito .MockBean ;
50
44
import org .springframework .http .HttpStatus ;
51
45
import retrofit2 .Retrofit ;
52
46
import retrofit2 .converter .jackson .JacksonConverterFactory ;
53
47
54
- @ SpringBootTest (
55
- classes = {
56
- OkHttpClientConfigurationProperties .class ,
57
- Retrofit2ServiceFactory .class ,
58
- ServiceClientProvider .class ,
59
- OkHttpClientProvider .class ,
60
- OkHttpClient .class ,
61
- DefaultServiceClientProvider .class ,
62
- DefaultOkHttpClientBuilderProvider .class ,
63
- Retrofit2ServiceFactoryAutoConfiguration .class ,
64
- ObjectMapper .class
65
- },
66
- webEnvironment = SpringBootTest .WebEnvironment .NONE )
48
+ @ SpringBootTest (classes = {DockerBearerTokenService .class })
67
49
public class DockerRegistryClientTest {
68
50
69
51
@ RegisterExtension
@@ -73,7 +55,6 @@ public class DockerRegistryClientTest {
73
55
static DockerRegistryClient .DockerRegistryService dockerRegistryService ;
74
56
@ MockBean DockerBearerTokenService dockerBearerTokenService ;
75
57
static DockerRegistryClient dockerRegistryClient ;
76
- @ Autowired ServiceClientProvider serviceClientProvider ;
77
58
ObjectMapper objectMapper = new ObjectMapper ();
78
59
Map <String , Object > tagsResponse ;
79
60
String tagsResponseString ;
@@ -134,7 +115,7 @@ private static <T> T buildService(Class<T> type, String baseUrl) {
134
115
@ Test
135
116
public void getTagsWithoutNextLink () {
136
117
wmDockerRegistry .stubFor (
137
- WireMock .get (urlMatching ("/v2/library/nginx/tags/list" ))
118
+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list\\ ?n=5 " ))
138
119
.willReturn (
139
120
aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsResponseString )));
140
121
@@ -146,7 +127,7 @@ public void getTagsWithoutNextLink() {
146
127
@ Test
147
128
public void getTagsWithNextLink () {
148
129
wmDockerRegistry .stubFor (
149
- WireMock .get (urlMatching ("/v2/library/nginx/tags/list" ))
130
+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list\\ ?n=5 " ))
150
131
.willReturn (
151
132
aResponse ()
152
133
.withStatus (HttpStatus .OK .value ())
@@ -165,7 +146,7 @@ public void getTagsWithNextLink() {
165
146
"</v2/library/nginx/tags/list1>; rel=\" next\" " )
166
147
.withBody (tagsSecondResponseString )));
167
148
wmDockerRegistry .stubFor (
168
- WireMock .get (urlMatching ("/v2/library/nginx/tags/list1" ))
149
+ WireMock .get (urlMatching ("/v2/library/nginx/tags/list1\\ ?n=5 " ))
169
150
.willReturn (
170
151
aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsThirdResponseString )));
171
152
@@ -202,4 +183,38 @@ public void getCatalogWithNextLink() {
202
183
DockerRegistryCatalog dockerRegistryCatalog = dockerRegistryClient .getCatalog ();
203
184
assertEquals (15 , dockerRegistryCatalog .getRepositories ().size ());
204
185
}
186
+
187
+ @ Test
188
+ public void getTagsWithNextLinkEncryptedAndEncoded () {
189
+ String tagsListEndPointMinusQueryParams = "/v2/library/nginx/tags/list" ;
190
+ String expectedEncodedParam = "Md1Woj%2FNOhjepFq7kPAr%2FEw%2FYxfcJoH9N52%2Blo3qAQ%3D%3D" ;
191
+
192
+ wmDockerRegistry .stubFor (
193
+ WireMock .get (urlMatching (tagsListEndPointMinusQueryParams + "\\ ?n=5" ))
194
+ .willReturn (
195
+ aResponse ()
196
+ .withStatus (HttpStatus .OK .value ())
197
+ .withHeader (
198
+ "link" ,
199
+ "</v2/library/nginx/tags/list?last=Md1Woj%2FNOhjepFq7kPAr%2FEw%2FYxfcJoH9N52%2Blo3qAQ%3D%3D&n=5>; rel=\" next\" " )
200
+ .withBody (tagsResponseString )));
201
+
202
+ wmDockerRegistry .stubFor (
203
+ WireMock .get (
204
+ urlMatching (
205
+ tagsListEndPointMinusQueryParams + "\\ ?last=" + expectedEncodedParam + "&n=5" ))
206
+ .willReturn (
207
+ aResponse ().withStatus (HttpStatus .OK .value ()).withBody (tagsSecondResponseString )));
208
+
209
+ DockerRegistryTags dockerRegistryTags = dockerRegistryClient .getTags ("library/nginx" );
210
+ assertThat (dockerRegistryTags .getTags ()).hasSize (10 );
211
+
212
+ wmDockerRegistry .verify (
213
+ 1 , getRequestedFor (urlMatching (tagsListEndPointMinusQueryParams + "\\ ?n=5" )));
214
+ wmDockerRegistry .verify (
215
+ 1 ,
216
+ getRequestedFor (
217
+ urlMatching (
218
+ tagsListEndPointMinusQueryParams + "\\ ?last=" + expectedEncodedParam + "&n=5" )));
219
+ }
205
220
}
0 commit comments