mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
chore: sas9 username parsing bring back
This commit is contained in:
@@ -217,7 +217,7 @@ export class AuthManager {
|
|||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
userName: userName,
|
userName: userName.toLowerCase(),
|
||||||
loginForm
|
loginForm
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -596,6 +596,7 @@ describe('AuthManager', () => {
|
|||||||
|
|
||||||
it('return session information when logged in - SAS9 - having full name in html', async () => {
|
it('return session information when logged in - SAS9 - having full name in html', async () => {
|
||||||
const fullname = 'FirstName LastName'
|
const fullname = 'FirstName LastName'
|
||||||
|
const username = 'firlas'
|
||||||
const serverType = ServerType.Sas9
|
const serverType = ServerType.Sas9
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
@@ -611,7 +612,7 @@ describe('AuthManager', () => {
|
|||||||
|
|
||||||
const response = await authManager.checkSession()
|
const response = await authManager.checkSession()
|
||||||
expect(response.isLoggedIn).toBeTruthy()
|
expect(response.isLoggedIn).toBeTruthy()
|
||||||
expect(response.userName).toEqual(fullname)
|
expect(response.userName).toEqual(username)
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
`http://test-server.com/SASStoredProcess`,
|
`http://test-server.com/SASStoredProcess`,
|
||||||
|
|||||||
@@ -13,20 +13,31 @@ export const extractUserNameSas9 = (response: string) => {
|
|||||||
const regex = /"title":\s?".*?"/
|
const regex = /"title":\s?".*?"/
|
||||||
|
|
||||||
const matched = response?.match(regex)
|
const matched = response?.match(regex)
|
||||||
let username = matched?.[0].split(':')[1].trim()
|
let fullName = matched?.[0].split(':')[1].trim()
|
||||||
let breakIndex = username?.indexOf(' ')
|
let breakIndex = fullName?.indexOf(' ')
|
||||||
|
|
||||||
|
if (!fullName) return 'unknown'
|
||||||
|
|
||||||
dictionary.map((logoutWord) => {
|
dictionary.map((logoutWord) => {
|
||||||
const index = username?.indexOf(logoutWord) || -1
|
const index = fullName?.indexOf(logoutWord) || -1
|
||||||
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
breakIndex = index + logoutWord.length
|
breakIndex = index + logoutWord.length
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
username = username?.slice(breakIndex, -1)
|
//Cut only name
|
||||||
|
let username = fullName.slice(breakIndex, -1).trim()
|
||||||
|
|
||||||
if (!username) return 'unknown'
|
//Create username by SAS method - first 3 chars of every word lowercase
|
||||||
|
const usernameSplit = username.split(' ')
|
||||||
|
username = usernameSplit
|
||||||
|
.map((name: string) =>
|
||||||
|
usernameSplit.length > 1
|
||||||
|
? name.slice(0, 3).toLowerCase()
|
||||||
|
: name.toLowerCase()
|
||||||
|
)
|
||||||
|
.join('')
|
||||||
|
|
||||||
return username.trim()
|
return username
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,21 +7,21 @@ describe('Extract username SAS9 English - two word logout handled language', ()
|
|||||||
const response = ` "title": "${logoutWord} SAS User One",`
|
const response = ` "title": "${logoutWord} SAS User One",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('SAS User One')
|
expect(username).toEqual('sasuseone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username without space after colon', () => {
|
it('should return username without space after colon', () => {
|
||||||
const response = ` "title":"${logoutWord} SAS User One",`
|
const response = ` "title":"${logoutWord} SAS User One",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('SAS User One')
|
expect(username).toEqual('sasuseone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username with one word user name', () => {
|
it('should return username with one word user name', () => {
|
||||||
const response = ` "title": "${logoutWord} SasUserOne",`
|
const response = ` "title": "${logoutWord} SasUserOne",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('SasUserOne')
|
expect(username).toEqual('sasuserone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username unknown', () => {
|
it('should return username unknown', () => {
|
||||||
@@ -39,21 +39,21 @@ describe('Extract username SAS9 two word logout unhandled language', () => {
|
|||||||
const response = ` "title": "${logoutWord} SAS User One",`
|
const response = ` "title": "${logoutWord} SAS User One",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('out SAS User One')
|
expect(username).toEqual('outsasuseone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username without space after colon', () => {
|
it('should return username without space after colon', () => {
|
||||||
const response = ` "title":"${logoutWord} SAS User One",`
|
const response = ` "title":"${logoutWord} SAS User One",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('out SAS User One')
|
expect(username).toEqual('outsasuseone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username with one word user name', () => {
|
it('should return username with one word user name', () => {
|
||||||
const response = ` "title": "${logoutWord} SasUserOne",`
|
const response = ` "title": "${logoutWord} SasUserOne",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('out SasUserOne')
|
expect(username).toEqual('outsas')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username unknown', () => {
|
it('should return username unknown', () => {
|
||||||
@@ -64,28 +64,28 @@ describe('Extract username SAS9 two word logout unhandled language', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Extract username SAS9 Spasnish - one word logout languages', () => {
|
describe('Extract username SAS9 Spanish - one word logout languages', () => {
|
||||||
const logoutWord = 'Desconexión'
|
const logoutWord = 'Desconexión'
|
||||||
|
|
||||||
it('should return username with space after colon', () => {
|
it('should return username with space after colon', () => {
|
||||||
const response = ` "title": "${logoutWord} SAS User One",`
|
const response = ` "title": "${logoutWord} SAS User One",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('SAS User One')
|
expect(username).toEqual('sasuseone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username without space after colon', () => {
|
it('should return username without space after colon', () => {
|
||||||
const response = ` "title":"${logoutWord} SAS User One",`
|
const response = ` "title":"${logoutWord} SAS User One",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('SAS User One')
|
expect(username).toEqual('sasuseone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username with one word user name', () => {
|
it('should return username with one word user name', () => {
|
||||||
const response = ` "title": "${logoutWord} SasUserOne",`
|
const response = ` "title": "${logoutWord} SasUserOne",`
|
||||||
const username = extractUserNameSas9(response)
|
const username = extractUserNameSas9(response)
|
||||||
|
|
||||||
expect(username).toEqual('SasUserOne')
|
expect(username).toEqual('sasuserone')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return username unknown', () => {
|
it('should return username unknown', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user