-
Notifications
You must be signed in to change notification settings - Fork 298
potential fix for no Jwks URI specified error in tests #3169
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -361,8 +361,17 @@ public void testConfirmInstanceInvalidAttestationData() { | |
| @Test | ||
| public void testConfirmInstanceAzureSubscriptionIssues() 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()); | ||
|
|
||
| InstanceAzureProvider provider = new InstanceAzureProvider(); | ||
| setUpExternalCredentialsProvider(provider); | ||
|
|
||
| provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider", null, null); | ||
|
|
||
| InstanceConfirmation confirmation = new InstanceConfirmation(); | ||
|
|
@@ -372,36 +381,24 @@ public void testConfirmInstanceAzureSubscriptionIssues() throws IOException { | |
| Map<String, String> attributes = new HashMap<>(); | ||
| confirmation.setAttributes(attributes); | ||
|
|
||
| AzureAttestationData data = new AzureAttestationData(); | ||
| data.setVmId("2222-3333"); | ||
| data.setSubscriptionId("1111-2222"); | ||
|
|
||
| confirmation.setAttestationData(provider.jsonMapper.writeValueAsString(data)); | ||
|
|
||
| try { | ||
| provider.confirmInstance(confirmation); | ||
| fail(); | ||
| } catch (ProviderResourceException ex) { | ||
| assertTrue(ex.getMessage().contains("Unable to extract Azure Subscription id")); | ||
| } | ||
|
|
||
| // add the subscription but different from what's in the data object | ||
|
|
||
| attributes.put(InstanceProvider.ZTS_INSTANCE_AZURE_SUBSCRIPTION, "1111-3333"); | ||
|
|
||
| try { | ||
| provider.confirmInstance(confirmation); | ||
| fail(); | ||
| } catch (ProviderResourceException ex) { | ||
| assertTrue(ex.getMessage().contains("Azure Subscription Id mismatch")); | ||
| } | ||
| System.clearProperty(InstanceAzureProvider.AZURE_PROP_ZTS_RESOURCE_URI); | ||
| System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_CONFIG_URI); | ||
| System.clearProperty(InstanceAzureProvider.AZURE_PROP_OPENID_JWKS_URI); | ||
|
|
||
| provider.close(); | ||
| removeOpenIdConfigFile(configFile, jwksUri); | ||
|
Comment on lines
+384
to
+388
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original test logic for AzureAttestationData data = new AzureAttestationData();
data.setVmId("2222-3333");
data.setSubscriptionId("1111-2222");
confirmation.setAttestationData(provider.jsonMapper.writeValueAsString(data));
try {
provider.confirmInstance(confirmation);
fail();
} catch (ProviderResourceException ex) {
assertTrue(ex.getMessage().contains("Unable to extract Azure Subscription id"));
}
// add the subscription but different from what's in the data object
attributes.put(InstanceProvider.ZTS_INSTANCE_AZURE_SUBSCRIPTION, "1111-3333");
try {
provider.confirmInstance(confirmation);
fail();
} catch (ProviderResourceException ex) {
assertTrue(ex.getMessage().contains("Azure Subscription Id mismatch"));
}
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); |
||
| } | ||
|
|
||
| @Test | ||
| public void testConfirmInstanceSanDnsMismatch() 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()); | ||
|
|
||
| InstanceAzureProvider provider = new InstanceAzureProvider(); | ||
| setUpExternalCredentialsProvider(provider); | ||
| provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider", null, null); | ||
|
|
@@ -430,6 +427,12 @@ public void testConfirmInstanceSanDnsMismatch() 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); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is significant code duplication across multiple tests for setting up and tearing down the Azure OpenID configuration (creating config files, setting system properties). This makes the tests harder to read and maintain. Consider refactoring this logic into helper methods. For example, you could create
setupAzureOpenIdConfig()andtearDownAzureOpenIdConfig()methods and call them from the respective tests. This would also require makingconfigFileandjwksUriclass members.