-
Notifications
You must be signed in to change notification settings - Fork 10
ATO-2559: Add feature flag for defaulting tokenAuthMethod #8362
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: main
Are you sure you want to change the base?
Changes from all commits
1ac2d9d
d7baa4f
728b856
0284f30
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package uk.gov.di.orchestration.shared.utils; | ||
|
|
||
| import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod; | ||
| import uk.gov.di.orchestration.shared.entity.ClientRegistry; | ||
| import uk.gov.di.orchestration.shared.services.ConfigurationService; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class ClientUtils { | ||
| private ClientUtils() {} | ||
|
|
||
| public static String getTokenAuthMethodOrDefault( | ||
| ClientRegistry clientRegistry, ConfigurationService configurationService) { | ||
| var tokenAuthMethod = clientRegistry.getTokenAuthMethod(); | ||
| if (Objects.isNull(tokenAuthMethod) && configurationService.isUseDefaultTokenAuthMethod()) { | ||
| tokenAuthMethod = ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue(); | ||
| } | ||
| return tokenAuthMethod; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package uk.gov.di.orchestration.shared.utils; | ||
|
|
||
| import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import uk.gov.di.orchestration.shared.entity.ClientRegistry; | ||
| import uk.gov.di.orchestration.shared.services.ConfigurationService; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class ClientUtilsTest { | ||
|
Check warning on line 14 in orchestration-shared/src/test/java/uk/gov/di/orchestration/shared/utils/ClientUtilsTest.java
|
||
| private final ConfigurationService configurationService = mock(ConfigurationService.class); | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
|
Check warning on line 18 in orchestration-shared/src/test/java/uk/gov/di/orchestration/shared/utils/ClientUtilsTest.java
|
||
| when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(false); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldDefaultToPrivateKeyJwtIfFeatureFlagIsEnabledAndTokenAuthMethodIsNull() { | ||
| when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(true); | ||
| var client = clientWithTokenAuthMethod(null); | ||
|
|
||
| var actualTokenAuthMethod = | ||
| ClientUtils.getTokenAuthMethodOrDefault(client, configurationService); | ||
| assertEquals(actualTokenAuthMethod, ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotDefaultToPrivateKeyJwtIfFeatureFlagDisabled() { | ||
| when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(false); | ||
| var client = clientWithTokenAuthMethod(null); | ||
|
|
||
| var actualTokenAuthMethod = | ||
| ClientUtils.getTokenAuthMethodOrDefault(client, configurationService); | ||
| assertNull(actualTokenAuthMethod); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotDefaultToPrivateKeyJwtIfFeatureFlagIsEnabledAndTokenAuthMethodIsAlreadySet() { | ||
| when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(true); | ||
| var client = | ||
| clientWithTokenAuthMethod(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()); | ||
|
|
||
| var actualTokenAuthMethod = | ||
| ClientUtils.getTokenAuthMethodOrDefault(client, configurationService); | ||
| assertEquals( | ||
| actualTokenAuthMethod, ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()); | ||
| } | ||
|
|
||
| private ClientRegistry clientWithTokenAuthMethod(String tokenAuthMethod) { | ||
| return new ClientRegistry() | ||
| .withClientID("client-id") | ||
| .withClientName("client-one") | ||
| .withTokenAuthMethod(tokenAuthMethod); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.