|
21 | 21 | import java.time.ZoneOffset; |
22 | 22 | import java.util.UUID; |
23 | 23 |
|
| 24 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | +import static org.hamcrest.core.IsInstanceOf.instanceOf; |
24 | 26 | import static org.mockito.Mockito.when; |
25 | 27 |
|
26 | 28 | @RunWith(PowerMockRunner.class) |
@@ -121,5 +123,86 @@ public void testInvalidIdCombination() { |
121 | 123 | new ManagedIdentityCredentialBuilder().clientId(CLIENT_ID).resourceId(resourceId).build(); |
122 | 124 | } |
123 | 125 |
|
| 126 | + @Test |
| 127 | + public void testArcIdentityCredentialCreated() { |
| 128 | + Configuration configuration = Configuration.getGlobalConfiguration().clone(); |
| 129 | + |
| 130 | + configuration.put("IDENTITY_ENDPOINT", "http://localhost"); |
| 131 | + configuration.put("IMDS_ENDPOINT", "http://localhost"); |
| 132 | + |
| 133 | + ManagedIdentityCredential cred = new ManagedIdentityCredentialBuilder().configuration(configuration).build(); |
| 134 | + assertThat("Received class " + cred.managedIdentityServiceCredential.getClass().toString(), |
| 135 | + cred.managedIdentityServiceCredential, instanceOf(ArcIdentityCredential.class)); |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void testServiceFabricMsiCredentialCreated() { |
| 140 | + Configuration configuration = Configuration.getGlobalConfiguration().clone(); |
| 141 | + |
| 142 | + configuration.put("IDENTITY_ENDPOINT", "http://localhost"); |
| 143 | + configuration.put("IDENTITY_SERVER_THUMBPRINT", "thumbprint"); |
| 144 | + configuration.put("IDENTITY_HEADER", "header"); |
| 145 | + |
| 146 | + ManagedIdentityCredential cred = new ManagedIdentityCredentialBuilder().configuration(configuration).build(); |
| 147 | + assertThat("Received class " + cred.managedIdentityServiceCredential.getClass().toString(), |
| 148 | + cred.managedIdentityServiceCredential, instanceOf(ServiceFabricMsiCredential.class)); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void testAppServiceMsi2019CredentialCreated() { |
| 153 | + Configuration configuration = Configuration.getGlobalConfiguration().clone(); |
| 154 | + |
| 155 | + configuration.put("IDENTITY_ENDPOINT", "http://localhost"); |
| 156 | + configuration.put("IDENTITY_HEADER", "header"); |
| 157 | + |
| 158 | + ManagedIdentityCredential cred = new ManagedIdentityCredentialBuilder().configuration(configuration).build(); |
| 159 | + assertThat("Received class " + cred.managedIdentityServiceCredential.getClass().toString(), |
| 160 | + cred.managedIdentityServiceCredential, instanceOf(AppServiceMsiCredential.class)); |
| 161 | + } |
| 162 | + |
| 163 | + @Test |
| 164 | + public void testAppServiceMsi2017CredentialCreated() { |
| 165 | + Configuration configuration = Configuration.getGlobalConfiguration().clone(); |
| 166 | + |
| 167 | + configuration.put("MSI_ENDPOINT", "http://localhost"); |
| 168 | + configuration.put("MSI_SECRET", "secret"); |
| 169 | + |
| 170 | + ManagedIdentityCredential cred = new ManagedIdentityCredentialBuilder().configuration(configuration).build(); |
| 171 | + assertThat("Received class " + cred.managedIdentityServiceCredential.getClass().toString(), |
| 172 | + cred.managedIdentityServiceCredential, instanceOf(AppServiceMsiCredential.class)); |
| 173 | + } |
| 174 | + |
| 175 | + @Test |
| 176 | + public void testCloudShellCredentialCreated() { |
| 177 | + Configuration configuration = Configuration.getGlobalConfiguration().clone(); |
| 178 | + |
| 179 | + configuration.put("MSI_ENDPOINT", "http://localhost"); |
| 180 | + |
| 181 | + ManagedIdentityCredential cred = new ManagedIdentityCredentialBuilder().configuration(configuration).build(); |
| 182 | + assertThat("Received class " + cred.managedIdentityServiceCredential.getClass().toString(), |
| 183 | + cred.managedIdentityServiceCredential, instanceOf(AppServiceMsiCredential.class)); |
| 184 | + } |
| 185 | + |
| 186 | + @Test |
| 187 | + public void testAksExchangeTokenCredentialCreated() { |
| 188 | + Configuration configuration = Configuration.getGlobalConfiguration().clone(); |
| 189 | + |
| 190 | + configuration.put("AZURE_TENANT_ID", "tenantId"); |
| 191 | + configuration.put("AZURE_CLIENT_ID", "clientId"); |
| 192 | + configuration.put("AZURE_FEDERATED_TOKEN_FILE", "tokenFile"); |
| 193 | + |
| 194 | + ManagedIdentityCredential cred = new ManagedIdentityCredentialBuilder().configuration(configuration).build(); |
| 195 | + assertThat("Received class " + cred.managedIdentityServiceCredential.getClass().toString(), |
| 196 | + cred.managedIdentityServiceCredential, instanceOf(AksExchangeTokenCredential.class)); |
| 197 | + } |
| 198 | + |
| 199 | + @Test |
| 200 | + public void testIMDSPodIdentityV1Credential() { |
| 201 | + Configuration configuration = Configuration.getGlobalConfiguration().clone(); |
| 202 | + |
| 203 | + ManagedIdentityCredential cred = new ManagedIdentityCredentialBuilder().configuration(configuration).build(); |
| 204 | + assertThat("Received class " + cred.managedIdentityServiceCredential.getClass().toString(), |
| 205 | + cred.managedIdentityServiceCredential, instanceOf(VirtualMachineMsiCredential.class)); |
| 206 | + } |
124 | 207 | } |
125 | 208 |
|
0 commit comments