Skip to content

Commit

Permalink
ConfigurationService Consistency Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminWCO committed May 14, 2024
1 parent ae96578 commit a985c38
Show file tree
Hide file tree
Showing 59 changed files with 361 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void setUp() {
cloudwatchMetricsService,
noSessionOrchestrationService);
when(configService.getLoginURI()).thenReturn(LOGIN_URL);
when(configService.getOidcApiBaseURL()).thenReturn(Optional.of(OIDC_BASE_URL));
when(configService.getOidcApiBaseURL()).thenReturn(Optional.of(URI.create(OIDC_BASE_URL)));
when(configService.getDocAppBackendURI()).thenReturn(CRI_URI);
when(context.getAwsRequestId()).thenReturn(REQUEST_ID);
when(cookieHelper.parseSessionCookie(anyMap())).thenCallRealMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void setUp() {
when(configService.getAccessTokenExpiry()).thenReturn(300L);
when(configService.getDocAppAuthorisationCallbackURI()).thenReturn(REDIRECT_URI);
when(configService.getEnvironment()).thenReturn("test");
when(configService.getDocAppJwksUri()).thenReturn(DOC_APP_JWKS_URI);
when(configService.getDocAppJwksURI()).thenReturn(DOC_APP_JWKS_URI);
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,21 @@ public boolean isAccountInterventionServiceActionEnabled() {
public boolean abortOnAccountInterventionsErrorResponse() {
return this.abortOnAisErrorResponse;
}

@Override
public URI getBackChannelLogoutQueueUri() {
return URI.create("back-channel-logout-queue-uri");
}

@Override
public URI getIPVAudience() {
return URI.create("ipv-audience");
}

@Override
public URI getIPVAuthorisationCallbackURI() {
return URI.create("ipv-authorisation-callback-uri");
}
}

private void setUpClientSession() throws Json.JsonException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import uk.gov.di.orchestration.shared.entity.ValidScopes;
import uk.gov.di.orchestration.shared.entity.VectorOfTrust;
import uk.gov.di.orchestration.shared.helpers.IdGenerator;
import uk.gov.di.orchestration.shared.helpers.LocaleHelper;
import uk.gov.di.orchestration.sharedtest.basetest.ApiGatewayHandlerIntegrationTest;
import uk.gov.di.orchestration.sharedtest.extensions.DocAppJwksExtension;
import uk.gov.di.orchestration.sharedtest.extensions.KmsKeyExtension;
Expand Down Expand Up @@ -132,13 +131,7 @@ public String getTxmaAuditQueueUrl() {
}

@Override
public boolean isLanguageEnabled(LocaleHelper.SupportedLanguage supportedLanguage) {
return supportedLanguage.equals(LocaleHelper.SupportedLanguage.EN)
|| supportedLanguage.equals(LocaleHelper.SupportedLanguage.CY);
}

@Override
public URI getDocAppJwksUri() {
public URI getDocAppJwksURI() {
try {
return new URIBuilder()
.setHost("localhost")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import uk.gov.di.orchestration.shared.entity.ClientType;
import uk.gov.di.orchestration.shared.entity.ValidClaims;
import uk.gov.di.orchestration.shared.serialization.Json;
import uk.gov.di.orchestration.shared.services.ConfigurationService;
import uk.gov.di.orchestration.sharedtest.basetest.ApiGatewayHandlerIntegrationTest;

import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -33,9 +35,12 @@ public class ClientRegistrationIntegrationTest extends ApiGatewayHandlerIntegrat
private static final String VALID_PUBLIC_CERT =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxt91w8GsMDdklOpS8ZXAsIM1ztQZd5QT/bRCQahZJeS1a6Os4hbuKwzHlz52zfTNp7BL4RB/KOcRIPhOQLgqeyM+bVngRa1EIfTkugJHS2/gu2Xv0aelwvXj8FZgAPRPD+ps2wiV4tUehrFIsRyHZM3yOp9g6qapCcxF7l0E1PlVkKPcPNmxn2oFiqnP6ZThGbE+N2avdXHcySIqt/v6Hbmk8cDHzSExazW7j/XvA+xnp0nQ5m2GisCZul5If5edCTXD0tKzx/I/gtEG4gkv9kENWOt4grP8/0zjNAl2ac6kpRny3tY5RkKBKCOB1VHwq2lUTSNKs32O1BsA5ByyYQIDAQAB";

private static final ConfigurationService CONFIGURATION_SERVICE =
new ClientRegistrationIntegrationTest.TestConfigurationService();

@BeforeEach
void setup() {
handler = new ClientRegistrationHandler(TXMA_ENABLED_CONFIGURATION_SERVICE);
handler = new ClientRegistrationHandler(CONFIGURATION_SERVICE);
txmaAuditQueue.clear();
}

Expand Down Expand Up @@ -96,4 +101,27 @@ void shouldCallRegisterEndpointAndReturn200(

assertTxmaAuditEventsReceived(txmaAuditQueue, List.of(REGISTER_CLIENT_REQUEST_RECEIVED));
}

protected static class TestConfigurationService extends IntegrationTestConfigurationService {

public TestConfigurationService() {
super(
externalTokenSigner,
storageTokenSigner,
ipvPrivateKeyJwtSigner,
spotQueue,
docAppPrivateKeyJwtSigner,
configurationParameters);
}

@Override
public String getTxmaAuditQueueUrl() {
return txmaAuditQueue.getQueueUrl();
}

@Override
public URI getBackChannelLogoutQueueUri() {
return URI.create("back-channel-logout-queue-uri");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public URI getDocAppAuthorisationCallbackURI() {
}

@Override
public URI getDocAppJwksUri() {
public URI getDocAppJwksURI() {
try {
return new URIBuilder()
.setHost("localhost")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ void shouldSendAuthenticationErrorResponseToRPWhenCRIRequestReturns404()
assertThat(response, hasStatus(302));
assertThat(
response.getHeaders().get(ResponseHeaders.LOCATION),
startsWith(
TEST_CONFIGURATION_SERVICE.getDocAppAuthorisationCallbackURI().toString()));
startsWith(configurationService.getDocAppAuthorisationCallbackURI().toString()));
assertThat(
response.getHeaders().get(ResponseHeaders.LOCATION),
containsString("error=access_denied&error_description=Not+found&state="));
Expand Down Expand Up @@ -414,11 +413,6 @@ public URI getDocAppAuthorisationCallbackURI() {
return URI.create("http://localhost/redirect");
}

@Override
public String getDocAppCriDataEndpoint() {
return "/userinfo/v2";
}

@Override
public String getTxmaAuditQueueUrl() {
return txmaAuditQueue.getQueueUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class IPVAuthorisationHandlerIntegrationTest extends ApiGatewayHandlerIntegratio
private static final String CLIENT_NAME = "some-client-name";

private static final URI REDIRECT_URI = URI.create("http://localhost/redirect");
private static final String INTERNAl_SECTOR_URI = "https://ipv/redirect";
private static final URI INTERNAl_SECTOR_URI = URI.create("https://ipv/redirect");

private static final String TEST_EMAIL_ADDRESS = "test@emailtest.com";
private static final String IPV_CLIENT_ID = "ipv-client-id";
Expand Down Expand Up @@ -195,7 +195,7 @@ public String getIPVAuthEncryptionPublicKey() {
}

@Override
public String getInternalSectorUri() {
public URI getInternalSectorURI() {
return INTERNAl_SECTOR_URI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import uk.gov.di.orchestration.shared.services.ConfigurationService;
import uk.gov.di.orchestration.sharedtest.basetest.ApiGatewayHandlerIntegrationTest;
import uk.gov.di.orchestration.sharedtest.extensions.IPVStubExtension;
import uk.gov.di.orchestration.sharedtest.extensions.KmsKeyExtension;
import uk.gov.di.orchestration.sharedtest.extensions.SnsTopicExtension;
import uk.gov.di.orchestration.sharedtest.extensions.SqsQueueExtension;
import uk.gov.di.orchestration.sharedtest.extensions.TokenSigningExtension;

Expand Down Expand Up @@ -76,13 +74,7 @@ class IPVCallbackHandlerIntegrationTest extends ApiGatewayHandlerIntegrationTest

protected final ConfigurationService configurationService =
new IPVCallbackHandlerIntegrationTest.TestConfigurationService(
ipvStub,
auditTopic,
notificationsQueue,
auditSigningKey,
externalTokenSigner,
ipvPrivateKeyJwtSigner,
spotQueue);
ipvStub, externalTokenSigner, ipvPrivateKeyJwtSigner, spotQueue);

private static final String CLIENT_ID = "test-client-id";
private static final String EMAIL = "joe.bloggs@digital.cabinet-office.gov.uk";
Expand Down Expand Up @@ -537,9 +529,6 @@ protected static class TestConfigurationService extends IntegrationTestConfigura

public TestConfigurationService(
IPVStubExtension ipvStub,
SnsTopicExtension auditEventTopic,
SqsQueueExtension notificationQueue,
KmsKeyExtension auditSigningKey,
TokenSigningExtension tokenSigningKey,
TokenSigningExtension ipvPrivateKeyJwtSigner,
SqsQueueExtension spotQueue) {
Expand Down Expand Up @@ -567,14 +556,13 @@ public URI getIPVBackendURI() {
}

@Override
public String getIPVAudience() {
public URI getIPVAudience() {
try {
return new URIBuilder()
.setHost("localhost")
.setPort(ipvStubExtension.getHttpPort())
.setScheme("http")
.build()
.toString();
.build();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -604,5 +592,15 @@ public String getTxmaAuditQueueUrl() {
public boolean isIPVNoSessionResponseEnabled() {
return true;
}

@Override
public URI getBackChannelLogoutQueueUri() {
return URI.create("back-channel-logout-queue-uri");
}

@Override
public URI getAccountInterventionServiceURI() {
return URI.create("account-interventions-service-uri");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import uk.gov.di.orchestration.shared.entity.ServiceType;
import uk.gov.di.orchestration.shared.helpers.NowHelper;
import uk.gov.di.orchestration.shared.serialization.Json;
import uk.gov.di.orchestration.shared.services.ConfigurationService;
import uk.gov.di.orchestration.sharedtest.basetest.ApiGatewayHandlerIntegrationTest;
import uk.gov.di.orchestration.sharedtest.helper.TokenGeneratorHelper;

Expand Down Expand Up @@ -52,10 +53,12 @@ public class LogoutIntegrationTest extends ApiGatewayHandlerIntegrationTest {
public static final String REDIRECT_URL = "https://rp-build.build.stubs.account.gov.uk/";
public static final String SESSION_ID = "session-id";
public static final String CLIENT_SESSION_ID = "client-session-id";
private static final ConfigurationService CONFIGURATION_SERVICE =
new LogoutIntegrationTest.TestConfigurationService();

@BeforeEach
void setup() {
handler = new LogoutHandler(TXMA_ENABLED_CONFIGURATION_SERVICE);
handler = new LogoutHandler(CONFIGURATION_SERVICE);
txmaAuditQueue.clear();
}

Expand Down Expand Up @@ -273,4 +276,27 @@ private AuthenticationRequest generateAuthRequest(Nonce nonce) {
.nonce(nonce)
.build();
}

protected static class TestConfigurationService extends IntegrationTestConfigurationService {

public TestConfigurationService() {
super(
externalTokenSigner,
storageTokenSigner,
ipvPrivateKeyJwtSigner,
spotQueue,
docAppPrivateKeyJwtSigner,
configurationParameters);
}

@Override
public String getTxmaAuditQueueUrl() {
return txmaAuditQueue.getQueueUrl();
}

@Override
public URI getBackChannelLogoutQueueUri() {
return URI.create("back-channel-logout-queue-uri");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import uk.gov.di.orchestration.shared.entity.ClientType;
import uk.gov.di.orchestration.shared.entity.ResponseHeaders;
import uk.gov.di.orchestration.shared.entity.ServiceType;
import uk.gov.di.orchestration.shared.helpers.LocaleHelper;
import uk.gov.di.orchestration.shared.services.ConfigurationService;
import uk.gov.di.orchestration.sharedtest.basetest.ApiGatewayHandlerIntegrationTest;
import uk.gov.di.orchestration.sharedtest.helper.KeyPairHelper;
Expand Down Expand Up @@ -57,7 +56,8 @@ class OrchestrationToAuthenticationAuthorizeIntegrationTest
private static final String AUTH_INTERNAL_CLIENT_ID = "authentication-orch-client-id";
private static final String RP_SECTOR_URI = "https://rp-sector-uri.com";
private static final String RP_REDIRECT_URI = "https://rp-uri/redirect";
private static final String ORCHESTRATION_REDIRECT_URI = "https://orchestration/redirect";
private static final URI ORCHESTRATION_REDIRECT_URI =
URI.create("https://orchestration/redirect");
private static final KeyPair KEY_PAIR = KeyPairHelper.GENERATE_RSA_KEY_PAIR();
private final String publicKey =
"-----BEGIN PUBLIC KEY-----\n"
Expand Down Expand Up @@ -295,7 +295,7 @@ private void validateStandardClaimsInJar(SignedJWT signedJWT) throws java.text.P
equalTo(ServiceType.MANDATORY.toString()));
assertThat(
signedJWT.getJWTClaimsSet().getClaim("redirect_uri"),
equalTo(ORCHESTRATION_REDIRECT_URI));
equalTo(ORCHESTRATION_REDIRECT_URI.toString()));
assertThat(signedJWT.getJWTClaimsSet().getClaim("rp_client_id"), equalTo(CLIENT_ID));
assertThat(
signedJWT.getJWTClaimsSet().getClaim("rp_sector_host"),
Expand Down Expand Up @@ -357,19 +357,13 @@ public String getTxmaAuditQueueUrl() {
return txmaAuditQueue.getQueueUrl();
}

@Override
public boolean isLanguageEnabled(LocaleHelper.SupportedLanguage supportedLanguage) {
return supportedLanguage.equals(LocaleHelper.SupportedLanguage.EN)
|| supportedLanguage.equals(LocaleHelper.SupportedLanguage.CY);
}

@Override
public String getOrchestrationClientId() {
return AUTH_INTERNAL_CLIENT_ID;
}

@Override
public String getOrchestrationRedirectUri() {
public URI getOrchestrationRedirectURI() {
return ORCHESTRATION_REDIRECT_URI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.gov.di.orchestration.shared.entity.ServiceType;
import uk.gov.di.orchestration.shared.entity.VectorOfTrust;
import uk.gov.di.orchestration.shared.serialization.Json;
import uk.gov.di.orchestration.shared.services.ConfigurationService;
import uk.gov.di.orchestration.sharedtest.basetest.ApiGatewayHandlerIntegrationTest;
import uk.gov.di.orchestration.sharedtest.helper.SignedCredentialHelper;

Expand Down Expand Up @@ -51,10 +52,12 @@ public class ProcessingIdentityIntegrationTest extends ApiGatewayHandlerIntegrat
private static final String TEST_EMAIL_ADDRESS = "test@emailtest.com";
public static final Scope SCOPE = new Scope(OIDCScopeValue.OPENID);
public static final State STATE = new State();
private static final ConfigurationService CONFIGURATION_SERVICE =
new ProcessingIdentityIntegrationTest.TestConfigurationService();

@BeforeEach
void setup() {
handler = new ProcessingIdentityHandler(TXMA_AND_AIS_ENABLED_CONFIGURATION_SERVICE);
handler = new ProcessingIdentityHandler(CONFIGURATION_SERVICE);
txmaAuditQueue.clear();
}

Expand Down Expand Up @@ -218,4 +221,32 @@ private byte[] setupUser() {
userStore.signUp(TEST_EMAIL_ADDRESS, "password-1", INTERNAL_SUBJECT);
return userStore.addSalt(TEST_EMAIL_ADDRESS);
}

protected static class TestConfigurationService extends IntegrationTestConfigurationService {

public TestConfigurationService() {
super(
externalTokenSigner,
storageTokenSigner,
ipvPrivateKeyJwtSigner,
spotQueue,
docAppPrivateKeyJwtSigner,
configurationParameters);
}

@Override
public String getTxmaAuditQueueUrl() {
return txmaAuditQueue.getQueueUrl();
}

@Override
public URI getBackChannelLogoutQueueUri() {
return URI.create("back-channel-logout-queue-uri");
}

@Override
public URI getAccountInterventionServiceURI() {
return URI.create("account-interventions-service-uri");
}
}
}

0 comments on commit a985c38

Please sign in to comment.