|
| 1 | +from behave import * |
| 2 | +import requests |
| 3 | +import json |
| 4 | + |
| 5 | + |
| 6 | +@when("the admin creates an identity provider configuration") |
| 7 | +def create_idp(context): |
| 8 | + base_url = context.config.userdata.get("base_url") |
| 9 | + headers = {"Authorization": f"Bearer {context.access_token}"} |
| 10 | + url = base_url + "/config/idp/open-ids" |
| 11 | + response = requests.get(url, verify=False, headers=headers) |
| 12 | + response_json = json.loads(response.content) |
| 13 | + if len(response_json["idps"]) > 0: |
| 14 | + idp_id = response_json["idps"][0]["id"] |
| 15 | + url = base_url + "/config/idp/open-id/" + idp_id |
| 16 | + response = requests.delete(url, verify=False, headers=headers) |
| 17 | + data = { |
| 18 | + "idp": { |
| 19 | + "issuerUrl": "http://keycloak:8080/realms/3pp-application", |
| 20 | + "authorisationUrl": "http://keycloak:8080/realms/3pp-application/protocol/openid-connect/auth", |
| 21 | + "tokenUrl": "http://keycloak:8080/realms/3pp-application/protocol/openid-connect/token", |
| 22 | + "logoutUrl": "http://keycloak:8080/realms/3pp-application/protocol/openid-connect/logout", |
| 23 | + "clientId": "3pp", |
| 24 | + "clientSecret": "0c7v1bd2M6a85MUDda2hKKY4tuZTxOrW", |
| 25 | + "jwksUrl": "http://keycloak:8080/realms/3pp-application/protocol/openid-connect/certs", |
| 26 | + "userInfoUrl": "http://keycloak:8080/realms/3pp-application/protocol/openid-connect/userinfo", |
| 27 | + "defaultScope": "openid", |
| 28 | + } |
| 29 | + } |
| 30 | + base_url = context.config.userdata.get("base_url") |
| 31 | + headers = {"Authorization": f"Bearer {context.access_token}"} |
| 32 | + url = base_url + "/config/idp/open-id" |
| 33 | + response = requests.post(url, json=data, verify=False, headers=headers) |
| 34 | + context.response = response |
| 35 | + |
| 36 | + |
| 37 | +@then("the identity provider configuration should be created") |
| 38 | +def is_idp_created(context): |
| 39 | + response_json = json.loads(context.response.content) |
| 40 | + idp_id = response_json["idp"]["id"] |
| 41 | + context.config.userdata.idp_id = idp_id |
| 42 | + assert context.response.status_code == 200 |
| 43 | + |
| 44 | + |
| 45 | +@when("the admin reads an identity provider configuration") |
| 46 | +def read_idp(context): |
| 47 | + base_url = context.config.userdata.get("base_url") |
| 48 | + headers = {"Authorization": f"Bearer {context.access_token}"} |
| 49 | + idp_id = context.config.userdata.idp_id |
| 50 | + url = base_url + "/config/idp/open-id/" + idp_id |
| 51 | + response = requests.get(url, verify=False, headers=headers) |
| 52 | + context.response = response |
| 53 | + |
| 54 | + |
| 55 | +@then("the admin should be able to view the identity provider configuration") |
| 56 | +def view_idp(context): |
| 57 | + assert context.response.status_code == 200 |
| 58 | + |
| 59 | + |
| 60 | +@when("the admin updates an identity provider configuration") |
| 61 | +def updates_idp(context): |
| 62 | + data = { |
| 63 | + "idp": { |
| 64 | + "issuerUrl": "http://keycloak:9090/realms/3pp-application", |
| 65 | + "authorisationUrl": "http://keycloak:9090/realms/3pp-application/protocol/openid-connect/auth", |
| 66 | + "tokenUrl": "http://keycloak:9090/realms/3pp-application/protocol/openid-connect/token", |
| 67 | + "logoutUrl": "http://keycloak:9090/realms/3pp-application/protocol/openid-connect/logout", |
| 68 | + "clientId": "3pp", |
| 69 | + "clientSecret": "0c7v1bd2M6a85MUDda2hKKY4tuZTxOrW", |
| 70 | + "jwksUrl": "http://keycloak:9090/realms/3pp-application/protocol/openid-connect/certs", |
| 71 | + "userInfoUrl": "http://keycloak:9090/realms/3pp-application/protocol/openid-connect/userinfo", |
| 72 | + "defaultScope": "openid", |
| 73 | + } |
| 74 | + } |
| 75 | + base_url = context.config.userdata.get("base_url") |
| 76 | + headers = {"Authorization": f"Bearer {context.access_token}"} |
| 77 | + idp_id = context.config.userdata.idp_id |
| 78 | + url = base_url + "/config/idp/open-id/" + idp_id |
| 79 | + response = requests.put(url, json=data, verify=False, headers=headers) |
| 80 | + context.response = response |
| 81 | + |
| 82 | + |
| 83 | +@then("the identity provider configuration should be updated") |
| 84 | +def is_idp_updated(context): |
| 85 | + assert context.response.status_code == 200 |
| 86 | + |
| 87 | + |
| 88 | +@when("the admin deletes an identity provider configuration") |
| 89 | +def deletes_idp(context): |
| 90 | + base_url = context.config.userdata.get("base_url") |
| 91 | + headers = {"Authorization": f"Bearer {context.access_token}"} |
| 92 | + idp_id = context.config.userdata.idp_id |
| 93 | + url = base_url + "/config/idp/open-id/" + idp_id |
| 94 | + response = requests.delete(url, verify=False, headers=headers) |
| 95 | + context.response = response |
| 96 | + |
| 97 | + |
| 98 | +@then("the identity provider configuration should be deleted") |
| 99 | +def is_idp_deleted(context): |
| 100 | + assert context.response.status_code == 200 |
| 101 | + |
| 102 | + |
| 103 | +@when("the admin bulk onboards individuals using a CSV file upload") |
| 104 | +def bulk_onboard_of_individuals(context): |
| 105 | + base_url = context.config.userdata.get("base_url") |
| 106 | + |
| 107 | + headers = { |
| 108 | + "Authorization": f"Bearer {context.access_token}" |
| 109 | + } |
| 110 | + csv_file_path = "assets/bulk_adding_of_individuals.csv" |
| 111 | + |
| 112 | + files = { |
| 113 | + "individuals": ("bulk_adding_of_individuals.csv", open(csv_file_path, "rb")), |
| 114 | + } |
| 115 | + url = base_url + "/config/individual/upload" |
| 116 | + response = requests.post(url, files=files, verify=False, headers=headers) |
| 117 | + context.response = response |
| 118 | + |
| 119 | + |
| 120 | +@then("the individuals should be created in the consent BB identity provider") |
| 121 | +def is_individuals_created(context): |
| 122 | + assert context.response.status_code == 200 |
0 commit comments