Skip to content

OpenConceptLab/ocl_online#327 | TBv2 at app.classic.<env> names the same environment as app.<env> - #64

Merged
snyaggarwal merged 2 commits into
masterfrom
ocl_online-327-app-classic
Dec 1, 2026
Merged

snyaggarwal merged 2 commits into
masterfrom
ocl_online-327-app-classic

Conversation

@snyaggarwal

@snyaggarwal snyaggarwal commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

TBv2 gets a third host, app.classic.<env> (production, staging and qa). After the switch it's the one TBv3 links to as the Classic Term Browser. This PR makes that host behave like app.v2.<env>.

Change

toAppOrigin (src/common/env.js) maps app.classic.<env> to app.<env>, as it already does for app.v2.<env>. So on app.classic:

  • getEnv returns the right environment (not development): the OpenMRS link, the logo link and error tags are right;
  • the TBv3 link (toV3URL) goes to app.v3.<env>, and the Mapper link (toMapperURL) goes to map.<env>.

Sign-in, sign-up and sign-out already return to window.location.origin, so SSO needs no change here. It only needs app.classic.<env>/* in the Keycloak clients.

Sign-in from TBv3 on app.<env>

  • Once TBv3 is the default at app.<env>, its Classic link sends ?referrer=https://app.<env>…/?auth=true.
  • isV3URL only accepted https://app.v3., so TBv2 didn't start the sign-in, and auth-required pages showed Access Denied until silent SSO caught up.
  • New isTBv3URL (env.js) accepts app[.<env>] and app.v3[.<env>], but not app.v2 or app.classic. isV3URL uses it.

Referrer auth=true check

isRedirectingToLoginViaReferrer read params inside its own initializer, where parts was meant. As a result, the auth=true hand-off to an auth-required route could never work. It now parses parts[1].

Nothing else changes on app.<env> or app.v2.<env>. It's safe to deploy before the host exists.

Checks

  • node --test src/common/__tests__/env.test.js src/common/__tests__/announcement.test.js: 27 pass, including isTBv3URL cases (app, app.<env>, app.v3; not app.v2, app.classic, map, look-alike or http hosts). CI eslint is clean. The new tests cover app.classic in every env, and toAppOrigin on app.classic and app.v3 origins.

🤖 Generated with Claude Code

…ame environment as app.<env>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Review: approve, with one should-fix before the app.<env> switch

Checked

  • node --test src/common/__tests__/env.test.js: 7 pass. Against master's env.js the 2 new tests fail, so they test the change. CI eslint is clean.
  • toAppOrigin matches only right after ://. Classic hosts, with or without an env label, map to app.<env>. localhost, app.v3.* and app.classicx.* are untouched.
  • On app.classic in production, staging, qa and demo:
    • getEnv and getEnv(true) are correct, and the OpenMRS link, production logo link and error tag follow from them;
    • the TBv3 link (toV3URL) goes to app.v3.<env>, and the Mapper link (toMapperURL) to map.<env>.
  • Sign-in, sign-up, sign-out, the OIDC callback token exchange and silent SSO all use window.location.origin, so they return to app.classic. The only other requirement is app.classic.<env>/* in the Keycloak clients (silent SSO included), which the description covers.

Should-fix

  1. src/common/utils.js isV3URL only accepts referrers starting with https://app.v3..
    • After the switch, TBv3 is at app.<env>. Its Classic button (oclweb3#119) sends ?referrer=https://app.<env>.openconceptlab.org/?auth=true.
    • isOtherOCLClientURL rejects that referrer. So for a user signed in on TBv3 who clicks Classic, forceLoginUser (App.jsx:127) doesn't send them to SSO, and an auth-required route (App.jsx:55) renders AccessDenied instead of CheckAuth.
    • Silent SSO usually signs them in a moment later, so in practice it's mostly a flash of Access Denied or of being signed out. It affects app.v2 in the same way.
    • Fix: isV3URL also accepts https://app.<env>.openconceptlab.org, meaning an app. host that isn't v2 or classic, and gets a test for it.

Pre-existing, in the same path
2. src/common/utils.js isRedirectingToLoginViaReferrer: let params = params?.length > 0 ? new URLSearchParams(parts[1]) : {} reads params inside its own initializer; parts was meant.

  • Left as let, that's a TDZ ReferenceError.
  • Transpiled to var, params is {}, so params.get('auth') throws once the referrer is an OCL client.
  • Either way, the auth=true path on an auth-required route can't work. Worth fixing together with 1.

Nits
3. .github/workflows/pr.yml runs eslint only, so env.test.js and announcement.test.js never run in CI. That was already the case before this PR.
4. src/common/utils.js toMapperURL: the branch that sends app.qa and app.demo to map.qa is dead, because the match('app.*.openconceptlab.org') on the next line always wins. app.classic.demo behaves like app.demo today, so this PR introduces no regression.

🤖 Generated with Claude Code

…n-in on TBv2; fix the referrer's auth=true check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Review follow-up, d55aec1:

  • 1, fixed: a new isTBv3URL in env.js accepts app[.<env>] and app.v3[.<env>], but not app.v2 or app.classic. isV3URL now uses it.
  • 2, fixed: isRedirectingToLoginViaReferrer now parses parts[1].

27 tests pass and eslint is clean. Nits 3 and 4 are unchanged: CI test wiring and the dead map.qa branch both predate this PR.

🤖 Generated with Claude Code

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Merge verdict: ready to merge

A fresh review of the latest commit (d55aec1) found no blockers and nothing to fix before merging. CI is green: eslint, CodeQL and Snyk. Locally, 27 tests pass.

  • isTBv3URL was run against every case:
    • It accepts app[.<env>] and app.v3[.<env>] (staging.who included), with paths, queries and hashes, plus the exact referrers TBv3's toSiblingAppURL builds.
    • It rejects app.v2, app.classic, http, explicit ports, map/api and look-alikes (app.openconceptlab.org.evil.example, …@evil.example, xapp., uppercase).
  • Blast radius: isV3URL is only used by isOtherOCLClientURL, which only decides whether a signed-out visitor with ?referrer=…?auth=true is sent to SSO. Before the switch, nothing builds an app.<env> referrer, so behaviour is unchanged until then.
  • The isRedirectingToLoginViaReferrer fix:
    • The old line crashed in both builds: a TDZ ReferenceError natively, and params.get is not a function after Babel (IE11 target). That broke auth-required routes whenever the referrer was an OCL client.
    • The new line was traced through history@4.10.1's createLocation. It returns true exactly for OCL-client referrers carrying auth=true (TBv3 on app and app.v3, and the Mapper with a hash), and agrees with forceLoginUser on all 13 cases.

Nits (can be follow-ups):

  • No regression test for isRedirectingToLoginViaReferrer: utils.js can't be imported by the plain-node tests.
  • isTBv3URL tests don't cover staging.who or app.v2.<env>. Both behave correctly.

Outside this PR (unchanged code): App.jsx forceLoginUser uses pathname in its !isSSOEnabled() branch before declaring it, so with SSO off the return URL would be /#undefined. It only matters where SSO is disabled.

🤖 Generated with Claude Code

@snyaggarwal
snyaggarwal merged commit a68c537 into master Dec 1, 2026
6 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online-327-app-classic branch December 1, 2026 08:48
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.

1 participant