|
| 1 | +// Copyright 2023 The Go Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package google |
| 6 | + |
| 7 | +import ( |
| 8 | + "context" |
| 9 | + "testing" |
| 10 | +) |
| 11 | + |
| 12 | +var jwtJSONKeyUniverseDomain = []byte(`{ |
| 13 | + "type": "service_account", |
| 14 | + "project_id": "fake_project", |
| 15 | + "universe_domain": "example.com", |
| 16 | + "private_key_id": "268f54e43a1af97cfc71731688434f45aca15c8b", |
| 17 | + "private_key": "super secret key", |
| 18 | + "client_email": "[email protected]", |
| 19 | + "client_id": "gopher.apps.googleusercontent.com", |
| 20 | + "auth_uri": "https://accounts.google.com/o/oauth2/auth", |
| 21 | + "token_uri": "https://oauth2.googleapis.com/token", |
| 22 | + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", |
| 23 | + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gopher%40fake_project.iam.gserviceaccount.com" |
| 24 | +}`) |
| 25 | + |
| 26 | +func TestCredentialsFromJSONWithParams_UniverseDomain(t *testing.T) { |
| 27 | + ctx := context.Background() |
| 28 | + scope := "https://www.googleapis.com/auth/cloud-platform" |
| 29 | + params := CredentialsParams{ |
| 30 | + Scopes: []string{scope}, |
| 31 | + } |
| 32 | + creds, err := CredentialsFromJSONWithParams(ctx, jwtJSONKeyUniverseDomain, params) |
| 33 | + if err != nil { |
| 34 | + t.Fatal(err) |
| 35 | + } |
| 36 | + |
| 37 | + if want := "fake_project"; creds.ProjectID != want { |
| 38 | + t.Fatalf("got %q, want %q", creds.ProjectID, want) |
| 39 | + } |
| 40 | + if want := "example.com"; creds.UniverseDomain() != want { |
| 41 | + t.Fatalf("got %q, want %q", creds.UniverseDomain(), want) |
| 42 | + } |
| 43 | +} |
0 commit comments