C.J. Collier | 37141e4 | 2020-02-13 13:49:49 -0800 | [diff] [blame] | 1 | # Copyright 2016 Google LLC |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import json |
| 16 | import os |
| 17 | |
| 18 | import mock |
| 19 | import pytest |
| 20 | |
| 21 | from google.auth import _default |
Jon Wayne Parrott | 2148fde | 2016-10-24 13:44:25 -0700 | [diff] [blame] | 22 | from google.auth import app_engine |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 23 | from google.auth import compute_engine |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 24 | from google.auth import credentials |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 25 | from google.auth import environment_vars |
| 26 | from google.auth import exceptions |
| 27 | from google.oauth2 import service_account |
| 28 | import google.oauth2.credentials |
| 29 | |
| 30 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 31 | DATA_DIR = os.path.join(os.path.dirname(__file__), "data") |
| 32 | AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, "authorized_user.json") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 33 | |
| 34 | with open(AUTHORIZED_USER_FILE) as fh: |
| 35 | AUTHORIZED_USER_FILE_DATA = json.load(fh) |
| 36 | |
Thea Flowers | a8d9348 | 2018-05-31 14:52:06 -0700 | [diff] [blame] | 37 | AUTHORIZED_USER_CLOUD_SDK_FILE = os.path.join( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 38 | DATA_DIR, "authorized_user_cloud_sdk.json" |
| 39 | ) |
Thea Flowers | a8d9348 | 2018-05-31 14:52:06 -0700 | [diff] [blame] | 40 | |
arithmetic1728 | f30b45a | 2020-06-17 23:36:04 -0700 | [diff] [blame] | 41 | AUTHORIZED_USER_CLOUD_SDK_WITH_QUOTA_PROJECT_ID_FILE = os.path.join( |
| 42 | DATA_DIR, "authorized_user_cloud_sdk_with_quota_project_id.json" |
| 43 | ) |
| 44 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 45 | SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, "service_account.json") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 46 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 47 | CLIENT_SECRETS_FILE = os.path.join(DATA_DIR, "client_secrets.json") |
| 48 | |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 49 | with open(SERVICE_ACCOUNT_FILE) as fh: |
| 50 | SERVICE_ACCOUNT_FILE_DATA = json.load(fh) |
| 51 | |
Bu Sun Kim | 41599ae | 2020-09-02 12:55:42 -0600 | [diff] [blame^] | 52 | MOCK_CREDENTIALS = mock.Mock(spec=credentials.CredentialsWithQuotaProject) |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 53 | MOCK_CREDENTIALS.with_quota_project.return_value = MOCK_CREDENTIALS |
| 54 | |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 55 | LOAD_FILE_PATCH = mock.patch( |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 56 | "google.auth._default.load_credentials_from_file", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 57 | return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 58 | autospec=True, |
| 59 | ) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 60 | |
| 61 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 62 | def test_load_credentials_from_missing_file(): |
weitaiting | 6e86c93 | 2017-08-12 03:26:59 +0800 | [diff] [blame] | 63 | with pytest.raises(exceptions.DefaultCredentialsError) as excinfo: |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 64 | _default.load_credentials_from_file("") |
weitaiting | 6e86c93 | 2017-08-12 03:26:59 +0800 | [diff] [blame] | 65 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 66 | assert excinfo.match(r"not found") |
weitaiting | 6e86c93 | 2017-08-12 03:26:59 +0800 | [diff] [blame] | 67 | |
| 68 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 69 | def test_load_credentials_from_file_invalid_json(tmpdir): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 70 | jsonfile = tmpdir.join("invalid.json") |
| 71 | jsonfile.write("{") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 72 | |
| 73 | with pytest.raises(exceptions.DefaultCredentialsError) as excinfo: |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 74 | _default.load_credentials_from_file(str(jsonfile)) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 75 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 76 | assert excinfo.match(r"not a valid json file") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 77 | |
| 78 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 79 | def test_load_credentials_from_file_invalid_type(tmpdir): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 80 | jsonfile = tmpdir.join("invalid.json") |
| 81 | jsonfile.write(json.dumps({"type": "not-a-real-type"})) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 82 | |
| 83 | with pytest.raises(exceptions.DefaultCredentialsError) as excinfo: |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 84 | _default.load_credentials_from_file(str(jsonfile)) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 85 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 86 | assert excinfo.match(r"does not have a valid type") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 87 | |
| 88 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 89 | def test_load_credentials_from_file_authorized_user(): |
| 90 | credentials, project_id = _default.load_credentials_from_file(AUTHORIZED_USER_FILE) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 91 | assert isinstance(credentials, google.oauth2.credentials.Credentials) |
| 92 | assert project_id is None |
| 93 | |
| 94 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 95 | def test_load_credentials_from_file_no_type(tmpdir): |
| 96 | # use the client_secrets.json, which is valid json but not a |
| 97 | # loadable credentials type |
| 98 | with pytest.raises(exceptions.DefaultCredentialsError) as excinfo: |
| 99 | _default.load_credentials_from_file(CLIENT_SECRETS_FILE) |
| 100 | |
| 101 | assert excinfo.match(r"does not have a valid type") |
| 102 | assert excinfo.match(r"Type is None") |
| 103 | |
| 104 | |
| 105 | def test_load_credentials_from_file_authorized_user_bad_format(tmpdir): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 106 | filename = tmpdir.join("authorized_user_bad.json") |
| 107 | filename.write(json.dumps({"type": "authorized_user"})) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 108 | |
| 109 | with pytest.raises(exceptions.DefaultCredentialsError) as excinfo: |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 110 | _default.load_credentials_from_file(str(filename)) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 111 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 112 | assert excinfo.match(r"Failed to load authorized user") |
| 113 | assert excinfo.match(r"missing fields") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 114 | |
| 115 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 116 | def test_load_credentials_from_file_authorized_user_cloud_sdk(): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 117 | with pytest.warns(UserWarning, match="Cloud SDK"): |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 118 | credentials, project_id = _default.load_credentials_from_file( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 119 | AUTHORIZED_USER_CLOUD_SDK_FILE |
| 120 | ) |
Thea Flowers | a8d9348 | 2018-05-31 14:52:06 -0700 | [diff] [blame] | 121 | assert isinstance(credentials, google.oauth2.credentials.Credentials) |
| 122 | assert project_id is None |
| 123 | |
arithmetic1728 | f30b45a | 2020-06-17 23:36:04 -0700 | [diff] [blame] | 124 | # No warning if the json file has quota project id. |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 125 | credentials, project_id = _default.load_credentials_from_file( |
arithmetic1728 | f30b45a | 2020-06-17 23:36:04 -0700 | [diff] [blame] | 126 | AUTHORIZED_USER_CLOUD_SDK_WITH_QUOTA_PROJECT_ID_FILE |
| 127 | ) |
| 128 | assert isinstance(credentials, google.oauth2.credentials.Credentials) |
| 129 | assert project_id is None |
| 130 | |
Thea Flowers | a8d9348 | 2018-05-31 14:52:06 -0700 | [diff] [blame] | 131 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 132 | def test_load_credentials_from_file_authorized_user_cloud_sdk_with_scopes(): |
| 133 | with pytest.warns(UserWarning, match="Cloud SDK"): |
| 134 | credentials, project_id = _default.load_credentials_from_file( |
| 135 | AUTHORIZED_USER_CLOUD_SDK_FILE, |
| 136 | scopes=["https://www.google.com/calendar/feeds"], |
| 137 | ) |
| 138 | assert isinstance(credentials, google.oauth2.credentials.Credentials) |
| 139 | assert project_id is None |
| 140 | assert credentials.scopes == ["https://www.google.com/calendar/feeds"] |
| 141 | |
| 142 | |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 143 | def test_load_credentials_from_file_authorized_user_cloud_sdk_with_quota_project(): |
| 144 | credentials, project_id = _default.load_credentials_from_file( |
| 145 | AUTHORIZED_USER_CLOUD_SDK_FILE, quota_project_id="project-foo" |
| 146 | ) |
| 147 | |
| 148 | assert isinstance(credentials, google.oauth2.credentials.Credentials) |
| 149 | assert project_id is None |
| 150 | assert credentials.quota_project_id == "project-foo" |
| 151 | |
| 152 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 153 | def test_load_credentials_from_file_service_account(): |
| 154 | credentials, project_id = _default.load_credentials_from_file(SERVICE_ACCOUNT_FILE) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 155 | assert isinstance(credentials, service_account.Credentials) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 156 | assert project_id == SERVICE_ACCOUNT_FILE_DATA["project_id"] |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 157 | |
| 158 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 159 | def test_load_credentials_from_file_service_account_with_scopes(): |
| 160 | credentials, project_id = _default.load_credentials_from_file( |
| 161 | SERVICE_ACCOUNT_FILE, scopes=["https://www.google.com/calendar/feeds"] |
| 162 | ) |
| 163 | assert isinstance(credentials, service_account.Credentials) |
| 164 | assert project_id == SERVICE_ACCOUNT_FILE_DATA["project_id"] |
| 165 | assert credentials.scopes == ["https://www.google.com/calendar/feeds"] |
| 166 | |
| 167 | |
Bu Sun Kim | ab2be5d | 2020-07-15 16:49:27 -0700 | [diff] [blame] | 168 | def test_load_credentials_from_file_service_account_with_quota_project(): |
| 169 | credentials, project_id = _default.load_credentials_from_file( |
| 170 | SERVICE_ACCOUNT_FILE, quota_project_id="project-foo" |
| 171 | ) |
| 172 | assert isinstance(credentials, service_account.Credentials) |
| 173 | assert project_id == SERVICE_ACCOUNT_FILE_DATA["project_id"] |
| 174 | assert credentials.quota_project_id == "project-foo" |
| 175 | |
| 176 | |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 177 | def test_load_credentials_from_file_service_account_bad_format(tmpdir): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 178 | filename = tmpdir.join("serivce_account_bad.json") |
| 179 | filename.write(json.dumps({"type": "service_account"})) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 180 | |
| 181 | with pytest.raises(exceptions.DefaultCredentialsError) as excinfo: |
Bu Sun Kim | 15d5fa9 | 2020-06-18 14:05:40 -0700 | [diff] [blame] | 182 | _default.load_credentials_from_file(str(filename)) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 183 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 184 | assert excinfo.match(r"Failed to load service account") |
| 185 | assert excinfo.match(r"missing fields") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 186 | |
| 187 | |
| 188 | @mock.patch.dict(os.environ, {}, clear=True) |
| 189 | def test__get_explicit_environ_credentials_no_env(): |
| 190 | assert _default._get_explicit_environ_credentials() == (None, None) |
| 191 | |
| 192 | |
| 193 | @LOAD_FILE_PATCH |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 194 | def test__get_explicit_environ_credentials(load, monkeypatch): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 195 | monkeypatch.setenv(environment_vars.CREDENTIALS, "filename") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 196 | |
| 197 | credentials, project_id = _default._get_explicit_environ_credentials() |
| 198 | |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 199 | assert credentials is MOCK_CREDENTIALS |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 200 | assert project_id is mock.sentinel.project_id |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 201 | load.assert_called_with("filename") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 202 | |
| 203 | |
| 204 | @LOAD_FILE_PATCH |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 205 | def test__get_explicit_environ_credentials_no_project_id(load, monkeypatch): |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 206 | load.return_value = MOCK_CREDENTIALS, None |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 207 | monkeypatch.setenv(environment_vars.CREDENTIALS, "filename") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 208 | |
| 209 | credentials, project_id = _default._get_explicit_environ_credentials() |
| 210 | |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 211 | assert credentials is MOCK_CREDENTIALS |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 212 | assert project_id is None |
| 213 | |
| 214 | |
| 215 | @LOAD_FILE_PATCH |
Jon Wayne Parrott | 8784b23 | 2016-11-10 12:53:55 -0800 | [diff] [blame] | 216 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 217 | "google.auth._cloud_sdk.get_application_default_credentials_path", autospec=True |
| 218 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 219 | def test__get_gcloud_sdk_credentials(get_adc_path, load): |
| 220 | get_adc_path.return_value = SERVICE_ACCOUNT_FILE |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 221 | |
| 222 | credentials, project_id = _default._get_gcloud_sdk_credentials() |
| 223 | |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 224 | assert credentials is MOCK_CREDENTIALS |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 225 | assert project_id is mock.sentinel.project_id |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 226 | load.assert_called_with(SERVICE_ACCOUNT_FILE) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 227 | |
| 228 | |
Jon Wayne Parrott | 8784b23 | 2016-11-10 12:53:55 -0800 | [diff] [blame] | 229 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 230 | "google.auth._cloud_sdk.get_application_default_credentials_path", autospec=True |
| 231 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 232 | def test__get_gcloud_sdk_credentials_non_existent(get_adc_path, tmpdir): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 233 | non_existent = tmpdir.join("non-existent") |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 234 | get_adc_path.return_value = str(non_existent) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 235 | |
| 236 | credentials, project_id = _default._get_gcloud_sdk_credentials() |
| 237 | |
| 238 | assert credentials is None |
| 239 | assert project_id is None |
| 240 | |
| 241 | |
| 242 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 243 | "google.auth._cloud_sdk.get_project_id", |
| 244 | return_value=mock.sentinel.project_id, |
| 245 | autospec=True, |
| 246 | ) |
| 247 | @mock.patch("os.path.isfile", return_value=True, autospec=True) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 248 | @LOAD_FILE_PATCH |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 249 | def test__get_gcloud_sdk_credentials_project_id(load, unused_isfile, get_project_id): |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 250 | # Don't return a project ID from load file, make the function check |
| 251 | # the Cloud SDK project. |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 252 | load.return_value = MOCK_CREDENTIALS, None |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 253 | |
| 254 | credentials, project_id = _default._get_gcloud_sdk_credentials() |
| 255 | |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 256 | assert credentials == MOCK_CREDENTIALS |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 257 | assert project_id == mock.sentinel.project_id |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 258 | assert get_project_id.called |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 259 | |
| 260 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 261 | @mock.patch("google.auth._cloud_sdk.get_project_id", return_value=None, autospec=True) |
| 262 | @mock.patch("os.path.isfile", return_value=True) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 263 | @LOAD_FILE_PATCH |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 264 | def test__get_gcloud_sdk_credentials_no_project_id(load, unused_isfile, get_project_id): |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 265 | # Don't return a project ID from load file, make the function check |
| 266 | # the Cloud SDK project. |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 267 | load.return_value = MOCK_CREDENTIALS, None |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 268 | |
| 269 | credentials, project_id = _default._get_gcloud_sdk_credentials() |
| 270 | |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 271 | assert credentials == MOCK_CREDENTIALS |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 272 | assert project_id is None |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 273 | assert get_project_id.called |
| 274 | |
| 275 | |
| 276 | class _AppIdentityModule(object): |
| 277 | """The interface of the App Idenity app engine module. |
| 278 | See https://cloud.google.com/appengine/docs/standard/python/refdocs\ |
| 279 | /google.appengine.api.app_identity.app_identity |
| 280 | """ |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 281 | |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 282 | def get_application_id(self): |
| 283 | raise NotImplementedError() |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 284 | |
| 285 | |
Jon Wayne Parrott | 2148fde | 2016-10-24 13:44:25 -0700 | [diff] [blame] | 286 | @pytest.fixture |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 287 | def app_identity(monkeypatch): |
Jon Wayne Parrott | 2148fde | 2016-10-24 13:44:25 -0700 | [diff] [blame] | 288 | """Mocks the app_identity module for google.auth.app_engine.""" |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 289 | app_identity_module = mock.create_autospec(_AppIdentityModule, instance=True) |
| 290 | monkeypatch.setattr(app_engine, "app_identity", app_identity_module) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 291 | yield app_identity_module |
Jon Wayne Parrott | 2148fde | 2016-10-24 13:44:25 -0700 | [diff] [blame] | 292 | |
| 293 | |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 294 | def test__get_gae_credentials(app_identity): |
| 295 | app_identity.get_application_id.return_value = mock.sentinel.project |
Jon Wayne Parrott | 2148fde | 2016-10-24 13:44:25 -0700 | [diff] [blame] | 296 | |
| 297 | credentials, project_id = _default._get_gae_credentials() |
| 298 | |
| 299 | assert isinstance(credentials, app_engine.Credentials) |
| 300 | assert project_id == mock.sentinel.project |
| 301 | |
| 302 | |
James Wilson | 6e0781b | 2018-12-20 20:38:52 -0500 | [diff] [blame] | 303 | def test__get_gae_credentials_no_app_engine(): |
| 304 | import sys |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 305 | |
| 306 | with mock.patch.dict("sys.modules"): |
| 307 | sys.modules["google.auth.app_engine"] = None |
James Wilson | 6e0781b | 2018-12-20 20:38:52 -0500 | [diff] [blame] | 308 | credentials, project_id = _default._get_gae_credentials() |
| 309 | assert credentials is None |
| 310 | assert project_id is None |
| 311 | |
| 312 | |
Jon Wayne Parrott | 2148fde | 2016-10-24 13:44:25 -0700 | [diff] [blame] | 313 | def test__get_gae_credentials_no_apis(): |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 314 | assert _default._get_gae_credentials() == (None, None) |
| 315 | |
| 316 | |
| 317 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 318 | "google.auth.compute_engine._metadata.ping", return_value=True, autospec=True |
| 319 | ) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 320 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 321 | "google.auth.compute_engine._metadata.get_project_id", |
| 322 | return_value="example-project", |
| 323 | autospec=True, |
| 324 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 325 | def test__get_gce_credentials(unused_get, unused_ping): |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 326 | credentials, project_id = _default._get_gce_credentials() |
| 327 | |
| 328 | assert isinstance(credentials, compute_engine.Credentials) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 329 | assert project_id == "example-project" |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 330 | |
| 331 | |
Jon Wayne Parrott | 8784b23 | 2016-11-10 12:53:55 -0800 | [diff] [blame] | 332 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 333 | "google.auth.compute_engine._metadata.ping", return_value=False, autospec=True |
| 334 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 335 | def test__get_gce_credentials_no_ping(unused_ping): |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 336 | credentials, project_id = _default._get_gce_credentials() |
| 337 | |
| 338 | assert credentials is None |
| 339 | assert project_id is None |
| 340 | |
| 341 | |
| 342 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 343 | "google.auth.compute_engine._metadata.ping", return_value=True, autospec=True |
| 344 | ) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 345 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 346 | "google.auth.compute_engine._metadata.get_project_id", |
| 347 | side_effect=exceptions.TransportError(), |
| 348 | autospec=True, |
| 349 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 350 | def test__get_gce_credentials_no_project_id(unused_get, unused_ping): |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 351 | credentials, project_id = _default._get_gce_credentials() |
| 352 | |
| 353 | assert isinstance(credentials, compute_engine.Credentials) |
| 354 | assert project_id is None |
| 355 | |
| 356 | |
James Wilson | 6e0781b | 2018-12-20 20:38:52 -0500 | [diff] [blame] | 357 | def test__get_gce_credentials_no_compute_engine(): |
| 358 | import sys |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 359 | |
| 360 | with mock.patch.dict("sys.modules"): |
| 361 | sys.modules["google.auth.compute_engine"] = None |
James Wilson | 6e0781b | 2018-12-20 20:38:52 -0500 | [diff] [blame] | 362 | credentials, project_id = _default._get_gce_credentials() |
| 363 | assert credentials is None |
| 364 | assert project_id is None |
| 365 | |
| 366 | |
Jon Wayne Parrott | 8784b23 | 2016-11-10 12:53:55 -0800 | [diff] [blame] | 367 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 368 | "google.auth.compute_engine._metadata.ping", return_value=False, autospec=True |
| 369 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 370 | def test__get_gce_credentials_explicit_request(ping): |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 371 | _default._get_gce_credentials(mock.sentinel.request) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 372 | ping.assert_called_with(request=mock.sentinel.request) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 373 | |
| 374 | |
| 375 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 376 | "google.auth._default._get_explicit_environ_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 377 | return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 378 | autospec=True, |
| 379 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 380 | def test_default_early_out(unused_get): |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 381 | assert _default.default() == (MOCK_CREDENTIALS, mock.sentinel.project_id) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 382 | |
| 383 | |
| 384 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 385 | "google.auth._default._get_explicit_environ_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 386 | return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 387 | autospec=True, |
| 388 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 389 | def test_default_explict_project_id(unused_get, monkeypatch): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 390 | monkeypatch.setenv(environment_vars.PROJECT, "explicit-env") |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 391 | assert _default.default() == (MOCK_CREDENTIALS, "explicit-env") |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 392 | |
| 393 | |
| 394 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 395 | "google.auth._default._get_explicit_environ_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 396 | return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 397 | autospec=True, |
| 398 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 399 | def test_default_explict_legacy_project_id(unused_get, monkeypatch): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 400 | monkeypatch.setenv(environment_vars.LEGACY_PROJECT, "explicit-env") |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 401 | assert _default.default() == (MOCK_CREDENTIALS, "explicit-env") |
Jon Wayne Parrott | ce37cba | 2016-11-07 16:41:42 -0800 | [diff] [blame] | 402 | |
| 403 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 404 | @mock.patch("logging.Logger.warning", autospec=True) |
Jon Wayne Parrott | ce37cba | 2016-11-07 16:41:42 -0800 | [diff] [blame] | 405 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 406 | "google.auth._default._get_explicit_environ_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 407 | return_value=(MOCK_CREDENTIALS, None), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 408 | autospec=True, |
| 409 | ) |
Jacob Hayes | 15af07b | 2017-12-13 14:09:47 -0600 | [diff] [blame] | 410 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 411 | "google.auth._default._get_gcloud_sdk_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 412 | return_value=(MOCK_CREDENTIALS, None), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 413 | autospec=True, |
| 414 | ) |
Jacob Hayes | 15af07b | 2017-12-13 14:09:47 -0600 | [diff] [blame] | 415 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 416 | "google.auth._default._get_gae_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 417 | return_value=(MOCK_CREDENTIALS, None), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 418 | autospec=True, |
| 419 | ) |
Jacob Hayes | 15af07b | 2017-12-13 14:09:47 -0600 | [diff] [blame] | 420 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 421 | "google.auth._default._get_gce_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 422 | return_value=(MOCK_CREDENTIALS, None), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 423 | autospec=True, |
| 424 | ) |
Jacob Hayes | 15af07b | 2017-12-13 14:09:47 -0600 | [diff] [blame] | 425 | def test_default_without_project_id( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 426 | unused_gce, unused_gae, unused_sdk, unused_explicit, logger_warning |
| 427 | ): |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 428 | assert _default.default() == (MOCK_CREDENTIALS, None) |
Jacob Hayes | 15af07b | 2017-12-13 14:09:47 -0600 | [diff] [blame] | 429 | logger_warning.assert_called_with(mock.ANY, mock.ANY, mock.ANY) |
| 430 | |
| 431 | |
| 432 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 433 | "google.auth._default._get_explicit_environ_credentials", |
| 434 | return_value=(None, None), |
| 435 | autospec=True, |
| 436 | ) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 437 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 438 | "google.auth._default._get_gcloud_sdk_credentials", |
| 439 | return_value=(None, None), |
| 440 | autospec=True, |
| 441 | ) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 442 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 443 | "google.auth._default._get_gae_credentials", |
| 444 | return_value=(None, None), |
| 445 | autospec=True, |
| 446 | ) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 447 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 448 | "google.auth._default._get_gce_credentials", |
| 449 | return_value=(None, None), |
| 450 | autospec=True, |
| 451 | ) |
Jon Wayne Parrott | aadb3de | 2016-10-19 09:34:05 -0700 | [diff] [blame] | 452 | def test_default_fail(unused_gce, unused_gae, unused_sdk, unused_explicit): |
| 453 | with pytest.raises(exceptions.DefaultCredentialsError): |
| 454 | assert _default.default() |
Jon Wayne Parrott | 8a7e506 | 2016-11-07 16:45:17 -0800 | [diff] [blame] | 455 | |
| 456 | |
| 457 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 458 | "google.auth._default._get_explicit_environ_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 459 | return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 460 | autospec=True, |
| 461 | ) |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 462 | @mock.patch( |
| 463 | "google.auth.credentials.with_scopes_if_required", |
| 464 | return_value=MOCK_CREDENTIALS, |
| 465 | autospec=True, |
| 466 | ) |
Jacob Hayes | 15af07b | 2017-12-13 14:09:47 -0600 | [diff] [blame] | 467 | def test_default_scoped(with_scopes, unused_get): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 468 | scopes = ["one", "two"] |
Jon Wayne Parrott | 8a7e506 | 2016-11-07 16:45:17 -0800 | [diff] [blame] | 469 | |
| 470 | credentials, project_id = _default.default(scopes=scopes) |
| 471 | |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 472 | assert credentials == with_scopes.return_value |
Jon Wayne Parrott | 8a7e506 | 2016-11-07 16:45:17 -0800 | [diff] [blame] | 473 | assert project_id == mock.sentinel.project_id |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 474 | with_scopes.assert_called_once_with(MOCK_CREDENTIALS, scopes) |
James Wilson | 6e0781b | 2018-12-20 20:38:52 -0500 | [diff] [blame] | 475 | |
| 476 | |
| 477 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 478 | "google.auth._default._get_explicit_environ_credentials", |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 479 | return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id), |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 480 | autospec=True, |
| 481 | ) |
Bu Sun Kim | ab2be5d | 2020-07-15 16:49:27 -0700 | [diff] [blame] | 482 | def test_default_quota_project(with_quota_project): |
| 483 | credentials, project_id = _default.default(quota_project_id="project-foo") |
| 484 | |
| 485 | MOCK_CREDENTIALS.with_quota_project.assert_called_once_with("project-foo") |
| 486 | assert project_id == mock.sentinel.project_id |
| 487 | |
| 488 | |
| 489 | @mock.patch( |
| 490 | "google.auth._default._get_explicit_environ_credentials", |
| 491 | return_value=(MOCK_CREDENTIALS, mock.sentinel.project_id), |
| 492 | autospec=True, |
| 493 | ) |
James Wilson | 6e0781b | 2018-12-20 20:38:52 -0500 | [diff] [blame] | 494 | def test_default_no_app_engine_compute_engine_module(unused_get): |
| 495 | """ |
| 496 | google.auth.compute_engine and google.auth.app_engine are both optional |
| 497 | to allow not including them when using this package. This verifies |
| 498 | that default fails gracefully if these modules are absent |
| 499 | """ |
| 500 | import sys |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 501 | |
| 502 | with mock.patch.dict("sys.modules"): |
| 503 | sys.modules["google.auth.compute_engine"] = None |
| 504 | sys.modules["google.auth.app_engine"] = None |
Bu Sun Kim | 3dda7b2 | 2020-07-09 10:39:39 -0700 | [diff] [blame] | 505 | assert _default.default() == (MOCK_CREDENTIALS, mock.sentinel.project_id) |