|
118 | 118 | " apim_service_id = output.get('apimServiceId', 'APIM Service Id')\n", |
119 | 119 | " apim_gateway_url = output.get('apimResourceGatewayURL', 'APIM API Gateway URL')\n", |
120 | 120 | " afd_endpoint_url = output.get('fdeSecureUrl', 'Front Door Endpoint URL')\n", |
| 121 | + " apim_apis = output.getJson('apiOutputs', 'APIs')\n", |
121 | 122 | "\n", |
122 | 123 | "utils.print_ok('Deployment completed')\n" |
123 | 124 | ] |
|
187 | 188 | "from apimrequests import ApimRequests\n", |
188 | 189 | "from apimtesting import ApimTesting\n", |
189 | 190 | "\n", |
190 | | - "reqs = ApimRequests(apim_gateway_url)\n", |
191 | 191 | "tests = ApimTesting(\"AFD-APIM-PE Tests (Pre-Lockdown)\", deployment, deployment)\n", |
192 | 192 | "\n", |
| 193 | + "api_subscription_key = apim_apis[0]['subscriptionPrimaryKey']\n", |
| 194 | + "reqs = ApimRequests(apim_gateway_url, api_subscription_key)\n", |
| 195 | + "\n", |
193 | 196 | "utils.print_message('Calling Hello World (Root) API via API Management Gateway URL. Expect 200 (if run before disabling API Management public network access).')\n", |
194 | 197 | "output = reqs.singleGet('/')\n", |
195 | 198 | "tests.verify(output, 'Hello World from API Management!')\n", |
|
228 | 231 | " raise SystemExit('Deployment failed')\n", |
229 | 232 | " \n", |
230 | 233 | "if output.success and output.json_data:\n", |
231 | | - " apim_gateway_url = output.get('apimResourceGatewayURL', 'APIM API Gateway URL')\n", |
232 | 234 | " afd_endpoint_url = output.get('fdeSecureUrl', 'Front Door Endpoint URL')\n", |
| 235 | + " apim_gateway_url = output.get('apimResourceGatewayURL', 'APIM API Gateway URL')\n", |
| 236 | + " apim_apis = output.getJson('apiOutputs', 'APIs')\n", |
233 | 237 | "\n", |
234 | 238 | "utils.print_ok('Deployment completed')\n" |
235 | 239 | ] |
|
250 | 254 | "outputs": [], |
251 | 255 | "source": [ |
252 | 256 | "import utils\n", |
253 | | - "import json\n", |
254 | 257 | "from apimrequests import ApimRequests\n", |
255 | 258 | "from apimtesting import ApimTesting\n", |
256 | 259 | "\n", |
257 | | - "reqsApim = ApimRequests(apim_gateway_url)\n", |
258 | | - "reqsAfd = ApimRequests(afd_endpoint_url)\n", |
259 | 260 | "tests = ApimTesting(\"AFD-APIM-PE Tests (Post-Lockdown)\", deployment, deployment)\n", |
260 | 261 | "\n", |
| 262 | + "api_subscription_key = apim_apis[0]['subscriptionPrimaryKey']\n", |
| 263 | + "reqsApim = ApimRequests(apim_gateway_url, api_subscription_key)\n", |
| 264 | + "reqsAfd = ApimRequests(afd_endpoint_url, api_subscription_key)\n", |
| 265 | + "\n", |
261 | 266 | "# 1) Unsuccessful call to APIM Gateway URL (should fail with 403 Forbidden)\n", |
262 | 267 | "output = reqsApim.singleGet('/', msg = '1) Calling Hello World (Root) API via API Management Gateway URL. Expect 403 as APIM public access is disabled now.')\n", |
263 | | - "tests.verify(json.loads(output)['statusCode'], 403)\n", |
| 268 | + "outputJson = utils.get_json(output)\n", |
| 269 | + "tests.verify(outputJson['statusCode'], 403)\n", |
264 | 270 | "\n", |
265 | 271 | "# 2) Successful call to Front Door (200)\n", |
266 | 272 | "output = reqsAfd.singleGet('/', msg = '2) Calling Hello World (Root) API via Azure Front Door. Expect 200.')\n", |
267 | 273 | "tests.verify(output, 'Hello World from API Management!')\n", |
268 | 274 | "\n", |
269 | 275 | "# 3) Successful calls to Front Door -> APIM -> ACA (200)\n", |
270 | 276 | "if use_ACA:\n", |
| 277 | + " reqsAfd = ApimRequests(afd_endpoint_url, apim_apis[1]['subscriptionPrimaryKey'])\n", |
271 | 278 | " output = reqsAfd.singleGet('/aca-1', msg = '3) Calling Hello World (ACA 1) API via Azure Front Door. Expect 200.')\n", |
272 | 279 | " tests.verify(output, 'Hello World!')\n", |
273 | 280 | "\n", |
| 281 | + " reqsAfd = ApimRequests(afd_endpoint_url, apim_apis[2]['subscriptionPrimaryKey'])\n", |
274 | 282 | " output = reqsAfd.singleGet('/aca-2', msg = '4) Calling Hello World (ACA 2) API via Azure Front Door. Expect 200.')\n", |
275 | 283 | " tests.verify(output, 'Hello World!')\n", |
276 | 284 | "\n", |
| 285 | + " reqsAfd = ApimRequests(afd_endpoint_url, apim_apis[3]['subscriptionPrimaryKey'])\n", |
277 | 286 | " output = reqsAfd.singleGet('/aca-pool', msg = '5) Calling Hello World (ACA Pool) API via Azure Front Door. Expect 200.')\n", |
278 | 287 | " tests.verify(output, 'Hello World!')\n", |
279 | 288 | "else:\n", |
280 | 289 | " utils.print_message('ACA APIs were not created. Skipping ACA API calls.', blank_above = True)\n", |
281 | 290 | "\n", |
| 291 | + "# 4) Unsuccessful call to Front Door without API subscription key (should fail with 401 Unauthorized)\n", |
| 292 | + "reqsNoApiSubscription = ApimRequests(afd_endpoint_url)\n", |
| 293 | + "output = reqsNoApiSubscription.singleGet('/', msg = 'Calling Hello World (Root) API without API subscription key. Expect 401.')\n", |
| 294 | + "outputJson = utils.get_json(output)\n", |
| 295 | + "tests.verify(outputJson['statusCode'], 401)\n", |
| 296 | + "tests.verify(outputJson['message'], 'Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API.')\n", |
| 297 | + "\n", |
282 | 298 | "tests.print_summary()\n", |
283 | 299 | "\n", |
284 | 300 | "utils.print_ok('All done!')" |
|
0 commit comments