Skip to content

fix: sas9 public access denied handling - #755

Open
medjedovicm wants to merge 6 commits into
masterfrom
issue-150
Open

fix: sas9 public access denied handling#755
medjedovicm wants to merge 6 commits into
masterfrom
issue-150

Conversation

@medjedovicm

Copy link
Copy Markdown
Member

Issue

Fixes #150

Intent

Covers the SAS9 Public Access Denied scenario. 2 places touched:

  1. login() - User is not logged in. The login function is called with Public Account credentials. The adapter will return an object that contains an error message with error details and loggedIn is false. (image 1.)
  2. request() - User with Public Account is already logged in within current browser. App loads, request function is called. The adapter will throw an error with details inside. (image 2.)

image 1.
public-access-on-login

image 2.
public-access-on-request

Checks

No PR (that involves a non-trivial code change) should be merged, unless all items below are confirmed! If an urgent fix is needed - use a tar file.

  • All sasjs-cli unit tests are passing (npm test).
  • (CI Runs this) All sasjs-tests are passing. If you want to run it manually (instructions available here).
  • Data Controller builds and is functional on both SAS 9 and Viya

@github-actions

github-actions Bot commented Jul 12, 2023

Copy link
Copy Markdown

Coverage report

Total coverage

Status Category Percentage Covered / Total
🟡 Statements 62.72% 2027/3232
🔴 Branches 44.67% 738/1652
🔴 Functions 53.56% 301/562
🟡 Lines 73.99% (+2.25% 🔼) 3283/4437

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Show files with reduced coverage 🔻

Reduced coverage

Status Filename Statements Branches Functions Lines
🟢 src/job-execution/WebJobExecutor.ts 16.07% 2.6% 10.53% 100% (+72.85% 🔼)

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Report generated by 🧪jest coverage report action from 3556eb3

@YuryShkoda

Copy link
Copy Markdown
Member

@medjedovicm please a test cases for both scenarios

@saadjutt01
saadjutt01 removed their request for review October 27, 2024 20:22
new ErrorResponse('Public access has been denied', responseObject)
)

resolve(responseObject)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: resolve(responseObject) on the next line will still execute after reject() is called. While the Promise is already settled (so resolve is a no-op), this is fragile and misleading. Add a return before reject:

if (this.isPublicAccessDenied(jsonResponse))
  return reject(
    new ErrorResponse('Public access has been denied', responseObject)
  )

}

private isPublicAccessDenied = (response: string): boolean => {
return /Public access has been denied/gm.test(response)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isPublicAccessDenied function is duplicated — the same regex check exists as a module-level function in AuthManager.ts (line 414). Consider extracting it to a shared utility (e.g. utils/isPublicAccessDenied.ts) and importing in both places, to avoid drift if the error message pattern changes.

Comment thread src/auth/AuthManager.ts
if (!(err instanceof NotFoundError)) throw err

return {
result: ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .catch() returns { result: '' } but the success path returns the full RequestClient.get response (which has .result plus other fields like .log). The caller does casSecurityCheckResponse.result so this works, but the return types are inconsistent — the catch path produces a partial object. Consider typing the return explicitly or using { result: '', log: '' } for consistency.

@4gl-reviewer 4gl-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hermes Agent Code Review

Verdict: Request Changes — 1 bug, 2 warnings, merge conflict

Blocking Issues

  1. Merge conflict — this PR is currently not mergeable (mergeable_state: dirty). Please rebase against main and resolve conflicts before this review can be considered for merge.

  2. Bug: WebJobExecutor.ts:196resolve(responseObject) executes after reject() on the public-access-denied path. While the Promise is already settled (so resolve is a no-op), this is fragile and could break if the code is refactored. Add return before reject:

if (this.isPublicAccessDenied(jsonResponse))
  return reject(
    new ErrorResponse('Public access has been denied', responseObject)
  )

Warnings

  1. Duplicated isPublicAccessDenied — The same regex check exists in both AuthManager.ts (module-level) and WebJobExecutor.ts (private method). Extract to a shared utility to avoid drift.

  2. Inconsistent return type in performCASSecurityCheck catch — The .catch() returns { result: '' } (partial object) while the success path returns the full response with .result, .log, etc. Type the return explicitly for safety.

Looks Good

  • Good test coverage: two new spec tests covering both logIn and redirectedLogIn paths for the public-access-denied scenario
  • The errorMessage field addition to LoginResult is clean and backward-compatible (optional field)
  • The regex pattern /Public access has been denied/gm is consistent across both implementations
  • Mock response added to mockResponses.ts for test reuse

Reviewed by Hermes Agent (GitHub App)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public access denied error is not handled when trying to log in

2 participants