|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package com.azure.spring.cloud.autoconfigure.implementation.aad.security.properties; |
| 5 | + |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 9 | + |
| 10 | +class AadAuthorizationServerEndpointsTests { |
| 11 | + |
| 12 | + private static final String DEFAULT_BASE_URI = "https://login.microsoftonline.com/"; |
| 13 | + private static final String CUSTOM_BASE_URI = "https://custom.endpoint.com/"; |
| 14 | + private static final String TENANT_ID = "test-tenant-id"; |
| 15 | + |
| 16 | + @Test |
| 17 | + void constructorWithNullBaseUri() { |
| 18 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(null, TENANT_ID); |
| 19 | + assertEquals(DEFAULT_BASE_URI, endpoints.getBaseUri()); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + void constructorWithEmptyBaseUri() { |
| 24 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints("", TENANT_ID); |
| 25 | + assertEquals(DEFAULT_BASE_URI, endpoints.getBaseUri()); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + void constructorWithWhitespaceBaseUri() { |
| 30 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(" ", TENANT_ID); |
| 31 | + assertEquals(DEFAULT_BASE_URI, endpoints.getBaseUri()); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void constructorWithValidBaseUri() { |
| 36 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(CUSTOM_BASE_URI, TENANT_ID); |
| 37 | + assertEquals(CUSTOM_BASE_URI, endpoints.getBaseUri()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void constructorWithBaseUriWithoutTrailingSlash() { |
| 42 | + String baseUriWithoutSlash = "https://custom.endpoint.com"; |
| 43 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(baseUriWithoutSlash, TENANT_ID); |
| 44 | + assertEquals(baseUriWithoutSlash + "/", endpoints.getBaseUri()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void getAuthorizationEndpoint() { |
| 49 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(DEFAULT_BASE_URI, TENANT_ID); |
| 50 | + String authEndpoint = endpoints.getAuthorizationEndpoint(); |
| 51 | + assertEquals(DEFAULT_BASE_URI + TENANT_ID + "/oauth2/v2.0/authorize", authEndpoint); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void getTokenEndpoint() { |
| 56 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(DEFAULT_BASE_URI, TENANT_ID); |
| 57 | + String tokenEndpoint = endpoints.getTokenEndpoint(); |
| 58 | + assertEquals(DEFAULT_BASE_URI + TENANT_ID + "/oauth2/v2.0/token", tokenEndpoint); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + void getJwkSetEndpoint() { |
| 63 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(DEFAULT_BASE_URI, TENANT_ID); |
| 64 | + String jwkSetEndpoint = endpoints.getJwkSetEndpoint(); |
| 65 | + assertEquals(DEFAULT_BASE_URI + TENANT_ID + "/discovery/v2.0/keys", jwkSetEndpoint); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + void getEndSessionEndpoint() { |
| 70 | + AadAuthorizationServerEndpoints endpoints = new AadAuthorizationServerEndpoints(DEFAULT_BASE_URI, TENANT_ID); |
| 71 | + String endSessionEndpoint = endpoints.getEndSessionEndpoint(); |
| 72 | + assertEquals(DEFAULT_BASE_URI + TENANT_ID + "/oauth2/v2.0/logout", endSessionEndpoint); |
| 73 | + } |
| 74 | +} |
0 commit comments