mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-14 15:40:06 +00:00
17128
package-lock.json
generated
17128
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -82,17 +82,33 @@ export class AuthManager {
|
|||||||
* @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
|
* @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
|
||||||
*/
|
*/
|
||||||
public async checkSession() {
|
public async checkSession() {
|
||||||
const { result: loginResponse } = await this.requestClient.get<string>(
|
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
|
||||||
this.loginUrl.replace('.do', ''),
|
//For SAS9 we will send request on SASStoredProcess
|
||||||
undefined,
|
const url =
|
||||||
'text/plain'
|
this.serverType === 'SASVIYA'
|
||||||
)
|
? `${this.serverUrl}/identities`
|
||||||
const responseText = loginResponse
|
: `${this.serverUrl}/SASStoredProcess`
|
||||||
const isLoggedIn = /<button.+onClick.+logout/gm.test(responseText)
|
|
||||||
let loginForm: any = null
|
const { result: loginResponse } = await this.requestClient
|
||||||
|
.get<string>(url, undefined, 'text/plain')
|
||||||
|
.catch((err: any) => {
|
||||||
|
return { result: 'authErr' }
|
||||||
|
})
|
||||||
|
|
||||||
|
const isLoggedIn = loginResponse !== 'authErr'
|
||||||
|
let loginForm = null
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
loginForm = await this.getLoginForm(responseText)
|
//We will logout to make sure cookies are removed and login form is presented
|
||||||
|
this.logOut()
|
||||||
|
|
||||||
|
const { result: formResponse } = await this.requestClient.get<string>(
|
||||||
|
this.loginUrl.replace('.do', ''),
|
||||||
|
undefined,
|
||||||
|
'text/plain'
|
||||||
|
)
|
||||||
|
|
||||||
|
loginForm = await this.getLoginForm(formResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
|
|||||||
@@ -176,41 +176,19 @@ describe('AuthManager', () => {
|
|||||||
|
|
||||||
const response = await authManager.checkSession()
|
const response = await authManager.checkSession()
|
||||||
expect(response.isLoggedIn).toBeTruthy()
|
expect(response.isLoggedIn).toBeTruthy()
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(1, `/SASLogon/login`, {
|
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
||||||
withCredentials: true,
|
1,
|
||||||
responseType: 'text',
|
`http://test-server.com/identities`,
|
||||||
transformResponse: undefined,
|
{
|
||||||
headers: {
|
withCredentials: true,
|
||||||
Accept: '*/*',
|
responseType: 'text',
|
||||||
'Content-Type': 'text/plain'
|
transformResponse: undefined,
|
||||||
|
headers: {
|
||||||
|
Accept: '*/*',
|
||||||
|
'Content-Type': 'text/plain'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should check and return session information if logged in', async (done) => {
|
|
||||||
const authManager = new AuthManager(
|
|
||||||
serverUrl,
|
|
||||||
serverType,
|
|
||||||
requestClient,
|
|
||||||
authCallback
|
|
||||||
)
|
)
|
||||||
mockedAxios.get.mockImplementation(() =>
|
|
||||||
Promise.resolve({ data: '<button onClick="logout">' })
|
|
||||||
)
|
|
||||||
|
|
||||||
const response = await authManager.checkSession()
|
|
||||||
expect(response.isLoggedIn).toBeTruthy()
|
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(1, `/SASLogon/login`, {
|
|
||||||
withCredentials: true,
|
|
||||||
responseType: 'text',
|
|
||||||
transformResponse: undefined,
|
|
||||||
headers: {
|
|
||||||
Accept: '*/*',
|
|
||||||
'Content-Type': 'text/plain'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user