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 @@ -20,6 +20,10 @@
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import static com.azure.spring.cloud.autoconfigure.FakeCredentialInTest.CLIENT_ID_PLACEHOLDER;
import static com.azure.spring.cloud.autoconfigure.FakeCredentialInTest.PASSWORD_PLACEHOLDER;
import static com.azure.spring.cloud.autoconfigure.FakeCredentialInTest.SECRET;
import static com.azure.spring.cloud.autoconfigure.FakeCredentialInTest.USERNAME_PLACEHOLDER;
import static com.azure.spring.cloud.core.implementation.util.ReflectionUtils.getField;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -37,55 +41,55 @@ public abstract class AbstractAzureServiceConfigurationTests<T extends AbstractA
@Test
protected void usGovCloudShouldWorkWithClientSecretCredential() {
getMinimalContextRunner()
.withPropertyValues(
getPropertyPrefix() + ".profile.cloud-type=AZURE_US_GOVERNMENT",
getPropertyPrefix() + ".profile.tenant-id=fake-tenant-id",
getPropertyPrefix() + ".credential.client-id=fake-client-id",
getPropertyPrefix() + ".credential.client-secret=fake-client-secret"
)
.withConfiguration(AutoConfigurations.of(
AzureTokenCredentialAutoConfiguration.class,
AzureGlobalPropertiesAutoConfiguration.class
))
.run(context -> {
assertSovereignCloudsSetInCredential(context, ClientSecretCredential.class);
});
.withPropertyValues(
getPropertyPrefix() + ".profile.cloud-type=AZURE_US_GOVERNMENT",
getPropertyPrefix() + ".profile.tenant-id=fake-tenant-id",
getPropertyPrefix() + ".credential." + CLIENT_ID_PLACEHOLDER + "=fakeClientIdPlaceholder",
getPropertyPrefix() + ".credential.client-" + SECRET + "=fake-client-secret"
)
.withConfiguration(AutoConfigurations.of(
AzureTokenCredentialAutoConfiguration.class,
AzureGlobalPropertiesAutoConfiguration.class
))
.run(context -> {
assertSovereignCloudsSetInCredential(context, ClientSecretCredential.class);
});
}

@Test
protected void usGovCloudShouldWorkWithClientCertificateCredential() {
getMinimalContextRunner()
.withPropertyValues(
getPropertyPrefix() + ".profile.cloud-type=AZURE_US_GOVERNMENT",
getPropertyPrefix() + ".profile.tenant-id=fake-tenant-id",
getPropertyPrefix() + ".credential.client-id=fake-client-id",
getPropertyPrefix() + ".credential.client-certificate-path=fake-client-cert-path"
)
.withConfiguration(AutoConfigurations.of(
AzureTokenCredentialAutoConfiguration.class,
AzureGlobalPropertiesAutoConfiguration.class
))
.run(context -> {
assertSovereignCloudsSetInCredential(context, ClientCertificateCredential.class);
});
.withPropertyValues(
getPropertyPrefix() + ".profile.cloud-type=AZURE_US_GOVERNMENT",
getPropertyPrefix() + ".profile.tenant-id=fake-tenant-id",
getPropertyPrefix() + ".credential." + CLIENT_ID_PLACEHOLDER + "=fakeClientIdPlaceholder",
getPropertyPrefix() + ".credential.client-certificate-path=fake-client-cert-path"
)
.withConfiguration(AutoConfigurations.of(
AzureTokenCredentialAutoConfiguration.class,
AzureGlobalPropertiesAutoConfiguration.class
))
.run(context -> {
assertSovereignCloudsSetInCredential(context, ClientCertificateCredential.class);
});
}

@Test
protected void usGovCloudShouldWorkWithUsernamePasswordCredential() {
getMinimalContextRunner()
.withPropertyValues(
getPropertyPrefix() + ".profile.cloud-type=AZURE_US_GOVERNMENT",
getPropertyPrefix() + ".credential.client-id=fake-client-id",
getPropertyPrefix() + ".credential.username=123",
getPropertyPrefix() + ".credential.password=123"
)
.withConfiguration(AutoConfigurations.of(
AzureTokenCredentialAutoConfiguration.class,
AzureGlobalPropertiesAutoConfiguration.class
))
.run(context -> {
assertSovereignCloudsSetInCredential(context, UsernamePasswordCredential.class);
});
.withPropertyValues(
getPropertyPrefix() + ".profile.cloud-type=AZURE_US_GOVERNMENT",
getPropertyPrefix() + ".credential." + CLIENT_ID_PLACEHOLDER + "=fakeClientIdPlaceholder",
getPropertyPrefix() + ".credential." + USERNAME_PLACEHOLDER + "=fakeNamePlaceholder",
getPropertyPrefix() + ".credential." + PASSWORD_PLACEHOLDER + "=fakePasswordPlaceholder"
)
.withConfiguration(AutoConfigurations.of(
AzureTokenCredentialAutoConfiguration.class,
AzureGlobalPropertiesAutoConfiguration.class
))
.run(context -> {
assertSovereignCloudsSetInCredential(context, UsernamePasswordCredential.class);
});
}

