|
62 | 62 | "products: List[Product] = [\n", |
63 | 63 | " Product(hr_product_name, 'Human Resources', \n", |
64 | 64 | " 'Product for Human Resources APIs providing access to employee data, organizational structure, benefits information, and HR management services. Includes JWT-based authentication for HR members.', \n", |
65 | | - " 'published', False, False, pol_hr_product)\n", |
| 65 | + " 'published', True, False, pol_hr_product)\n", |
66 | 66 | "]\n", |
67 | 67 | "\n", |
68 | 68 | "# 6) Define the APIs and their operations and policies\n", |
|
76 | 76 | "hr_employees_api_path = f'/{api_prefix}employees'\n", |
77 | 77 | "hr_employees_get = GET_APIOperation('Gets the employees', pol_hr_get,)\n", |
78 | 78 | "hr_employees_post = POST_APIOperation('Creates a new employee', pol_hr_post)\n", |
79 | | - "hr_employees = API(f'{api_prefix}Employees', 'Employees Pro', hr_employees_api_path, 'This is a Human Resources API for employee information', \n", |
| 79 | + "hr_employees = API(f'{api_prefix}Employees', 'Employees Pro', hr_employees_api_path, 'This is a Human Resources API for employee information', pol_hr_all_operations_pro,\n", |
80 | 80 | " operations = [hr_employees_get, hr_employees_post], tags = tags, productNames = [hr_product_name], subscriptionRequired = False)\n", |
81 | 81 | "\n", |
82 | 82 | "# Benefits (HR)\n", |
|
123 | 123 | "if output.json_data:\n", |
124 | 124 | " apim_name = output.get('apimServiceName', 'APIM Service Name')\n", |
125 | 125 | " apim_gateway_url = output.get('apimResourceGatewayURL', 'APIM API Gateway URL')\n", |
| 126 | + " apim_products = output.getJson('productOutputs', 'Products')\n", |
126 | 127 | "\n", |
127 | 128 | "utils.print_ok('Deployment completed')" |
128 | 129 | ] |
|
151 | 152 | "from users import UserHelper\n", |
152 | 153 | "from authfactory import AuthFactory\n", |
153 | 154 | "\n", |
| 155 | + "# Test the function\n", |
| 156 | + "hr_product_apim_subscription_key = apim_products[0]['subscriptionPrimaryKey']\n", |
| 157 | + "\n", |
154 | 158 | "tests = ApimTesting(\"AuthX-Pro Sample Tests\", sample_folder, deployment)\n", |
155 | 159 | "\n", |
156 | 160 | "# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door. If so, assume that APIM is not directly accessible and use the Front Door URL instead.\n", |
|
162 | 166 | "print(f'\\nJWT token for HR Admin:\\n{encoded_jwt_token_hr_admin}') # this value is used to call the APIs via APIM\n", |
163 | 167 | "\n", |
164 | 168 | "# Set up an APIM requests object with the JWT token\n", |
165 | | - "reqsApimAdmin = ApimRequests(endpoint_url)\n", |
| 169 | + "reqsApimAdmin = ApimRequests(endpoint_url, hr_product_apim_subscription_key)\n", |
166 | 170 | "reqsApimAdmin.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_admin}'\n", |
167 | 171 | "\n", |
168 | 172 | "# Call APIM\n", |
|
184 | 188 | "print(f'\\nJWT token for HR Associate:\\n{encoded_jwt_token_hr_associate}') # this value is used to call the APIs via APIM\n", |
185 | 189 | "\n", |
186 | 190 | "# Set up an APIM requests object with the JWT token\n", |
187 | | - "reqsApimAssociate = ApimRequests(endpoint_url)\n", |
| 191 | + "reqsApimAssociate = ApimRequests(endpoint_url, hr_product_apim_subscription_key)\n", |
188 | 192 | "reqsApimAssociate.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_associate}'\n", |
189 | 193 | "\n", |
190 | 194 | "# Call APIM\n", |
|
200 | 204 | "output = reqsApimAssociate.singlePost(hr_benefits_api_path, msg = 'Calling POST Benefits API via API Management Gateway URL. Expect 403.')\n", |
201 | 205 | "tests.verify(output, 'Access denied - no matching roles found')\n", |
202 | 206 | "\n", |
| 207 | + "# 3) HR Administrator but no HR product subscription key (api-key)\n", |
| 208 | + "# Set up an APIM requests object with the JWT token\n", |
| 209 | + "reqsApimAdminNoHrProduct = ApimRequests(endpoint_url)\n", |
| 210 | + "reqsApimAdminNoHrProduct.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_admin}'\n", |
| 211 | + "\n", |
| 212 | + "# Call APIM\n", |
| 213 | + "output = reqsApimAdminNoHrProduct.singleGet(hr_employees_api_path, msg = 'Calling GET Employees API via API Management Gateway URL but with no HR product subscription key. Expect 403.')\n", |
| 214 | + "tests.verify(output, 'Access denied - no matching product found')\n", |
| 215 | + "\n", |
| 216 | + "# 4) HR Associate but no HR product subscription key (api-key)\n", |
| 217 | + "# Set up an APIM requests object with the JWT token\n", |
| 218 | + "reqsApimAssociateNoHrProduct = ApimRequests(endpoint_url)\n", |
| 219 | + "reqsApimAssociateNoHrProduct.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_associate}'\n", |
| 220 | + "\n", |
| 221 | + "# Call APIM\n", |
| 222 | + "output = reqsApimAssociateNoHrProduct.singleGet(hr_employees_api_path, msg = 'Calling GET Employees API via API Management Gateway URL but with no HR product subscription key. Expect 403.')\n", |
| 223 | + "tests.verify(output, 'Access denied - no matching product found')\n", |
| 224 | + "\n", |
203 | 225 | "tests.print_summary()\n", |
204 | 226 | "\n", |
205 | 227 | "utils.print_ok('All done!')" |
|
0 commit comments