|
3 | 3 | let(:fake_binary) { double("Binary") }
|
4 | 4 | let(:fake_binary_contents) { double("Contents") }
|
5 | 5 | let(:firebase_auth) { Signet::OAuth2::Client }
|
6 |
| - let(:service_auth) { Google::Auth::ServiceAccountCredentials } |
| 6 | + let(:service_account_auth) { Google::Auth::ServiceAccountCredentials } |
| 7 | + let(:fake_service_account_contents_json) { "{\"type\": \"service_account\"}" } |
| 8 | + let(:external_account_auth) { Google::Auth::ExternalAccount::Credentials } |
| 9 | + let(:fake_external_account_contents_json) { "{\"type\": \"external_account\"}" } |
7 | 10 | let(:fake_firebase_tools_contents) { "{\"tokens\": {\"refresh_token\": \"refresh_token\"} }" }
|
8 | 11 | let(:fake_firebase_tools_contents_no_tokens_field) { "{}" }
|
9 | 12 | let(:fake_firebase_tools_contents_no_refresh_field) { "{\"tokens\": \"empty\"}" }
|
|
20 | 23 | allow(fake_oauth_client).to receive(:access_token)
|
21 | 24 | .and_return("fake_auth_token")
|
22 | 25 |
|
23 |
| - allow(service_auth).to receive(:make_creds) |
| 26 | + allow(service_account_auth).to receive(:make_creds) |
| 27 | + .and_return(fake_service_creds) |
| 28 | + allow(external_account_auth).to receive(:make_creds) |
24 | 29 | .and_return(fake_service_creds)
|
25 | 30 | allow(fake_service_creds).to receive(:fetch_access_token!)
|
26 | 31 | .and_return(payload)
|
27 | 32 |
|
28 | 33 | allow(File).to receive(:open).and_call_original
|
29 | 34 | allow(File).to receive(:open)
|
30 | 35 | .and_return(fake_binary)
|
| 36 | + allow(File).to receive(:read) |
| 37 | + .and_return(fake_service_account_contents_json) |
31 | 38 | allow(fake_binary).to receive(:read)
|
32 | 39 | .and_return(fake_binary_contents)
|
33 | 40 | allow(fake_binary_contents).to receive(:key)
|
|
56 | 63 | .to eq(fake_service_creds)
|
57 | 64 | end
|
58 | 65 |
|
59 |
| - it 'auths with service credentials environment variable' do |
| 66 | + it 'auths with service account credentials environment variable' do |
| 67 | + allow(ENV).to receive(:[]) |
| 68 | + .with("GOOGLE_APPLICATION_CREDENTIALS") |
| 69 | + .and_return("google_service_path") |
| 70 | + expect(auth_client.get_authorization(empty_val, empty_val)) |
| 71 | + .to eq(fake_service_creds) |
| 72 | + end |
| 73 | + |
| 74 | + it 'auths with external account credentials environment variable' do |
60 | 75 | allow(ENV).to receive(:[])
|
61 | 76 | .with("GOOGLE_APPLICATION_CREDENTIALS")
|
62 | 77 | .and_return("google_service_path")
|
| 78 | + allow(File).to receive(:read) |
| 79 | + .and_return(fake_external_account_contents_json) |
63 | 80 | expect(auth_client.get_authorization(empty_val, empty_val))
|
64 | 81 | .to eq(fake_service_creds)
|
65 | 82 | end
|
|
0 commit comments