|
9 | 9 | "io/ioutil"
|
10 | 10 | "net/http"
|
11 | 11 | "net/http/httptest"
|
12 |
| - "strings" |
13 | 12 | "testing"
|
14 | 13 | "time"
|
15 | 14 |
|
@@ -208,140 +207,6 @@ func TestNonworkforceWithWorkforcePoolUserProject(t *testing.T) {
|
208 | 207 | }
|
209 | 208 | }
|
210 | 209 |
|
211 |
| -func TestValidateURLTokenURL(t *testing.T) { |
212 |
| - var urlValidityTests = []struct { |
213 |
| - tokURL string |
214 |
| - expectSuccess bool |
215 |
| - }{ |
216 |
| - {"https://east.sts.googleapis.com", true}, |
217 |
| - {"https://sts.googleapis.com", true}, |
218 |
| - {"https://sts.asfeasfesef.googleapis.com", true}, |
219 |
| - {"https://us-east-1-sts.googleapis.com", true}, |
220 |
| - {"https://sts.googleapis.com/your/path/here", true}, |
221 |
| - {"https://.sts.googleapis.com", false}, |
222 |
| - {"https://badsts.googleapis.com", false}, |
223 |
| - {"https://sts.asfe.asfesef.googleapis.com", false}, |
224 |
| - {"https://sts..googleapis.com", false}, |
225 |
| - {"https://-sts.googleapis.com", false}, |
226 |
| - {"https://us-ea.st-1-sts.googleapis.com", false}, |
227 |
| - {"https://sts.googleapis.com.evil.com/whatever/path", false}, |
228 |
| - {"https://us-eas\\t-1.sts.googleapis.com", false}, |
229 |
| - {"https:/us-ea/st-1.sts.googleapis.com", false}, |
230 |
| - {"https:/us-east 1.sts.googleapis.com", false}, |
231 |
| - {"https://", false}, |
232 |
| - {"http://us-east-1.sts.googleapis.com", false}, |
233 |
| - {"https://us-east-1.sts.googleapis.comevil.com", false}, |
234 |
| - {"https://sts-xyz.p.googleapis.com", true}, |
235 |
| - {"https://sts.pgoogleapis.com", false}, |
236 |
| - {"https://p.googleapis.com", false}, |
237 |
| - {"https://sts.p.com", false}, |
238 |
| - {"http://sts.p.googleapis.com", false}, |
239 |
| - {"https://xyz-sts.p.googleapis.com", false}, |
240 |
| - {"https://sts-xyz.123.p.googleapis.com", false}, |
241 |
| - {"https://sts-xyz.p1.googleapis.com", false}, |
242 |
| - {"https://sts-xyz.p.foo.com", false}, |
243 |
| - {"https://sts-xyz.p.foo.googleapis.com", false}, |
244 |
| - } |
245 |
| - ctx := context.Background() |
246 |
| - for _, tt := range urlValidityTests { |
247 |
| - t.Run(" "+tt.tokURL, func(t *testing.T) { // We prepend a space ahead of the test input when outputting for sake of readability. |
248 |
| - config := testConfig |
249 |
| - config.TokenURL = tt.tokURL |
250 |
| - _, err := config.TokenSource(ctx) |
251 |
| - |
252 |
| - if tt.expectSuccess && err != nil { |
253 |
| - t.Errorf("got %v but want nil", err) |
254 |
| - } else if !tt.expectSuccess && err == nil { |
255 |
| - t.Errorf("got nil but expected an error") |
256 |
| - } |
257 |
| - }) |
258 |
| - } |
259 |
| - for _, el := range urlValidityTests { |
260 |
| - el.tokURL = strings.ToUpper(el.tokURL) |
261 |
| - } |
262 |
| - for _, tt := range urlValidityTests { |
263 |
| - t.Run(" "+tt.tokURL, func(t *testing.T) { // We prepend a space ahead of the test input when outputting for sake of readability. |
264 |
| - config := testConfig |
265 |
| - config.TokenURL = tt.tokURL |
266 |
| - _, err := config.TokenSource(ctx) |
267 |
| - |
268 |
| - if tt.expectSuccess && err != nil { |
269 |
| - t.Errorf("got %v but want nil", err) |
270 |
| - } else if !tt.expectSuccess && err == nil { |
271 |
| - t.Errorf("got nil but expected an error") |
272 |
| - } |
273 |
| - }) |
274 |
| - } |
275 |
| -} |
276 |
| - |
277 |
| -func TestValidateURLImpersonateURL(t *testing.T) { |
278 |
| - var urlValidityTests = []struct { |
279 |
| - impURL string |
280 |
| - expectSuccess bool |
281 |
| - }{ |
282 |
| - {"https://east.iamcredentials.googleapis.com", true}, |
283 |
| - {"https://iamcredentials.googleapis.com", true}, |
284 |
| - {"https://iamcredentials.asfeasfesef.googleapis.com", true}, |
285 |
| - {"https://us-east-1-iamcredentials.googleapis.com", true}, |
286 |
| - {"https://iamcredentials.googleapis.com/your/path/here", true}, |
287 |
| - {"https://.iamcredentials.googleapis.com", false}, |
288 |
| - {"https://badiamcredentials.googleapis.com", false}, |
289 |
| - {"https://iamcredentials.asfe.asfesef.googleapis.com", false}, |
290 |
| - {"https://iamcredentials..googleapis.com", false}, |
291 |
| - {"https://-iamcredentials.googleapis.com", false}, |
292 |
| - {"https://us-ea.st-1-iamcredentials.googleapis.com", false}, |
293 |
| - {"https://iamcredentials.googleapis.com.evil.com/whatever/path", false}, |
294 |
| - {"https://us-eas\\t-1.iamcredentials.googleapis.com", false}, |
295 |
| - {"https:/us-ea/st-1.iamcredentials.googleapis.com", false}, |
296 |
| - {"https:/us-east 1.iamcredentials.googleapis.com", false}, |
297 |
| - {"https://", false}, |
298 |
| - {"http://us-east-1.iamcredentials.googleapis.com", false}, |
299 |
| - {"https://us-east-1.iamcredentials.googleapis.comevil.com", false}, |
300 |
| - {"https://iamcredentials-xyz.p.googleapis.com", true}, |
301 |
| - {"https://iamcredentials.pgoogleapis.com", false}, |
302 |
| - {"https://p.googleapis.com", false}, |
303 |
| - {"https://iamcredentials.p.com", false}, |
304 |
| - {"http://iamcredentials.p.googleapis.com", false}, |
305 |
| - {"https://xyz-iamcredentials.p.googleapis.com", false}, |
306 |
| - {"https://iamcredentials-xyz.123.p.googleapis.com", false}, |
307 |
| - {"https://iamcredentials-xyz.p1.googleapis.com", false}, |
308 |
| - {"https://iamcredentials-xyz.p.foo.com", false}, |
309 |
| - {"https://iamcredentials-xyz.p.foo.googleapis.com", false}, |
310 |
| - } |
311 |
| - ctx := context.Background() |
312 |
| - for _, tt := range urlValidityTests { |
313 |
| - t.Run(" "+tt.impURL, func(t *testing.T) { // We prepend a space ahead of the test input when outputting for sake of readability. |
314 |
| - config := testConfig |
315 |
| - config.TokenURL = "https://sts.googleapis.com" // Setting the most basic acceptable tokenURL |
316 |
| - config.ServiceAccountImpersonationURL = tt.impURL |
317 |
| - _, err := config.TokenSource(ctx) |
318 |
| - |
319 |
| - if tt.expectSuccess && err != nil { |
320 |
| - t.Errorf("got %v but want nil", err) |
321 |
| - } else if !tt.expectSuccess && err == nil { |
322 |
| - t.Errorf("got nil but expected an error") |
323 |
| - } |
324 |
| - }) |
325 |
| - } |
326 |
| - for _, el := range urlValidityTests { |
327 |
| - el.impURL = strings.ToUpper(el.impURL) |
328 |
| - } |
329 |
| - for _, tt := range urlValidityTests { |
330 |
| - t.Run(" "+tt.impURL, func(t *testing.T) { // We prepend a space ahead of the test input when outputting for sake of readability. |
331 |
| - config := testConfig |
332 |
| - config.TokenURL = "https://sts.googleapis.com" // Setting the most basic acceptable tokenURL |
333 |
| - config.ServiceAccountImpersonationURL = tt.impURL |
334 |
| - _, err := config.TokenSource(ctx) |
335 |
| - |
336 |
| - if tt.expectSuccess && err != nil { |
337 |
| - t.Errorf("got %v but want nil", err) |
338 |
| - } else if !tt.expectSuccess && err == nil { |
339 |
| - t.Errorf("got nil but expected an error") |
340 |
| - } |
341 |
| - }) |
342 |
| - } |
343 |
| -} |
344 |
| - |
345 | 210 | func TestWorkforcePoolCreation(t *testing.T) {
|
346 | 211 | var audienceValidatyTests = []struct {
|
347 | 212 | audience string
|
|
0 commit comments