Skip to content

Commit

Permalink
[#IOCIT-161] Add new config for test CIE metadata (#128)
Browse files Browse the repository at this point in the history
* [#IOCIT-161] Add new config for test CIE metadata

* [#IOCIT-161] Remove useless console log

* [#IOCIT-161] Add test cie url in example app
  • Loading branch information
BurnedMarshal committed Jan 5, 2023
1 parent 48a3226 commit fbfed7f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/__mocks__/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ export const mockCIEIdpMetadata: Record<string, IDPEntityDescriptor> = {
}
};

export const mockCIETestIdpMetadata: Record<string, IDPEntityDescriptor> = {
xx_servizicie_coll: {
cert: (["CERT"] as unknown) as NonEmptyArray<NonEmptyString>,
entityID:
"https://collaudo.idserver.servizicie.interno.gov.it/idp/profile/SAML2/POST/SSO",
entryPoint:
"https://collaudo.idserver.servizicie.interno.gov.it/idp/profile/SAML2/Redirect/SLO",
logoutUrl: ""
}
};

export const mockTestenvIdpMetadata: Record<string, IDPEntityDescriptor> = {
xx_testenv2: {
cert: (["CERT"] as unknown) as NonEmptyArray<NonEmptyString>,
Expand Down
17 changes: 16 additions & 1 deletion src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getSpidStrategyOption } from "../utils/middleware";

import {
mockCIEIdpMetadata,
mockCIETestIdpMetadata,
mockIdpMetadata,
mockTestenvIdpMetadata
} from "../__mocks__/metadata";
Expand Down Expand Up @@ -84,6 +85,8 @@ const IDPMetadataUrl =
"https://registry.spid.gov.it/metadata/idp/spid-entities-idps.xml";
const spidCieUrl =
"https://idserver.servizicie.interno.gov.it:8443/idp/shibboleth";
const spidCieTestUrl =
"https://collaudo.idserver.servizicie.interno.gov.it/idp/shibboleth";

const expectedLoginPath = "/login";
const expectedSloPath = "/logout";
Expand Down Expand Up @@ -134,6 +137,7 @@ const serviceProviderConfig: IServiceProviderConfig = {
name: "Required attrs"
},
spidCieUrl,
spidCieTestUrl,
spidTestEnvUrl,
strictResponseValidation: {
"http://localhost:8080": true
Expand All @@ -153,6 +157,11 @@ function initMockFetchIDPMetadata(): void {
right<Error, Record<string, IDPEntityDescriptor>>(mockCIEIdpMetadata)
);
});
mockFetchIdpsMetadata.mockImplementationOnce(() => {
return fromEither(
right<Error, Record<string, IDPEntityDescriptor>>(mockCIETestIdpMetadata)
);
});
mockFetchIdpsMetadata.mockImplementationOnce(() => {
return fromEither(
right<Error, Record<string, IDPEntityDescriptor>>(mockTestenvIdpMetadata)
Expand All @@ -177,7 +186,7 @@ describe("io-spid-commons withSpid", () => {
acs: async () => ResponsePermanentRedirect({ href: "/success?acs" }),
logout: async () => ResponsePermanentRedirect({ href: "/success?logout" })
})();
expect(mockFetchIdpsMetadata).toBeCalledTimes(3);
expect(mockFetchIdpsMetadata).toBeCalledTimes(4);
const emptySpidStrategyOption = getSpidStrategyOption(spid.app);
expect(emptySpidStrategyOption).toHaveProperty("idp", {});

Expand All @@ -197,13 +206,19 @@ describe("io-spid-commons withSpid", () => {
);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
3,
spidCieTestUrl,
expect.any(Object)
);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
4,
`${spidTestEnvUrl}/metadata`,
expect.any(Object)
);
const spidStrategyOption = getSpidStrategyOption(spid.app);
expect(spidStrategyOption).toHaveProperty("idp", {
...mockIdpMetadata,
...mockCIEIdpMetadata,
...mockCIETestIdpMetadata,
...mockTestenvIdpMetadata
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const SPID_IDP_IDENTIFIERS = {
};

export const CIE_IDP_IDENTIFIERS = {
"https://collaudo.idserver.servizicie.interno.gov.it/idp/profile/SAML2/POST/SSO":
"xx_servizicie_coll",
"https://idserver.servizicie.interno.gov.it/idp/profile/SAML2/POST/SSO":
"xx_servizicie",
"https://preproduzione.idserver.servizicie.interno.gov.it/idp/profile/SAML2/POST/SSO":
Expand Down
2 changes: 2 additions & 0 deletions src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const serviceProviderConfig: IServiceProviderConfig = {
],
name: "Required attrs"
},
spidCieTestUrl:
"https://collaudo.idserver.servizicie.interno.gov.it/idp/shibboleth",
spidCieUrl:
"https://preproduzione.idserver.servizicie.interno.gov.it/idp/shibboleth?Metadata",
spidTestEnvUrl: "https://spid-testenv2:8088",
Expand Down
4 changes: 3 additions & 1 deletion src/strategy/__tests__/saml_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const serviceProviderConfig: IServiceProviderConfig = {
name: "Required attrs"
},
spidCieUrl: "https://idserver.servizicie.interno.gov.it:8443/idp/shibboleth",
spidCieTestUrl:
"https://collaudo.idserver.servizicie.interno.gov.it/idp/shibboleth",
spidTestEnvUrl: "https://spid-testenv2:8088",
spidValidatorUrl: "http://localhost:8080"
};
Expand Down Expand Up @@ -104,7 +106,7 @@ describe("CustomSamlClient#constructor", () => {
redisCacheProvider
);
expect(customSamlClient).toBeTruthy();

expect(customSamlClient["options"]).toHaveProperty(
"validateInResponseTo",
false
Expand Down
34 changes: 32 additions & 2 deletions src/utils/__tests__/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

import {
mockCIEIdpMetadata,
mockCIETestIdpMetadata,
mockIdpMetadata,
mockTestenvIdpMetadata
} from "../../__mocks__/metadata";
Expand All @@ -20,6 +21,8 @@ const mockFetchIdpsMetadata = jest.spyOn(metadata, "fetchIdpsMetadata");
const idpMetadataUrl = "http://ipd.metadata.example/metadata.xml";
const cieMetadataUrl =
"https://idserver.servizicie.interno.gov.it:8443/idp/shibboleth";
const cieTestMetadataUrl =
"https://collaudo.idserver.servizicie.interno.gov.it/idp/shibboleth";
const spidTestEnvUrl = "https://spid-testenv2:8088";

const serviceProviderConfig: IServiceProviderConfig = {
Expand All @@ -42,6 +45,7 @@ const serviceProviderConfig: IServiceProviderConfig = {
name: "Required attrs"
},
spidCieUrl: cieMetadataUrl,
spidCieTestUrl: cieTestMetadataUrl,
spidTestEnvUrl
};
const expectedSamlConfig: SamlConfig = {
Expand Down Expand Up @@ -79,6 +83,13 @@ describe("getSpidStrategyOptionsUpdater", () => {
right<Error, Record<string, IDPEntityDescriptor>>(mockCIEIdpMetadata)
);
});
mockFetchIdpsMetadata.mockImplementationOnce(() => {
return fromEither(
right<Error, Record<string, IDPEntityDescriptor>>(
mockCIETestIdpMetadata
)
);
});
mockFetchIdpsMetadata.mockImplementationOnce(() => {
return fromEither(
right<Error, Record<string, IDPEntityDescriptor>>(
Expand All @@ -91,7 +102,7 @@ describe("getSpidStrategyOptionsUpdater", () => {
expectedSamlConfig,
serviceProviderConfig
)()();
expect(mockFetchIdpsMetadata).toBeCalledTimes(3);
expect(mockFetchIdpsMetadata).toBeCalledTimes(4);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
1,
idpMetadataUrl,
Expand All @@ -104,6 +115,11 @@ describe("getSpidStrategyOptionsUpdater", () => {
);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
3,
cieTestMetadataUrl,
CIE_IDP_IDENTIFIERS
);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
4,
`${spidTestEnvUrl}/metadata`,
{
[spidTestEnvUrl]: "xx_testenv2"
Expand All @@ -113,6 +129,7 @@ describe("getSpidStrategyOptionsUpdater", () => {
expect(updatedSpidStrategyOption).toHaveProperty("idp", {
...mockIdpMetadata,
...mockCIEIdpMetadata,
...mockCIETestIdpMetadata,
...mockTestenvIdpMetadata
});
});
Expand All @@ -129,6 +146,13 @@ describe("getSpidStrategyOptionsUpdater", () => {
right<Error, Record<string, IDPEntityDescriptor>>(mockCIEIdpMetadata)
);
});
mockFetchIdpsMetadata.mockImplementationOnce(() => {
return fromEither(
right<Error, Record<string, IDPEntityDescriptor>>(
mockCIETestIdpMetadata
)
);
});
mockFetchIdpsMetadata.mockImplementationOnce(() => {
return fromEither(
right<Error, Record<string, IDPEntityDescriptor>>(
Expand All @@ -140,7 +164,7 @@ describe("getSpidStrategyOptionsUpdater", () => {
expectedSamlConfig,
serviceProviderConfig
)()();
expect(mockFetchIdpsMetadata).toBeCalledTimes(3);
expect(mockFetchIdpsMetadata).toBeCalledTimes(4);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
1,
idpMetadataUrl,
Expand All @@ -153,6 +177,11 @@ describe("getSpidStrategyOptionsUpdater", () => {
);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
3,
cieTestMetadataUrl,
CIE_IDP_IDENTIFIERS
);
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
4,
`${spidTestEnvUrl}/metadata`,
{
[spidTestEnvUrl]: "xx_testenv2"
Expand All @@ -161,6 +190,7 @@ describe("getSpidStrategyOptionsUpdater", () => {
expect(updatedSpidStrategyOption).toHaveProperty("sp", expectedSPProperty);
expect(updatedSpidStrategyOption).toHaveProperty("idp", {
...mockCIEIdpMetadata,
...mockCIETestIdpMetadata,
...mockTestenvIdpMetadata
});
});
Expand Down
14 changes: 14 additions & 0 deletions src/utils/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface IServiceProviderConfig {
readonly name: string;
};
readonly spidCieUrl?: string;
readonly spidCieTestUrl?: string;
readonly spidTestEnvUrl?: string;
readonly spidValidatorUrl?: string;
readonly IDPMetadataUrl: string;
Expand Down Expand Up @@ -175,6 +176,19 @@ export const getSpidStrategyOptionsUpdater = (
]
: []
)
.concat(
NonEmptyString.is(serviceProviderConfig.spidCieTestUrl)
? [
pipe(
fetchIdpsMetadata(
serviceProviderConfig.spidCieTestUrl,
CIE_IDP_IDENTIFIERS
),
TE.getOrElseW(() => T.of({}))
)
]
: []
)
.concat(
NonEmptyString.is(serviceProviderConfig.spidTestEnvUrl)
? [
Expand Down

0 comments on commit fbfed7f

Please sign in to comment.