diff options
author | chojoyce <chojoyce@google.com> | 2021-12-24 11:54:02 +0800 |
---|---|---|
committer | chojoyce <chojoyce@google.com> | 2022-01-04 17:44:09 +0800 |
commit | 8c673285f7eda845e99cc693855307b589b4ce7f (patch) | |
tree | c5f0cf22de9f5323689a83dfef06907864fdd028 /system_tests/system_tests_sync/test_urllib3.py | |
parent | d75f43fb5f091b4542704d5ebed57e9dc920fae5 (diff) | |
parent | e6278a815895e050e57fc516f086b4bc89a0864a (diff) | |
download | google-auth-library-python-8c673285f7eda845e99cc693855307b589b4ce7f.tar.gz |
Merge platform/external/python/google-auth-library-python v2.3.3
Inital commit of google-auth-library-python 2.3.3 with history
Added:
- Android.bp
- MODULE_LICENSE_APACHE2
- NOTICE
- METADATA
Bug: 154879379
Bug: 209653360
Test: None
Change-Id: Id05bf27857ef5ce5ec9010fc0507acc9b994530f
Diffstat (limited to 'system_tests/system_tests_sync/test_urllib3.py')
-rw-r--r-- | system_tests/system_tests_sync/test_urllib3.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/system_tests/system_tests_sync/test_urllib3.py b/system_tests/system_tests_sync/test_urllib3.py new file mode 100644 index 0000000..1932e19 --- /dev/null +++ b/system_tests/system_tests_sync/test_urllib3.py @@ -0,0 +1,44 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import google.auth +import google.auth.credentials +import google.auth.transport.requests +from google.oauth2 import service_account + + +def test_authorized_session_with_service_account_and_self_signed_jwt(): + credentials, project_id = google.auth.default() + + credentials = credentials.with_scopes( + scopes=[], + default_scopes=["https://www.googleapis.com/auth/pubsub"], + ) + + http = google.auth.transport.urllib3.AuthorizedHttp( + credentials=credentials, default_host="pubsub.googleapis.com" + ) + + # List Pub/Sub Topics through the REST API + # https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/list + response = http.urlopen( + method="GET", + url="https://pubsub.googleapis.com/v1/projects/{}/topics".format(project_id) + ) + + assert response.status == 200 + + # Check that self-signed JWT was created and is being used + assert credentials._jwt_credentials is not None + assert credentials._jwt_credentials.token == credentials.token |