|
29 | 29 | import org.springframework.security.oauth2.jwt.JwtDecoder; |
30 | 30 | import org.springframework.security.oauth2.jwt.NimbusJwtDecoder; |
31 | 31 |
|
| 32 | +import java.util.Set; |
| 33 | + |
32 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
33 | 35 | import static org.mockito.ArgumentMatchers.any; |
34 | 36 | import static org.mockito.Mockito.atLeastOnce; |
@@ -182,6 +184,82 @@ void testExistAADB2CTrustedIssuerRepositoryBean() { |
182 | 184 | context.getBean(AadB2cTrustedIssuerRepository.class); |
183 | 185 | assertThat(aadb2CTrustedIssuerRepository).isNotNull(); |
184 | 186 | assertThat(aadb2CTrustedIssuerRepository).isExactlyInstanceOf(AadB2cTrustedIssuerRepository.class); |
| 187 | + |
| 188 | + Set<String> trustedIssuers = aadb2CTrustedIssuerRepository.getTrustedIssuers(); |
| 189 | + assertThat(trustedIssuers) |
| 190 | + .noneMatch(issuer -> issuer.startsWith("https://login.microsoftonline.com/")) |
| 191 | + .noneMatch(issuer -> issuer.startsWith("https://sts.windows.net/")) |
| 192 | + .noneMatch(issuer -> issuer.startsWith("https://sts.chinacloudapi.cn/")); |
| 193 | + }); |
| 194 | + } |
| 195 | + |
| 196 | + @Test |
| 197 | + void testValidateTenantIdRejectsCommon() { |
| 198 | + getDefaultContextRunner() |
| 199 | + .withPropertyValues(getB2CResourceServerProperties()) |
| 200 | + .withPropertyValues(String.format("%s=common", AadB2cConstants.TENANT_ID)) |
| 201 | + .withUserConfiguration(AadB2cResourceServerAutoConfiguration.class) |
| 202 | + .run(context -> { |
| 203 | + assertThat(context).hasFailed(); |
| 204 | + assertThat(context.getStartupFailure()) |
| 205 | + .hasRootCauseInstanceOf(IllegalArgumentException.class) |
| 206 | + .hasMessageContaining("cannot be null, empty, or set to"); |
| 207 | + }); |
| 208 | + } |
| 209 | + |
| 210 | + @Test |
| 211 | + void testValidateTenantIdRejectsEmptyString() { |
| 212 | + getDefaultContextRunner() |
| 213 | + .withPropertyValues(getB2CResourceServerProperties()) |
| 214 | + .withPropertyValues(String.format("%s=", AadB2cConstants.TENANT_ID)) |
| 215 | + .withUserConfiguration(AadB2cResourceServerAutoConfiguration.class) |
| 216 | + .run(context -> { |
| 217 | + assertThat(context).hasFailed(); |
| 218 | + assertThat(context.getStartupFailure()) |
| 219 | + .hasRootCauseInstanceOf(IllegalArgumentException.class) |
| 220 | + .hasMessageContaining("cannot be null, empty, or set to"); |
| 221 | + }); |
| 222 | + } |
| 223 | + |
| 224 | + @Test |
| 225 | + void testValidateTenantIdRejectsOrganizations() { |
| 226 | + getDefaultContextRunner() |
| 227 | + .withPropertyValues(getB2CResourceServerProperties()) |
| 228 | + .withPropertyValues(String.format("%s=organizations", AadB2cConstants.TENANT_ID)) |
| 229 | + .withUserConfiguration(AadB2cResourceServerAutoConfiguration.class) |
| 230 | + .run(context -> { |
| 231 | + assertThat(context).hasFailed(); |
| 232 | + assertThat(context.getStartupFailure()) |
| 233 | + .hasRootCauseInstanceOf(IllegalArgumentException.class) |
| 234 | + .hasMessageContaining("cannot be null, empty, or set to"); |
| 235 | + }); |
| 236 | + } |
| 237 | + |
| 238 | + @Test |
| 239 | + void testValidateTenantIdRejectsConsumers() { |
| 240 | + getDefaultContextRunner() |
| 241 | + .withPropertyValues(getB2CResourceServerProperties()) |
| 242 | + .withPropertyValues(String.format("%s=consumers", AadB2cConstants.TENANT_ID)) |
| 243 | + .withUserConfiguration(AadB2cResourceServerAutoConfiguration.class) |
| 244 | + .run(context -> { |
| 245 | + assertThat(context).hasFailed(); |
| 246 | + assertThat(context.getStartupFailure()) |
| 247 | + .hasRootCauseInstanceOf(IllegalArgumentException.class) |
| 248 | + .hasMessageContaining("cannot be null, empty, or set to"); |
| 249 | + }); |
| 250 | + } |
| 251 | + |
| 252 | + @Test |
| 253 | + void testValidateTenantIdRejectsReservedValuesWithWhitespaceAndCase() { |
| 254 | + getDefaultContextRunner() |
| 255 | + .withPropertyValues(getB2CResourceServerProperties()) |
| 256 | + .withPropertyValues(String.format("%s= COMMON ", AadB2cConstants.TENANT_ID)) |
| 257 | + .withUserConfiguration(AadB2cResourceServerAutoConfiguration.class) |
| 258 | + .run(context -> { |
| 259 | + assertThat(context).hasFailed(); |
| 260 | + assertThat(context.getStartupFailure()) |
| 261 | + .hasRootCauseInstanceOf(IllegalArgumentException.class) |
| 262 | + .hasMessageContaining("cannot be null, empty, or set to"); |
185 | 263 | }); |
186 | 264 | } |
187 | 265 |
|
|
0 commit comments