Skip to content

Commit 925ee8a

Browse files
authored
Fixed bug with DataLakeImplUtils.endpointToDesiredEndpoint (Azure#17449)
Co-authored-by: gapra <[email protected]>
1 parent d0fbe8d commit 925ee8a

File tree

9 files changed

+36
-423
lines changed

9 files changed

+36
-423
lines changed

sdk/storage/azure-storage-file-datalake/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 12.3.0-beta.2 (Unreleased)
44
- Added support to specify whether or not a pipeline policy should be added per call or per retry.
55
- Modified DataLakeAclChangeFailedException to extend AzureException
6+
- Fixed a bug where the endpoint would be improperly converted if the account name contained the word dfs.
67

78
## 12.3.0-beta.1 (2020-10-01)
89
- Added support for the 2020-02-10 service version.

sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
public class DataLakeImplUtils {
1313
public static String endpointToDesiredEndpoint(String endpoint, String desiredEndpoint, String currentEndpoint) {
14-
// Add the . on either side to prevent overwriting an endpoint if a user provides a
14+
// Add the . on either side to prevent overwriting an account name.
1515
String desiredStringToMatch = "." + desiredEndpoint + ".";
16-
String currentStringToMatch = "." + currentEndpoint + ".";
16+
String currentRegexToMatch = "\\." + currentEndpoint + "\\.";
1717
if (endpoint.contains(desiredStringToMatch)) {
1818
return endpoint;
1919
} else {
20-
return endpoint.replaceFirst(currentStringToMatch, desiredStringToMatch);
20+
return endpoint.replaceFirst(currentRegexToMatch, desiredStringToMatch);
2121
}
2222
}
2323

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,64 @@
11
package com.azure.storage.file.datalake
22

3+
import com.azure.storage.common.StorageSharedKeyCredential
4+
import spock.lang.Specification
35
import spock.lang.Unroll
46

5-
class UrlTests extends APISpec {
7+
class UrlTests extends Specification {
8+
9+
StorageSharedKeyCredential credential = new StorageSharedKeyCredential("accountname", "accountkey");
610

711
@Unroll
812
def "test urls that should not change for datalake"() {
913
when:
1014
DataLakeServiceClient client = new DataLakeServiceClientBuilder()
1115
.endpoint(endpoint)
12-
.credential(primaryCredential)
16+
.credential(credential)
1317
.buildClient()
1418
then:
1519
client.getAccountUrl() == client.blobServiceClient.getAccountUrl()
1620

1721
where:
18-
endpoint | _
19-
"https://www.customstorageurl.com" | _
20-
"https://account.core.windows.net" | _
21-
"https://0.0.0.0/account" | _
22-
"https://account.file.core.windows.net" | _
22+
endpoint | _
23+
"https://www.customstorageurl.com" | _
24+
"https://account.core.windows.net" | _
25+
"https://0.0.0.0/account" | _
26+
"https://account.file.core.windows.net" | _
27+
"https://www.customdfsstorageurl.com" | _
28+
"https://dfsaccount.core.windows.net" | _
29+
"https://0.0.0.0/dfsaccount" | _
30+
"https://dfsaccount.file.core.windows.net" | _
2331
}
2432

2533
@Unroll
2634
def "test correct service url set"() {
2735
when:
28-
def blobUrl = "https://account.blob.core.windows.net"
29-
def dfsUrl = "https://account.dfs.core.windows.net"
30-
31-
def testUrl = blobUrl
32-
if (useDfsurl) {
33-
testUrl = dfsUrl
34-
}
35-
3636
DataLakeServiceClient serviceClient = new DataLakeServiceClientBuilder()
37-
.endpoint(testUrl)
38-
.credential(primaryCredential)
37+
.endpoint(url)
38+
.credential(credential)
3939
.buildClient()
4040
DataLakeFileSystemClient fileSystemClient = new DataLakeFileSystemClientBuilder()
41-
.endpoint(testUrl + "/container")
42-
.credential(primaryCredential)
41+
.endpoint(url + "/container")
42+
.credential(credential)
4343
.buildClient()
4444
DataLakeFileClient pathClient = new DataLakePathClientBuilder()
45-
.endpoint(testUrl + "/container/blob")
46-
.credential(primaryCredential)
45+
.endpoint(url + "/container/blob")
46+
.credential(credential)
4747
.buildFileClient()
4848
then:
4949
// In either case the dfs url should be set to the dfs client and blob url set to the blob client
50-
serviceClient.getAccountUrl() == dfsUrl
51-
serviceClient.blobServiceClient.getAccountUrl() == blobUrl
52-
fileSystemClient.getFileSystemUrl() == dfsUrl + "/container"
53-
fileSystemClient.blobContainerClient.getBlobContainerUrl() == blobUrl + "/container"
54-
pathClient.getPathUrl() == dfsUrl + "/container/blob"
55-
pathClient.blockBlobClient.getBlobUrl() == blobUrl + "/container/blob"
50+
serviceClient.getAccountUrl() == expectedDfsUrl
51+
serviceClient.blobServiceClient.getAccountUrl() == expectedBlobUrl
52+
fileSystemClient.getFileSystemUrl() == expectedDfsUrl + "/container"
53+
fileSystemClient.blobContainerClient.getBlobContainerUrl() == expectedBlobUrl + "/container"
54+
pathClient.getPathUrl() == expectedDfsUrl + "/container/blob"
55+
pathClient.blockBlobClient.getBlobUrl() == expectedBlobUrl + "/container/blob"
5656

5757
where:
58-
useDfsurl | _
59-
true | _
60-
false | _
58+
url || expectedBlobUrl | expectedDfsUrl
59+
"https://account.blob.core.windows.net" || "https://account.blob.core.windows.net" | "https://account.dfs.core.windows.net"
60+
"https://dfsaccount.blob.core.windows.net" || "https://dfsaccount.blob.core.windows.net" | "https://dfsaccount.dfs.core.windows.net"
61+
"https://account.dfs.core.windows.net" || "https://account.blob.core.windows.net" | "https://account.dfs.core.windows.net"
62+
"https://dfsaccount.dfs.core.windows.net" || "https://dfsaccount.blob.core.windows.net" | "https://dfsaccount.dfs.core.windows.net"
6163
}
6264
}

sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/UrlTeststestcorrectserviceurlset[0].json

Lines changed: 0 additions & 65 deletions
This file was deleted.

sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/UrlTeststestcorrectserviceurlset[1].json

Lines changed: 0 additions & 65 deletions
This file was deleted.

sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/UrlTeststesturlsthatshouldnotchangefordatalake[0].json

Lines changed: 0 additions & 65 deletions
This file was deleted.

sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/UrlTeststesturlsthatshouldnotchangefordatalake[1].json

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)