Skip to content

Commit

Permalink
test: add test eid reissuing
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoMolinari95 committed Dec 23, 2024
1 parent 38afaa3 commit 503d15d
Showing 1 changed file with 136 additions and 1 deletion.
137 changes: 136 additions & 1 deletion ts/features/itwallet/machine/eid/__tests__/machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ describe("itwEidIssuanceMachine", () => {
resetWalletInstance,
trackWalletInstanceCreation,
trackWalletInstanceRevocation,
onInit: assign(onInit)
onInit: assign(onInit),
setIsReissuing : assign({
isReissuing: true
})
},
actors: {
createWalletInstance: fromPromise<string>(createWalletInstance),
Expand Down Expand Up @@ -982,4 +985,136 @@ describe("itwEidIssuanceMachine", () => {

expect(actor.getSnapshot().value).toStrictEqual("Idle");
});

it("Should obtain an eID (SPID), reissuing mode", async () => {

//The wallet instance and attestation already exist
const initialContext = {
...InitialContext,
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA,
};

const actor = createActor(mockedMachine);
actor.start();

actor.getSnapshot().context = initialContext;

await waitFor(() => expect(onInit).toHaveBeenCalledTimes(1));

expect(actor.getSnapshot().value).toStrictEqual("Idle");
expect(actor.getSnapshot().tags).toStrictEqual(new Set());

actor.send({ type: "start-reissuing" });

expect(actor.getSnapshot().value).toStrictEqual({
UserIdentification: "ModeSelection"
});

expect(actor.getSnapshot().context).toStrictEqual<Context>({
...initialContext,
isReissuing: true
});

/**
* Choose SPID as identification mode
*/

actor.send({ type: "select-identification-mode", mode: "spid" });

expect(actor.getSnapshot().value).toStrictEqual({
UserIdentification: {
Spid: "IdpSelection"
}
});
expect(actor.getSnapshot().tags).toStrictEqual(new Set());
expect(navigateToIdpSelectionScreen).toHaveBeenCalledTimes(1);

/**
* Choose first IDP in list for SPID identification
*/

startAuthFlow.mockImplementation(() => Promise.resolve({}));

requestEid.mockImplementation(() =>
Promise.resolve(ItwStoredCredentialsMocks.eid)
);

issuedEidMatchesAuthenticatedUser.mockImplementation(() => true);

actor.send({ type: "select-spid-idp", idp: idps[0] });

expect(actor.getSnapshot().value).toStrictEqual({
UserIdentification: {
Spid: "StartingSpidAuthFlow"
}
});

expect(actor.getSnapshot().context).toStrictEqual<Context>({
...initialContext,
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA,
isReissuing: true,
identification: {
mode: "spid",
idpId: idps[0].id
}
});

expect(actor.getSnapshot().tags).toStrictEqual(new Set([ItwTags.Loading]));

await waitFor(() => expect(startAuthFlow).toHaveBeenCalledTimes(1));

expect(actor.getSnapshot().value).toStrictEqual({
UserIdentification: {
Spid: "CompletingSpidAuthFlow"
}
});

actor.send({
type: "user-identification-completed",
authRedirectUrl: "http://test.it"
});

expect(actor.getSnapshot().value).toStrictEqual({
Issuance: "RequestingEid"
});

expect(actor.getSnapshot().tags).toStrictEqual(new Set([ItwTags.Loading]));
expect(actor.getSnapshot().context).toMatchObject({
authenticationContext: {
callbackUrl: "http://test.it"
}
});
expect(navigateToEidPreviewScreen).toHaveBeenCalledTimes(1);

// EID obtained

await waitFor(() =>
expect(actor.getSnapshot().value).toStrictEqual({
Issuance: "DisplayingPreview"
})
);

actor.send({ type: "add-to-wallet" });

expect(storeEidCredential).toHaveBeenCalledTimes(1);
expect(setWalletInstanceToValid).toHaveBeenCalledTimes(1);
expect(navigateToWallet).toHaveBeenCalledTimes(1);

expect(actor.getSnapshot().context).toStrictEqual<Context>({
...initialContext,
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA,
isReissuing: true,
identification: {
mode: "spid",
idpId: idps[0].id
},
authenticationContext: expect.objectContaining({
callbackUrl: "http://test.it"
}),
eid: ItwStoredCredentialsMocks.eid
});
});
});

0 comments on commit 503d15d

Please sign in to comment.