Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIF-2065 - Set affinity cookie for all requests in WDIO tests #135

Merged
merged 3 commits into from
Jun 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions ui.tests/test-module/lib/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,38 @@ function takeScreenshot(browser, prefix) {
}

function getAuthenticatedRequestOptions(browser) {
let loginTokenCookie = _getLoginTokenCookie(browser);
let loginCookies = _getLoginCookies(browser);
let jar = request.jar();
let currentUrl = new URL(browser.getUrl());

jar.setCookie(loginTokenCookie.toString(), currentUrl.origin);
loginCookies.forEach(cookie => jar.setCookie(cookie.toString(), currentUrl.origin));

return {
jar: jar
};
}

function _getLoginTokenCookie(browser) {
function _getLoginCookies(browser) {
let cookies = browser.getCookies();
let cookie = cookies.find(element => element.name == 'login-token');

if (!cookie) {
// Get login and affinity cookies only
let loginCookies = cookies.filter(e => ['login-token', 'affinity'].includes(e.name));

// Throw if mandatory login cookie is not there
if (!loginCookies.find(element => element.name == 'login-token')) {
throw new Error('could not get login-token cookie');
}

return new tough.Cookie({
key: cookie.name,
value: cookie.value,
httpOnly: cookie.httpOnly,
secure: false,
path: cookie.path
});
return loginCookies.map(
c =>
new tough.Cookie({
key: c.name,
value: c.value,
httpOnly: c.httpOnly,
secure: false,
path: c.path
})
);
}

function randomString() {
Expand Down