Changeset 0.37.14 (#226)
Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
@@ -241,3 +241,82 @@ describe('init() profile gate', () => {
|
||||
// Without guard: UI renders. With guard: splash shown.
|
||||
});
|
||||
});
|
||||
|
||||
// ── Boot-time 401 redirect suppression ──────
|
||||
// v0.37.14: Stale cookie blank-login-page fix.
|
||||
// When the login page boots the SDK with stale localStorage tokens,
|
||||
// the REST client's 401 handler must NOT redirect to /login (we're
|
||||
// already there). boot() handles 401 gracefully on its own.
|
||||
|
||||
describe('on401Failure redirect suppression', () => {
|
||||
|
||||
// Model of the _on401Failure guard logic
|
||||
function make401Handler() {
|
||||
let _booting = false;
|
||||
let redirectedTo = null;
|
||||
|
||||
return {
|
||||
set booting(v) { _booting = v; },
|
||||
get booting() { return _booting; },
|
||||
get redirectedTo() { return redirectedTo; },
|
||||
reset() { redirectedTo = null; },
|
||||
|
||||
on401Failure(pathname, basePath) {
|
||||
// Mirrors the real _on401Failure logic
|
||||
if (_booting) return;
|
||||
const loginPath = basePath + '/login';
|
||||
const here = pathname.replace(/\/+$/, '');
|
||||
if (here === loginPath) return;
|
||||
redirectedTo = loginPath;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
it('suppresses redirect during boot', () => {
|
||||
const h = make401Handler();
|
||||
h.booting = true;
|
||||
h.on401Failure('/chat', '');
|
||||
assert.equal(h.redirectedTo, null, 'must NOT redirect during boot');
|
||||
});
|
||||
|
||||
it('allows redirect after boot completes', () => {
|
||||
const h = make401Handler();
|
||||
h.booting = true;
|
||||
h.on401Failure('/chat', '');
|
||||
assert.equal(h.redirectedTo, null);
|
||||
|
||||
h.booting = false;
|
||||
h.on401Failure('/chat', '');
|
||||
assert.equal(h.redirectedTo, '/login', 'must redirect after boot');
|
||||
});
|
||||
|
||||
it('suppresses redirect when already on /login', () => {
|
||||
const h = make401Handler();
|
||||
h.on401Failure('/login', '');
|
||||
assert.equal(h.redirectedTo, null, 'must NOT redirect to /login from /login');
|
||||
});
|
||||
|
||||
it('suppresses redirect when on /login with trailing slash', () => {
|
||||
const h = make401Handler();
|
||||
h.on401Failure('/login/', '');
|
||||
assert.equal(h.redirectedTo, null, 'must NOT redirect from /login/');
|
||||
});
|
||||
|
||||
it('handles basePath correctly', () => {
|
||||
const h = make401Handler();
|
||||
h.on401Failure('/app/login', '/app');
|
||||
assert.equal(h.redirectedTo, null, 'must NOT redirect from basePath + /login');
|
||||
});
|
||||
|
||||
it('redirects from non-login paths normally', () => {
|
||||
const h = make401Handler();
|
||||
h.on401Failure('/chat', '');
|
||||
assert.equal(h.redirectedTo, '/login');
|
||||
});
|
||||
|
||||
it('redirects from non-login paths with basePath', () => {
|
||||
const h = make401Handler();
|
||||
h.on401Failure('/app/chat', '/app');
|
||||
assert.equal(h.redirectedTo, '/app/login');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user