1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-10 17:04:36 +00:00

fix: while checking session extract username also

This commit is contained in:
Saad Jutt
2021-08-07 07:32:48 +05:00
parent f172ad66bc
commit fc1c93957c
3 changed files with 267 additions and 330 deletions

582
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -110,7 +110,7 @@ export class AuthManager {
//For SAS9 we will send request on SASStoredProcess
const url =
this.serverType === 'SASVIYA'
? `${this.serverUrl}/identities`
? `${this.serverUrl}/identities/users/@currentUser`
: `${this.serverUrl}/SASStoredProcess`
const { result: loginResponse } = await this.requestClient
@@ -120,6 +120,10 @@ export class AuthManager {
})
const isLoggedIn = loginResponse !== 'authErr'
const userName = isLoggedIn
? this.extractUserName(loginResponse)
: this.userName
let loginForm = null
if (!isLoggedIn) {
@@ -137,11 +141,16 @@ export class AuthManager {
return Promise.resolve({
isLoggedIn,
userName: this.userName,
userName: userName ?? this.userName,
loginForm
})
}
private extractUserName = (response: string) =>
this.serverType === 'SASVIYA'
? response?.match(/<id>[0-1a-zA-Z]*<\/id>/)?.[0].slice(4, -5)
: response?.match(/"title":"Log Off [0-1a-zA-Z]*"/)?.[0].slice(17, -1)
private getLoginForm(response: any) {
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
const matches = pattern.exec(response)

View File

@@ -175,7 +175,7 @@ describe('AuthManager', () => {
expect(response.isLoggedIn).toBeTruthy()
expect(mockedAxios.get).toHaveBeenNthCalledWith(
1,
`http://test-server.com/identities`,
`http://test-server.com/identities/users/@currentUser`,
{
withCredentials: true,
responseType: 'text',