Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.core.exception.UnexpectedLengthException;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.UrlBuilder;
import com.azure.core.util.logging.ClientLogger;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -154,6 +155,24 @@ private static String encode(final String stringToEncode) {
}
}

/**
* Performs a safe encoding of a url string, only encoding the path.
*
* @param url The url to encode.
* @return The encoded url.
*/
public static String encodeUrlPath(String url) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone have a better idea on a name for this method?

/* Deconstruct the URL and reconstruct it making sure the path is encoded. */
UrlBuilder builder = UrlBuilder.parse(url);
String path = builder.getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}
path = Utility.urlEncode(Utility.urlDecode(path));
builder.setPath(path);
return builder.toString();
}

/**
* Given a String representing a date in a form of the ISO8601 pattern, generates a Date representing it with up to
* millisecond precision.
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-file-share/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release History

## 12.5.0-beta.1 (Unreleased)
- Fixed bug in ShareFileClient.uploadRangeFromUrl and ShareFileClient.beginCopy where sourceUrl was not getting encoded.

## 12.4.1 (2020-05-06)
- Updated `azure-core` version to `1.5.0` to pickup fixes for percent encoding `UTF-8` and invalid leading bytes in a body string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.azure.core.util.polling.PollResponse;
import com.azure.core.util.polling.PollerFlux;
import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.common.Utility;
import com.azure.storage.common.implementation.Constants;
import com.azure.storage.common.implementation.SasImplUtils;
import com.azure.storage.common.implementation.StorageImplUtils;
Expand Down Expand Up @@ -427,11 +428,13 @@ public PollerFlux<ShareFileCopyInfo, Void> beginCopy(String sourceUrl, FileSmbPr
.setIgnoreReadOnly(ignoreReadOnly)
.setSetArchiveAttribute(setArchiveAttribute);

final String copySource = Utility.encodeUrlPath(sourceUrl);

return new PollerFlux<>(interval,
(pollingContext) -> {
try {
return withContext(context -> azureFileStorageClient.files()
.startCopyWithRestResponseAsync(shareName, filePath, sourceUrl, null,
.startCopyWithRestResponseAsync(shareName, filePath, copySource, null,
metadata, filePermission, tempSmbProperties.getFilePermissionKey(),
finalRequestConditions.getLeaseId(), copyFileSmbInfo, context))
.map(response -> {
Expand Down Expand Up @@ -1382,8 +1385,10 @@ Mono<Response<ShareFileUploadRangeFromUrlInfo>> uploadRangeFromUrlWithResponse(l
ShareFileRange sourceRange = new ShareFileRange(sourceOffset, sourceOffset + length - 1);
context = context == null ? Context.NONE : context;

final String copySource = Utility.encodeUrlPath(sourceUrl);

return azureFileStorageClient.files()
.uploadRangeFromURLWithRestResponseAsync(shareName, filePath, destinationRange.toString(), sourceUrl, 0,
.uploadRangeFromURLWithRestResponseAsync(shareName, filePath, destinationRange.toString(), copySource, 0,
null, sourceRange.toString(), null, destinationRequestConditions.getLeaseId(), null,
context.addData(AZ_TRACING_NAMESPACE_KEY, STORAGE_TRACING_NAMESPACE_VALUE))
.map(this::uploadRangeFromUrlResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ class APISpec extends Specification {
static TestMode testMode = getTestMode()
String connectionString

// If debugging is enabled, recordings cannot run as there can only be one proxy at a time.
static boolean enableDebugging = false

/*
Note that this value is only used to check if we are depending on the received etag. This value will not actually
be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,10 @@ class FileAPITests extends APISpec {
FileTestHelper.deleteFilesIfExists(testFolder.getPath())
}

@Unroll
def "Upload range from URL"() {
given:
primaryFileClient = fileBuilderHelper(interceptorManager, shareName, filePath + pathSuffix).buildFileClient()
primaryFileClient.create(1024)
def data = "The quick brown fox jumps over the lazy dog"
def sourceOffset = 5
Expand All @@ -458,7 +460,7 @@ class FileAPITests extends APISpec {
.encode()

when:
ShareFileClient client = fileBuilderHelper(interceptorManager, shareName, "destination")
ShareFileClient client = fileBuilderHelper(interceptorManager, shareName, "destination" + pathSuffix)
.endpoint(primaryFileClient.getFileUrl().toString())
.buildFileClient()

Expand All @@ -473,10 +475,16 @@ class FileAPITests extends APISpec {
for(int i = 0; i < length; i++) {
result.charAt(destinationOffset + i) == data.charAt(sourceOffset + i)
}
where:
pathSuffix || _
"" || _
"ü1ü" || _ /* Something that needs to be url encoded. */
}