private <C> void assertSovereignCloudsSetInCredential(AssertableApplicationContext context, Class<C> credentialType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure;

/**
* Fake credential shared in Tests
*/
public class FakeCredentialInTest {
/**
* Username placeholder
*/
public static final String USERNAME_PLACEHOLDER = "username";

/**
* Password placeholder
*/
public static final String PASSWORD_PLACEHOLDER = "password";

/**
* Client ID placeholder
*/
public static final String CLIENT_ID_PLACEHOLDER = "client-id";

/**
* Secret placeholder
*/
public static final String SECRET = "secret";
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void setup() {
properties.getProfile().getEnvironment().setMicrosoftGraphEndpoint(MOCK_MICROSOFT_GRAPH_ENDPOINT);
endpoints = new AadAuthorizationServerEndpoints(properties.getProfile().getEnvironment().getActiveDirectoryEndpoint(), properties.getProfile().getTenantId());
clientId = "client";
clientSecret = "pass";
clientSecret = "fakeCredentialPlaceholder";
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testVcapSingleServiceWithNulls() throws IOException {
assertEquals("dbs/ZFxCAA==/", config.getCredentials().get("documentdb_database_link"));
assertEquals("https://hostname:443/", config.getCredentials().get("documentdb_host_endpoint"));
assertEquals(
"3becR7JFnWamMvGwWYWWTV4WpeNhN8tOzJ74yjAxPKDpx65q2lYz60jt8WXU6HrIKrAIwhs0Hglf0123456789==",
"fakeCredentialPlaceholder",
config.getCredentials().get("documentdb_master_key"));
} catch (IOException e) {
LOG.error("Error reading json file", e);
Expand Down Expand Up @@ -127,7 +127,7 @@ public void testVcapUserProvidedService() throws IOException {
assertEquals("dbs/ZFxCAA==/", config.getCredentials().get("documentdb_database_link"));
assertEquals("https://hostname:443/", config.getCredentials().get("documentdb_host_endpoint"));
assertEquals(
"3becR7JFnWamMvGwWYWWTV4WpeNhN8tOzJ74yjAxPKDpx65q2lYz60jt8WXU6HrIKrAIwhs0Hglf0123456789==",
"fakeCredentialPlaceholder",
config.getCredentials().get("documentdb_master_key"));
} catch (IOException e) {
LOG.error("Error reading json file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"documentdb_database_id": "docdb123mj",
"documentdb_database_link": "dbs/ZFxCAA==/",
"documentdb_host_endpoint": "https://hostname:443/",
"documentdb_master_key": "3becR7JFnWamMvGwWYWWTV4WpeNhN8tOzJ74yjAxPKDpx65q2lYz60jt8WXU6HrIKrAIwhs0Hglf0123456789=="
"documentdb_master_key": "fakeCredentialPlaceholder"
},
"label": "azure-documentdb",
"name": "mydocumentdb",
Expand All @@ -17,4 +17,3 @@
}
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"documentdb_database_id": "docdb123mj",
"documentdb_database_link": "dbs/ZFxCAA==/",
"documentdb_host_endpoint": "https://hostname:443/",
"documentdb_master_key": "3becR7JFnWamMvGwWYWWTV4WpeNhN8tOzJ74yjAxPKDpx65q2lYz60jt8WXU6HrIKrAIwhs0Hglf0123456789=="
"documentdb_master_key": "fakeCredentialPlaceholder"
},
"label": "user-provided",
"name": "mydocumentdb",
Expand All @@ -17,4 +17,3 @@
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.service.implementation.storage;

/**
* Fake credential list.
*/
public final class FakeCredentialInTest {
/**
* Fake customer provided key credential.
*/
public static final String FAKE_CUSTOMER_PROVIDED_KEY =
"JdppJP5eH1w/CQ0cx4RGYWoC7NmQ0nmDbYR2PYWSDTXojV9bI1ck0Eh0sUIg8xj4KYj7tv+ZPLICu3BgLt6mMz==";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.List;

import static com.azure.spring.cloud.service.implementation.storage.FakeCredentialInTest.FAKE_CUSTOMER_PROVIDED_KEY;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand All @@ -34,7 +35,6 @@ class AzureBlobClientBuilderFactoryTests
AzureBlobClientBuilderFactoryTests.BlobServiceClientBuilderFactoryExt> {

private static final String ENDPOINT = "https://abc.blob.core.windows.net/";
private static final String CUSTOMER_PROVIDED_KEY = "JdppJP5eH1w/CQ0cx4RGYWoC7NmQ0nmDbYR2PYWSDTXojV9bI1ck0Eh0sUIg8xj4KYj7tv+ZPLICu3BgLt6mMz==";
private static final String CONNECTION_STRING = "BlobEndpoint=https://test.blob.core.windows.net/;"
+ "QueueEndpoint=https://test.queue.core.windows.net/;FileEndpoint=https://test.file.core.windows.net/;"
+ "TableEndpoint=https://test.table.core.windows.net/;SharedAccessSignature=sv=2020-08-04"
Expand Down Expand Up @@ -92,7 +92,7 @@ protected void buildClient(BlobServiceClientBuilder builder) {
protected void verifyServicePropertiesConfigured() {
AzureStorageBlobTestProperties properties = new AzureStorageBlobTestProperties();
properties.setEndpoint(ENDPOINT);
properties.setCustomerProvidedKey(CUSTOMER_PROVIDED_KEY);
properties.setCustomerProvidedKey(FAKE_CUSTOMER_PROVIDED_KEY);
properties.setEncryptionScope("test-scope");
properties.setServiceVersion(BlobServiceVersion.V2019_07_07);

Expand Down