diff --git a/README.md b/README.md index 5dadee7..d59b88c 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,15 @@ console.log(url[0]); * `assertTicketGrantingCookie` - Check that we received a TickerGrantingCookie (TGT) - Example: `await gunet.assertTicketGrantingCookie(page);` +* `casLogin` + - Perform all necessary elements of checking for successful SSO login utilizing a provided web page element. Useful when performing an SSO login is just *one* of many steps of a scenario. + - Arguments: + * `page` element + * `url` of SSO + * `user` to use + * `password` to use + * `cas_type` to use. Can be one of `cas` (the default) for regular CAS SSO and `simple-cas` for the `gunet/simple-cas` container + - Example: ```await gunet.casLogin(page, url[0], `${process.env.CAS_USER}`,`${process.env.CAS_PASSWORD}`,`${process.env.CAS_TYPE}`);``` ## Usage * Environment variables diff --git a/gunet.js b/gunet.js index 4bf3edc..4afb5a3 100644 --- a/gunet.js +++ b/gunet.js @@ -132,6 +132,20 @@ exports.assertNoTicketGrantingCookie = async (page) => { assert(tgc.length === 0); } +exports.casLogin = async (page, url, user, password, cas_type = "cas") => { + await page.goto(url); + await page.waitForTimeout(1000) + await this.loginWith(page, user, password); + await this.assertTicketGrantingCookie(page); + await page.waitForTimeout(2000) + if (cas_type === 'cas') { + await this.assertInnerText(page, '#content div h2', "Επιτυχής Σύνδεση"); + } + else if (cas_type === 'simple-cas') { + await this.assertInnerText(page, '#content div h2', "Log In Successful"); + } +} + exports.submitForm = async (page, selector) => { console.log(`Submitting form ${selector}`); await page.$eval(selector, form => form.submit()); diff --git a/login.js b/login.js index dd69908..42e4731 100644 --- a/login.js +++ b/login.js @@ -6,16 +6,7 @@ console.log(url[0]); (async () => { const browser = await puppeteer.launch(gunet.browserOptions()); const page = await gunet.newPage(browser); - await page.goto(url[0]); - await page.waitForTimeout(1000) - await gunet.loginWith(page, `${process.env.CAS_USER}`, `${process.env.CAS_PASSWORD}`); - await gunet.assertTicketGrantingCookie(page); - await page.waitForTimeout(2000) - if (process.env.CAS_TYPE === 'cas') { - await gunet.assertInnerText(page, '#content div h2', "Επιτυχής Σύνδεση"); - } - else if (process.env.CAS_TYPE === 'simple-cas') { - await gunet.assertInnerText(page, '#content div h2', "Log In Successful"); - } + await gunet.casLogin(page, url[0], `${process.env.CAS_USER}`, + `${process.env.CAS_PASSWORD}`,`${process.env.CAS_TYPE}`); await browser.close(); })();