Skip to content
Merged
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 @@ -113,13 +113,7 @@ public void testInitializeDefaults() throws IOException {
@Test
public void testInitializeEmptyValues() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, false);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(false);

System.clearProperty(InstanceAzureProvider.AZURE_PROP_DNS_SUFFIX);

Expand All @@ -129,10 +123,7 @@ public void testInitializeEmptyValues() throws IOException {

assertTrue(provider.dnsSuffixes.isEmpty());
provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);
clearProviderSettings();
}

@Test
Expand Down Expand Up @@ -237,13 +228,8 @@ public void testConfirmInstanceProviderConfig() throws IOException, ProviderReso
@Test
public void testRefreshInstance() throws IOException, ProviderResourceException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, true);
setupProviderSettings(true);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider", null, null);
Expand Down Expand Up @@ -296,12 +282,7 @@ public void testRefreshInstance() throws IOException, ProviderResourceException
assertNotNull(providerConfirm);

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

private HttpDriver setupHttpDriver() throws IOException {
Expand Down Expand Up @@ -361,6 +342,8 @@ public void testConfirmInstanceInvalidAttestationData() {
@Test
public void testConfirmInstanceAzureSubscriptionIssues() throws IOException {

setupProviderSettings(false);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider", null, null);
Expand Down Expand Up @@ -397,11 +380,14 @@ public void testConfirmInstanceAzureSubscriptionIssues() throws IOException {
}

provider.close();
clearProviderSettings();
}

@Test
public void testConfirmInstanceSanDnsMismatch() throws IOException {

setupProviderSettings(false);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider", null, null);
Expand Down Expand Up @@ -430,18 +416,13 @@ public void testConfirmInstanceSanDnsMismatch() throws IOException {
}

provider.close();
clearProviderSettings();
}

@Test
public void testConfirmInstanceInvalidAccessToken() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, false);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(false);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
Expand Down Expand Up @@ -475,12 +456,7 @@ public void testConfirmInstanceInvalidAccessToken() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

@Test
Expand Down Expand Up @@ -526,24 +502,13 @@ public void testConfirmInstanceAudienceMismatch() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

@Test
public void testConfirmInstanceUnableToFetchVMDetails() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, true);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(true);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
Expand Down Expand Up @@ -619,24 +584,13 @@ public void testConfirmInstanceUnableToFetchVMDetails() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

@Test
public void testConfirmInstanceInvalidVMDetails() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, true);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(true);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
Expand Down Expand Up @@ -674,24 +628,13 @@ public void testConfirmInstanceInvalidVMDetails() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

@Test
public void testConfirmInstanceSubjectMismatch() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, true);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(true);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
Expand Down Expand Up @@ -746,24 +689,13 @@ public void testConfirmInstanceSubjectMismatch() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

@Test
public void testConfirmInstanceServiceNameMismatch() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, true);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(true);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
Expand Down Expand Up @@ -818,24 +750,13 @@ public void testConfirmInstanceServiceNameMismatch() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

@Test
public void testConfirmInstanceVMIdMismatch() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, true);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(true);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
Expand Down Expand Up @@ -890,12 +811,7 @@ public void testConfirmInstanceVMIdMismatch() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

@Test
Expand All @@ -913,13 +829,7 @@ public void testConfirmInstanceWithoutCredentialsProvider() {
@Test
public void testConfirmInstanceProviderMismatch() throws IOException {

File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, true);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
setupProviderSettings(true);

InstanceAzureProvider provider = new InstanceAzureProvider();
setUpExternalCredentialsProvider(provider);
Expand Down Expand Up @@ -974,12 +884,7 @@ public void testConfirmInstanceProviderMismatch() throws IOException {
}

provider.close();

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);

removeOpenIdConfigFile(configFile, jwksUri);
clearProviderSettings();
}

private String createAccessToken() {
Expand Down Expand Up @@ -1044,4 +949,24 @@ private void createOpenIdConfigFile(File configFile, File jwksUri, boolean creat
Files.write(jwksUri.toPath(), keyContents.getBytes());
}
}

private void setupProviderSettings(boolean bCreateJwksFile) throws IOException {
File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
createOpenIdConfigFile(configFile, jwksUri, bCreateJwksFile);

System.setProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI, "https://azure-zts");
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI, "file://" + configFile.getCanonicalPath());
System.setProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI, "file://" + jwksUri.getCanonicalPath());
}

private void clearProviderSettings() {
File configFile = new File("./src/test/resources/azure-openid.json");
File jwksUri = new File("./src/test/resources/azure-jwks.json");
removeOpenIdConfigFile(configFile, jwksUri);

System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI);
System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI);
}
}
Loading