@shellui/core 0.6.1 → 0.7.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +2 -2
- package/schemas/shellui.config.schema.json +116 -72
- package/src/app.tsx +2 -0
- package/src/components/ContentView.tsx +2 -22
- package/src/components/iframeUrlSafety.spec.ts +67 -0
- package/src/components/iframeUrlSafety.ts +50 -0
- package/src/features/admin/AdminView.tsx +18 -4
- package/src/features/auth/AuthProvider.tsx +42 -2
- package/src/features/auth/appBackend/AppBackendSessionHost.tsx +58 -0
- package/src/features/auth/appBackend/appBackendSessions.spec.ts +195 -0
- package/src/features/auth/appBackend/appBackendSessions.ts +292 -0
- package/src/features/auth/appBackend/configSchema.spec.ts +41 -0
- package/src/features/auth/appBackend/frameAuth.ts +167 -0
- package/src/features/auth/appBackend/identity.spec.ts +201 -0
- package/src/features/auth/appBackend/identity.ts +173 -0
- package/src/features/auth/appBackend/silentSignIn.spec.ts +207 -0
- package/src/features/auth/appBackend/silentSignIn.ts +240 -0
- package/src/features/auth/backends/shellui.spec.ts +51 -19
- package/src/features/auth/backends/shellui.ts +20 -5
- package/src/features/auth/backends/types.ts +7 -2
- package/src/features/auth/components/LoginView.tsx +40 -18
- package/src/features/auth/components/OAuthCallbackView.tsx +29 -2
- package/src/features/auth/utils/authRequestError.ts +3 -0
- package/src/features/auth/utils/desktopSignIn.spec.ts +41 -0
- package/src/features/auth/utils/desktopSignIn.ts +38 -0
- package/src/features/auth/utils/index.ts +9 -0
- package/src/features/auth/utils/loginCancelTarget.spec.ts +73 -0
- package/src/features/auth/utils/loginCancelTarget.ts +45 -0
- package/src/features/auth/utils/loginPanelFrame.spec.ts +24 -0
- package/src/features/auth/utils/loginPanelFrame.ts +14 -0
- package/src/features/auth/utils/webPkce.spec.ts +96 -0
- package/src/features/auth/utils/webPkce.ts +152 -0
- package/src/features/chromeActions/ChromeActionsHost.tsx +7 -1
- package/src/features/chromeActions/computeActionInsets.ts +6 -0
- package/src/features/config/types.ts +41 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +39 -9
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +14 -7
- package/src/features/layouts/chrome/DesktopChrome.tsx +3 -1
- package/src/features/layouts/floating/FloatingLayout.tsx +4 -1
- package/src/features/layouts/floating/FloatingSidebar.tsx +84 -28
- package/src/features/layouts/floating/computeFloatingInsets.spec.ts +19 -0
- package/src/features/layouts/floating/computeFloatingInsets.ts +40 -8
- package/src/features/layouts/floating/layoutChromeStore.ts +13 -0
- package/src/features/layouts/floating/useFloatingChrome.ts +11 -5
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +3 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +5 -0
- package/src/features/layouts/sidebar/SidebarLayout.tsx +1 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +106 -46
- package/src/features/security/trustedFrames.spec.ts +17 -1
- package/src/features/security/trustedFrames.ts +31 -9
- package/src/features/settings/SettingsProvider.tsx +48 -32
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +374 -0
- package/src/features/settings/utils/buildSettingsForPropagation.ts +70 -35
- package/src/i18n/translations/en/common.json +2 -0
- package/src/i18n/translations/fr/common.json +2 -0
- package/src/index.css +16 -1
- package/src/index.ts +1 -0
- package/src/lib/z-index.ts +5 -0
|
@@ -19,7 +19,12 @@ import {
|
|
|
19
19
|
import { SettingsContext } from './SettingsContext';
|
|
20
20
|
import { useConfig } from '../config/useConfig';
|
|
21
21
|
import { useAuth } from '../auth/hooks/useAuth';
|
|
22
|
-
import {
|
|
22
|
+
import { frameAuthPropagationOptions } from '../auth/appBackend/frameAuth';
|
|
23
|
+
import {
|
|
24
|
+
getAppBackendSession,
|
|
25
|
+
refreshAppBackendSessionIfDue,
|
|
26
|
+
subscribeAppBackendSessions,
|
|
27
|
+
} from '../auth/appBackend/appBackendSessions';
|
|
23
28
|
import { isMainLayoutFrame } from '../layouts/floating/layoutChromeStore';
|
|
24
29
|
import { defaultTheme } from '../theme/themes';
|
|
25
30
|
import {
|
|
@@ -192,27 +197,31 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
192
197
|
return defaultSettings;
|
|
193
198
|
});
|
|
194
199
|
|
|
195
|
-
const isTrustedFrameForAuthTokenCallback = useCallback(
|
|
196
|
-
(frameSrc: string): boolean => isTrustedFrameForAuthToken(frameSrc, config),
|
|
197
|
-
[config],
|
|
198
|
-
);
|
|
199
|
-
|
|
200
200
|
const accessTokenRef = useRef<string | null>(session?.accessToken ?? null);
|
|
201
201
|
accessTokenRef.current = session?.accessToken ?? null;
|
|
202
202
|
|
|
203
|
+
const authOptionsForFrame = useCallback(
|
|
204
|
+
(frameSrc: string) =>
|
|
205
|
+
frameAuthPropagationOptions({
|
|
206
|
+
frameSrc,
|
|
207
|
+
config,
|
|
208
|
+
shellAccessToken: accessTokenRef.current,
|
|
209
|
+
getAppSession: getAppBackendSession,
|
|
210
|
+
}),
|
|
211
|
+
[config],
|
|
212
|
+
);
|
|
213
|
+
|
|
203
214
|
const propagateSettingsToIframes = useCallback(
|
|
204
215
|
(baseSettings: Settings) => {
|
|
205
216
|
const iframes = shellui.frameRegistry.getLiveIframes();
|
|
206
217
|
if (iframes.length === 0) return;
|
|
207
218
|
const lang = baseSettings.language?.code || 'en';
|
|
208
|
-
const accessToken = accessTokenRef.current;
|
|
209
219
|
for (const [uuid, iframe] of iframes) {
|
|
210
220
|
const frameSrc = iframe?.src ?? '';
|
|
211
|
-
const includeAuthAccessToken = isTrustedFrameForAuthTokenCallback(frameSrc);
|
|
212
221
|
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
213
|
-
|
|
214
|
-
accessToken,
|
|
222
|
+
...authOptionsForFrame(frameSrc),
|
|
215
223
|
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
224
|
+
frameUuid: uuid,
|
|
216
225
|
});
|
|
217
226
|
shellui.sendMessage({
|
|
218
227
|
type: 'SHELLUI_SETTINGS',
|
|
@@ -221,20 +230,19 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
221
230
|
});
|
|
222
231
|
}
|
|
223
232
|
},
|
|
224
|
-
[
|
|
233
|
+
[authOptionsForFrame, config],
|
|
225
234
|
);
|
|
226
235
|
|
|
227
236
|
const pushSettingsToFrame = useCallback(
|
|
228
237
|
(iframeUuid: string, frameSrc: string, baseSettings: Settings) => {
|
|
229
238
|
const lang = baseSettings.language?.code || 'en';
|
|
230
|
-
const includeAuthAccessToken = isTrustedFrameForAuthTokenCallback(frameSrc);
|
|
231
239
|
const iframe = shellui.frameRegistry
|
|
232
240
|
.getAllIframes()
|
|
233
241
|
.find(([uuid]) => uuid === iframeUuid)?.[1];
|
|
234
242
|
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
235
|
-
|
|
236
|
-
accessToken: accessTokenRef.current,
|
|
243
|
+
...authOptionsForFrame(frameSrc),
|
|
237
244
|
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
245
|
+
frameUuid: iframeUuid,
|
|
238
246
|
});
|
|
239
247
|
shellui.sendMessage({
|
|
240
248
|
type: 'SHELLUI_SETTINGS',
|
|
@@ -242,7 +250,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
242
250
|
to: [iframeUuid],
|
|
243
251
|
});
|
|
244
252
|
},
|
|
245
|
-
[
|
|
253
|
+
[authOptionsForFrame, config],
|
|
246
254
|
);
|
|
247
255
|
|
|
248
256
|
const applyHandoffToken = useCallback((token: string | null | undefined) => {
|
|
@@ -254,6 +262,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
254
262
|
return deliverSessionHandoff(() => propagateSettingsToIframes(base));
|
|
255
263
|
}, [propagateSettingsToIframes]);
|
|
256
264
|
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
return subscribeAppBackendSessions(() => {
|
|
267
|
+
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
268
|
+
handoffSettingsToIframes();
|
|
269
|
+
});
|
|
270
|
+
}, [handoffSettingsToIframes]);
|
|
271
|
+
|
|
257
272
|
// When the shell rotates the JWT, `authUser` often does not change, so the user-sync effect
|
|
258
273
|
// above skips — still push `SHELLUI_SETTINGS` so trusted iframes get the new `accessToken`.
|
|
259
274
|
// The follow-up turn covers an app that subscribes after the first post.
|
|
@@ -480,28 +495,31 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
480
495
|
// not the JWT that died while the tab was hidden.
|
|
481
496
|
const token = await refreshFrameAccessTokenIfNeeded();
|
|
482
497
|
applyHandoffToken(token);
|
|
498
|
+
const requestingPath = (message.from ?? []).filter(Boolean);
|
|
499
|
+
const [firstHopIframeUuid] = requestingPath;
|
|
500
|
+
const requestingFrame = firstHopIframeUuid
|
|
501
|
+
? shellui.frameRegistry
|
|
502
|
+
.getAllIframes()
|
|
503
|
+
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1]
|
|
504
|
+
: undefined;
|
|
505
|
+
if (requestingFrame?.src) {
|
|
506
|
+
await refreshAppBackendSessionIfDue(requestingFrame.src, config);
|
|
507
|
+
}
|
|
483
508
|
|
|
484
509
|
const send = () => {
|
|
485
510
|
const currentSettings = settingsRef.current ?? defaultSettings;
|
|
486
|
-
const requestingPath = (message.from ?? []).filter(Boolean);
|
|
487
511
|
|
|
488
512
|
if (requestingPath.length > 0) {
|
|
489
|
-
const [firstHopIframeUuid] = requestingPath;
|
|
490
|
-
const frame = shellui.frameRegistry
|
|
491
|
-
.getAllIframes()
|
|
492
|
-
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1];
|
|
493
513
|
const lang = currentSettings.language?.code || 'en';
|
|
494
|
-
const
|
|
495
|
-
? isTrustedFrameForAuthTokenCallback(frame.src ?? '')
|
|
496
|
-
: false;
|
|
514
|
+
const frameSrc = requestingFrame?.src ?? '';
|
|
497
515
|
const settingsToPropagate = buildSettingsForPropagation(
|
|
498
516
|
currentSettings,
|
|
499
517
|
config,
|
|
500
518
|
lang,
|
|
501
519
|
{
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
520
|
+
...authOptionsForFrame(frameSrc),
|
|
521
|
+
includeLayoutChrome: isMainLayoutFrame(requestingFrame),
|
|
522
|
+
frameUuid: firstHopIframeUuid,
|
|
505
523
|
},
|
|
506
524
|
);
|
|
507
525
|
|
|
@@ -562,12 +580,10 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
562
580
|
void (async () => {
|
|
563
581
|
const token = await refreshFrameAccessTokenIfNeeded();
|
|
564
582
|
applyHandoffToken(token);
|
|
583
|
+
const frameSrc = iframe?.src ?? '';
|
|
584
|
+
if (frameSrc) await refreshAppBackendSessionIfDue(frameSrc, config);
|
|
565
585
|
deliverSessionHandoff(() =>
|
|
566
|
-
pushSettingsToFrame(
|
|
567
|
-
iframeUuid,
|
|
568
|
-
iframe?.src ?? '',
|
|
569
|
-
settingsRef.current ?? defaultSettings,
|
|
570
|
-
),
|
|
586
|
+
pushSettingsToFrame(iframeUuid, frameSrc, settingsRef.current ?? defaultSettings),
|
|
571
587
|
);
|
|
572
588
|
})();
|
|
573
589
|
},
|
|
@@ -580,8 +596,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
580
596
|
cleanupInitialized();
|
|
581
597
|
};
|
|
582
598
|
}, [
|
|
599
|
+
authOptionsForFrame,
|
|
583
600
|
config,
|
|
584
|
-
isTrustedFrameForAuthTokenCallback,
|
|
585
601
|
applyHandoffToken,
|
|
586
602
|
propagateSettingsToIframes,
|
|
587
603
|
pushSettingsToFrame,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import type { Settings } from '@shellui/sdk';
|
|
3
|
+
import type { AuthSession } from '../../auth/types';
|
|
4
|
+
import { frameAuthPropagationOptions } from '../../auth/appBackend/frameAuth';
|
|
3
5
|
import type { ShellUIConfig } from '../../config/types';
|
|
4
6
|
import { buildSettingsForPropagation } from './buildSettingsForPropagation';
|
|
5
7
|
|
|
@@ -319,4 +321,376 @@ describe('buildSettingsForPropagation', () => {
|
|
|
319
321
|
const result = buildSettingsForPropagation(baseSettings, config, 'en');
|
|
320
322
|
expect(result.email).toEqual({ url: 'https://email.shellui.com' });
|
|
321
323
|
});
|
|
324
|
+
|
|
325
|
+
const shellToken = 'shell-access-token';
|
|
326
|
+
const foreignToken = 'foreign-access-token';
|
|
327
|
+
const shellUser = {
|
|
328
|
+
id: 'shell-user',
|
|
329
|
+
email: 'shell@example.com',
|
|
330
|
+
name: 'Shell User',
|
|
331
|
+
profilePicture: null,
|
|
332
|
+
authProvider: 'google',
|
|
333
|
+
isStaff: true,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const appConfig = {
|
|
337
|
+
backend: {
|
|
338
|
+
type: 'shellui' as const,
|
|
339
|
+
url: 'https://id.example.com/',
|
|
340
|
+
companyId: 1,
|
|
341
|
+
adminUrl: 'https://admin.example/',
|
|
342
|
+
login: { oauthProviders: ['google'] },
|
|
343
|
+
},
|
|
344
|
+
storage: { url: 'https://files-api.example', filesUrl: 'https://files.example/' },
|
|
345
|
+
email: { url: 'https://email.example' },
|
|
346
|
+
hosting: { url: 'https://hosting.example/', app: 'shell-app' },
|
|
347
|
+
navigation: [
|
|
348
|
+
{
|
|
349
|
+
label: 'Billing',
|
|
350
|
+
path: 'billing',
|
|
351
|
+
url: 'https://billing.example/',
|
|
352
|
+
safeForAuthToken: true,
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
label: 'Directory',
|
|
356
|
+
path: 'directory',
|
|
357
|
+
url: 'https://directory.example/',
|
|
358
|
+
safeForAuthToken: true,
|
|
359
|
+
backend: {
|
|
360
|
+
url: 'https://id.directory.example/',
|
|
361
|
+
companyId: 4,
|
|
362
|
+
provider: 'google',
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
label: 'Public directory',
|
|
367
|
+
path: 'public-directory',
|
|
368
|
+
url: 'https://public.example/',
|
|
369
|
+
backend: { url: 'https://id.public.example' },
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
} as ShellUIConfig;
|
|
373
|
+
|
|
374
|
+
const foreignSession = {
|
|
375
|
+
accessToken: foreignToken,
|
|
376
|
+
refreshToken: 'foreign-refresh',
|
|
377
|
+
tokenType: 'bearer',
|
|
378
|
+
expiresAt: 4_000_000_000,
|
|
379
|
+
provider: 'google',
|
|
380
|
+
userId: 'foreign-user',
|
|
381
|
+
userEmail: 'foreign@example.com',
|
|
382
|
+
userName: 'Foreign User',
|
|
383
|
+
userAvatarUrl: null,
|
|
384
|
+
userIsStaff: false,
|
|
385
|
+
userIsCompanyOwner: true,
|
|
386
|
+
userGroups: ['directory'],
|
|
387
|
+
} satisfies AuthSession;
|
|
388
|
+
|
|
389
|
+
const propagate = (frameSrc: string, session: AuthSession | null = foreignSession) => {
|
|
390
|
+
const options = frameAuthPropagationOptions({
|
|
391
|
+
frameSrc,
|
|
392
|
+
config: appConfig,
|
|
393
|
+
shellAccessToken: shellToken,
|
|
394
|
+
getAppSession: () => session,
|
|
395
|
+
shellOrigin: 'https://shell.example',
|
|
396
|
+
});
|
|
397
|
+
return buildSettingsForPropagation(
|
|
398
|
+
{ ...baseSettings, user: shellUser },
|
|
399
|
+
appConfig,
|
|
400
|
+
'en',
|
|
401
|
+
options,
|
|
402
|
+
);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const shellServices = {
|
|
406
|
+
storage: { url: 'https://files-api.example', filesUrl: 'https://files.example/' },
|
|
407
|
+
email: { url: 'https://email.example' },
|
|
408
|
+
hosting: { url: 'https://hosting.example', app: 'shell-app' },
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const expectNoShellServices = (result: ReturnType<typeof propagate>) => {
|
|
412
|
+
expect(result.storage).toBeNull();
|
|
413
|
+
expect(result.email).toBeNull();
|
|
414
|
+
expect(result.hosting).toBeNull();
|
|
415
|
+
const json = JSON.stringify(result);
|
|
416
|
+
expect(json).not.toContain('https://files-api.example');
|
|
417
|
+
expect(json).not.toContain('https://files.example');
|
|
418
|
+
expect(json).not.toContain('https://email.example');
|
|
419
|
+
expect(json).not.toContain('https://hosting.example');
|
|
420
|
+
expect(json).not.toContain('https://email.shellui.com');
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
it('falls back to the shell backend and token when the app has no override', () => {
|
|
424
|
+
const result = propagate('https://billing.example/');
|
|
425
|
+
expect(result.accessToken).toBe(shellToken);
|
|
426
|
+
expect(result.authBackendBaseUrl).toBe('https://id.example.com');
|
|
427
|
+
expect(result.user?.email).toBe('shell@example.com');
|
|
428
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
429
|
+
expect(result.email).toEqual(shellServices.email);
|
|
430
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('sends each foreign app its own backend URL and token', () => {
|
|
434
|
+
const result = propagate('https://directory.example/people');
|
|
435
|
+
expect(result.accessToken).toBe(foreignToken);
|
|
436
|
+
expect(result.authBackendBaseUrl).toBe('https://id.directory.example');
|
|
437
|
+
expect(result.user).toMatchObject({
|
|
438
|
+
id: 'foreign-user',
|
|
439
|
+
email: 'foreign@example.com',
|
|
440
|
+
groups: ['directory'],
|
|
441
|
+
});
|
|
442
|
+
expect(JSON.stringify(result)).not.toContain(shellToken);
|
|
443
|
+
expect(JSON.stringify(result)).not.toContain('shell@example.com');
|
|
444
|
+
expect(result).not.toHaveProperty('refreshToken');
|
|
445
|
+
expectNoShellServices(result);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('sends a null token, not the shell token, when the foreign session is missing', () => {
|
|
449
|
+
const result = propagate('https://directory.example/', null);
|
|
450
|
+
expect(result.accessToken).toBeNull();
|
|
451
|
+
expect(result.authBackendBaseUrl).toBe('https://id.directory.example');
|
|
452
|
+
expect(result.user).toBeNull();
|
|
453
|
+
expect(JSON.stringify(result)).not.toContain(shellToken);
|
|
454
|
+
expectNoShellServices(result);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('does not send either token to an untrusted app on another identity server', () => {
|
|
458
|
+
const result = propagate('https://public.example/');
|
|
459
|
+
expect(result.accessToken).toBeNull();
|
|
460
|
+
expect(result.authBackendBaseUrl).toBe('https://id.public.example');
|
|
461
|
+
expect(JSON.stringify(result)).not.toContain(shellToken);
|
|
462
|
+
expect(JSON.stringify(result)).not.toContain(foreignToken);
|
|
463
|
+
expectNoShellServices(result);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it('keeps the shell token for the built-in admin and storage frames', () => {
|
|
467
|
+
const admin = propagate('https://admin.example/#/users');
|
|
468
|
+
const files = propagate('https://files.example/company/docs');
|
|
469
|
+
expect(admin.accessToken).toBe(shellToken);
|
|
470
|
+
expect(admin.authBackendBaseUrl).toBe('https://id.example.com');
|
|
471
|
+
expect(files.accessToken).toBe(shellToken);
|
|
472
|
+
expect(files.authBackendBaseUrl).toBe('https://id.example.com');
|
|
473
|
+
expect(admin.storage).toEqual(shellServices.storage);
|
|
474
|
+
expect(admin.email).toEqual(shellServices.email);
|
|
475
|
+
expect(files.hosting).toEqual(shellServices.hosting);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('keeps the shell token for shell settings even if a root item names another server', () => {
|
|
479
|
+
vi.stubGlobal('window', {
|
|
480
|
+
location: { origin: 'https://shell.example' },
|
|
481
|
+
matchMedia: () => ({ matches: false }),
|
|
482
|
+
});
|
|
483
|
+
const withRoot = {
|
|
484
|
+
...appConfig,
|
|
485
|
+
navigation: [
|
|
486
|
+
...(appConfig.navigation ?? []),
|
|
487
|
+
{
|
|
488
|
+
label: 'Home',
|
|
489
|
+
path: 'home',
|
|
490
|
+
url: 'https://shell.example/',
|
|
491
|
+
safeForAuthToken: true,
|
|
492
|
+
backend: { url: 'https://id.other.example' },
|
|
493
|
+
},
|
|
494
|
+
],
|
|
495
|
+
} as ShellUIConfig;
|
|
496
|
+
const options = frameAuthPropagationOptions({
|
|
497
|
+
frameSrc: 'https://shell.example/__settings/storage',
|
|
498
|
+
config: withRoot,
|
|
499
|
+
shellAccessToken: shellToken,
|
|
500
|
+
getAppSession: () => foreignSession,
|
|
501
|
+
shellOrigin: 'https://shell.example',
|
|
502
|
+
});
|
|
503
|
+
const result = buildSettingsForPropagation(
|
|
504
|
+
{ ...baseSettings, user: shellUser },
|
|
505
|
+
withRoot,
|
|
506
|
+
'en',
|
|
507
|
+
options,
|
|
508
|
+
);
|
|
509
|
+
expect(result.accessToken).toBe(shellToken);
|
|
510
|
+
expect(result.authBackendBaseUrl).toBe('https://id.example.com');
|
|
511
|
+
expect(result.user?.email).toBe('shell@example.com');
|
|
512
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
513
|
+
expect(result.email).toEqual(shellServices.email);
|
|
514
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it('sends a foreign app its own service URLs and not the shell URLs', () => {
|
|
518
|
+
const withServices = {
|
|
519
|
+
...appConfig,
|
|
520
|
+
navigation: (appConfig.navigation ?? []).map((item) =>
|
|
521
|
+
item.path === 'directory'
|
|
522
|
+
? {
|
|
523
|
+
...item,
|
|
524
|
+
email: { url: 'https://email.directory.example/' },
|
|
525
|
+
storage: {
|
|
526
|
+
url: 'https://files-api.directory.example',
|
|
527
|
+
filesUrl: 'https://files.directory.example/',
|
|
528
|
+
},
|
|
529
|
+
hosting: { url: 'https://hosting.directory.example', showInAdmin: false },
|
|
530
|
+
}
|
|
531
|
+
: item,
|
|
532
|
+
),
|
|
533
|
+
} as ShellUIConfig;
|
|
534
|
+
const options = frameAuthPropagationOptions({
|
|
535
|
+
frameSrc: 'https://directory.example/people',
|
|
536
|
+
config: withServices,
|
|
537
|
+
shellAccessToken: shellToken,
|
|
538
|
+
getAppSession: () => foreignSession,
|
|
539
|
+
shellOrigin: 'https://shell.example',
|
|
540
|
+
});
|
|
541
|
+
const result = buildSettingsForPropagation(
|
|
542
|
+
{ ...baseSettings, user: shellUser },
|
|
543
|
+
withServices,
|
|
544
|
+
'en',
|
|
545
|
+
options,
|
|
546
|
+
);
|
|
547
|
+
expect(result.storage).toEqual({
|
|
548
|
+
url: 'https://files-api.directory.example',
|
|
549
|
+
filesUrl: 'https://files.directory.example/',
|
|
550
|
+
});
|
|
551
|
+
expect(result.email).toEqual({ url: 'https://email.directory.example' });
|
|
552
|
+
expect(result.hosting).toEqual({
|
|
553
|
+
url: 'https://hosting.directory.example',
|
|
554
|
+
showInAdmin: false,
|
|
555
|
+
});
|
|
556
|
+
const json = JSON.stringify(result);
|
|
557
|
+
expect(json).not.toContain('https://files-api.example');
|
|
558
|
+
expect(json).not.toContain('https://email.example');
|
|
559
|
+
expect(json).not.toContain('https://hosting.example');
|
|
560
|
+
expect(json).not.toContain('https://email.shellui.com');
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
it('uses the default email URL when a foreign app sets an empty email object', () => {
|
|
564
|
+
const withEmptyEmail = {
|
|
565
|
+
...appConfig,
|
|
566
|
+
navigation: (appConfig.navigation ?? []).map((item) =>
|
|
567
|
+
item.path === 'directory' ? { ...item, email: {} } : item,
|
|
568
|
+
),
|
|
569
|
+
} as ShellUIConfig;
|
|
570
|
+
const options = frameAuthPropagationOptions({
|
|
571
|
+
frameSrc: 'https://directory.example/',
|
|
572
|
+
config: withEmptyEmail,
|
|
573
|
+
shellAccessToken: shellToken,
|
|
574
|
+
getAppSession: () => foreignSession,
|
|
575
|
+
shellOrigin: 'https://shell.example',
|
|
576
|
+
});
|
|
577
|
+
const result = buildSettingsForPropagation(
|
|
578
|
+
{ ...baseSettings, user: shellUser },
|
|
579
|
+
withEmptyEmail,
|
|
580
|
+
'en',
|
|
581
|
+
options,
|
|
582
|
+
);
|
|
583
|
+
expect(result.email).toEqual({ url: 'https://email.shellui.com' });
|
|
584
|
+
expect(result.storage).toBeNull();
|
|
585
|
+
expect(result.hosting).toBeNull();
|
|
586
|
+
const json = JSON.stringify(result);
|
|
587
|
+
expect(json).not.toContain('https://files-api.example');
|
|
588
|
+
expect(json).not.toContain('https://email.example');
|
|
589
|
+
expect(json).not.toContain('https://hosting.example');
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it('replaces only the service an app sets when it keeps the shell backend', () => {
|
|
593
|
+
const withEmail = {
|
|
594
|
+
...appConfig,
|
|
595
|
+
navigation: [
|
|
596
|
+
...(appConfig.navigation ?? []),
|
|
597
|
+
{
|
|
598
|
+
label: 'Mail',
|
|
599
|
+
path: 'mail',
|
|
600
|
+
url: 'https://mail.example/',
|
|
601
|
+
safeForAuthToken: true,
|
|
602
|
+
email: {},
|
|
603
|
+
},
|
|
604
|
+
],
|
|
605
|
+
} as ShellUIConfig;
|
|
606
|
+
const options = frameAuthPropagationOptions({
|
|
607
|
+
frameSrc: 'https://mail.example/',
|
|
608
|
+
config: withEmail,
|
|
609
|
+
shellAccessToken: shellToken,
|
|
610
|
+
getAppSession: () => foreignSession,
|
|
611
|
+
shellOrigin: 'https://shell.example',
|
|
612
|
+
});
|
|
613
|
+
const result = buildSettingsForPropagation(
|
|
614
|
+
{ ...baseSettings, user: shellUser },
|
|
615
|
+
withEmail,
|
|
616
|
+
'en',
|
|
617
|
+
options,
|
|
618
|
+
);
|
|
619
|
+
expect(result.accessToken).toBe(shellToken);
|
|
620
|
+
expect(result.authBackendBaseUrl).toBe('https://id.example.com');
|
|
621
|
+
expect(result.email).toEqual({ url: 'https://email.shellui.com' });
|
|
622
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
623
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('keeps shell services when the item backend is the same server', () => {
|
|
627
|
+
const sameServer = {
|
|
628
|
+
...appConfig,
|
|
629
|
+
navigation: [
|
|
630
|
+
...(appConfig.navigation ?? []),
|
|
631
|
+
{
|
|
632
|
+
label: 'Same',
|
|
633
|
+
path: 'same',
|
|
634
|
+
url: 'https://same.example/',
|
|
635
|
+
safeForAuthToken: true,
|
|
636
|
+
backend: { url: 'https://id.example.com/', companyId: 1 },
|
|
637
|
+
},
|
|
638
|
+
],
|
|
639
|
+
} as ShellUIConfig;
|
|
640
|
+
const options = frameAuthPropagationOptions({
|
|
641
|
+
frameSrc: 'https://same.example/',
|
|
642
|
+
config: sameServer,
|
|
643
|
+
shellAccessToken: shellToken,
|
|
644
|
+
getAppSession: () => foreignSession,
|
|
645
|
+
shellOrigin: 'https://shell.example',
|
|
646
|
+
});
|
|
647
|
+
const result = buildSettingsForPropagation(
|
|
648
|
+
{ ...baseSettings, user: shellUser },
|
|
649
|
+
sameServer,
|
|
650
|
+
'en',
|
|
651
|
+
options,
|
|
652
|
+
);
|
|
653
|
+
expect(result.accessToken).toBe(shellToken);
|
|
654
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
655
|
+
expect(result.email).toEqual(shellServices.email);
|
|
656
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('sends no service URLs when the named backend cannot be used', () => {
|
|
660
|
+
const invalid = {
|
|
661
|
+
...appConfig,
|
|
662
|
+
navigation: [
|
|
663
|
+
...(appConfig.navigation ?? []),
|
|
664
|
+
{
|
|
665
|
+
label: 'Broken',
|
|
666
|
+
path: 'broken',
|
|
667
|
+
url: 'https://broken.example/',
|
|
668
|
+
safeForAuthToken: true,
|
|
669
|
+
backend: { url: 'not-a-url' },
|
|
670
|
+
email: { url: 'https://email.broken.example' },
|
|
671
|
+
},
|
|
672
|
+
],
|
|
673
|
+
} as ShellUIConfig;
|
|
674
|
+
const options = frameAuthPropagationOptions({
|
|
675
|
+
frameSrc: 'https://broken.example/',
|
|
676
|
+
config: invalid,
|
|
677
|
+
shellAccessToken: shellToken,
|
|
678
|
+
getAppSession: () => foreignSession,
|
|
679
|
+
shellOrigin: 'https://shell.example',
|
|
680
|
+
});
|
|
681
|
+
const result = buildSettingsForPropagation(
|
|
682
|
+
{ ...baseSettings, user: shellUser },
|
|
683
|
+
invalid,
|
|
684
|
+
'en',
|
|
685
|
+
options,
|
|
686
|
+
);
|
|
687
|
+
expect(result.accessToken).toBeNull();
|
|
688
|
+
expect(result.email).toEqual({ url: 'https://email.broken.example' });
|
|
689
|
+
expect(result.storage).toBeNull();
|
|
690
|
+
expect(result.hosting).toBeNull();
|
|
691
|
+
const json = JSON.stringify(result);
|
|
692
|
+
expect(json).not.toContain('https://files-api.example');
|
|
693
|
+
expect(json).not.toContain('https://hosting.example');
|
|
694
|
+
expect(json).not.toContain(shellToken);
|
|
695
|
+
});
|
|
322
696
|
});
|