From a23103b2c30afcf7bd037b86137b2c4f908e0724 Mon Sep 17 00:00:00 2001 From: Mihajlo Medjedovic Date: Wed, 18 Nov 2020 13:09:49 +0100 Subject: [PATCH 1/3] fix: viya login issue --- src/SASjs.ts | 57 +++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index edb0232..1d0bf4d 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -411,6 +411,29 @@ export default class SASjs { } } + private async getLoginForm(response: any) { + const pattern: RegExp = // + const matches = pattern.exec(response) + const formInputs: any = {} + + if (matches && matches.length) { + this.setLoginUrl(matches) + const inputs = response.match(/]*>/g) + + if (inputs) { + inputs.forEach((inputStr: string) => { + const valueMatch = inputStr.match(/name="([^"]*)"\svalue="([^"]*)/) + + if (valueMatch && valueMatch.length) { + formInputs[valueMatch[1]] = valueMatch[2] + } + }) + } + } + + return Object.keys(formInputs).length ? formInputs : null + } + /** * Checks whether a session is active, or login is required. * @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`. @@ -419,10 +442,16 @@ export default class SASjs { const loginResponse = await fetch(this.loginUrl.replace('.do', '')) const responseText = await loginResponse.text() const isLoggedIn = // - const response = await fetch(this.loginUrl).then((r) => r.text()) - const matches = pattern.exec(response) - const formInputs: any = {} - if (matches && matches.length) { - this.setLoginUrl(matches) - const inputs = response.match(/]*>/g) - if (inputs) { - inputs.forEach((inputStr: string) => { - const valueMatch = inputStr.match(/name="([^"]*)"\svalue="([^"]*)/) - if (valueMatch && valueMatch.length) { - formInputs[valueMatch[1]] = valueMatch[2] - } - }) - } - } - return Object.keys(formInputs).length ? formInputs : null - } - private async createFoldersAndServices( parentFolder: string, membersJson: any[], From 24dd5e32adf558d7553b3649d7ea12a02cbde94d Mon Sep 17 00:00:00 2001 From: Mihajlo Medjedovic Date: Wed, 18 Nov 2020 13:10:29 +0100 Subject: [PATCH 2/3] style: lint --- src/SASjs.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index 1d0bf4d..27e0489 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -415,22 +415,22 @@ export default class SASjs { const pattern: RegExp = // const matches = pattern.exec(response) const formInputs: any = {} - + if (matches && matches.length) { this.setLoginUrl(matches) const inputs = response.match(/]*>/g) - + if (inputs) { inputs.forEach((inputStr: string) => { const valueMatch = inputStr.match(/name="([^"]*)"\svalue="([^"]*)/) - + if (valueMatch && valueMatch.length) { formInputs[valueMatch[1]] = valueMatch[2] } }) } } - + return Object.keys(formInputs).length ? formInputs : null } From c934eb2b08c1b2c1c6f5418e2947ec726df82dd7 Mon Sep 17 00:00:00 2001 From: Mihajlo Medjedovic Date: Wed, 18 Nov 2020 14:13:13 +0100 Subject: [PATCH 3/3] test: added test for multiple login attempts --- sasjs-tests/src/testSuites/Basic.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sasjs-tests/src/testSuites/Basic.ts b/sasjs-tests/src/testSuites/Basic.ts index 3e1e256..b045874 100644 --- a/sasjs-tests/src/testSuites/Basic.ts +++ b/sasjs-tests/src/testSuites/Basic.ts @@ -37,6 +37,17 @@ export const basicTests = ( assertion: (response: any) => response && response.isLoggedIn && response.userName === userName }, + { + title: "Multiple Log in attempts", + description: "Should fail on first attempt and should log the user in on second attempt", + test: async () => { + await adapter.logOut() + await adapter.logIn('invalid', 'invalid') + return adapter.logIn(userName, password) + }, + assertion: (response: any) => + response && response.isLoggedIn && response.userName === userName + }, { title: "Default config", description: