22
22
import com .google .cloud .tools .jib .http .FailoverHttpClient ;
23
23
import com .google .cloud .tools .jib .http .Response ;
24
24
import com .google .cloud .tools .jib .http .ResponseException ;
25
+ import com .google .common .collect .Lists ;
25
26
import java .net .MalformedURLException ;
26
27
import java .net .URL ;
27
28
import java .util .Collections ;
@@ -102,7 +103,7 @@ public void testHandleHttpResponseException_noHeader() throws ResponseException
102
103
Mockito .when (mockResponseException .getStatusCode ())
103
104
.thenReturn (HttpStatusCodes .STATUS_CODE_UNAUTHORIZED );
104
105
Mockito .when (mockResponseException .getHeaders ()).thenReturn (mockHeaders );
105
- Mockito .when (mockHeaders .getAuthenticate ()).thenReturn (null );
106
+ Mockito .when (mockHeaders .getAuthenticateAsList ()).thenReturn (null );
106
107
107
108
try {
108
109
testAuthenticationMethodRetriever .handleHttpResponseException (mockResponseException );
@@ -122,7 +123,8 @@ public void testHandleHttpResponseException_badAuthenticationMethod() throws Res
122
123
Mockito .when (mockResponseException .getStatusCode ())
123
124
.thenReturn (HttpStatusCodes .STATUS_CODE_UNAUTHORIZED );
124
125
Mockito .when (mockResponseException .getHeaders ()).thenReturn (mockHeaders );
125
- Mockito .when (mockHeaders .getAuthenticate ()).thenReturn (authenticationMethod );
126
+ Mockito .when (mockHeaders .getAuthenticateAsList ())
127
+ .thenReturn (Lists .newArrayList (authenticationMethod ));
126
128
127
129
try {
128
130
testAuthenticationMethodRetriever .handleHttpResponseException (mockResponseException );
@@ -133,7 +135,7 @@ public void testHandleHttpResponseException_badAuthenticationMethod() throws Res
133
135
MatcherAssert .assertThat (
134
136
ex .getMessage (),
135
137
CoreMatchers .containsString (
136
- "Failed get authentication method from 'WWW-Authenticate' header" ));
138
+ "Failed getting supported authentication method from 'WWW-Authenticate' header" ));
137
139
}
138
140
}
139
141
@@ -146,7 +148,30 @@ public void testHandleHttpResponseException_pass()
146
148
Mockito .when (mockResponseException .getStatusCode ())
147
149
.thenReturn (HttpStatusCodes .STATUS_CODE_UNAUTHORIZED );
148
150
Mockito .when (mockResponseException .getHeaders ()).thenReturn (mockHeaders );
149
- Mockito .when (mockHeaders .getAuthenticate ()).thenReturn (authenticationMethod );
151
+ Mockito .when (mockHeaders .getAuthenticateAsList ())
152
+ .thenReturn (Lists .newArrayList (authenticationMethod ));
153
+
154
+ RegistryAuthenticator registryAuthenticator =
155
+ testAuthenticationMethodRetriever .handleHttpResponseException (mockResponseException ).get ();
156
+
157
+ Assert .assertEquals (
158
+ new URL ("https://somerealm?service=someservice&scope=repository:someImageName:someScope" ),
159
+ registryAuthenticator .getAuthenticationUrl (
160
+ null , Collections .singletonMap ("someImageName" , "someScope" )));
161
+ }
162
+
163
+ @ Test
164
+ public void testHandleHttpResponseExceptionWithKerberosFirst_pass ()
165
+ throws RegistryErrorException , ResponseException , MalformedURLException {
166
+ String authenticationMethodNegotiate = "Negotiate" ;
167
+ String authenticationMethodBearer =
168
+ "Bearer realm=\" https://somerealm\" ,service=\" someservice\" ,scope=\" somescope\" " ;
169
+
170
+ Mockito .when (mockResponseException .getStatusCode ())
171
+ .thenReturn (HttpStatusCodes .STATUS_CODE_UNAUTHORIZED );
172
+ Mockito .when (mockResponseException .getHeaders ()).thenReturn (mockHeaders );
173
+ Mockito .when (mockHeaders .getAuthenticateAsList ())
174
+ .thenReturn (Lists .newArrayList (authenticationMethodNegotiate , authenticationMethodBearer ));
150
175
151
176
RegistryAuthenticator registryAuthenticator =
152
177
testAuthenticationMethodRetriever .handleHttpResponseException (mockResponseException ).get ();
0 commit comments