Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue that prevented creating while providing an AzureNamedKeyCredential as the sole form of authentication. #22492

Merged
merged 5 commits into from
Jun 24, 2021
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
3 changes: 2 additions & 1 deletion sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## 12.1.0-beta.1 (Unreleased)

### Bug Fixes
### Bug fixes
- Fixed issue where HTTP headers set in a `ClientOptions` object passed to a client builder would not be set on a client instantiated by said builder.
- Fixed an issue where a `connectionString` with an account name and key would override a `sasToken`'s authentication settings in client builders.

## 12.0.0 (2021-06-11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,14 @@ static void validateCredentials(AzureNamedKeyCredential azureNamedKeyCredential,
return;
} else {
throw logger.logExceptionAsError(new IllegalStateException("'connectionString' contains a SAS token"
+ " with different settings than 'sasToken'."));
+ " with different settings than the one provided using the builder's 'sasToken()' method."));
}
} else if (authSettings.getType() == StorageAuthenticationSettings.Type.ACCOUNT_NAME_KEY) {
throw logger.logExceptionAsError(new IllegalStateException("A 'connectionString' containing an account"
+ "name and key cannot be provided alongside a 'sasToken'."));
}

// If the 'connectionString' auth type is not SAS_TOKEN and a 'sasToken' was provided, then multiplte
// If the 'connectionString' auth type is not SAS_TOKEN and a 'sasToken' was provided, then multiple
// incompatible forms of authentication were specified in the client builder.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ public TableAsyncClient buildAsyncClient() {
}

HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline(
namedKeyCredential, azureSasCredential, sasToken, endpoint, retryPolicy, httpLogOptions,
clientOptions, httpClient, perCallPolicies, perRetryPolicies, configuration, logger);
namedKeyCredential != null ? namedKeyCredential : azureNamedKeyCredential, azureSasCredential, sasToken,
endpoint, retryPolicy, httpLogOptions, clientOptions, httpClient, perCallPolicies, perRetryPolicies,
configuration, logger);

return new TableAsyncClient(tableName, pipeline, endpoint, serviceVersion, TABLES_SERIALIZER,
TRANSACTIONAL_BATCH_SERIALIZER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ public TableServiceAsyncClient buildAsyncClient() {
}

HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline(
namedKeyCredential, azureSasCredential, sasToken, endpoint, retryPolicy, httpLogOptions,
clientOptions, httpClient, perCallPolicies, perRetryPolicies, configuration, logger);
namedKeyCredential != null ? namedKeyCredential : azureNamedKeyCredential, azureSasCredential, sasToken,
endpoint, retryPolicy, httpLogOptions, clientOptions, httpClient, perCallPolicies, perRetryPolicies,
configuration, logger);

