mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-19 18:10:06 +00:00
Compare commits
1 Commits
issue-150
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65ae198c27 |
12
package-lock.json
generated
12
package-lock.json
generated
@@ -16800,9 +16800,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/word-wrap": {
|
"node_modules/word-wrap": {
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
|
||||||
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
|
"integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
@@ -29626,9 +29626,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"word-wrap": {
|
"word-wrap": {
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
|
||||||
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
|
"integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"wordwrap": {
|
"wordwrap": {
|
||||||
|
|||||||
@@ -78,16 +78,7 @@ export class AuthManager {
|
|||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
if (this.serverType === ServerType.Sas9) {
|
if (this.serverType === ServerType.Sas9) {
|
||||||
const casSecurityCheckResponse = await this.performCASSecurityCheck()
|
await this.performCASSecurityCheck()
|
||||||
|
|
||||||
if (isPublicAccessDenied(casSecurityCheckResponse.result)) {
|
|
||||||
return {
|
|
||||||
isLoggedIn: false,
|
|
||||||
userName: this.userName || '',
|
|
||||||
userLongName: this.userLongName || '',
|
|
||||||
errorMessage: 'Public access has been denied.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { userName, userLongName } = await this.fetchUserName()
|
const { userName, userLongName } = await this.fetchUserName()
|
||||||
@@ -158,17 +149,7 @@ export class AuthManager {
|
|||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
if (this.serverType === ServerType.Sas9) {
|
if (this.serverType === ServerType.Sas9) {
|
||||||
const casSecurityCheckResponse = await this.performCASSecurityCheck()
|
await this.performCASSecurityCheck()
|
||||||
if (isPublicAccessDenied(casSecurityCheckResponse.result)) {
|
|
||||||
isLoggedIn = false
|
|
||||||
|
|
||||||
return {
|
|
||||||
isLoggedIn,
|
|
||||||
userName: this.userName || '',
|
|
||||||
userLongName: this.userLongName || '',
|
|
||||||
errorMessage: 'Public access has been denied.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loginCallback()
|
this.loginCallback()
|
||||||
@@ -185,15 +166,11 @@ export class AuthManager {
|
|||||||
private async performCASSecurityCheck() {
|
private async performCASSecurityCheck() {
|
||||||
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
||||||
|
|
||||||
return await this.requestClient
|
await this.requestClient
|
||||||
.get<string>(`/SASLogon/login?service=${casAuthenticationUrl}`, undefined)
|
.get<string>(`/SASLogon/login?service=${casAuthenticationUrl}`, undefined)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
// ignore if resource not found error
|
// ignore if resource not found error
|
||||||
if (!(err instanceof NotFoundError)) throw err
|
if (!(err instanceof NotFoundError)) throw err
|
||||||
|
|
||||||
return {
|
|
||||||
result: ''
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +387,3 @@ const isLogInSuccess = (serverType: ServerType, response: any): boolean => {
|
|||||||
|
|
||||||
return /You have signed in/gm.test(response)
|
return /You have signed in/gm.test(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isPublicAccessDenied = (response: any): boolean => {
|
|
||||||
return /Public access has been denied/gm.test(response)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import axios from 'axios'
|
|||||||
import {
|
import {
|
||||||
mockedCurrentUserApi,
|
mockedCurrentUserApi,
|
||||||
mockLoginAuthoriseRequiredResponse,
|
mockLoginAuthoriseRequiredResponse,
|
||||||
mockLoginPublicAccessDeniedResponse,
|
|
||||||
mockLoginSuccessResponse
|
mockLoginSuccessResponse
|
||||||
} from './mockResponses'
|
} from './mockResponses'
|
||||||
import { serialize } from '../../utils'
|
import { serialize } from '../../utils'
|
||||||
@@ -214,61 +213,6 @@ describe('AuthManager', () => {
|
|||||||
expect(authCallback).toHaveBeenCalledTimes(1)
|
expect(authCallback).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should post a login & a cas_security request to the SAS9 server when not logged in & get rejected due to public access denied', async () => {
|
|
||||||
const serverType = ServerType.Sas9
|
|
||||||
const authManager = new AuthManager(
|
|
||||||
serverUrl,
|
|
||||||
serverType,
|
|
||||||
requestClient,
|
|
||||||
authCallback
|
|
||||||
)
|
|
||||||
jest.spyOn(authManager, 'checkSession').mockImplementation(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
isLoggedIn: false,
|
|
||||||
userName: '',
|
|
||||||
userLongName: '',
|
|
||||||
loginForm: { name: 'test' }
|
|
||||||
})
|
|
||||||
)
|
|
||||||
mockedAxios.post.mockImplementationOnce(() =>
|
|
||||||
Promise.resolve({ data: mockLoginSuccessResponse })
|
|
||||||
)
|
|
||||||
mockedAxios.get.mockImplementationOnce(() =>
|
|
||||||
Promise.resolve({ data: mockLoginPublicAccessDeniedResponse })
|
|
||||||
)
|
|
||||||
|
|
||||||
const loginResponse = await authManager.logIn(userName, password)
|
|
||||||
|
|
||||||
expect(loginResponse.isLoggedIn).toBeFalse()
|
|
||||||
expect(loginResponse.userName).toEqual('')
|
|
||||||
expect(loginResponse.errorMessage).toEqual(
|
|
||||||
'Public access has been denied.'
|
|
||||||
)
|
|
||||||
|
|
||||||
const loginParams = serialize({
|
|
||||||
_service: 'default',
|
|
||||||
username: userName,
|
|
||||||
password,
|
|
||||||
name: 'test'
|
|
||||||
})
|
|
||||||
expect(mockedAxios.post).toHaveBeenCalledWith(
|
|
||||||
`/SASLogon/login`,
|
|
||||||
loginParams,
|
|
||||||
{
|
|
||||||
withCredentials: true,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
Accept: '*/*'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
const casAuthenticationUrl = `${serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
|
||||||
expect(mockedAxios.get).toHaveBeenCalledWith(
|
|
||||||
`/SASLogon/login?service=${casAuthenticationUrl}`,
|
|
||||||
getHeadersJson
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should return empty username if unable to logged in', async () => {
|
it('should return empty username if unable to logged in', async () => {
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
@@ -478,53 +422,6 @@ describe('AuthManager', () => {
|
|||||||
expect(authCallback).toHaveBeenCalledTimes(1)
|
expect(authCallback).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return error if public account access is denied', async () => {
|
|
||||||
const serverType = ServerType.Sas9
|
|
||||||
const authManager = new AuthManager(
|
|
||||||
serverUrl,
|
|
||||||
serverType,
|
|
||||||
requestClient,
|
|
||||||
authCallback
|
|
||||||
)
|
|
||||||
jest
|
|
||||||
.spyOn<any, any>(authManager, 'fetchUserName')
|
|
||||||
.mockImplementationOnce(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
isLoggedIn: false,
|
|
||||||
userName: ''
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.mockImplementationOnce(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
isLoggedIn: true,
|
|
||||||
userName
|
|
||||||
})
|
|
||||||
)
|
|
||||||
mockedAxios.get.mockImplementation(() =>
|
|
||||||
Promise.resolve({ data: mockLoginPublicAccessDeniedResponse })
|
|
||||||
)
|
|
||||||
|
|
||||||
const loginResponse = await authManager.redirectedLogIn({})
|
|
||||||
|
|
||||||
expect(loginResponse.isLoggedIn).toBeFalse()
|
|
||||||
expect(loginResponse.userName).toEqual('')
|
|
||||||
expect(loginResponse.errorMessage).toEqual(
|
|
||||||
'Public access has been denied.'
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(openWebPageModule.openWebPage).toHaveBeenCalledWith(
|
|
||||||
`/SASLogon`,
|
|
||||||
'SASLogon',
|
|
||||||
{
|
|
||||||
width: 500,
|
|
||||||
height: 600
|
|
||||||
},
|
|
||||||
undefined
|
|
||||||
)
|
|
||||||
expect(authManager['fetchUserName']).toHaveBeenCalledTimes(1)
|
|
||||||
expect(verifySas9LoginModule.verifySas9Login).toHaveBeenCalledTimes(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should return empty username if user unable to re-login via pop up', async () => {
|
it('should return empty username if user unable to re-login via pop up', async () => {
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { SasAuthResponse } from '@sasjs/utils/types'
|
|||||||
|
|
||||||
export const mockLoginAuthoriseRequiredResponse = `<form id="application_authorization" action="/SASLogon/oauth/authorize" method="POST"><input type="hidden" name="X-Uaa-Csrf" value="2nfuxIn6WaOURWL7tzTXCe"/>`
|
export const mockLoginAuthoriseRequiredResponse = `<form id="application_authorization" action="/SASLogon/oauth/authorize" method="POST"><input type="hidden" name="X-Uaa-Csrf" value="2nfuxIn6WaOURWL7tzTXCe"/>`
|
||||||
export const mockLoginSuccessResponse = `You have signed in`
|
export const mockLoginSuccessResponse = `You have signed in`
|
||||||
export const mockLoginPublicAccessDeniedResponse = `Public access has been denied`
|
|
||||||
|
|
||||||
export const mockAuthResponse: SasAuthResponse = {
|
export const mockAuthResponse: SasAuthResponse = {
|
||||||
access_token: 'acc355',
|
access_token: 'acc355',
|
||||||
|
|||||||
@@ -187,12 +187,6 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
{ result: jsonResponse, log: res.log },
|
{ result: jsonResponse, log: res.log },
|
||||||
extraResponseAttributes
|
extraResponseAttributes
|
||||||
)
|
)
|
||||||
|
|
||||||
if (this.isPublicAccessDenied(jsonResponse))
|
|
||||||
reject(
|
|
||||||
new ErrorResponse('Public access has been denied', responseObject)
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve(responseObject)
|
resolve(responseObject)
|
||||||
})
|
})
|
||||||
.catch(async (e: Error) => {
|
.catch(async (e: Error) => {
|
||||||
@@ -268,8 +262,4 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
}
|
}
|
||||||
return uri
|
return uri
|
||||||
}
|
}
|
||||||
|
|
||||||
private isPublicAccessDenied = (response: string): boolean => {
|
|
||||||
return /Public access has been denied/gm.test(response)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ export interface LoginResult {
|
|||||||
isLoggedIn: boolean
|
isLoggedIn: boolean
|
||||||
userName: string
|
userName: string
|
||||||
userLongName: string
|
userLongName: string
|
||||||
errorMessage?: string
|
|
||||||
}
|
}
|
||||||
export interface LoginResultInternal {
|
export interface LoginResultInternal {
|
||||||
isLoggedIn: boolean
|
isLoggedIn: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user