1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

Merge pull request #794 from sasjs/issue-303

fix: modify the regex to handle the loginForm response on latest sas9
This commit is contained in:
Allan Bowe
2023-03-27 13:09:11 +01:00
committed by GitHub
4 changed files with 42 additions and 28 deletions

46
package-lock.json generated
View File

@@ -31,7 +31,7 @@
"jest-extended": "2.0.0",
"node-polyfill-webpack-plugin": "1.1.4",
"path": "0.12.7",
"pem": "1.14.6",
"pem": "1.14.5",
"prettier": "2.7.1",
"process": "0.11.10",
"rimraf": "3.0.2",
@@ -6053,10 +6053,13 @@
"dev": true
},
"node_modules/es6-promisify": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-6.1.1.tgz",
"integrity": "sha512-HBL8I3mIki5C1Cc9QjKUenHtnG0A5/xA8Q/AllRcfiwl2CZFXGK7ddBiCoRwAix4i2KxcQfjtIVcrVbB3vbmwg==",
"dev": true
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-7.0.0.tgz",
"integrity": "sha512-ginqzK3J90Rd4/Yz7qRrqUeIpe3TwSXTPPZtPne7tGBPeAaQiU8qt4fpKApnxHcq1AwtUdHVg5P77x/yrggG8Q==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/escalade": {
"version": "3.1.1",
@@ -13755,18 +13758,19 @@
}
},
"node_modules/pem": {
"version": "1.14.6",
"resolved": "https://registry.npmjs.org/pem/-/pem-1.14.6.tgz",
"integrity": "sha512-I5GKUer2PPv5qzUfxaZ6IGRkhp+357Kyv2t1JJg9vP8hGGI13qU34N2QupmggbpIZGPuudH0jn8KU5hjFpPk3g==",
"version": "1.14.5",
"resolved": "https://registry.npmjs.org/pem/-/pem-1.14.5.tgz",
"integrity": "sha512-5zJ2mR6+S2rKZWLW8Pdwufz3zkJBUyWJgevgQVUZ/znFcN80vOlsgnBPUY+umiWN2L8Fq9SHq9pIDSRR5bwuMw==",
"deprecated": "wrong release - minor changes done and should not released! Also requirments changed. NODEJS >= 14",
"dev": true,
"dependencies": {
"es6-promisify": "^6.0.0",
"md5": "^2.2.1",
"os-tmpdir": "^1.0.1",
"es6-promisify": "^7.0.0",
"md5": "^2.3.0",
"os-tmpdir": "^1.0.2",
"which": "^2.0.2"
},
"engines": {
"node": ">=6.0.0"
"node": ">=14.0.0"
}
},
"node_modules/pend": {
@@ -21631,9 +21635,9 @@
"dev": true
},
"es6-promisify": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-6.1.1.tgz",
"integrity": "sha512-HBL8I3mIki5C1Cc9QjKUenHtnG0A5/xA8Q/AllRcfiwl2CZFXGK7ddBiCoRwAix4i2KxcQfjtIVcrVbB3vbmwg==",
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-7.0.0.tgz",
"integrity": "sha512-ginqzK3J90Rd4/Yz7qRrqUeIpe3TwSXTPPZtPne7tGBPeAaQiU8qt4fpKApnxHcq1AwtUdHVg5P77x/yrggG8Q==",
"dev": true
},
"escalade": {
@@ -27289,14 +27293,14 @@
}
},
"pem": {
"version": "1.14.6",
"resolved": "https://registry.npmjs.org/pem/-/pem-1.14.6.tgz",
"integrity": "sha512-I5GKUer2PPv5qzUfxaZ6IGRkhp+357Kyv2t1JJg9vP8hGGI13qU34N2QupmggbpIZGPuudH0jn8KU5hjFpPk3g==",
"version": "1.14.5",
"resolved": "https://registry.npmjs.org/pem/-/pem-1.14.5.tgz",
"integrity": "sha512-5zJ2mR6+S2rKZWLW8Pdwufz3zkJBUyWJgevgQVUZ/znFcN80vOlsgnBPUY+umiWN2L8Fq9SHq9pIDSRR5bwuMw==",
"dev": true,
"requires": {
"es6-promisify": "^6.0.0",
"md5": "^2.2.1",
"os-tmpdir": "^1.0.1",
"es6-promisify": "^7.0.0",
"md5": "^2.3.0",
"os-tmpdir": "^1.0.2",
"which": "^2.0.2"
}
},

View File

@@ -59,7 +59,7 @@
"jest-extended": "2.0.0",
"node-polyfill-webpack-plugin": "1.1.4",
"path": "0.12.7",
"pem": "1.14.6",
"pem": "1.14.5",
"prettier": "2.7.1",
"process": "0.11.10",
"rimraf": "3.0.2",

View File

@@ -1,5 +1,6 @@
import { ServerType } from '@sasjs/utils/types'
import { RequestClient } from '../request/RequestClient'
import { NotFoundError } from '../types/errors'
import { LoginOptions, LoginResult, LoginResultInternal } from '../types/Login'
import { serialize } from '../utils'
import { extractUserLongNameSas9 } from '../utils/sas9/extractUserLongNameSas9'
@@ -42,6 +43,9 @@ export class AuthManager {
} = await this.fetchUserName()
if (isLoggedInAlready) {
const logger = process.logger || console
logger.log('login was not attempted as a valid session already exists')
await this.loginCallback()
return {
@@ -109,6 +113,9 @@ export class AuthManager {
} = await this.checkSession()
if (isLoggedInAlready) {
const logger = process.logger || console
logger.log('login was not attempted as a valid session already exists')
await this.loginCallback()
this.userName = loginParams.username
@@ -155,10 +162,12 @@ export class AuthManager {
private async performCASSecurityCheck() {
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
await this.requestClient.get<string>(
`/SASLogon/login?service=${casAuthenticationUrl}`,
undefined
)
await this.requestClient
.get<string>(`/SASLogon/login?service=${casAuthenticationUrl}`, undefined)
.catch((err) => {
// ignore if resource not found error
if (!(err instanceof NotFoundError)) throw err
})
}
private async sendLoginRequest(
@@ -312,12 +321,13 @@ export class AuthManager {
}
private getLoginForm(response: any) {
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
const pattern: RegExp = /<form.+action="(.*(Logon)|(login)[^"]*).*>/
const matches = pattern.exec(response)
const formInputs: any = {}
if (matches && matches.length) {
this.setLoginUrl(matches)
response = response.replace(/<input/g, '\n<input')
const inputs = response.match(/<input.*"hidden"[^>]*>/g)
if (inputs) {

View File

@@ -1,5 +1,5 @@
export const isLogInRequired = (response: string): boolean => {
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/gm
const pattern: RegExp = /<form.+action="(.*(Logon)|(login)[^"]*).*>/gm
const matches = pattern.test(response)
return matches
}