[grade=B] fix(auth): reuse valid session for cross-host SSO
This commit is contained in:
@@ -93,3 +93,41 @@ test('same-origin and tokenless destinations keep their direct URL', () => {
|
||||
assert.equal(buildHandoffTarget('/settings', 'one-time'), 'https://status.sami/settings');
|
||||
assert.equal(buildHandoffTarget('https://router.sami/config', ''), 'https://router.sami/config');
|
||||
});
|
||||
|
||||
test('an existing status.sami session returns to a service without another TOTP prompt', async () => {
|
||||
const query = new URLSearchParams({ auth: 'required', return: 'https://plex.sami/web/' });
|
||||
let scheduled;
|
||||
let redirected;
|
||||
const location = {
|
||||
origin: 'https://status.sami',
|
||||
pathname: '/',
|
||||
search: `?${query.toString()}`,
|
||||
replace(value) { redirected = value; },
|
||||
};
|
||||
const context = {
|
||||
URL,
|
||||
URLSearchParams,
|
||||
SITE: { tld: '.sami' },
|
||||
sessionStorage: { setItem() {} },
|
||||
document: { getElementById() { return null; } },
|
||||
setTimeout(fn) { scheduled = fn; },
|
||||
console,
|
||||
fetch: async (url) => {
|
||||
assert.equal(url, '/api/v1/auth/sso-handoff');
|
||||
return { ok: true, json: async () => ({ success: true, ssoToken: 'existing-session-token' }) };
|
||||
},
|
||||
window: {
|
||||
location,
|
||||
history: { replaceState() {} },
|
||||
},
|
||||
};
|
||||
context.window.window = context.window;
|
||||
vm.runInNewContext(source, context, { filename: 'auth-gate.js' });
|
||||
|
||||
assert.equal(typeof scheduled, 'function');
|
||||
await scheduled();
|
||||
assert.equal(
|
||||
redirected,
|
||||
'https://plex.sami/dashcaddy-sso?token=existing-session-token&return=%2Fweb%2F',
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user