Skip to content

Commit

Permalink
Fixed bug with DataLakeImplUtils.endpointToDesiredEndpoint (Azure#17449)
Browse files Browse the repository at this point in the history
Co-authored-by: gapra <gapra@microsoft.com>
  • Loading branch information
gapra-msft and gapra-msft authored Nov 10, 2020
1 parent d0fbe8d commit 925ee8a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 423 deletions.
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-file-datalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 12.3.0-beta.2 (Unreleased)
- Added support to specify whether or not a pipeline policy should be added per call or per retry.
- Modified DataLakeAclChangeFailedException to extend AzureException
- Fixed a bug where the endpoint would be improperly converted if the account name contained the word dfs.

## 12.3.0-beta.1 (2020-10-01)
- Added support for the 2020-02-10 service version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

public class DataLakeImplUtils {
public static String endpointToDesiredEndpoint(String endpoint, String desiredEndpoint, String currentEndpoint) {
// Add the . on either side to prevent overwriting an endpoint if a user provides a
// Add the . on either side to prevent overwriting an account name.
String desiredStringToMatch = "." + desiredEndpoint + ".";
String currentStringToMatch = "." + currentEndpoint + ".";
String currentRegexToMatch = "\\." + currentEndpoint + "\\.";
if (endpoint.contains(desiredStringToMatch)) {
return endpoint;
} else {
return endpoint.replaceFirst(currentStringToMatch, desiredStringToMatch);
return endpoint.replaceFirst(currentRegexToMatch, desiredStringToMatch);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,64 @@
package com.azure.storage.file.datalake

import com.azure.storage.common.StorageSharedKeyCredential
import spock.lang.Specification
import spock.lang.Unroll

class UrlTests extends APISpec {
class UrlTests extends Specification {

StorageSharedKeyCredential credential = new StorageSharedKeyCredential("accountname", "accountkey");

@Unroll
def "test urls that should not change for datalake"() {
when:
DataLakeServiceClient client = new DataLakeServiceClientBuilder()
.endpoint(endpoint)
.credential(primaryCredential)
.credential(credential)
.buildClient()
then:
client.getAccountUrl() == client.blobServiceClient.getAccountUrl()

where:
endpoint | _
"https://www.customstorageurl.com" | _
"https://account.core.windows.net" | _
"https://0.0.0.0/account" | _
"https://account.file.core.windows.net" | _
endpoint | _
"https://www.customstorageurl.com" | _
"https://account.core.windows.net" | _
"https://0.0.0.0/account" | _
"https://account.file.core.windows.net" | _
"https://www.customdfsstorageurl.com" | _
"https://dfsaccount.core.windows.net" | _
"https://0.0.0.0/dfsaccount" | _
"https://dfsaccount.file.core.windows.net" | _
}

@Unroll
def "test correct service url set"() {
when:
def blobUrl = "https://account.blob.core.windows.net"
def dfsUrl = "https://account.dfs.core.windows.net"

def testUrl = blobUrl
if (useDfsurl) {
testUrl = dfsUrl
}

DataLakeServiceClient serviceClient = new DataLakeServiceClientBuilder()
.endpoint(testUrl)
.credential(primaryCredential)
.endpoint(url)
.credential(credential)
.buildClient()
DataLakeFileSystemClient fileSystemClient = new DataLakeFileSystemClientBuilder()
.endpoint(testUrl + "/container")
.credential(primaryCredential)
.endpoint(url + "/container")
.credential(credential)
.buildClient()
DataLakeFileClient pathClient = new DataLakePathClientBuilder()
.endpoint(testUrl + "/container/blob")
.credential(primaryCredential)
.endpoint(url + "/container/blob")
.credential(credential)
.buildFileClient()
then:
// In either case the dfs url should be set to the dfs client and blob url set to the blob client
serviceClient.getAccountUrl() == dfsUrl
serviceClient.blobServiceClient.getAccountUrl() == blobUrl
fileSystemClient.getFileSystemUrl() == dfsUrl + "/container"
fileSystemClient.blobContainerClient.getBlobContainerUrl() == blobUrl + "/container"
pathClient.getPathUrl() == dfsUrl + "/container/blob"
pathClient.blockBlobClient.getBlobUrl() == blobUrl + "/container/blob"
serviceClient.getAccountUrl() == expectedDfsUrl
serviceClient.blobServiceClient.getAccountUrl() == expectedBlobUrl
fileSystemClient.getFileSystemUrl() == expectedDfsUrl + "/container"
fileSystemClient.blobContainerClient.getBlobContainerUrl() == expectedBlobUrl + "/container"
pathClient.getPathUrl() == expectedDfsUrl + "/container/blob"
pathClient.blockBlobClient.getBlobUrl() == expectedBlobUrl + "/container/blob"

where:
useDfsurl | _
true | _
false | _
url || expectedBlobUrl | expectedDfsUrl
"https://account.blob.core.windows.net" || "https://account.blob.core.windows.net" | "https://account.dfs.core.windows.net"
"https://dfsaccount.blob.core.windows.net" || "https://dfsaccount.blob.core.windows.net" | "https://dfsaccount.dfs.core.windows.net"
"https://account.dfs.core.windows.net" || "https://account.blob.core.windows.net" | "https://account.dfs.core.windows.net"
"https://dfsaccount.dfs.core.windows.net" || "https://dfsaccount.blob.core.windows.net" | "https://dfsaccount.dfs.core.windows.net"
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 925ee8a

Please sign in to comment.