Skip to content

Commit

Permalink
Merge pull request #2398 from govuk-one-login/pyic-7383-ticf-routing
Browse files Browse the repository at this point in the history
PYIC-7383 TICF special routing
  • Loading branch information
Joe-Edwards-GDS authored Sep 10, 2024
2 parents a8ac9c8 + 0aead2d commit 0dae422
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 94 deletions.
16 changes: 14 additions & 2 deletions journey-map/public/render.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const addDefinitionOptions = (definition, disabledOptions, featureFlagOptions) =

// Traverse the journey map to collect the available 'disabled' and 'featureFlag' options
export const getOptions = (journeyMaps) => {
const disabledOptions = [];
const disabledOptions = ['ticf'];
const featureFlagOptions = [];

Object.values(journeyMaps).forEach((journeyMap) => {
Expand All @@ -31,6 +31,9 @@ export const getOptions = (journeyMaps) => {
});
});

disabledOptions.sort();
featureFlagOptions.sort();

return { disabledOptions, featureFlagOptions };
};

Expand Down Expand Up @@ -140,7 +143,16 @@ const renderTransitions = (journeyStates, formData) => {

const eventsByTarget = {};
Object.entries(events).forEach(([eventName, def]) => {
const { targetJourney, targetState, exitEventToEmit } = resolveEventTarget(def, formData);
let resolvedTarget = resolveEventTarget(def, formData);

// Special case for disabling TICF, to match the special case in the journey engine
if (journeyStates[resolvedTarget.targetState]?.response?.lambda === 'call-ticf-cri' &&
formData.getAll('disabledCri').includes('ticf')) {
resolvedTarget = resolveEventTarget(
journeyStates[resolvedTarget.targetState].events.next, formData);
}

const { targetJourney, targetState, exitEventToEmit } = resolvedTarget;

const target = exitEventToEmit
? `exit_${exitEventToEmit}`.toUpperCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import uk.gov.di.ipv.core.library.auditing.extension.AuditExtensions;
import uk.gov.di.ipv.core.library.auditing.restricted.AuditRestrictedDeviceInformation;
import uk.gov.di.ipv.core.library.config.ConfigurationVariable;
import uk.gov.di.ipv.core.library.domain.Cri;
import uk.gov.di.ipv.core.library.domain.ErrorResponse;
import uk.gov.di.ipv.core.library.domain.IpvJourneyTypes;
import uk.gov.di.ipv.core.library.domain.JourneyRequest;
Expand Down Expand Up @@ -59,6 +60,7 @@

import static com.amazonaws.util.CollectionUtils.isNullOrEmpty;
import static uk.gov.di.ipv.core.library.config.ConfigurationVariable.BACKEND_SESSION_TIMEOUT;
import static uk.gov.di.ipv.core.library.config.ConfigurationVariable.CREDENTIAL_ISSUER_ENABLED;
import static uk.gov.di.ipv.core.library.domain.IpvJourneyTypes.SESSION_TIMEOUT;
import static uk.gov.di.ipv.core.library.helpers.LogHelper.LogField.LOG_JOURNEY_EVENT;
import static uk.gov.di.ipv.core.library.helpers.LogHelper.LogField.LOG_JOURNEY_TYPE;
Expand All @@ -74,6 +76,8 @@ public class ProcessJourneyEventHandler
private static final StepResponse BUILD_CLIENT_OAUTH_RESPONSE =
new ProcessStepResponse(BUILD_CLIENT_OAUTH_RESPONSE_EVENT, null);
public static final String BACK_EVENT = "back";
private static final String TICF_CRI_LAMBDA = "call-ticf-cri";

private final IpvSessionService ipvSessionService;
private final AuditService auditService;
private final ConfigService configService;
Expand Down Expand Up @@ -305,6 +309,23 @@ private State executeStateTransition(
}
}

// Special case to skip TICF CRI if it has been disabled,
// to save us defining lots of fallback routes in the journey map
if (result.state() instanceof BasicState basicState
&& basicState.getResponse() instanceof ProcessStepResponse processResponse
&& TICF_CRI_LAMBDA.equals(processResponse.getLambda())
&& !configService.getBooleanParameter(
CREDENTIAL_ISSUER_ENABLED, Cri.TICF.getId())) {
LOGGER.info(LogHelper.buildLogMessage("Skipping disabled TICF CRI state"));
return executeStateTransition(
new JourneyState(basicState.getJourneyType(), basicState.getName()),
ipvSessionItem,
NEXT_EVENT,
null,
auditEventUser,
deviceInformation);
}

if (result.state() instanceof BasicState basicState) {
ipvSessionItem.pushState(
new JourneyState(basicState.getJourneyType(), basicState.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ states:
events:
met:
targetState: CRI_TICF_BEFORE_SUCCESS
checkIfDisabled:
ticf:
targetState: STORE_IDENTITY_BEFORE_SUCCESS
unmet:
targetJourney: FAILED
targetState: FAILED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_F2F
checkIfDisabled:
ticf:
targetState: CRI_F2F

# Parent states
CRI_STATE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_NO_MATCH
checkIfDisabled:
ticf:
targetState: NO_MATCH_PAGE

FAILED_SKIP_MESSAGE:
events:
next:
targetState: CRI_TICF_BEFORE_RETURN_TO_RP
checkIfDisabled:
ticf:
targetState: RETURN_TO_RP

FAILED_CONFIRM_DETAILS:
events:
Expand All @@ -32,20 +26,6 @@ states:
- IPV_USER_DETAILS_UPDATE_END
auditContext:
successful: false
checkIfDisabled:
ticf:
targetState: COULD_NOT_CONFIRM_DETAILS_PAGE
auditEvents:
- IPV_USER_DETAILS_UPDATE_END
auditContext:
successful: false
checkFeatureFlag:
updateDetailsAccountDeletion:
targetState: COULD_NOT_CONFIRM_DETAILS_PAGE_WITH_DELETION
auditEvents:
- IPV_USER_DETAILS_UPDATE_END
auditContext:
successful: false
checkFeatureFlag:
updateDetailsAccountDeletion:
targetState: CRI_TICF_BEFORE_COULD_NOT_CONFIRM_DETAILS_WITH_DELETION
Expand All @@ -62,27 +42,6 @@ states:
- IPV_USER_DETAILS_UPDATE_END
auditContext:
successful: false
checkIfDisabled:
ticf:
targetState: COULD_NOT_CONFIRM_DETAILS_PAGE
auditEvents:
- IPV_USER_DETAILS_UPDATE_END
auditContext:
successful: false
checkFeatureFlag:
updateDetailsAccountDeletion:
targetState: COULD_NOT_UPDATE_DETAILS_PAGE
auditEvents:
- IPV_USER_DETAILS_UPDATE_END
auditContext:
successful: false
checkJourneyContext:
rfc:
targetState: COULD_NOT_UPDATE_DETAILS_PAGE_RFC
auditEvents:
- IPV_USER_DETAILS_UPDATE_END
auditContext:
successful: false
checkFeatureFlag:
updateDetailsAccountDeletion:
targetState: CRI_TICF_BEFORE_COULD_NOT_UPDATE_DETAILS
Expand All @@ -102,17 +61,11 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_NO_MATCH_BAV
checkIfDisabled:
ticf:
targetState: NO_MATCH_PAGE_BAV

FAILED_NINO:
events:
next:
targetState: CRI_TICF_BEFORE_NO_MATCH_NINO
checkIfDisabled:
ticf:
targetState: NO_MATCH_PAGE_NINO

FAILED_NO_TICF:
events:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_ANOTHER_WAY
checkIfDisabled:
ticf:
targetState: ANOTHER_WAY_PAGE

INELIGIBLE_NO_TICF:
events:
Expand All @@ -24,9 +21,6 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_RETURN_TO_RP
checkIfDisabled:
ticf:
targetState: RETURN_TO_RP

# Journey states

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_RETURN_TO_RP
checkIfDisabled:
ticf:
targetState: RETURN_TO_RP

# Journey states

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_RETURN_TO_RP
checkIfDisabled:
ticf:
targetState: RETURN_TO_RP

# Journey states

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ states:
events:
met:
targetState: CRI_TICF_BEFORE_SUCCESS_RFC
checkIfDisabled:
ticf:
targetState: STORE_IDENTITY_BEFORE_SUCCESS
unmet:
targetJourney: FAILED
targetState: FAILED_CONFIRM_DETAILS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_REUSE
checkIfDisabled:
ticf:
targetState: IDENTITY_REUSE_PAGE
checkFeatureFlag:
deleteDetailsEnabled:
targetState: IDENTITY_REUSE_PAGE_TEST

UPDATE_DETAILS_START:
events:
Expand All @@ -41,12 +35,6 @@ states:
targetState: ERROR
identity-stored:
targetState: CRI_TICF_BEFORE_REUSE
checkIfDisabled:
ticf:
targetState: IDENTITY_REUSE_PAGE
checkFeatureFlag:
deleteDetailsEnabled:
targetState: IDENTITY_REUSE_PAGE_TEST

CRI_TICF_BEFORE_REUSE:
response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ states:
events:
coi-check-passed:
targetState: CRI_TICF
checkIfDisabled:
ticf:
targetState: RETURN_TO_RP
coi-check-failed:
targetJourney: FAILED
targetState: FAILED_CONFIRM_DETAILS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ states:
events:
next:
targetState: CRI_TICF_BEFORE_ERROR
checkIfDisabled:
ticf:
targetState: ERROR_PAGE

ERROR_NO_TICF:
events:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ states:
events:
met:
targetState: CRI_TICF_BEFORE_SUCCESS_UPDATE_ADDRESS
checkIfDisabled:
ticf:
targetState: STORE_IDENTITY_BEFORE_SUCCESS
unmet:
targetJourney: FAILED
targetState: FAILED_CONFIRM_DETAILS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,6 @@ states:
events:
met:
targetState: CRI_TICF_BEFORE_SUCCESS
checkIfDisabled:
ticf:
targetState: STORE_IDENTITY_BEFORE_SUCCESS
unmet:
targetJourney: FAILED
targetState: FAILED_CONFIRM_DETAILS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ states:
targetState: PAGE_STATE_AT_START_OF_NO_PHOTO_ID
eventFive:
targetState: PAGE_STATE_WITH_BACK_EVENT
eventSix:
targetState: TICF_CRI_STATE

CRI_STATE:
response:
Expand Down Expand Up @@ -145,3 +147,11 @@ states:
response:
type: page
pageId: page-id-for-another-page-state

TICF_CRI_STATE:
response:
type: process
lambda: call-ticf-cri
events:
next:
targetState: ANOTHER_PAGE_STATE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand All @@ -22,6 +23,7 @@
import uk.gov.di.ipv.core.library.auditing.extension.AuditExtensionSubjourneyType;
import uk.gov.di.ipv.core.library.auditing.extension.AuditExtensionSuccessful;
import uk.gov.di.ipv.core.library.auditing.extension.AuditExtensionUserDetailsUpdateSelected;
import uk.gov.di.ipv.core.library.domain.Cri;
import uk.gov.di.ipv.core.library.domain.ErrorResponse;
import uk.gov.di.ipv.core.library.domain.IpvJourneyTypes;
import uk.gov.di.ipv.core.library.domain.JourneyRequest;
Expand Down Expand Up @@ -947,6 +949,37 @@ void shouldReturn500IfStateMachineNotFoundWhenCheckingPageState() throws Excepti
assertEquals(ErrorResponse.FAILED_JOURNEY_ENGINE_STEP.getMessage(), response.get(MESSAGE));
}

@ParameterizedTest
@CsvSource({"true,/journey/call-ticf-cri,", "false,,page-id-for-another-page-state"})
void shouldSkipTicfCriOnlyIfDisabled(
boolean enabled, String expectedJourney, String expectedPage) throws Exception {
var input =
JourneyRequest.builder()
.ipAddress(TEST_IP)
.journey("eventSix")
.ipvSessionId(TEST_IP)
.build();

when(mockConfigService.getBooleanParameter(CREDENTIAL_ISSUER_ENABLED, Cri.TICF.getId()))
.thenReturn(enabled);

mockIpvSessionItemAndTimeout("PAGE_STATE");

ProcessJourneyEventHandler processJourneyEventHandler =
new ProcessJourneyEventHandler(
mockAuditService,
mockIpvSessionService,
mockConfigService,
mockClientOAuthSessionService,
List.of(INITIAL_JOURNEY_SELECTION, TECHNICAL_ERROR),
StateMachineInitializerMode.TEST);

Map<String, Object> output = processJourneyEventHandler.handleRequest(input, mockContext);

assertEquals(expectedJourney, output.get("journey"));
assertEquals(expectedPage, output.get("page"));
}

private void mockIpvSessionItemAndTimeout(String userState) throws Exception {
IpvSessionItem ipvSessionItem = spy(IpvSessionItem.class);
ipvSessionItem.setIpvSessionId(SecureTokenHelper.getInstance().generate());
Expand Down

0 comments on commit 0dae422

Please sign in to comment.