Skip to content

Commit

Permalink
Fixed the getPermission playback test (Azure#6361)
Browse files Browse the repository at this point in the history
* Fixed the getPermission playback test

* Added constant for CONTENT_LENGTH
  • Loading branch information
sima-zhu authored Nov 15, 2019
1 parent 7411f8e commit 1ad76ca
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class RecordNetworkCallPolicy implements HttpPipelinePolicy {
private static final int DEFAULT_BUFFER_LENGTH = 1024;
private static final String CONTENT_TYPE = "Content-Type";
private static final String CONTENT_ENCODING = "Content-Encoding";
private static final String CONTENT_LENGTH = "Content-Length";
private static final String X_MS_CLIENT_REQUEST_ID = "x-ms-client-request-id";
private static final String X_MS_ENCRYPTION_KEY_SHA256 = "x-ms-encryption-key-sha256";
private static final String X_MS_VERSION = "x-ms-version";
Expand Down Expand Up @@ -145,7 +146,16 @@ private Mono<Map<String, String>> extractResponseData(final HttpResponse respons

String contentType = response.getHeaderValue(CONTENT_TYPE);
if (contentType == null) {
return Mono.just(responseData);
return response.getBodyAsByteArray().switchIfEmpty(Mono.just(new byte[0])).map(bytes -> {
if (bytes.length == 0) {
return responseData;
}

String content = new String(bytes, StandardCharsets.UTF_8);
responseData.put(CONTENT_LENGTH, Integer.toString(content.length()));
responseData.put(BODY, content);
return responseData;
});
} else if (contentType.equalsIgnoreCase("application/octet-stream")) {
return response.getBodyAsByteArray().switchIfEmpty(Mono.just(new byte[0])).map(bytes -> {
if (bytes.length == 0) {
Expand Down Expand Up @@ -189,7 +199,7 @@ private Mono<Map<String, String>> extractResponseData(final HttpResponse respons
}

responseData.remove(CONTENT_ENCODING);
responseData.put("Content-Length", Integer.toString(content.length()));
responseData.put(CONTENT_LENGTH, Integer.toString(content.length()));

responseData.put(BODY, content);
return responseData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,13 @@ class ShareAPITests extends APISpec {
primaryShareClient.createPermissionWithResponse(filePermission, null), 201)
}

// Only run this test in live mode as BlobOutputStream dynamically assigns blocks
@Ignore
def "Create and get permission"() {
given:
primaryShareClient.create()
def permissionKey = primaryShareClient.createPermission(filePermission)

when:
def permission = primaryShareClient.setPermission(permissionKey)
def permission = primaryShareClient.getPermission(permissionKey)

then:
permission == filePermission
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://azstoragesdkaccount.file.core.windows.net/shareapitestscreateandgetpermission72072c5686adb11?restype=share",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.0.0-beta.6 1.8.0_221; Windows 10 10.0",
"x-ms-client-request-id" : "b9bc1559-9e0b-4ff9-9af3-3f62bc3d2038"
},
"Response" : {
"x-ms-version" : "2019-02-02",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8D769623EA2C5E1",
"Last-Modified" : "Fri, 15 Nov 2019 00:24:57 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "cb798a14-b01a-0024-324b-9ba938000000",
"Date" : "Fri, 15 Nov 2019 00:24:57 GMT",
"x-ms-client-request-id" : "b9bc1559-9e0b-4ff9-9af3-3f62bc3d2038"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azstoragesdkaccount.file.core.windows.net/shareapitestscreateandgetpermission72072c5686adb11?restype=share&comp=filepermission",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.0.0-beta.6 1.8.0_221; Windows 10 10.0",
"x-ms-client-request-id" : "a23fe7a8-2d47-449b-9226-c7050d01a9f3",
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"x-ms-version" : "2019-02-02",
"x-ms-file-permission-key" : "1226745640258142193*13168958551941065216",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "cb798a16-b01a-0024-334b-9ba938000000",
"Date" : "Fri, 15 Nov 2019 00:24:57 GMT",
"x-ms-client-request-id" : "a23fe7a8-2d47-449b-9226-c7050d01a9f3"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://azstoragesdkaccount.file.core.windows.net/shareapitestscreateandgetpermission72072c5686adb11?restype=share&comp=filepermission",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.0.0-beta.6 1.8.0_221; Windows 10 10.0",
"x-ms-client-request-id" : "0dddcfd9-a2d6-47f2-8e7b-21ac086698cf"
},
"Response" : {
"x-ms-version" : "2019-02-02",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"Content-Length" : "225",
"StatusCode" : "200",
"x-ms-request-id" : "cb798a1d-b01a-0024-384b-9ba938000000",
"Body" : "{\"permission\":\"O:S-1-5-21-2127521184-1604012920-1887927527-21560751G:S-1-5-21-2127521184-1604012920-1887927527-513D:AI(A;;FA;;;SY)(A;;FA;;;BA)(A;;0x1200a9;;;S-1-5-21-397955417-626881126-188441444-3053964)S:NO_ACCESS_CONTROL\"}",
"Date" : "Fri, 15 Nov 2019 00:24:57 GMT",
"x-ms-client-request-id" : "0dddcfd9-a2d6-47f2-8e7b-21ac086698cf"
},
"Exception" : null
} ],
"variables" : [ "shareapitestscreateandgetpermission72072c5686adb11" ]
}

0 comments on commit 1ad76ca

Please sign in to comment.