diff --git a/devops/gc/pipeline/override-stages.yml b/devops/gc/pipeline/override-stages.yml index bc1e767490f8bd4991fc779a1d83402a0978613c..29f7b7d16099b6d925361261ed5afda01bf182bb 100644 --- a/devops/gc/pipeline/override-stages.yml +++ b/devops/gc/pipeline/override-stages.yml @@ -8,10 +8,12 @@ variables: gc-test-python: variables: VIRTUAL_SERVICE_HOST_NAME: $GC_UNIT_HOSTNAME + GOOGLE_APPLICATION_CREDENTIALS: $GC_INTEGRATION_TESTER_ENCODE gc-dev2-test-python: variables: VIRTUAL_SERVICE_HOST_NAME: $GC_UNIT_HOSTNAME + GOOGLE_APPLICATION_CREDENTIALS: $GC_INTEGRATION_TESTER_ENCODE gc-baremetal-test-python: variables: diff --git a/testing/unit_test_gc/jwt_client.py b/testing/unit_test_gc/jwt_client.py index eee5cad77645aa8d328f81741786c88fbb65eb8c..979f21cf1b2bcd4b3f66ae43c2a2003ac68935fc 100644 --- a/testing/unit_test_gc/jwt_client.py +++ b/testing/unit_test_gc/jwt_client.py @@ -14,57 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys - -def main(argv): - pass - - -if __name__ == '__main__': - main(sys.argv) -import http.client -import time -import google.auth.crypt -import google.auth.jwt -import json -import base64 -import os -from urllib.parse import urlencode - -def generate_jwt(): - INTEGRATION_TESTER = str(os.getenv('INTEGRATION_TESTER')) - decoded_user_key = base64.b64decode(INTEGRATION_TESTER).decode("utf-8") - signer = google.auth.crypt.RSASigner.from_string(json.loads(decoded_user_key)['private_key']) - integration_test_service_account = json.loads(decoded_user_key)['client_email'] - now = int(time.time()) - - payload = { - 'iat': now, - "exp": now + 3600, - 'iss': integration_test_service_account, - "target_audience": 'osdu', - "aud": "https://www.googleapis.com/oauth2/v4/token" - } - - jwt = google.auth.jwt.encode(signer, payload) - - return jwt +import google +import google.auth +from google.auth.transport.requests import Request def get_id_token(): try: - jwt = generate_jwt() - params = urlencode({ - 'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer', - 'assertion': jwt - }) - headers = {"Content-Type": "application/x-www-form-urlencoded"} - conn = http.client.HTTPSConnection("www.googleapis.com") - conn.request("POST", "/oauth2/v4/token", params, headers) - res = json.loads(conn.getresponse().read().decode('utf-8')) - conn.close() - return res['id_token'] + credentials, _ = google.auth.default(scopes=["email", "openid", "profile"]) + credentials.refresh(Request()) + token = credentials.token + return token except (IOError, KeyError, ValueError) as e: print (e) raise ValueError('Bearer token could not be obtained - missing service account file? ' + repr(e) + ' ' + str(e)) diff --git a/testing/unit_test_gc/run-integration-tests.sh b/testing/unit_test_gc/run-integration-tests.sh old mode 100644 new mode 100755 index 7c2eebe79fd38f5afc319286bf315b5bab00dda7..080617c0ef033c1be9b265ae2d87a3cab95d94b8 --- a/testing/unit_test_gc/run-integration-tests.sh +++ b/testing/unit_test_gc/run-integration-tests.sh @@ -22,13 +22,13 @@ python3 -m pip install -r requirements.txt # Run tests export API_VER="v2" echo ***RUNNING UNIT API $API_VER TESTS*** -python3 run_test.py +python3 -W ignore run_test.py TEST_STATUS_V2=$? echo ***FINISHED UNIT API $API_VER TESTS*** echo "" export API_VER="v3" echo ***RUNNING UNIT API $API_VER TESTS*** -python3 run_test.py +python3 -W ignore run_test.py TEST_STATUS_V3=$? echo ***FINISHED UNIT API $API_VER TESTS***