From 2ebea3d4487bc97de12829c284451c2c5f6e6f13 Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Fri, 5 Jun 2020 20:20:24 +0800 Subject: [PATCH 1/5] Add tests for az rest with Microsoft Graph --- .../recordings/test_rest_microsoft_graph.yaml | 573 ++++++++++++++++++ .../util/tests/latest/test_rest.py | 77 +++ 2 files changed, 650 insertions(+) create mode 100644 src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml diff --git a/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml b/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml new file mode 100644 index 00000000000..ab2353e7f7b --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml @@ -0,0 +1,573 @@ +interactions: +- request: + body: '{"displayName": "az-rest-test-app000001"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '44' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/applications + response: + body: + string: '{"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications/$entity", + "id": "2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c", "deletedDateTime": null, "appId": + "f017bab3-0f27-4953-b9bd-24ca5af298bc", "applicationTemplateId": null, "createdDateTime": + "2020-06-05T12:18:14.027154Z", "displayName": "az-rest-test-app000001", "groupMembershipClaims": + null, "identifierUris": [], "isDeviceOnlyAuthSupported": null, "isFallbackPublicClient": + null, "optionalClaims": null, "publisherDomain": "AzureSDKTeam.onmicrosoft.com", + "signInAudience": "AzureADandPersonalMicrosoftAccount", "tags": [], "tokenEncryptionKeyId": + null, "spa": {"redirectUris": []}, "addIns": [], "api": {"acceptMappedClaims": + null, "knownClientApplications": [], "requestedAccessTokenVersion": 2, "oauth2PermissionScopes": + [], "preAuthorizedApplications": []}, "appRoles": [], "info": {"logoUrl": + null, "marketingUrl": null, "privacyStatementUrl": null, "supportUrl": null, + "termsOfServiceUrl": null}, "keyCredentials": [], "parentalControlSettings": + {"countriesBlockedForMinors": [], "legalAgeGroupRule": "Allow"}, "passwordCredentials": + [], "publicClient": {"redirectUris": []}, "requiredResourceAccess": [], "web": + {"homePageUrl": null, "logoutUrl": null, "redirectUris": [], "implicitGrantSettings": + {"enableAccessTokenIssuance": false, "enableIdTokenIssuance": false}}}' + headers: + cache-control: + - private + content-length: + - '1259' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Fri, 05 Jun 2020 12:18:17 GMT + location: + - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c/Microsoft.DirectoryServices.Application + odata-version: + - '4.0' + request-id: + - 944c880d-05e3-4a19-a869-f6e023988e51 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_20"}}' + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --uri + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#applications/$entity","id":"2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c","deletedDateTime":null,"appId":"f017bab3-0f27-4953-b9bd-24ca5af298bc","applicationTemplateId":null,"createdDateTime":"2020-06-05T12:18:14Z","displayName":"az-rest-test-app000001","groupMembershipClaims":null,"identifierUris":[],"isDeviceOnlyAuthSupported":null,"isFallbackPublicClient":null,"optionalClaims":null,"publisherDomain":"AzureSDKTeam.onmicrosoft.com","signInAudience":"AzureADandPersonalMicrosoftAccount","tags":[],"tokenEncryptionKeyId":null,"spa":{"redirectUris":[]},"addIns":[],"api":{"acceptMappedClaims":null,"knownClientApplications":[],"requestedAccessTokenVersion":2,"oauth2PermissionScopes":[],"preAuthorizedApplications":[]},"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"parentalControlSettings":{"countriesBlockedForMinors":[],"legalAgeGroupRule":"Allow"},"passwordCredentials":[],"publicClient":{"redirectUris":[]},"requiredResourceAccess":[],"web":{"homePageUrl":null,"logoutUrl":null,"redirectUris":[],"implicitGrantSettings":{"enableAccessTokenIssuance":false,"enableIdTokenIssuance":false}}}' + headers: + cache-control: + - private + content-length: + - '1252' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Fri, 05 Jun 2020 12:18:18 GMT + odata-version: + - '4.0' + request-id: + - 57cc3f6d-1350-4ad8-a1da-0b87848866da + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_5"}}' + status: + code: 200 + message: OK +- request: + body: '{"web":{"redirectUris":["https://myapp.com"]}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '46' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: PATCH + uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Fri, 05 Jun 2020 12:18:21 GMT + request-id: + - b6d028e0-31b4-44c4-b21a-10b01c910a69 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_25"}}' + status: + code: 204 + message: No Content +- request: + body: '{"passwordCredential": {"displayName": "Password friendly name"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '65' + Content-Type: + - application/json + ParameterSetName: + - --method --uri --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c/addPassword + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential","customKeyIdentifier":null,"displayName":"Password + friendly name","endDateTime":"2022-06-05T12:18:22.2955982Z","hint":"~~b","keyId":"8493b406-ea97-4aff-a99e-ddca1acab2b9","secretText":"~~bbDW3Gm8Lf_uCO279~dFR83G5mS2-FJr","startDateTime":"2020-06-05T12:18:22.2955982Z"}' + headers: + cache-control: + - private + content-length: + - '366' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Fri, 05 Jun 2020 12:18:22 GMT + location: + - https://graph.microsoft.com + odata-version: + - '4.0' + request-id: + - 34c07bd2-3f79-49b4-8b59-4ac338077154 + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_14"}}' + status: + code: 200 + message: OK +- request: + body: '{"appId": "f017bab3-0f27-4953-b9bd-24ca5af298bc"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '49' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/serviceprincipals + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"f99481a7-ccf2-4885-a5e9-aa977ff09f56","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"f017bab3-0f27-4953-b9bd-24ca5af298bc","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["f017bab3-0f27-4953-b9bd-24ca5af298bc"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' + headers: + cache-control: + - private + content-length: + - '1036' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Fri, 05 Jun 2020 12:18:23 GMT + location: + - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/f99481a7-ccf2-4885-a5e9-aa977ff09f56/Microsoft.DirectoryServices.ServicePrincipal + odata-version: + - '4.0' + request-id: + - 8e5d87c5-48f0-489a-9892-749a824a3b2d + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_1"}}' + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --uri + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"f99481a7-ccf2-4885-a5e9-aa977ff09f56","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"f017bab3-0f27-4953-b9bd-24ca5af298bc","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["f017bab3-0f27-4953-b9bd-24ca5af298bc"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' + headers: + cache-control: + - private + content-length: + - '1036' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Fri, 05 Jun 2020 12:18:24 GMT + odata-version: + - '4.0' + request-id: + - 4dfea8dd-f70c-4cfb-8a49-69284262a390 + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_5"}}' + status: + code: 200 + message: OK +- request: + body: '{"appRoleAssignmentRequired": true}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '35' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: PATCH + uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Fri, 05 Jun 2020 12:18:25 GMT + request-id: + - ee15d3f6-be46-4324-9760-0de473af830d + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_15"}}' + status: + code: 204 + message: No Content +- request: + body: '{"passwordCredential": {"displayName": "Password friendly name"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '65' + Content-Type: + - application/json + ParameterSetName: + - --method --uri --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56/addPassword + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential","customKeyIdentifier":null,"displayName":"Password + friendly name","endDateTime":"2022-06-05T12:18:27.0666616Z","hint":null,"keyId":"f39d2dc3-77bb-4594-9ad6-5ed186c19181","secretText":"5O.2.DO09oK8F2_.0efKp953TZAXExcFg.","startDateTime":"2020-06-05T12:18:27.0666616Z"}' + headers: + cache-control: + - private + content-length: + - '365' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Fri, 05 Jun 2020 12:18:27 GMT + location: + - https://graph.microsoft.com + odata-version: + - '4.0' + request-id: + - 1c801061-9496-47d7-9b1b-834da3f811a6 + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_4"}}' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: DELETE + uri: https://graph.microsoft.com/v1.0/serviceprincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Fri, 05 Jun 2020 12:18:28 GMT + request-id: + - 0f04b047-f842-4c35-8782-41de06f3503e + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_12"}}' + status: + code: 204 + message: No Content +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + response: + body: + string: "{\r\n \"error\": {\r\n \"code\": \"Request_ResourceNotFound\",\r\n + \ \"message\": \"Resource 'f99481a7-ccf2-4885-a5e9-aa977ff09f56' does not + exist or one of its queried reference-property objects are not present.\",\r\n + \ \"innerError\": {\r\n \"request-id\": \"10867b9f-d748-4761-8dd8-5dd938db7234\",\r\n + \ \"date\": \"2020-06-05T12:18:29\"\r\n }\r\n }\r\n}" + headers: + cache-control: + - private + content-length: + - '338' + content-type: + - application/json + date: + - Fri, 05 Jun 2020 12:18:28 GMT + request-id: + - 10867b9f-d748-4761-8dd8-5dd938db7234 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_29"}}' + status: + code: 404 + message: Not Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: DELETE + uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Fri, 05 Jun 2020 12:18:35 GMT + request-id: + - f95b8524-31af-4d03-87c5-481c180ab562 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_26"}}' + status: + code: 204 + message: No Content +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + response: + body: + string: "{\r\n \"error\": {\r\n \"code\": \"Request_ResourceNotFound\",\r\n + \ \"message\": \"Resource '2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c' does not + exist or one of its queried reference-property objects are not present.\",\r\n + \ \"innerError\": {\r\n \"request-id\": \"8290f49b-7d5b-478d-bd6c-a6900403300f\",\r\n + \ \"date\": \"2020-06-05T12:18:36\"\r\n }\r\n }\r\n}" + headers: + cache-control: + - private + content-length: + - '338' + content-type: + - application/json + date: + - Fri, 05 Jun 2020 12:18:36 GMT + request-id: + - 8290f49b-7d5b-478d-bd6c-a6900403300f + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_13"}}' + status: + code: 404 + message: Not Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - -m -u + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/applications?$filter=startswith(displayName,%20'az-rest-test-app') + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#applications","value":[]}' + headers: + cache-control: + - private + content-length: + - '87' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Fri, 05 Jun 2020 12:18:37 GMT + odata-version: + - '4.0' + request-id: + - 4e2198f1-0932-4a64-95e6-fe34f217aee5 + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_22"}}' + status: + code: 200 + message: OK +version: 1 diff --git a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py index 4e6abc55b9b..bf39a9a8e7f 100644 --- a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py +++ b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py @@ -77,6 +77,83 @@ def test_rest(self, resource_group): # https://docs.microsoft.com/en-us/rest/api/storagerp/storageaccounts/delete self.cmd('az rest -m DELETE -u "/subscriptions/{{subscriptionId}}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{sa}?api-version=2019-06-01"') + def test_rest_microsoft_graph(self): + display_name_prefix = "az-rest-test-app" + self.kwargs.update({ + 'display_name_prefix': display_name_prefix, + 'display_name': self.create_random_name(display_name_prefix, length=25) + }) + + # Create application + # https://docs.microsoft.com/en-us/graph/api/application-post-applications?view=graph-rest-1.0&tabs=http + # Escape single quote for `shlex` and curly braces for `format` + app = self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/applications --body \'{{"displayName": "{display_name}"}}\'', + checks=[ + self.check('displayName', '{display_name}') + ]).get_output_in_json() + + self.kwargs["app_object_id"] = app["id"] + self.kwargs["app_id"] = app["appId"] + + # Get application + # https://docs.microsoft.com/en-us/graph/api/application-get?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method GET --uri https://graph.microsoft.com/v1.0/applications/{app_object_id}', + checks=[self.check('displayName', '{display_name}')]) + + # Update application + # https://docs.microsoft.com/en-us/graph/api/application-update?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method PATCH --url https://graph.microsoft.com/v1.0/applications/{app_object_id} --body \'{{"web":{{"redirectUris":["https://myapp.com"]}}}}\'') + + # application: addPassword + # https://docs.microsoft.com/en-us/graph/api/application-addpassword?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method POST --uri https://graph.microsoft.com/v1.0/applications/{app_object_id}/addPassword ' + '--body \'{{"passwordCredential": {{"displayName": "Password friendly name"}}}}\'', + checks=[self.check('displayName', "Password friendly name")]) + + # Create servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-post-serviceprincipals?view=graph-rest-1.0&tabs=http + sp = self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/serviceprincipals --body \'{{"appId": "{app_id}"}}\'').get_output_in_json() + self.kwargs["sp_object_id"] = sp["id"] + + # Get servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-get?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method GET --uri https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}', + checks=[self.check('appId', '{app_id}'), + self.check('id', '{sp_object_id}')]) + + # Update servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-update?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method PATCH --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id} ' + '--body \'{{"appRoleAssignmentRequired": true}}\'') + + # servicePrincipal: addPassword + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-addpassword?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method POST --uri https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}/addPassword ' + '--body \'{{"passwordCredential": {{"displayName": "Password friendly name"}}}}\'', + checks=[self.check('displayName', "Password friendly name")]) + + # Delete servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-delete?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/serviceprincipals/{sp_object_id}') + + from knack.util import CLIError + with self.assertRaisesRegex(CLIError, "Request_ResourceNotFound"): + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}') + + # Delete application + # https://docs.microsoft.com/en-us/graph/api/application-delete?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/applications/{app_object_id}') + + from knack.util import CLIError + with self.assertRaisesRegex(CLIError, "Request_ResourceNotFound"): + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/applications/{app_object_id}') + + # Clear the trash left behind by failed tests + response = self.cmd('az rest -m GET -u "https://graph.microsoft.com/v1.0/applications?$filter=startswith(displayName, \'{display_name_prefix}\')"').get_output_in_json() + apps = response['value'] + for app in apps: + self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/applications/{}'.format(app['id'])) + if __name__ == '__main__': unittest.main() From 023f8316332c9c9f5bc9d7e9d61339eeef2c62ec Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Fri, 5 Jun 2020 20:29:38 +0800 Subject: [PATCH 2/5] Update --- .../cli/command_modules/util/tests/latest/test_rest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py index bf39a9a8e7f..903209def14 100644 --- a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py +++ b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py @@ -78,6 +78,8 @@ def test_rest(self, resource_group): self.cmd('az rest -m DELETE -u "/subscriptions/{{subscriptionId}}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{sa}?api-version=2019-06-01"') def test_rest_microsoft_graph(self): + from knack.util import CLIError + display_name_prefix = "az-rest-test-app" self.kwargs.update({ 'display_name_prefix': display_name_prefix, @@ -86,7 +88,7 @@ def test_rest_microsoft_graph(self): # Create application # https://docs.microsoft.com/en-us/graph/api/application-post-applications?view=graph-rest-1.0&tabs=http - # Escape single quote for `shlex` and curly braces for `format` + # Escape single quotes for `shlex` and curly braces for `format` app = self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/applications --body \'{{"displayName": "{display_name}"}}\'', checks=[ self.check('displayName', '{display_name}') @@ -136,7 +138,6 @@ def test_rest_microsoft_graph(self): # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-delete?view=graph-rest-1.0&tabs=http self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/serviceprincipals/{sp_object_id}') - from knack.util import CLIError with self.assertRaisesRegex(CLIError, "Request_ResourceNotFound"): self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}') @@ -144,7 +145,6 @@ def test_rest_microsoft_graph(self): # https://docs.microsoft.com/en-us/graph/api/application-delete?view=graph-rest-1.0&tabs=http self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/applications/{app_object_id}') - from knack.util import CLIError with self.assertRaisesRegex(CLIError, "Request_ResourceNotFound"): self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/applications/{app_object_id}') From 25925dd1794505be878e3a3ffd081c3f7f69b510 Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Fri, 5 Jun 2020 20:54:29 +0800 Subject: [PATCH 3/5] Refine wording --- src/azure-cli/azure/cli/command_modules/util/_help.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/util/_help.py b/src/azure-cli/azure/cli/command_modules/util/_help.py index fecd0525057..a8797910ac7 100644 --- a/src/azure-cli/azure/cli/command_modules/util/_help.py +++ b/src/azure-cli/azure/cli/command_modules/util/_help.py @@ -11,7 +11,7 @@ type: command short-summary: Invoke a custom request. long-summary: > - This command automatically authenticates using the credential logged in: If Authorization header is not set, it + This command automatically authenticates using the logged-in credential: If Authorization header is not set, it attaches header `Authorization: Bearer `, where `` is retrieved from AAD. The target resource of the token is derived from --url if --url starts with an endpoint from `az cloud show --query endpoints`. You may also use --resource for a custom resource. @@ -21,16 +21,16 @@ examples: - name: Get Audit log through Microsoft Graph text: > - az rest --method get --uri https://graph.microsoft.com/beta/auditLogs/directoryAudits + az rest --method get --url https://graph.microsoft.com/beta/auditLogs/directoryAudits - name: Update a Azure Active Directory Graph User's display name text: > - az rest --method patch --uri "https://graph.microsoft.com/v1.0/users/johndoe@azuresdkteam.onmicrosoft.com" --body "{\\"displayName\\": \\"jondoe2\\"}" + az rest --method patch --url "https://graph.microsoft.com/v1.0/users/johndoe@azuresdkteam.onmicrosoft.com" --body "{\\"displayName\\": \\"jondoe2\\"}" - name: Get a virtual machine text: > - az rest --method get --uri /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2019-03-01 + az rest --method get --url /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2019-03-01 - name: Create a public IP address from body.json file text: > - az rest --method put --uri https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2019-09-01 --body @body.json + az rest --method put --url https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2019-09-01 --body @body.json """ helps['version'] = """ From 7f7c70785b2e19c8924d066aba5a414a2897dee2 Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Mon, 8 Jun 2020 10:26:42 +0800 Subject: [PATCH 4/5] Re-run tests --- .../recordings/test_rest_microsoft_graph.yaml | 134 +++++++++--------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml b/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml index ab2353e7f7b..c0cf01794c3 100644 --- a/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml +++ b/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml @@ -23,9 +23,9 @@ interactions: response: body: string: '{"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications/$entity", - "id": "2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c", "deletedDateTime": null, "appId": - "f017bab3-0f27-4953-b9bd-24ca5af298bc", "applicationTemplateId": null, "createdDateTime": - "2020-06-05T12:18:14.027154Z", "displayName": "az-rest-test-app000001", "groupMembershipClaims": + "id": "a375e981-6e57-4946-a1bc-b38c480d7f03", "deletedDateTime": null, "appId": + "04c487f7-c8c7-4f5f-b086-53eee11f142f", "applicationTemplateId": null, "createdDateTime": + "2020-06-08T02:25:29.8512139Z", "displayName": "az-rest-test-app000001", "groupMembershipClaims": null, "identifierUris": [], "isDeviceOnlyAuthSupported": null, "isFallbackPublicClient": null, "optionalClaims": null, "publisherDomain": "AzureSDKTeam.onmicrosoft.com", "signInAudience": "AzureADandPersonalMicrosoftAccount", "tags": [], "tokenEncryptionKeyId": @@ -42,21 +42,21 @@ interactions: cache-control: - private content-length: - - '1259' + - '1260' content-type: - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 date: - - Fri, 05 Jun 2020 12:18:17 GMT + - Mon, 08 Jun 2020 02:25:32 GMT location: - - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c/Microsoft.DirectoryServices.Application + - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/a375e981-6e57-4946-a1bc-b38c480d7f03/Microsoft.DirectoryServices.Application odata-version: - '4.0' request-id: - - 944c880d-05e3-4a19-a869-f6e023988e51 + - ded0e1c3-7b58-4325-b721-80602e0c3181 strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_20"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_10"}}' status: code: 201 message: Created @@ -76,10 +76,10 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: GET - uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + uri: https://graph.microsoft.com/v1.0/applications/a375e981-6e57-4946-a1bc-b38c480d7f03 response: body: - string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#applications/$entity","id":"2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c","deletedDateTime":null,"appId":"f017bab3-0f27-4953-b9bd-24ca5af298bc","applicationTemplateId":null,"createdDateTime":"2020-06-05T12:18:14Z","displayName":"az-rest-test-app000001","groupMembershipClaims":null,"identifierUris":[],"isDeviceOnlyAuthSupported":null,"isFallbackPublicClient":null,"optionalClaims":null,"publisherDomain":"AzureSDKTeam.onmicrosoft.com","signInAudience":"AzureADandPersonalMicrosoftAccount","tags":[],"tokenEncryptionKeyId":null,"spa":{"redirectUris":[]},"addIns":[],"api":{"acceptMappedClaims":null,"knownClientApplications":[],"requestedAccessTokenVersion":2,"oauth2PermissionScopes":[],"preAuthorizedApplications":[]},"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"parentalControlSettings":{"countriesBlockedForMinors":[],"legalAgeGroupRule":"Allow"},"passwordCredentials":[],"publicClient":{"redirectUris":[]},"requiredResourceAccess":[],"web":{"homePageUrl":null,"logoutUrl":null,"redirectUris":[],"implicitGrantSettings":{"enableAccessTokenIssuance":false,"enableIdTokenIssuance":false}}}' + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#applications/$entity","id":"a375e981-6e57-4946-a1bc-b38c480d7f03","deletedDateTime":null,"appId":"04c487f7-c8c7-4f5f-b086-53eee11f142f","applicationTemplateId":null,"createdDateTime":"2020-06-08T02:25:29Z","displayName":"az-rest-test-app000001","groupMembershipClaims":null,"identifierUris":[],"isDeviceOnlyAuthSupported":null,"isFallbackPublicClient":null,"optionalClaims":null,"publisherDomain":"AzureSDKTeam.onmicrosoft.com","signInAudience":"AzureADandPersonalMicrosoftAccount","tags":[],"tokenEncryptionKeyId":null,"spa":{"redirectUris":[]},"addIns":[],"api":{"acceptMappedClaims":null,"knownClientApplications":[],"requestedAccessTokenVersion":2,"oauth2PermissionScopes":[],"preAuthorizedApplications":[]},"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"parentalControlSettings":{"countriesBlockedForMinors":[],"legalAgeGroupRule":"Allow"},"passwordCredentials":[],"publicClient":{"redirectUris":[]},"requiredResourceAccess":[],"web":{"homePageUrl":null,"logoutUrl":null,"redirectUris":[],"implicitGrantSettings":{"enableAccessTokenIssuance":false,"enableIdTokenIssuance":false}}}' headers: cache-control: - private @@ -88,17 +88,17 @@ interactions: content-type: - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 date: - - Fri, 05 Jun 2020 12:18:18 GMT + - Mon, 08 Jun 2020 02:25:32 GMT odata-version: - '4.0' request-id: - - 57cc3f6d-1350-4ad8-a1da-0b87848866da + - d363790f-9f5b-4a9a-a8f9-9361fa75abba strict-transport-security: - max-age=31536000 vary: - Accept-Encoding x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_5"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_22"}}' status: code: 200 message: OK @@ -122,7 +122,7 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: PATCH - uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + uri: https://graph.microsoft.com/v1.0/applications/a375e981-6e57-4946-a1bc-b38c480d7f03 response: body: string: '' @@ -132,13 +132,13 @@ interactions: content-type: - text/plain date: - - Fri, 05 Jun 2020 12:18:21 GMT + - Mon, 08 Jun 2020 02:25:34 GMT request-id: - - b6d028e0-31b4-44c4-b21a-10b01c910a69 + - d57f8ed5-6ea7-413a-a40a-47e05927afa6 strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_25"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_18"}}' status: code: 204 message: No Content @@ -162,11 +162,11 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: POST - uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c/addPassword + uri: https://graph.microsoft.com/v1.0/applications/a375e981-6e57-4946-a1bc-b38c480d7f03/addPassword response: body: string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential","customKeyIdentifier":null,"displayName":"Password - friendly name","endDateTime":"2022-06-05T12:18:22.2955982Z","hint":"~~b","keyId":"8493b406-ea97-4aff-a99e-ddca1acab2b9","secretText":"~~bbDW3Gm8Lf_uCO279~dFR83G5mS2-FJr","startDateTime":"2020-06-05T12:18:22.2955982Z"}' + friendly name","endDateTime":"2022-06-08T02:25:35.9601957Z","hint":"8FL","keyId":"4082b4b2-4835-47d5-aac1-e582171f70af","secretText":"8FLN1Sc2OK.-Kl6WDygKo.ZB~ut8PP.F97","startDateTime":"2020-06-08T02:25:35.9601957Z"}' headers: cache-control: - private @@ -175,24 +175,24 @@ interactions: content-type: - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 date: - - Fri, 05 Jun 2020 12:18:22 GMT + - Mon, 08 Jun 2020 02:25:36 GMT location: - https://graph.microsoft.com odata-version: - '4.0' request-id: - - 34c07bd2-3f79-49b4-8b59-4ac338077154 + - 378fd8eb-ca86-474f-9cb0-60240610abfc strict-transport-security: - max-age=31536000 vary: - Accept-Encoding x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"001","RoleInstance":"AGSFE_IN_14"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_29"}}' status: code: 200 message: OK - request: - body: '{"appId": "f017bab3-0f27-4953-b9bd-24ca5af298bc"}' + body: '{"appId": "04c487f7-c8c7-4f5f-b086-53eee11f142f"}' headers: Accept: - '*/*' @@ -214,7 +214,7 @@ interactions: uri: https://graph.microsoft.com/v1.0/serviceprincipals response: body: - string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"f99481a7-ccf2-4885-a5e9-aa977ff09f56","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"f017bab3-0f27-4953-b9bd-24ca5af298bc","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["f017bab3-0f27-4953-b9bd-24ca5af298bc"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"28c7007f-9414-4d9e-8753-d3a63c5a7fac","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"04c487f7-c8c7-4f5f-b086-53eee11f142f","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["04c487f7-c8c7-4f5f-b086-53eee11f142f"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' headers: cache-control: - private @@ -223,17 +223,17 @@ interactions: content-type: - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 date: - - Fri, 05 Jun 2020 12:18:23 GMT + - Mon, 08 Jun 2020 02:25:37 GMT location: - - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/f99481a7-ccf2-4885-a5e9-aa977ff09f56/Microsoft.DirectoryServices.ServicePrincipal + - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/28c7007f-9414-4d9e-8753-d3a63c5a7fac/Microsoft.DirectoryServices.ServicePrincipal odata-version: - '4.0' request-id: - - 8e5d87c5-48f0-489a-9892-749a824a3b2d + - 8097fe60-e047-4814-99cd-a7ce133cbd10 strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_1"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_13"}}' status: code: 201 message: Created @@ -253,10 +253,10 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: GET - uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + uri: https://graph.microsoft.com/v1.0/servicePrincipals/28c7007f-9414-4d9e-8753-d3a63c5a7fac response: body: - string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"f99481a7-ccf2-4885-a5e9-aa977ff09f56","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"f017bab3-0f27-4953-b9bd-24ca5af298bc","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["f017bab3-0f27-4953-b9bd-24ca5af298bc"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"28c7007f-9414-4d9e-8753-d3a63c5a7fac","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"04c487f7-c8c7-4f5f-b086-53eee11f142f","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["04c487f7-c8c7-4f5f-b086-53eee11f142f"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' headers: cache-control: - private @@ -265,17 +265,17 @@ interactions: content-type: - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 date: - - Fri, 05 Jun 2020 12:18:24 GMT + - Mon, 08 Jun 2020 02:25:37 GMT odata-version: - '4.0' request-id: - - 4dfea8dd-f70c-4cfb-8a49-69284262a390 + - 369161fe-04a7-4b4a-8680-eb020f81bd67 strict-transport-security: - max-age=31536000 vary: - Accept-Encoding x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_5"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_1"}}' status: code: 200 message: OK @@ -299,7 +299,7 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: PATCH - uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + uri: https://graph.microsoft.com/v1.0/servicePrincipals/28c7007f-9414-4d9e-8753-d3a63c5a7fac response: body: string: '' @@ -309,13 +309,13 @@ interactions: content-type: - text/plain date: - - Fri, 05 Jun 2020 12:18:25 GMT + - Mon, 08 Jun 2020 02:25:39 GMT request-id: - - ee15d3f6-be46-4324-9760-0de473af830d + - 4ceb9019-1fe0-4caf-951c-d4603864239d strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_15"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_22"}}' status: code: 204 message: No Content @@ -339,11 +339,11 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: POST - uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56/addPassword + uri: https://graph.microsoft.com/v1.0/servicePrincipals/28c7007f-9414-4d9e-8753-d3a63c5a7fac/addPassword response: body: string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential","customKeyIdentifier":null,"displayName":"Password - friendly name","endDateTime":"2022-06-05T12:18:27.0666616Z","hint":null,"keyId":"f39d2dc3-77bb-4594-9ad6-5ed186c19181","secretText":"5O.2.DO09oK8F2_.0efKp953TZAXExcFg.","startDateTime":"2020-06-05T12:18:27.0666616Z"}' + friendly name","endDateTime":"2022-06-08T02:25:40.5429064Z","hint":null,"keyId":"c0a87b55-44a4-4b8b-ae7b-88e8a1703820","secretText":"eAK_cVWIDGNm1qi~zj~bix8~98oJyrg386","startDateTime":"2020-06-08T02:25:40.5429064Z"}' headers: cache-control: - private @@ -352,19 +352,19 @@ interactions: content-type: - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 date: - - Fri, 05 Jun 2020 12:18:27 GMT + - Mon, 08 Jun 2020 02:25:40 GMT location: - https://graph.microsoft.com odata-version: - '4.0' request-id: - - 1c801061-9496-47d7-9b1b-834da3f811a6 + - 68f82f4b-9bbe-4157-b319-bd6f423b75ed strict-transport-security: - max-age=31536000 vary: - Accept-Encoding x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_4"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_20"}}' status: code: 200 message: OK @@ -386,7 +386,7 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: DELETE - uri: https://graph.microsoft.com/v1.0/serviceprincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + uri: https://graph.microsoft.com/v1.0/serviceprincipals/28c7007f-9414-4d9e-8753-d3a63c5a7fac response: body: string: '' @@ -396,13 +396,13 @@ interactions: content-type: - text/plain date: - - Fri, 05 Jun 2020 12:18:28 GMT + - Mon, 08 Jun 2020 02:25:40 GMT request-id: - - 0f04b047-f842-4c35-8782-41de06f3503e + - e7ec4a44-0292-48cd-a13a-051eb838f1f5 strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_12"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_11"}}' status: code: 204 message: No Content @@ -422,14 +422,14 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: GET - uri: https://graph.microsoft.com/v1.0/servicePrincipals/f99481a7-ccf2-4885-a5e9-aa977ff09f56 + uri: https://graph.microsoft.com/v1.0/servicePrincipals/28c7007f-9414-4d9e-8753-d3a63c5a7fac response: body: string: "{\r\n \"error\": {\r\n \"code\": \"Request_ResourceNotFound\",\r\n - \ \"message\": \"Resource 'f99481a7-ccf2-4885-a5e9-aa977ff09f56' does not + \ \"message\": \"Resource '28c7007f-9414-4d9e-8753-d3a63c5a7fac' does not exist or one of its queried reference-property objects are not present.\",\r\n - \ \"innerError\": {\r\n \"request-id\": \"10867b9f-d748-4761-8dd8-5dd938db7234\",\r\n - \ \"date\": \"2020-06-05T12:18:29\"\r\n }\r\n }\r\n}" + \ \"innerError\": {\r\n \"request-id\": \"a2c58fad-6e38-4706-8720-708a22b02ad7\",\r\n + \ \"date\": \"2020-06-08T02:25:42\"\r\n }\r\n }\r\n}" headers: cache-control: - private @@ -438,13 +438,13 @@ interactions: content-type: - application/json date: - - Fri, 05 Jun 2020 12:18:28 GMT + - Mon, 08 Jun 2020 02:25:42 GMT request-id: - - 10867b9f-d748-4761-8dd8-5dd938db7234 + - a2c58fad-6e38-4706-8720-708a22b02ad7 strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_29"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_27"}}' status: code: 404 message: Not Found @@ -466,7 +466,7 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: DELETE - uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + uri: https://graph.microsoft.com/v1.0/applications/a375e981-6e57-4946-a1bc-b38c480d7f03 response: body: string: '' @@ -476,13 +476,13 @@ interactions: content-type: - text/plain date: - - Fri, 05 Jun 2020 12:18:35 GMT + - Mon, 08 Jun 2020 02:25:54 GMT request-id: - - f95b8524-31af-4d03-87c5-481c180ab562 + - 2e83e8bc-7769-4fc9-bf28-13e9fe4827b0 strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_26"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_8"}}' status: code: 204 message: No Content @@ -502,14 +502,14 @@ interactions: User-Agent: - AZURECLI/2.7.0 method: GET - uri: https://graph.microsoft.com/v1.0/applications/2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c + uri: https://graph.microsoft.com/v1.0/applications/a375e981-6e57-4946-a1bc-b38c480d7f03 response: body: string: "{\r\n \"error\": {\r\n \"code\": \"Request_ResourceNotFound\",\r\n - \ \"message\": \"Resource '2dfe6ef4-97bc-4372-a56b-c3a1c126ac1c' does not + \ \"message\": \"Resource 'a375e981-6e57-4946-a1bc-b38c480d7f03' does not exist or one of its queried reference-property objects are not present.\",\r\n - \ \"innerError\": {\r\n \"request-id\": \"8290f49b-7d5b-478d-bd6c-a6900403300f\",\r\n - \ \"date\": \"2020-06-05T12:18:36\"\r\n }\r\n }\r\n}" + \ \"innerError\": {\r\n \"request-id\": \"e8189099-94fe-4b62-9c32-34b1e9dbf995\",\r\n + \ \"date\": \"2020-06-08T02:25:55\"\r\n }\r\n }\r\n}" headers: cache-control: - private @@ -518,13 +518,13 @@ interactions: content-type: - application/json date: - - Fri, 05 Jun 2020 12:18:36 GMT + - Mon, 08 Jun 2020 02:25:55 GMT request-id: - - 8290f49b-7d5b-478d-bd6c-a6900403300f + - e8189099-94fe-4b62-9c32-34b1e9dbf995 strict-transport-security: - max-age=31536000 x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_13"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"002","RoleInstance":"AGSFE_IN_9"}}' status: code: 404 message: Not Found @@ -556,17 +556,17 @@ interactions: content-type: - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 date: - - Fri, 05 Jun 2020 12:18:37 GMT + - Mon, 08 Jun 2020 02:25:55 GMT odata-version: - '4.0' request-id: - - 4e2198f1-0932-4a64-95e6-fe34f217aee5 + - 4daf063b-eb2c-4997-ac49-4e1f6e29aea9 strict-transport-security: - max-age=31536000 vary: - Accept-Encoding x-ms-ags-diagnostic: - - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_22"}}' + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"002","RoleInstance":"AGSFE_IN_13"}}' status: code: 200 message: OK From 8b199e93ca2504a565b4bfeeea746987751e4d0d Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Mon, 8 Jun 2020 13:36:14 +0800 Subject: [PATCH 5/5] Use --uri and --url more accurately --- src/azure-cli/azure/cli/command_modules/util/_help.py | 2 +- .../cli/command_modules/util/tests/latest/test_rest.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/util/_help.py b/src/azure-cli/azure/cli/command_modules/util/_help.py index a8797910ac7..af5e35cb632 100644 --- a/src/azure-cli/azure/cli/command_modules/util/_help.py +++ b/src/azure-cli/azure/cli/command_modules/util/_help.py @@ -27,7 +27,7 @@ az rest --method patch --url "https://graph.microsoft.com/v1.0/users/johndoe@azuresdkteam.onmicrosoft.com" --body "{\\"displayName\\": \\"jondoe2\\"}" - name: Get a virtual machine text: > - az rest --method get --url /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2019-03-01 + az rest --method get --uri /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2019-03-01 - name: Create a public IP address from body.json file text: > az rest --method put --url https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2019-09-01 --body @body.json diff --git a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py index 903209def14..e75770e4b5d 100644 --- a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py +++ b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py @@ -99,7 +99,7 @@ def test_rest_microsoft_graph(self): # Get application # https://docs.microsoft.com/en-us/graph/api/application-get?view=graph-rest-1.0&tabs=http - self.cmd('az rest --method GET --uri https://graph.microsoft.com/v1.0/applications/{app_object_id}', + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/applications/{app_object_id}', checks=[self.check('displayName', '{display_name}')]) # Update application @@ -108,7 +108,7 @@ def test_rest_microsoft_graph(self): # application: addPassword # https://docs.microsoft.com/en-us/graph/api/application-addpassword?view=graph-rest-1.0&tabs=http - self.cmd('az rest --method POST --uri https://graph.microsoft.com/v1.0/applications/{app_object_id}/addPassword ' + self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/applications/{app_object_id}/addPassword ' '--body \'{{"passwordCredential": {{"displayName": "Password friendly name"}}}}\'', checks=[self.check('displayName', "Password friendly name")]) @@ -119,7 +119,7 @@ def test_rest_microsoft_graph(self): # Get servicePrincipal # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-get?view=graph-rest-1.0&tabs=http - self.cmd('az rest --method GET --uri https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}', + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}', checks=[self.check('appId', '{app_id}'), self.check('id', '{sp_object_id}')]) @@ -130,7 +130,7 @@ def test_rest_microsoft_graph(self): # servicePrincipal: addPassword # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-addpassword?view=graph-rest-1.0&tabs=http - self.cmd('az rest --method POST --uri https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}/addPassword ' + self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}/addPassword ' '--body \'{{"passwordCredential": {{"displayName": "Password friendly name"}}}}\'', checks=[self.check('displayName', "Password friendly name")])