@Unroll
def "Start copy"() {
given:
primaryFileClient = fileBuilderHelper(interceptorManager, shareName, filePath + pathSuffix).buildFileClient()
primaryFileClient.create(1024)
// TODO: Need another test account if using SAS token for authentication.
// TODO: SasToken auth cannot be used until the logging redaction
Expand All @@ -491,6 +499,11 @@ class FileAPITests extends APISpec {

then:
assert pollResponse.getValue().getCopyId() != null

where:
pathSuffix || _
"" || _
"ü1ü" || _ /* Something that needs to be url encoded. */
}

@Unroll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy0fileapitestsstartcopy09c324747c5eb?restype=share",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "b980efd1-7393-4fcc-b12c-448c30f5a465"
},
"Response" : {
"x-ms-version" : "2019-07-07",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8D803E1CE3A4D05",
"Last-Modified" : "Fri, 29 May 2020 15:06:03 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "23e454f3-d01a-0015-0bca-358588000000",
"Date" : "Fri, 29 May 2020 15:06:02 GMT",
"x-ms-client-request-id" : "b980efd1-7393-4fcc-b12c-448c30f5a465"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy0fileapitestsstartcopy09c324747c5eb/fileapitestsstartcopy0fileapitestsstartcopy09c3795483c2d",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "d3a7310a-1ce3-4389-930d-f71a381a00cd"
},
"Response" : {
"x-ms-version" : "2019-07-07",
"x-ms-file-permission-key" : "15581347578553677299*8114634751575874941",
"x-ms-file-id" : "13835128424026341376",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-file-creation-time" : "2020-05-29T15:06:05.9956406Z",
"Last-Modified" : "Fri, 29 May 2020 15:06:05 GMT",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Fri, 29 May 2020 15:06:05 GMT",
"ETag" : "0x8D803E1CFB158B6",
"x-ms-file-attributes" : "Archive",
"x-ms-file-change-time" : "2020-05-29T15:06:05.9956406Z",
"x-ms-file-parent-id" : "0",
"Content-Length" : "0",
"x-ms-request-id" : "b9433e0a-501a-000b-14ca-356950000000",
"x-ms-client-request-id" : "d3a7310a-1ce3-4389-930d-f71a381a00cd",
"x-ms-file-last-write-time" : "2020-05-29T15:06:05.9956406Z"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy0fileapitestsstartcopy09c324747c5eb/fileapitestsstartcopy0fileapitestsstartcopy09c3795483c2d",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "69ed53a4-5a40-47af-a797-cb9b733ceac8"
},
"Response" : {
"x-ms-version" : "2019-07-07",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-copy-id" : "f8b2b87c-8160-4e90-8f79-cf4121be5117",
"ETag" : "0x8D803E1D238EE14",
"Last-Modified" : "Fri, 29 May 2020 15:06:10 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"x-ms-copy-status" : "success",
"StatusCode" : "202",
"x-ms-request-id" : "e17b8d7d-701a-0041-6eca-35cadf000000",
"Date" : "Fri, 29 May 2020 15:06:09 GMT",
"x-ms-client-request-id" : "69ed53a4-5a40-47af-a797-cb9b733ceac8"
},
"Exception" : null
}, {
"Method" : "HEAD",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy0fileapitestsstartcopy09c324747c5eb/fileapitestsstartcopy0fileapitestsstartcopy09c3795483c2d",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "3f208c80-76be-4adf-88a8-cbdf29ac3ae0"
},
"Response" : {
"x-ms-lease-status" : "unlocked",
"x-ms-file-id" : "13835128424026341376",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-file-creation-time" : "2020-05-29T15:06:10.2396436Z",
"x-ms-lease-state" : "available",
"Last-Modified" : "Fri, 29 May 2020 15:06:10 GMT",
"retry-after" : "0",
"StatusCode" : "200",
"x-ms-file-attributes" : "Archive",
"Content-Length" : "1024",
"x-ms-request-id" : "dd9309d6-401a-0028-7bca-35f393000000",
"Content-Type" : "application/octet-stream",
"x-ms-file-permission-key" : "15581347578553677299*8114634751575874941",
"x-ms-version" : "2019-07-07",
"x-ms-copy-id" : "f8b2b87c-8160-4e90-8f79-cf4121be5117",
"x-ms-copy-source" : "https://gapradev.file.core.windows.net/fileapitestsstartcopy0fileapitestsstartcopy09c324747c5eb%2Ffileapitestsstartcopy0fileapitestsstartcopy09c3795483c2d",
"x-ms-copy-progress" : "1024/1024",
"Date" : "Fri, 29 May 2020 15:06:12 GMT",
"x-ms-copy-completion-time" : "Fri, 29 May 2020 15:06:10 GMT",
"x-ms-server-encrypted" : "true",
"x-ms-type" : "File",
"ETag" : "0x8D803E1D238EE14",
"Vary" : "Origin",
"x-ms-file-change-time" : "2020-05-29T15:06:10.2396436Z",
"x-ms-file-parent-id" : "0",
"x-ms-copy-status" : "success",
"x-ms-client-request-id" : "3f208c80-76be-4adf-88a8-cbdf29ac3ae0",
"x-ms-file-last-write-time" : "2020-05-29T15:06:10.2396436Z"
},
"Exception" : null
} ],
"variables" : [ "fileapitestsstartcopy0fileapitestsstartcopy09c324747c5eb", "fileapitestsstartcopy0fileapitestsstartcopy09c3795483c2d" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy1fileapitestsstartcopy1caa430668050?restype=share",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "a98df336-19b5-4b31-b82f-ecdb575437dc"
},
"Response" : {
"x-ms-version" : "2019-07-07",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8D803E1D6BA3D4A",
"Last-Modified" : "Fri, 29 May 2020 15:06:17 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "60169b0f-001a-0039-32ca-356927000000",
"Date" : "Fri, 29 May 2020 15:06:17 GMT",
"x-ms-client-request-id" : "a98df336-19b5-4b31-b82f-ecdb575437dc"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy1fileapitestsstartcopy1caa430668050/fileapitestsstartcopy1fileapitestsstartcopy1caa068238373%C3%BC1%C3%BC",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "8691ab09-8f8f-497b-b08e-080981c031a8"
},
"Response" : {
"x-ms-version" : "2019-07-07",
"x-ms-file-permission-key" : "15581347578553677299*8114634751575874941",
"x-ms-file-id" : "13835128424026341376",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-file-creation-time" : "2020-05-29T15:06:19.8696601Z",
"Last-Modified" : "Fri, 29 May 2020 15:06:19 GMT",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Fri, 29 May 2020 15:06:19 GMT",
"ETag" : "0x8D803E1D7F65A99",
"x-ms-file-attributes" : "Archive",
"x-ms-file-change-time" : "2020-05-29T15:06:19.8696601Z",
"x-ms-file-parent-id" : "0",
"Content-Length" : "0",
"x-ms-request-id" : "6f7958e4-201a-003e-4fca-350544000000",
"x-ms-client-request-id" : "8691ab09-8f8f-497b-b08e-080981c031a8",
"x-ms-file-last-write-time" : "2020-05-29T15:06:19.8696601Z"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy1fileapitestsstartcopy1caa430668050/fileapitestsstartcopy1fileapitestsstartcopy1caa068238373%C3%BC1%C3%BC",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "22f3f717-d5b6-4de0-ba54-a8e424bcd9cb"
},
"Response" : {
"x-ms-version" : "2019-07-07",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-copy-id" : "75fe1060-e02b-4ead-ac6f-9d468d58be98",
"ETag" : "0x8D803E1D85A749A",
"Last-Modified" : "Fri, 29 May 2020 15:06:20 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"x-ms-copy-status" : "success",
"StatusCode" : "202",
"x-ms-request-id" : "e17b8d96-701a-0041-71ca-35cadf000000",
"Date" : "Fri, 29 May 2020 15:06:20 GMT",
"x-ms-client-request-id" : "22f3f717-d5b6-4de0-ba54-a8e424bcd9cb"
},
"Exception" : null
}, {
"Method" : "HEAD",
"Uri" : "https://REDACTED.file.core.windows.net/fileapitestsstartcopy1fileapitestsstartcopy1caa430668050/fileapitestsstartcopy1fileapitestsstartcopy1caa068238373%C3%BC1%C3%BC",
"Headers" : {
"x-ms-version" : "2019-07-07",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.5.0-beta.1 (11.0.7; Windows 10 10.0)",
"x-ms-client-request-id" : "e4a16991-1fa6-4314-9a96-b32386511246"
},
"Response" : {
"x-ms-lease-status" : "unlocked",
"x-ms-file-id" : "13835128424026341376",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-file-creation-time" : "2020-05-29T15:06:20.5256858Z",
"x-ms-lease-state" : "available",
"Last-Modified" : "Fri, 29 May 2020 15:06:20 GMT",
"retry-after" : "0",
"StatusCode" : "200",
"x-ms-file-attributes" : "Archive",
"Content-Length" : "1024",
"x-ms-request-id" : "04433d5a-e01a-000e-50ca-35bb8b000000",
"Content-Type" : "application/octet-stream",
"x-ms-file-permission-key" : "15581347578553677299*8114634751575874941",
"x-ms-version" : "2019-07-07",
"x-ms-copy-id" : "75fe1060-e02b-4ead-ac6f-9d468d58be98",
"x-ms-copy-source" : "https://gapradev.file.core.windows.net/fileapitestsstartcopy1fileapitestsstartcopy1caa430668050%2Ffileapitestsstartcopy1fileapitestsstartcopy1caa068238373%C3%BC1%C3%BC",
"x-ms-copy-progress" : "1024/1024",
"Date" : "Fri, 29 May 2020 15:06:21 GMT",
"x-ms-copy-completion-time" : "Fri, 29 May 2020 15:06:20 GMT",
"x-ms-server-encrypted" : "true",
"x-ms-type" : "File",
"ETag" : "0x8D803E1D85A749A",
"Vary" : "Origin",
"x-ms-file-change-time" : "2020-05-29T15:06:20.5256858Z",
"x-ms-file-parent-id" : "0",
"x-ms-copy-status" : "success",
"x-ms-client-request-id" : "e4a16991-1fa6-4314-9a96-b32386511246",
"x-ms-file-last-write-time" : "2020-05-29T15:06:20.5256858Z"
},
"Exception" : null
} ],
"variables" : [ "fileapitestsstartcopy1fileapitestsstartcopy1caa430668050", "fileapitestsstartcopy1fileapitestsstartcopy1caa068238373" ]
}
Loading