return new TableServiceAsyncClient(pipeline, endpoint, serviceVersion, serializerAdapter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,43 +194,78 @@ public void addPerCallPolicy() {
assertTrue(retryPolicyPosition < perRetryPolicyPosition);
}

@Test
public void singleFormOfAuthenticationPresent() {
assertDoesNotThrow(() -> new TableClientBuilder()
.sasToken("sasToken")
.endpoint("https://myAccount.table.core.windows.net")
.tableName("myTable")
.buildAsyncClient());

assertDoesNotThrow(() -> new TableClientBuilder()
.credential(new AzureSasCredential("sasToken"))
.endpoint("https://myAccount.table.core.windows.net")
.tableName("myTable")
.buildAsyncClient());

assertDoesNotThrow(() -> new TableClientBuilder()
.credential(new AzureNamedKeyCredential("name", "key"))
.endpoint("https://myAccount.table.core.windows.net")
.tableName("myTable")
.buildAsyncClient());

// Should internally create an AzureNamedKeyCredential and not throw when building a client.
assertDoesNotThrow(() -> new TableClientBuilder()
.connectionString("DefaultEndpointsProtocol=https;AccountName=myAccount;AccountKey=myKey;EndpointSuffix=core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.tableName("myTable")
.buildAsyncClient());

// Should internally create an AzureSasCredential and not throw when building a client.
assertDoesNotThrow(() -> new TableClientBuilder()
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myAccount.table.core.windows.net")
.tableName("myTable")
.buildAsyncClient());
}

@Test
public void multipleFormsOfAuthenticationPresent() {
assertThrows(IllegalStateException.class, () -> new TableClientBuilder()
.sasToken("sasToken")
.credential(new AzureNamedKeyCredential("name", "key"))
.tableName("myTable")
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableClientBuilder()
.sasToken("sasToken")
.credential(new AzureSasCredential("sasToken"))
.tableName("myTable")
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableClientBuilder()
.credential(new AzureNamedKeyCredential("name", "key"))
.credential(new AzureSasCredential("sasToken"))
.tableName("myTable")
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableClientBuilder()
.sasToken("sasToken")
.credential(new AzureNamedKeyCredential("name", "key"))
.credential(new AzureSasCredential("sasToken"))
.tableName("myTable")
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());
}

@Test
public void buildWithSameSasTokenInConnectionStringDoesNotThrow() {
assertDoesNotThrow(() -> new TableClientBuilder()
.sasToken("sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.tableName("myTable")
.buildAsyncClient());
}
Expand All @@ -239,34 +274,47 @@ public void buildWithSameSasTokenInConnectionStringDoesNotThrow() {
public void buildWithDifferentSasTokenInConnectionStringThrows() {
assertThrows(IllegalStateException.class, () -> new TableClientBuilder()
.sasToken("sv=2020-02-10&ss=t&srt=o&sp=rwd&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=anotherSignature")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=anotherSignature")
.tableName("myTable")
.buildAsyncClient());
}

@Test
public void buildWithSameEndpointInConnectionStringDoesNotThrow() {
assertDoesNotThrow(() -> new TableClientBuilder()
.endpoint("https://myaccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myAccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.tableName("myTable")
.buildAsyncClient());
}

@Test
public void buildWithSameEndpointInConnectionStringWithTrailingSlashDoesNotThrow() {
public void buildWithWithTrailingSlashInEndpointOrConnectionStringDoesNotThrow() {
assertDoesNotThrow(() -> new TableClientBuilder()
.endpoint("https://myaccount.table.core.windows.net")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myAccount.table.core.windows.net")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.tableName("myTable")
.buildAsyncClient());

assertDoesNotThrow(() -> new TableClientBuilder()
.endpoint("https://myAccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.tableName("myTable")
.buildAsyncClient());
}


@Test
public void buildWithDifferentEndpointInConnectionStringThrows() {
assertThrows(IllegalStateException.class, () -> new TableClientBuilder()
.endpoint("https://myotheraccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myOtherAccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.tableName("myTable")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableClientBuilder()
.endpoint("https://myAccount.table.core.windows.net/")
.connectionString("DefaultEndpointsProtocol=https;AccountName=myOtherAccount;AccountKey=myKey;EndpointSuffix=core.windows.net")
.tableName("myTable")
.buildAsyncClient());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,71 +185,111 @@ public void addPerCallPolicy() {
assertTrue(retryPolicyPosition < perRetryPolicyPosition);
}

@Test
public void singleFormOfAuthenticationPresent() {
assertDoesNotThrow(() -> new TableServiceClientBuilder()
.sasToken("sasToken")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertDoesNotThrow(() -> new TableServiceClientBuilder()
.credential(new AzureSasCredential("sasToken"))
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertDoesNotThrow(() -> new TableServiceClientBuilder()
.credential(new AzureNamedKeyCredential("name", "key"))
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

// Should internally create an AzureNamedKeyCredential and not throw when building a client.
assertDoesNotThrow(() -> new TableServiceClientBuilder()
.connectionString("DefaultEndpointsProtocol=https;AccountName=myAccount;AccountKey=myKey;EndpointSuffix=core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

// Should internally create an AzureSasCredential and not throw when building a client.
assertDoesNotThrow(() -> new TableServiceClientBuilder()
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());
}

@Test
public void multipleFormsOfAuthenticationPresent() {
assertThrows(IllegalStateException.class, () -> new TableServiceClientBuilder()
.sasToken("sasToken")
.credential(new AzureNamedKeyCredential("name", "key"))
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableServiceClientBuilder()
.sasToken("sasToken")
.credential(new AzureSasCredential("sasToken"))
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableServiceClientBuilder()
.credential(new AzureNamedKeyCredential("name", "key"))
.credential(new AzureSasCredential("sasToken"))
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableServiceClientBuilder()
.sasToken("sasToken")
.credential(new AzureNamedKeyCredential("name", "key"))
.credential(new AzureSasCredential("sasToken"))
.endpoint("https://myaccount.table.core.windows.net")
.endpoint("https://myAccount.table.core.windows.net")
.buildAsyncClient());
}

@Test
public void buildWithSameSasTokenInConnectionStringDoesNotThrow() {
assertDoesNotThrow(() -> new TableServiceClientBuilder()
.sasToken("sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.buildAsyncClient());
}

@Test
public void buildWithDifferentSasTokenInConnectionStringThrows() {
assertThrows(IllegalStateException.class, () -> new TableServiceClientBuilder()
.sasToken("sv=2020-02-10&ss=t&srt=o&sp=rwd&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=anotherSignature")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=anotherSignature")
.buildAsyncClient());
}

@Test
public void buildWithSameEndpointInConnectionStringDoesNotThrow() {
assertDoesNotThrow(() -> new TableServiceClientBuilder()
.endpoint("https://myaccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myAccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.buildAsyncClient());
}

@Test
public void buildWithSameEndpointInConnectionStringWithTrailingSlashDoesNotThrow() {
public void buildWithWithTrailingSlashInEndpointOrConnectionStringDoesNotThrow() {
assertDoesNotThrow(() -> new TableServiceClientBuilder()
.endpoint("https://myaccount.table.core.windows.net")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myAccount.table.core.windows.net")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.buildAsyncClient());

assertDoesNotThrow(() -> new TableServiceClientBuilder()
.endpoint("https://myAccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myAccount.table.core.windows.net;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.buildAsyncClient());
}

@Test
public void buildWithDifferentEndpointInConnectionStringThrows() {
assertThrows(IllegalStateException.class, () -> new TableServiceClientBuilder()
.endpoint("https://myotheraccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.endpoint("https://myAccount.table.core.windows.net/")
.connectionString("TableEndpoint=https://myOtherAccount.table.core.windows.net/;SharedAccessSignature=sv=2020-02-10&ss=t&srt=o&sp=rwdlacu&se=2021-06-04T04:45:57Z&st=2021-06-03T20:45:57Z&spr=https&sig=someSignature")
.buildAsyncClient());

assertThrows(IllegalStateException.class, () -> new TableServiceClientBuilder()
.endpoint("https://myAccount.table.core.windows.net/")
.connectionString("DefaultEndpointsProtocol=https;AccountName=myOtherAccount;AccountKey=myKey;EndpointSuffix=core.windows.net")
.buildAsyncClient());
}
}