1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-01 01:40:04 +00:00

Compare commits

..

17 Commits

Author SHA1 Message Date
3556eb3903 chore(auth manager): tests fix 2023-07-12 20:07:39 +02:00
600e561a45 chore(auth manager): tests fixing 2023-07-12 15:53:56 +02:00
6a161a05ef fix: auth manager merge issues 2023-07-12 10:42:47 +02:00
8db02012e5 style: lint 2023-07-12 10:13:29 +02:00
a01b1a9feb chore(git): Merge branch 'master' into issue-150 2023-07-12 10:13:20 +02:00
Yury Shkoda
76bf5b88e9 Merge pull request #818 from sasjs/deps-bump
Dependencies bump
2023-07-12 09:50:50 +03:00
Yury Shkoda
a97ac4eaa6 chore: commiting changes 2023-07-11 15:36:13 +03:00
Yury Shkoda
37cfea6ca7 chore(deps): Merge branch 'dependabot/npm_and_yarn/sasjs-tests/loader-utils-2.0.4' of github.com:sasjs/adapter into deps-bump 2023-07-11 14:53:19 +03:00
Yury Shkoda
f74c8aca57 chore(deps): Merge branch 'dependabot/npm_and_yarn/sasjs-tests/json5-1.0.2' of github.com:sasjs/adapter into deps-bump 2023-07-11 14:52:28 +03:00
Yury Shkoda
77baaabfcd chore(deps): Merge branch 'dependabot/npm_and_yarn/sasjs-tests/http-cache-semantics-4.1.1' of github.com:sasjs/adapter into deps-bump 2023-07-11 14:51:32 +03:00
Yury Shkoda
510ba771f0 chore(deps): Merge branch 'dependabot/npm_and_yarn/sasjs-tests/webpack-5.76.3' of github.com:sasjs/adapter into deps-bump 2023-07-11 14:50:38 +03:00
dependabot[bot]
d166231c12 chore(deps): bump webpack from 5.73.0 to 5.76.3 in /sasjs-tests
Bumps [webpack](https://github.com/webpack/webpack) from 5.73.0 to 5.76.3.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v5.73.0...v5.76.3)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-27 12:12:06 +00:00
dependabot[bot]
4cb150e951 chore(deps): bump http-cache-semantics in /sasjs-tests
Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/kornelski/http-cache-semantics/releases)
- [Commits](https://github.com/kornelski/http-cache-semantics/compare/v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: http-cache-semantics
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-04 13:53:04 +00:00
dependabot[bot]
fc8598473f chore(deps): bump json5 from 1.0.1 to 1.0.2 in /sasjs-tests
Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-08 11:36:38 +00:00
dependabot[bot]
367e0ae25a chore(deps): bump loader-utils from 2.0.2 to 2.0.4 in /sasjs-tests
Bumps [loader-utils](https://github.com/webpack/loader-utils) from 2.0.2 to 2.0.4.
- [Release notes](https://github.com/webpack/loader-utils/releases)
- [Changelog](https://github.com/webpack/loader-utils/blob/v2.0.4/CHANGELOG.md)
- [Commits](https://github.com/webpack/loader-utils/compare/v2.0.2...v2.0.4)

---
updated-dependencies:
- dependency-name: loader-utils
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-16 06:56:29 +00:00
e6ec51c7eb fix: sas9 public access denied handling 2022-09-07 18:34:45 +02:00
dependabot[bot]
85dde61baf chore(deps): bump semver-regex from 3.1.3 to 3.1.4
Bumps [semver-regex](https://github.com/sindresorhus/semver-regex) from 3.1.3 to 3.1.4.
- [Release notes](https://github.com/sindresorhus/semver-regex/releases)
- [Commits](https://github.com/sindresorhus/semver-regex/commits/v3.1.4)

---
updated-dependencies:
- dependency-name: semver-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-03 23:43:27 +00:00
6 changed files with 13874 additions and 410 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -78,7 +78,16 @@ export class AuthManager {
if (isLoggedIn) {
if (this.serverType === ServerType.Sas9) {
await this.performCASSecurityCheck()
const casSecurityCheckResponse = 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()
@@ -149,7 +158,17 @@ export class AuthManager {
if (isLoggedIn) {
if (this.serverType === ServerType.Sas9) {
await this.performCASSecurityCheck()
const casSecurityCheckResponse = 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()
@@ -166,11 +185,15 @@ export class AuthManager {
private async performCASSecurityCheck() {
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
await this.requestClient
return await this.requestClient
.get<string>(`/SASLogon/login?service=${casAuthenticationUrl}`, undefined)
.catch((err) => {
// ignore if resource not found error
if (!(err instanceof NotFoundError)) throw err
return {
result: ''
}
})
}
@@ -387,3 +410,7 @@ const isLogInSuccess = (serverType: ServerType, response: any): boolean => {
return /You have signed in/gm.test(response)
}
const isPublicAccessDenied = (response: any): boolean => {
return /Public access has been denied/gm.test(response)
}

View File

@@ -5,6 +5,7 @@ import axios from 'axios'
import {
mockedCurrentUserApi,
mockLoginAuthoriseRequiredResponse,
mockLoginPublicAccessDeniedResponse,
mockLoginSuccessResponse
} from './mockResponses'
import { serialize } from '../../utils'
@@ -213,6 +214,61 @@ describe('AuthManager', () => {
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 () => {
const authManager = new AuthManager(
serverUrl,
@@ -422,6 +478,53 @@ describe('AuthManager', () => {
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 () => {
const authManager = new AuthManager(
serverUrl,

View File

@@ -2,6 +2,7 @@ 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 mockLoginSuccessResponse = `You have signed in`
export const mockLoginPublicAccessDeniedResponse = `Public access has been denied`
export const mockAuthResponse: SasAuthResponse = {
access_token: 'acc355',

View File

@@ -187,6 +187,12 @@ export class WebJobExecutor extends BaseJobExecutor {
{ result: jsonResponse, log: res.log },
extraResponseAttributes
)
if (this.isPublicAccessDenied(jsonResponse))
reject(
new ErrorResponse('Public access has been denied', responseObject)
)
resolve(responseObject)
})
.catch(async (e: Error) => {
@@ -262,4 +268,8 @@ export class WebJobExecutor extends BaseJobExecutor {
}
return uri
}
private isPublicAccessDenied = (response: string): boolean => {
return /Public access has been denied/gm.test(response)
}
}

View File

@@ -6,6 +6,7 @@ export interface LoginResult {
isLoggedIn: boolean
userName: string
userLongName: string
errorMessage?: string
}
export interface LoginResultInternal {
isLoggedIn: boolean