@@ -113,13 +113,7 @@ public void testInitializeDefaults() throws IOException {
113113 @ Test
114114 public void testInitializeEmptyValues () throws IOException {
115115
116- File configFile = new File ("./src/test/resources/azure-openid.json" );
117- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
118- createOpenIdConfigFile (configFile , jwksUri , false );
119-
120- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
121- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
122- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
116+ setupProviderSettings (false );
123117
124118 System .clearProperty (InstanceAzureProvider .AZURE_PROP_DNS_SUFFIX );
125119
@@ -129,10 +123,7 @@ public void testInitializeEmptyValues() throws IOException {
129123
130124 assertTrue (provider .dnsSuffixes .isEmpty ());
131125 provider .close ();
132-
133- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
134- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
135- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
126+ clearProviderSettings ();
136127 }
137128
138129 @ Test
@@ -237,13 +228,8 @@ public void testConfirmInstanceProviderConfig() throws IOException, ProviderReso
237228 @ Test
238229 public void testRefreshInstance () throws IOException , ProviderResourceException {
239230
240- File configFile = new File ("./src/test/resources/azure-openid.json" );
241- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
242- createOpenIdConfigFile (configFile , jwksUri , true );
231+ setupProviderSettings (true );
243232
244- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
245- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
246- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
247233 InstanceAzureProvider provider = new InstanceAzureProvider ();
248234 setUpExternalCredentialsProvider (provider );
249235 provider .initialize ("provider" , "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider" , null , null );
@@ -296,12 +282,7 @@ public void testRefreshInstance() throws IOException, ProviderResourceException
296282 assertNotNull (providerConfirm );
297283
298284 provider .close ();
299-
300- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
301- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
302- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
303-
304- removeOpenIdConfigFile (configFile , jwksUri );
285+ clearProviderSettings ();
305286 }
306287
307288 private HttpDriver setupHttpDriver () throws IOException {
@@ -361,6 +342,8 @@ public void testConfirmInstanceInvalidAttestationData() {
361342 @ Test
362343 public void testConfirmInstanceAzureSubscriptionIssues () throws IOException {
363344
345+ setupProviderSettings (false );
346+
364347 InstanceAzureProvider provider = new InstanceAzureProvider ();
365348 setUpExternalCredentialsProvider (provider );
366349 provider .initialize ("provider" , "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider" , null , null );
@@ -397,11 +380,14 @@ public void testConfirmInstanceAzureSubscriptionIssues() throws IOException {
397380 }
398381
399382 provider .close ();
383+ clearProviderSettings ();
400384 }
401385
402386 @ Test
403387 public void testConfirmInstanceSanDnsMismatch () throws IOException {
404388
389+ setupProviderSettings (false );
390+
405391 InstanceAzureProvider provider = new InstanceAzureProvider ();
406392 setUpExternalCredentialsProvider (provider );
407393 provider .initialize ("provider" , "com.yahoo.athenz.instance.provider.impl.InstanceAzureProvider" , null , null );
@@ -430,18 +416,13 @@ public void testConfirmInstanceSanDnsMismatch() throws IOException {
430416 }
431417
432418 provider .close ();
419+ clearProviderSettings ();
433420 }
434421
435422 @ Test
436423 public void testConfirmInstanceInvalidAccessToken () throws IOException {
437424
438- File configFile = new File ("./src/test/resources/azure-openid.json" );
439- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
440- createOpenIdConfigFile (configFile , jwksUri , false );
441-
442- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
443- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
444- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
425+ setupProviderSettings (false );
445426
446427 InstanceAzureProvider provider = new InstanceAzureProvider ();
447428 setUpExternalCredentialsProvider (provider );
@@ -475,12 +456,7 @@ public void testConfirmInstanceInvalidAccessToken() throws IOException {
475456 }
476457
477458 provider .close ();
478-
479- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
480- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
481- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
482-
483- removeOpenIdConfigFile (configFile , jwksUri );
459+ clearProviderSettings ();
484460 }
485461
486462 @ Test
@@ -526,24 +502,13 @@ public void testConfirmInstanceAudienceMismatch() throws IOException {
526502 }
527503
528504 provider .close ();
529-
530- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
531- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
532- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
533-
534- removeOpenIdConfigFile (configFile , jwksUri );
505+ clearProviderSettings ();
535506 }
536507
537508 @ Test
538509 public void testConfirmInstanceUnableToFetchVMDetails () throws IOException {
539510
540- File configFile = new File ("./src/test/resources/azure-openid.json" );
541- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
542- createOpenIdConfigFile (configFile , jwksUri , true );
543-
544- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
545- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
546- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
511+ setupProviderSettings (true );
547512
548513 InstanceAzureProvider provider = new InstanceAzureProvider ();
549514 setUpExternalCredentialsProvider (provider );
@@ -619,24 +584,13 @@ public void testConfirmInstanceUnableToFetchVMDetails() throws IOException {
619584 }
620585
621586 provider .close ();
622-
623- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
624- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
625- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
626-
627- removeOpenIdConfigFile (configFile , jwksUri );
587+ clearProviderSettings ();
628588 }
629589
630590 @ Test
631591 public void testConfirmInstanceInvalidVMDetails () throws IOException {
632592
633- File configFile = new File ("./src/test/resources/azure-openid.json" );
634- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
635- createOpenIdConfigFile (configFile , jwksUri , true );
636-
637- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
638- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
639- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
593+ setupProviderSettings (true );
640594
641595 InstanceAzureProvider provider = new InstanceAzureProvider ();
642596 setUpExternalCredentialsProvider (provider );
@@ -674,24 +628,13 @@ public void testConfirmInstanceInvalidVMDetails() throws IOException {
674628 }
675629
676630 provider .close ();
677-
678- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
679- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
680- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
681-
682- removeOpenIdConfigFile (configFile , jwksUri );
631+ clearProviderSettings ();
683632 }
684633
685634 @ Test
686635 public void testConfirmInstanceSubjectMismatch () throws IOException {
687636
688- File configFile = new File ("./src/test/resources/azure-openid.json" );
689- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
690- createOpenIdConfigFile (configFile , jwksUri , true );
691-
692- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
693- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
694- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
637+ setupProviderSettings (true );
695638
696639 InstanceAzureProvider provider = new InstanceAzureProvider ();
697640 setUpExternalCredentialsProvider (provider );
@@ -746,24 +689,13 @@ public void testConfirmInstanceSubjectMismatch() throws IOException {
746689 }
747690
748691 provider .close ();
749-
750- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
751- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
752- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
753-
754- removeOpenIdConfigFile (configFile , jwksUri );
692+ clearProviderSettings ();
755693 }
756694
757695 @ Test
758696 public void testConfirmInstanceServiceNameMismatch () throws IOException {
759697
760- File configFile = new File ("./src/test/resources/azure-openid.json" );
761- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
762- createOpenIdConfigFile (configFile , jwksUri , true );
763-
764- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
765- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
766- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
698+ setupProviderSettings (true );
767699
768700 InstanceAzureProvider provider = new InstanceAzureProvider ();
769701 setUpExternalCredentialsProvider (provider );
@@ -818,24 +750,13 @@ public void testConfirmInstanceServiceNameMismatch() throws IOException {
818750 }
819751
820752 provider .close ();
821-
822- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
823- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
824- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
825-
826- removeOpenIdConfigFile (configFile , jwksUri );
753+ clearProviderSettings ();
827754 }
828755
829756 @ Test
830757 public void testConfirmInstanceVMIdMismatch () throws IOException {
831758
832- File configFile = new File ("./src/test/resources/azure-openid.json" );
833- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
834- createOpenIdConfigFile (configFile , jwksUri , true );
835-
836- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
837- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
838- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
759+ setupProviderSettings (true );
839760
840761 InstanceAzureProvider provider = new InstanceAzureProvider ();
841762 setUpExternalCredentialsProvider (provider );
@@ -890,12 +811,7 @@ public void testConfirmInstanceVMIdMismatch() throws IOException {
890811 }
891812
892813 provider .close ();
893-
894- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
895- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
896- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
897-
898- removeOpenIdConfigFile (configFile , jwksUri );
814+ clearProviderSettings ();
899815 }
900816
901817 @ Test
@@ -913,13 +829,7 @@ public void testConfirmInstanceWithoutCredentialsProvider() {
913829 @ Test
914830 public void testConfirmInstanceProviderMismatch () throws IOException {
915831
916- File configFile = new File ("./src/test/resources/azure-openid.json" );
917- File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
918- createOpenIdConfigFile (configFile , jwksUri , true );
919-
920- System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
921- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
922- System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
832+ setupProviderSettings (true );
923833
924834 InstanceAzureProvider provider = new InstanceAzureProvider ();
925835 setUpExternalCredentialsProvider (provider );
@@ -974,12 +884,7 @@ public void testConfirmInstanceProviderMismatch() throws IOException {
974884 }
975885
976886 provider .close ();
977-
978- System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
979- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
980- System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
981-
982- removeOpenIdConfigFile (configFile , jwksUri );
887+ clearProviderSettings ();
983888 }
984889
985890 private String createAccessToken () {
@@ -1044,4 +949,24 @@ private void createOpenIdConfigFile(File configFile, File jwksUri, boolean creat
1044949 Files .write (jwksUri .toPath (), keyContents .getBytes ());
1045950 }
1046951 }
952+
953+ private void setupProviderSettings (boolean bCreateJwksFile ) throws IOException {
954+ File configFile = new File ("./src/test/resources/azure-openid.json" );
955+ File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
956+ createOpenIdConfigFile (configFile , jwksUri , bCreateJwksFile );
957+
958+ System .setProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI , "https://azure-zts" );
959+ System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI , "file://" + configFile .getCanonicalPath ());
960+ System .setProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI , "file://" + jwksUri .getCanonicalPath ());
961+ }
962+
963+ private void clearProviderSettings () {
964+ File configFile = new File ("./src/test/resources/azure-openid.json" );
965+ File jwksUri = new File ("./src/test/resources/azure-jwks.json" );
966+ removeOpenIdConfigFile (configFile , jwksUri );
967+
968+ System .clearProperty (InstanceAzureProvider .AZURE_PROP_ZTS_RESOURCE_URI );
969+ System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_CONFIG_URI );
970+ System .clearProperty (InstanceAzureProvider .AZURE_PROP_OPENID_JWKS_URI );
971+ }
1047972}
0 commit comments