From 54b351d7543bb14e863aa935ae818c516f80808d Mon Sep 17 00:00:00 2001 From: John Weisz Date: Tue, 17 Dec 2024 16:13:29 -0500 Subject: [PATCH] ui test --- src/Template.test.js | 31 +++++++++++++++++++++++++++++++ src/cli/index.js | 2 +- src/routes/handlers.js | 34 +++++++--------------------------- src/routes/handlers.test.ts | 14 ++++++++++++++ 4 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 src/Template.test.js diff --git a/src/Template.test.js b/src/Template.test.js new file mode 100644 index 00000000..16990a70 --- /dev/null +++ b/src/Template.test.js @@ -0,0 +1,31 @@ +import { renderFile } from "ejs"; +import { join } from "path"; + +describe("button configuration renders correctly", () => { + const templatePath = join(__dirname, "..", "views", "login_selection.ejs"); + + test("does not render element", async () => { + const html = await renderFile(templatePath, { + login_gov_enabled: false, + mhv_logon_enabled: false, + ds_logon_enabled: false, + id_me_login_link: "something", + }); + expect(html).not.toMatch(/DS Logon/); + expect(html).not.toMatch(/My HealtheVet/); + }); + + test("does render element", async () => { + const html = await renderFile(templatePath, { + login_gov_enabled: true, + mhv_logon_enabled: true, + ds_logon_enabled: true, + id_me_login_link: "something", + mhv_login_link: "something", + dslogon_login_link: "something", + login_gov_login_link: "something", + }); + expect(html).toMatch(/DS Logon/); + expect(html).toMatch(/My HealtheVet/); + }); +}); diff --git a/src/cli/index.js b/src/cli/index.js index fa0b7ee9..3038ebb0 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -525,7 +525,7 @@ export function processArgs() { default: true, }, mhvLogonEnabled: { - description: "Enables MHV Logon signin option, enabled by default", + description: "Enables MHV signin option, enabled by default", required: false, boolean: true, default: true, diff --git a/src/routes/handlers.js b/src/routes/handlers.js index ba1ab0e8..969fc5e8 100644 --- a/src/routes/handlers.js +++ b/src/routes/handlers.js @@ -122,14 +122,14 @@ export const samlLogin = function (template) { }); }); }, Promise.resolve({})) - .then((authOptions) => { - authOptions.mhv_logon_enabled = isMhvLogonEnabled(req); - authOptions.ds_logon_enabled = isDsLogonEnabled(req); - authOptions.body = template; - authOptions.login_gov_enabled = login_gov_enabled; - authOptions.login_gov_signup_link_enabled = + .then((loginViewModel) => { + loginViewModel.mhv_logon_enabled = !!req.sps?.options?.id_me?.mhvLogonEnabled; + loginViewModel.ds_logon_enabled = !!req.sps?.options?.id_me?.dsLogonEnabled; + loginViewModel.body = template; + loginViewModel.login_gov_enabled = login_gov_enabled; + loginViewModel.login_gov_signup_link_enabled = login_gov_enabled && req.sps.options.logingov.signupLinkEnabled; - res.render("layout", authOptions); + res.render("layout", loginViewModel); logger.info("User arrived from Okta. Rendering IDP login template.", { action: "parseSamlRequest", result: "success", @@ -201,23 +201,3 @@ function enabled_logingov(req) { } return false; } - -/** - * Is MHV enabled? - * - * @param {*} req service provider request - * @returns {*} boolean - */ -function isMhvLogonEnabled(req) { - return !!req.sps.options.id_me.mhvLogonEnabled; -} - -/** - * Is DS Logon enabled? - * - * @param {*} req service provider request - * @returns {*} boolean - */ -function isDsLogonEnabled(req) { - return !!req.sps.options.id_me.dsLogonEnabled; -} diff --git a/src/routes/handlers.test.ts b/src/routes/handlers.test.ts index 97e07f49..904b33aa 100644 --- a/src/routes/handlers.test.ts +++ b/src/routes/handlers.test.ts @@ -112,6 +112,8 @@ describe("samlLogin", () => { const spOptionsJustIdMe = { id_me: { + dsLogonEnabled: true, + mhvLogonEnabled: true, idpLoginLink: "https://api.idmelabs.com/saml/SingleSignOnService?SAMLRequest=fVJNTwIxED37Lza9s13BaGxYAoGYkOBHQD14G8sITfqxdmYR%2F73dZSEc1GQP3c57M%2B%2B96ZDA2UpNat76JX7WSJztnfWk2kIp6uhVADKkPDgkxVqtJvcL1c8LVcXAQQcrzij%2FM4AII5vgRTaflWI8ns%2FG43QmqnHuicFzKfpFv%2BgVt71i8Hx5ra7Sd%2FsmsovJkTsNnmqHcYVxZzS%2BLBel2DJXSkobNNhtIFY3RVHI1kMM%2B29JVfsjiYK4mCWXxkPT68CkRIXK5Gbt0MI75Tq4A35l%2FMbiymz8o%2B%2FmiewVI7XcZElkdyFqbAMsBccaxWjYUFVrKo5OGvIdbMIuX%2BNuKM8Bw8MKHlJY89lTsEZ%2FNz0d8P9ZNjdm3ftooapqNBGjZ5FNrA1f04jA2EmSxyndjnHdCk5JMu45mwZXQTTUeMI9aD56OEdNbdreEj9GXdYpLPCwQZdm5smZ9CQToo7gNaZNgBx0Rn%2Ftcqj9oehUPX%2BYox8%3D&RelayState=%2F&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256&Signature=crqsP27LiAeJpKx7%2Bjshr4OeqHvFnp1rYmkP4rHTYXdEIjp6iIo7Zu3uwzXfkm%2BJp0ShXPAy7R6855y1dMBmOz3eVjdvdm8rQ7%2B044hTw3Cxmcuf836up4rsKLeT4vIHc3%2FA3qtDK3ut%2FXiArNLZJ%2FwOrC6KNWAuhJQ8fZIPv18uiCw1eNBJA2iCUD6KKtI%2FDgwA%2B1MtpRCsHNcpX23XQryIPkH8l6MsRDw1ZM3vttF7UZa6OkIsxFEXFJ4VZMal%2BciNZV%2FiB0%2FK3QvmbbKX8k%2BuJKL8rmIJr0XhNw%2BYLcMTNnpL%2FTQloi0xS18gu3J6GY%2BTEsG1CeJRNHkuJyF3LQ%3D%3D", getResponseParams: () => { @@ -135,6 +137,8 @@ describe("samlLogin", () => { const spOptionsJustwithLoginGov = { id_me: { + dsLogonEnabled: true, + mhvLogonEnabled: true, idpLoginLink: "https://api.idmelabs.com/saml/SingleSignOnService?SAMLRequest=fVJNTwIxED37Lza9s13BaGxYAoGYkOBHQD14G8sITfqxdmYR%2F73dZSEc1GQP3c57M%2B%2B96ZDA2UpNat76JX7WSJztnfWk2kIp6uhVADKkPDgkxVqtJvcL1c8LVcXAQQcrzij%2FM4AII5vgRTaflWI8ns%2FG43QmqnHuicFzKfpFv%2BgVt71i8Hx5ra7Sd%2FsmsovJkTsNnmqHcYVxZzS%2BLBel2DJXSkobNNhtIFY3RVHI1kMM%2B29JVfsjiYK4mCWXxkPT68CkRIXK5Gbt0MI75Tq4A35l%2FMbiymz8o%2B%2FmiewVI7XcZElkdyFqbAMsBccaxWjYUFVrKo5OGvIdbMIuX%2BNuKM8Bw8MKHlJY89lTsEZ%2FNz0d8P9ZNjdm3ftooapqNBGjZ5FNrA1f04jA2EmSxyndjnHdCk5JMu45mwZXQTTUeMI9aD56OEdNbdreEj9GXdYpLPCwQZdm5smZ9CQToo7gNaZNgBx0Rn%2Ftcqj9oehUPX%2BYox8%3D&RelayState=%2F&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256&Signature=crqsP27LiAeJpKx7%2Bjshr4OeqHvFnp1rYmkP4rHTYXdEIjp6iIo7Zu3uwzXfkm%2BJp0ShXPAy7R6855y1dMBmOz3eVjdvdm8rQ7%2B044hTw3Cxmcuf836up4rsKLeT4vIHc3%2FA3qtDK3ut%2FXiArNLZJ%2FwOrC6KNWAuhJQ8fZIPv18uiCw1eNBJA2iCUD6KKtI%2FDgwA%2B1MtpRCsHNcpX23XQryIPkH8l6MsRDw1ZM3vttF7UZa6OkIsxFEXFJ4VZMal%2BciNZV%2FiB0%2FK3QvmbbKX8k%2BuJKL8rmIJr0XhNw%2BYLcMTNnpL%2FTQloi0xS18gu3J6GY%2BTEsG1CeJRNHkuJyF3LQ%3D%3D", getResponseParams: () => { @@ -155,6 +159,8 @@ describe("samlLogin", () => { }, }, logingov: { + dsLogonEnabled: true, + mhvLogonEnabled: true, idpLoginLink: "https://idp.int.identitysandbox.gov/api/saml/metadata2021?SAMLRequest=fVJNTwIxED37Lza9s13BaGxYAoGYkOBHQD14G8sITfqxdmYR%2F73dZSEc1GQP3c57M%2B%2B96ZDA2UpNat76JX7WSJztnfWk2kIp6uhVADKkPDgkxVqtJvcL1c8LVcXAQQcrzij%2FM4AII5vgRTaflWI8ns%2FG43QmqnHuicFzKfpFv%2BgVt71i8Hx5ra7Sd%2FsmsovJkTsNnmqHcYVxZzS%2BLBel2DJXSkobNNhtIFY3RVHI1kMM%2B29JVfsjiYK4mCWXxkPT68CkRIXK5Gbt0MI75Tq4A35l%2FMbiymz8o%2B%2FmiewVI7XcZElkdyFqbAMsBccaxWjYUFVrKo5OGvIdbMIuX%2BNuKM8Bw8MKHlJY89lTsEZ%2FNz0d8P9ZNjdm3ftooapqNBGjZ5FNrA1f04jA2EmSxyndjnHdCk5JMu45mwZXQTTUeMI9aD56OEdNbdreEj9GXdYpLPCwQZdm5smZ9CQToo7gNaZNgBx0Rn%2Ftcqj9oehUPX%2BYox8%3D&RelayState=%2F&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256&Signature=crqsP27LiAeJpKx7%2Bjshr4OeqHvFnp1rYmkP4rHTYXdEIjp6iIo7Zu3uwzXfkm%2BJp0ShXPAy7R6855y1dMBmOz3eVjdvdm8rQ7%2B044hTw3Cxmcuf836up4rsKLeT4vIHc3%2FA3qtDK3ut%2FXiArNLZJ%2FwOrC6KNWAuhJQ8fZIPv18uiCw1eNBJA2iCUD6KKtI%2FDgwA%2B1MtpRCsHNcpX23XQryIPkH8l6MsRDw1ZM3vttF7UZa6OkIsxFEXFJ4VZMal%2BciNZV%2FiB0%2FK3QvmbbKX8k%2BuJKL8rmIJr0XhNw%2BYLcMTNnpL%2FTQloi0xS18gu3J6GY%2BTEsG1CeJRNHkuJyF3LQ%3D%3D", getResponseParams: () => { @@ -206,6 +212,8 @@ describe("samlLogin", () => { "https://identityProviderUrl.com?SAMLRequest=utrequest&RelayState=&op=signup", login_gov_enabled: false, login_gov_signup_link_enabled: false, + ds_logon_enabled: true, + mhv_logon_enabled: true, }; const expected_authoptions = { @@ -220,6 +228,8 @@ describe("samlLogin", () => { "https://identityProviderUrl.com?SAMLRequest=utrequest&RelayState=&op=signup", login_gov_enabled: false, login_gov_signup_link_enabled: false, + ds_logon_enabled: true, + mhv_logon_enabled: true, }; const expected_authoptions_failure_to_proof = { @@ -234,6 +244,8 @@ describe("samlLogin", () => { "https://identityProviderUrl.com?SAMLRequest=utrequest&RelayState=&op=signup", login_gov_enabled: false, login_gov_signup_link_enabled: false, + ds_logon_enabled: true, + mhv_logon_enabled: true, }; const expected_authoptions_login_gov_enabled = { body: "login_selection", @@ -251,6 +263,8 @@ describe("samlLogin", () => { login_gov_signup_link_enabled: true, login_gov_signup_link: "https://identityProviderUrl.com?SAMLRequest=utrequest&RelayState=", + ds_logon_enabled: true, + mhv_logon_enabled: true, }; const mockGetSamlRequestUrl = jest