Skip to content

Commit

Permalink
Add a casLogin function to do a full SSO login
Browse files Browse the repository at this point in the history
  • Loading branch information
kkalev committed Nov 26, 2023
1 parent 0d47af4 commit 6710991
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions gunet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
13 changes: 2 additions & 11 deletions login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})();

0 comments on commit 6710991

Please sign in to comment.