Skip to content
Snippets Groups Projects
Commit 49cfd3be authored by Yan Sushchynski (EPAM)'s avatar Yan Sushchynski (EPAM) Committed by Oleksandr Kosse (EPAM)
Browse files

fix: GC test token

parent 5c907106
No related branches found
No related tags found
1 merge request!346fix: GC test token
......@@ -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:
......
......@@ -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))
......
......@@ -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***
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment