@shellui/core 0.7.0-alpha.1 → 0.7.0-alpha.10

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.
Files changed (69) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +37 -4
  3. package/src/components/ContentView.tsx +19 -8
  4. package/src/components/ui/sidebar.tsx +11 -5
  5. package/src/features/admin/AdminView.tsx +9 -6
  6. package/src/features/auth/AuthProvider.tsx +25 -4
  7. package/src/features/auth/appBackend/appBackendSessions.spec.ts +134 -0
  8. package/src/features/auth/appBackend/appBackendSessions.ts +168 -17
  9. package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
  10. package/src/features/auth/appBackend/childFrames.ts +180 -0
  11. package/src/features/auth/appBackend/frameAuth.ts +47 -10
  12. package/src/features/auth/appBackend/silentSignIn.spec.ts +18 -0
  13. package/src/features/auth/appBackend/silentSignIn.ts +15 -1
  14. package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
  15. package/src/features/auth/appBackend/tokenExchange.ts +76 -0
  16. package/src/features/auth/components/OAuthCallbackView.tsx +7 -5
  17. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
  18. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
  19. package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
  20. package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
  21. package/src/features/auth/utils/index.ts +7 -1
  22. package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
  23. package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
  24. package/src/features/auth/utils/webPkce.spec.ts +23 -0
  25. package/src/features/auth/utils/webPkce.ts +23 -6
  26. package/src/features/chromeActions/computeActionInsets.ts +7 -4
  27. package/src/features/config/types.ts +30 -4
  28. package/src/features/layouts/appbar/AppBarLayout.tsx +63 -30
  29. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +12 -23
  30. package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
  31. package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
  32. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
  33. package/src/features/layouts/chrome/MacStrip.tsx +33 -0
  34. package/src/features/layouts/chrome/constants.ts +33 -8
  35. package/src/features/layouts/chrome/index.ts +8 -0
  36. package/src/features/layouts/chrome/stripDragMap.ts +35 -0
  37. package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
  38. package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
  39. package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
  40. package/src/features/layouts/floating/FloatingBottomDock.tsx +199 -20
  41. package/src/features/layouts/floating/FloatingLayout.tsx +13 -8
  42. package/src/features/layouts/floating/FloatingSidebar.tsx +144 -70
  43. package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
  44. package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
  45. package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
  46. package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
  47. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +38 -10
  48. package/src/features/layouts/sidebar/NavigationContent.tsx +14 -6
  49. package/src/features/layouts/sidebar/SidebarIcons.tsx +3 -9
  50. package/src/features/layouts/sidebar/SidebarInner.tsx +50 -39
  51. package/src/features/layouts/sidebar/SidebarLayout.tsx +8 -11
  52. package/src/features/layouts/utils.ts +4 -3
  53. package/src/features/layouts/windows/DesktopDots.tsx +76 -0
  54. package/src/features/layouts/windows/WindowsLayout.tsx +184 -125
  55. package/src/features/layouts/windows/deskDots.spec.ts +52 -0
  56. package/src/features/layouts/windows/deskDots.ts +314 -0
  57. package/src/features/settings/SettingsProvider.tsx +158 -2
  58. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +8 -7
  59. package/src/features/settings/utils/buildSettingsForPropagation.ts +4 -6
  60. package/src/features/theme/applyTheme.ts +8 -0
  61. package/src/features/theme/navContrast.spec.ts +49 -0
  62. package/src/features/theme/navContrast.ts +108 -0
  63. package/src/features/transfers/transferQueue.spec.ts +6 -2
  64. package/src/i18n/translations/en/common.json +25 -0
  65. package/src/i18n/translations/fr/common.json +25 -0
  66. package/src/index.css +935 -46
  67. package/src/index.ts +1 -0
  68. package/src/routes/hooks/useNavigationItems.ts +14 -3
  69. package/src/routes/hooks/withShellSearch.spec.ts +13 -0
@@ -10,9 +10,45 @@ import {
10
10
  type ResolvedAppBackend,
11
11
  } from './identity';
12
12
  import { runSilentPkceSignIn, type SilentSignInOutcome } from './silentSignIn';
13
+ import {
14
+ describeAppSessionFailure,
15
+ exchangeShellTokenForAppSession,
16
+ type TokenExchangeOutcome,
17
+ } from './tokenExchange';
18
+ import { refreshFrameAccessTokenIfNeeded } from '../utils/frameSessionRefresher';
19
+ import { decodeJwtPayload } from '../utils/decodeJwtPayload';
13
20
 
14
21
  const logger = getLogger('shellcore');
15
22
 
23
+ /** Why the last session attempt for an app identity server failed (no secrets). */
24
+ const lastFailure = new Map<string, string>();
25
+
26
+ export function getAppBackendSessionFailure(key: string): string | null {
27
+ return lastFailure.get(key) ?? null;
28
+ }
29
+
30
+ /** Let the next ensure call try silent sign-in again (user asked to retry). */
31
+ export function allowSilentRetry(key: string): void {
32
+ silentAttempted.delete(key);
33
+ failedShellToken.delete(key);
34
+ }
35
+
36
+ /** Identity servers that trust the shell's global identity get a session by token exchange. */
37
+ export function usesTokenExchange(identity: ResolvedAppBackend): boolean {
38
+ return identity.type === 'shellui' && identity.provider === 'upstream';
39
+ }
40
+
41
+ function fail(identity: ResolvedAppBackend, reason: string): null {
42
+ lastFailure.set(identity.key, reason);
43
+ logger.warn('App session: no session for an app identity server', {
44
+ url: identity.url,
45
+ companyId: identity.companyId ?? null,
46
+ reason,
47
+ hint: describeAppSessionFailure(reason),
48
+ });
49
+ return null;
50
+ }
51
+
16
52
  /** Tab-scoped refresh tokens for app identity servers. Not the shell refresh key. */
17
53
  export const APP_BACKEND_REFRESH_PREFIX = 'shellui.auth.app.refresh.';
18
54
 
@@ -30,6 +66,8 @@ const memory = new Map<string, StoredEntry>();
30
66
  const refreshTimers = new Map<string, ReturnType<typeof setTimeout>>();
31
67
  const inFlight = new Map<string, Promise<string | null>>();
32
68
  const silentAttempted = new Set<string>();
69
+ /** Shell token that last failed an exchange, so the same token is not retried in a loop. Memory only. */
70
+ const failedShellToken = new Map<string, string>();
33
71
  const listeners = new Set<() => void>();
34
72
 
35
73
  let backendFactory: (config: BackendConfig) => AppBackendClient = createAuthBackend;
@@ -39,6 +77,24 @@ let signInImpl: (input: {
39
77
  companyId?: string | number;
40
78
  }) => Promise<SilentSignInOutcome> = runSilentPkceSignIn;
41
79
 
80
+ let shellTokenImpl: () => Promise<string | null | undefined> = refreshFrameAccessTokenIfNeeded;
81
+ let exchangeImpl: typeof exchangeShellTokenForAppSession = exchangeShellTokenForAppSession;
82
+
83
+ export function setAppBackendTokenExchange(
84
+ shellToken: () => Promise<string | null | undefined>,
85
+ exchange: (
86
+ input: Parameters<typeof exchangeShellTokenForAppSession>[0],
87
+ ) => Promise<TokenExchangeOutcome> = exchangeShellTokenForAppSession,
88
+ ): void {
89
+ shellTokenImpl = shellToken;
90
+ exchangeImpl = exchange;
91
+ }
92
+
93
+ export function resetAppBackendTokenExchange(): void {
94
+ shellTokenImpl = refreshFrameAccessTokenIfNeeded;
95
+ exchangeImpl = exchangeShellTokenForAppSession;
96
+ }
97
+
42
98
  export function setAppBackendFactory(factory: (config: BackendConfig) => AppBackendClient): void {
43
99
  backendFactory = factory;
44
100
  }
@@ -55,6 +111,7 @@ export function setAppBackendSignIn(
55
111
 
56
112
  export function resetAppBackendSilentAttempts(): void {
57
113
  silentAttempted.clear();
114
+ failedShellToken.clear();
58
115
  }
59
116
 
60
117
  export function subscribeAppBackendSessions(listener: () => void): () => void {
@@ -170,6 +227,7 @@ async function doEnsure(
170
227
  identity: ResolvedAppBackend,
171
228
  allowSilent: boolean,
172
229
  ): Promise<string | null> {
230
+ if (usesTokenExchange(identity)) return ensureByTokenExchange(identity);
173
231
  const now = Math.floor(Date.now() / 1000);
174
232
  const current = memory.get(identity.key)?.session ?? null;
175
233
  if (current?.accessToken && !accessTokenRefreshDue(current.expiresAt, now)) {
@@ -194,8 +252,13 @@ async function doEnsure(
194
252
  }
195
253
  }
196
254
 
197
- if (!allowSilent || identity.type !== 'shellui' || !identity.provider) return null;
198
- if (silentAttempted.has(identity.key)) return null;
255
+ if (!allowSilent) return null;
256
+ if (identity.type !== 'shellui' || !identity.provider) {
257
+ return fail(identity, 'silent_sign_in_unsupported');
258
+ }
259
+ if (silentAttempted.has(identity.key)) {
260
+ return null;
261
+ }
199
262
  silentAttempted.add(identity.key);
200
263
 
201
264
  let outcome: SilentSignInOutcome;
@@ -206,18 +269,10 @@ async function doEnsure(
206
269
  companyId: identity.companyId,
207
270
  });
208
271
  } catch {
209
- logger.info('Silent sign-in did not complete for an app identity server', {
210
- url: identity.url,
211
- });
212
- return null;
213
- }
214
- if (!outcome.ok) {
215
- logger.info('Silent sign-in did not complete for an app identity server', {
216
- url: identity.url,
217
- reason: outcome.reason,
218
- });
219
- return null;
272
+ return fail(identity, 'silent_sign_in_error');
220
273
  }
274
+ if (!outcome.ok) return fail(identity, outcome.reason);
275
+ logger.info('App session: silent sign-in returned a code, exchanging it', { url: identity.url });
221
276
 
222
277
  try {
223
278
  const session = await backendFactory(toBackendConfig(identity)).exchangeOAuthSessionCode({
@@ -226,17 +281,112 @@ async function doEnsure(
226
281
  codeVerifier: outcome.codeVerifier,
227
282
  nowSeconds: Math.floor(Date.now() / 1000),
228
283
  });
229
- if (!session?.accessToken) return null;
284
+ if (!session?.accessToken) return fail(identity, 'token_exchange_empty');
230
285
  remember(identity, session);
286
+ lastFailure.delete(identity.key);
287
+ logger.info('App session: signed in to app identity server', { url: identity.url });
231
288
  return session.accessToken;
289
+ } catch (err) {
290
+ const message = err instanceof Error ? err.message.slice(0, 200) : '';
291
+ return fail(identity, `token_exchange_failed${message ? `: ${message}` : ''}`);
292
+ }
293
+ }
294
+
295
+ function shellSubject(token: string): string | null {
296
+ const sub = decodeJwtPayload(token)?.sub;
297
+ return typeof sub === 'string' || typeof sub === 'number' ? `${sub}` : null;
298
+ }
299
+
300
+ function subjectKey(key: string): string {
301
+ return `${storageKey(key)}#sub`;
302
+ }
303
+
304
+ function readSubject(key: string): string | null {
305
+ try {
306
+ return sessionStorage.getItem(subjectKey(key));
232
307
  } catch {
233
- logger.info('Silent sign-in did not complete for an app identity server', {
234
- url: identity.url,
235
- });
236
308
  return null;
237
309
  }
238
310
  }
239
311
 
312
+ function writeSubject(key: string, sub: string | null): void {
313
+ try {
314
+ if (sub) sessionStorage.setItem(subjectKey(key), sub);
315
+ else sessionStorage.removeItem(subjectKey(key));
316
+ } catch {
317
+ // Ignore.
318
+ }
319
+ }
320
+
321
+ /**
322
+ * Regional session for an upstream identity server:
323
+ * keep it while valid, renew it with its own refresh token, and exchange the shell token
324
+ * only when there is none, the refresh fails, or the shell user changed.
325
+ */
326
+ async function ensureByTokenExchange(identity: ResolvedAppBackend): Promise<string | null> {
327
+ let shellToken: string | null | undefined;
328
+ try {
329
+ shellToken = await shellTokenImpl();
330
+ } catch {
331
+ shellToken = null;
332
+ }
333
+ if (!shellToken) {
334
+ forget(identity.key);
335
+ writeSubject(identity.key, null);
336
+ return fail(identity, 'no_shell_session');
337
+ }
338
+ const subject = shellSubject(shellToken);
339
+ if (readSubject(identity.key) !== subject) {
340
+ // Another shell user, or a session from before subjects were kept: never reuse it.
341
+ forget(identity.key);
342
+ writeSubject(identity.key, null);
343
+ }
344
+
345
+ const now = Math.floor(Date.now() / 1000);
346
+ const current = memory.get(identity.key)?.session ?? null;
347
+ if (current?.accessToken && !accessTokenRefreshDue(current.expiresAt, now)) {
348
+ return current.accessToken;
349
+ }
350
+ const refreshToken = current?.refreshToken || readRefresh(identity.key);
351
+ if (refreshToken) {
352
+ try {
353
+ const next = await backendFactory(toBackendConfig(identity)).refreshAuthSession(
354
+ current ? { ...current, refreshToken } : sessionForRefresh(refreshToken),
355
+ now,
356
+ );
357
+ if (next?.accessToken) {
358
+ remember(identity, next);
359
+ return next.accessToken;
360
+ }
361
+ } catch {
362
+ // Fall through to a new exchange.
363
+ }
364
+ forget(identity.key);
365
+ }
366
+
367
+ if (failedShellToken.get(identity.key) === shellToken) return null;
368
+ const outcome = await exchangeImpl({
369
+ backendUrl: identity.url,
370
+ companyId: identity.companyId,
371
+ shellAccessToken: shellToken,
372
+ nowSeconds: now,
373
+ });
374
+ if (!outcome.ok) {
375
+ failedShellToken.set(identity.key, shellToken);
376
+ forget(identity.key);
377
+ return fail(identity, outcome.reason);
378
+ }
379
+ failedShellToken.delete(identity.key);
380
+ writeSubject(identity.key, subject);
381
+ remember(identity, outcome.session);
382
+ lastFailure.delete(identity.key);
383
+ logger.info('App session: token exchange succeeded', {
384
+ url: identity.url,
385
+ companyId: identity.companyId ?? null,
386
+ });
387
+ return outcome.session.accessToken;
388
+ }
389
+
240
390
  export function ensureAppBackendSession(
241
391
  identity: ResolvedAppBackend,
242
392
  options?: { allowSilent?: boolean },
@@ -278,6 +428,7 @@ export async function endAppBackendSessions(): Promise<void> {
278
428
  refreshTimers.clear();
279
429
  inFlight.clear();
280
430
  silentAttempted.clear();
431
+ failedShellToken.clear();
281
432
  clearAllRefresh();
282
433
  notify();
283
434
  await Promise.all(
@@ -0,0 +1,328 @@
1
+ import { afterEach, describe, expect, it } from 'vitest';
2
+ import type { ShellUIConfig } from '../../config/types';
3
+ import {
4
+ addChildFrame,
5
+ clearChildFrames,
6
+ findChildFrame,
7
+ listChildFrames,
8
+ removeChildFrame,
9
+ validateChildFrameRegistration,
10
+ } from './childFrames';
11
+ import { childFrameAuthPropagationOptions } from './frameAuth';
12
+ import type { AuthSession } from '../types';
13
+
14
+ const config: ShellUIConfig = {
15
+ backend: { type: 'shellui', url: 'https://id.example.com', companyId: 1 },
16
+ navigation: [
17
+ {
18
+ label: 'Dashboard',
19
+ path: '',
20
+ url: 'https://dashboard.example.com/',
21
+ safeForAuthToken: true,
22
+ childFrames: {
23
+ origins: ['https://admin.example.com', 'https://*.example.com', '*'],
24
+ backendOrigins: ['https://id.eu.example.com'],
25
+ },
26
+ },
27
+ { label: 'Other', path: 'other', url: 'https://other.example.com/' },
28
+ ],
29
+ };
30
+
31
+ const host = 'https://dashboard.example.com/';
32
+ const good = {
33
+ frameId: 'child-1',
34
+ url: 'https://admin.example.com/companies?x=1',
35
+ backend: { url: 'https://id.eu.example.com', companyId: 'abc' },
36
+ };
37
+
38
+ afterEach(() => clearChildFrames());
39
+
40
+ describe('validateChildFrameRegistration', () => {
41
+ it('accepts an allowed child and backend', () => {
42
+ const result = validateChildFrameRegistration({
43
+ from: ['h1'],
44
+ hostSrc: host,
45
+ payload: good,
46
+ config,
47
+ });
48
+ expect(result.ok).toBe(true);
49
+ if (!result.ok) return;
50
+ expect(result.entry.hostUuid).toBe('h1');
51
+ expect(result.entry.identity?.url).toBe('https://id.eu.example.com');
52
+ expect(result.entry.identity?.companyId).toBe('abc');
53
+ });
54
+
55
+ it('rejects a message relayed from deeper than one hop', () => {
56
+ const result = validateChildFrameRegistration({
57
+ from: ['h1', 'child'],
58
+ hostSrc: host,
59
+ payload: good,
60
+ config,
61
+ });
62
+ expect(result).toEqual({ ok: false, reason: 'not sent by a direct app frame' });
63
+ });
64
+
65
+ it('rejects hosts without childFrames', () => {
66
+ const result = validateChildFrameRegistration({
67
+ from: ['h1'],
68
+ hostSrc: 'https://other.example.com/',
69
+ payload: good,
70
+ config,
71
+ });
72
+ expect(result.ok).toBe(false);
73
+ });
74
+
75
+ it('only matches exact origins, never wildcards', () => {
76
+ for (const url of [
77
+ 'https://evil.example.com/',
78
+ 'https://admin.example.com.evil.io/',
79
+ 'javascript:alert(1)',
80
+ ]) {
81
+ const result = validateChildFrameRegistration({
82
+ from: ['h1'],
83
+ hostSrc: host,
84
+ payload: { ...good, url },
85
+ config,
86
+ });
87
+ expect(result.ok).toBe(false);
88
+ }
89
+ });
90
+
91
+ it('rejects a backend that is not allowlisted', () => {
92
+ const result = validateChildFrameRegistration({
93
+ from: ['h1'],
94
+ hostSrc: host,
95
+ payload: { ...good, backend: { url: 'https://id.example.com' } },
96
+ config,
97
+ });
98
+ expect(result).toEqual({ ok: false, reason: 'child identity server is not allowed' });
99
+ });
100
+
101
+ it('accepts a child without backend and gives it no identity', () => {
102
+ const result = validateChildFrameRegistration({
103
+ from: ['h1'],
104
+ hostSrc: host,
105
+ payload: { ...good, backend: null },
106
+ config,
107
+ });
108
+ expect(result.ok && result.entry.identity).toBeNull();
109
+ });
110
+ });
111
+
112
+ describe('child frame registry', () => {
113
+ it('finds by host and child path, and drops entries for gone hosts', () => {
114
+ const result = validateChildFrameRegistration({
115
+ from: ['h1'],
116
+ hostSrc: host,
117
+ payload: good,
118
+ config,
119
+ });
120
+ if (!result.ok) throw new Error(result.reason);
121
+ addChildFrame(result.entry);
122
+ expect(findChildFrame(['h1', 'child-1'])).toBe(result.entry);
123
+ expect(findChildFrame(['h1'])).toBeNull();
124
+ expect(findChildFrame(['h2', 'child-1'])).toBeNull();
125
+ expect(listChildFrames(() => false)).toEqual([]);
126
+ expect(findChildFrame(['h1', 'child-1'])).toBeNull();
127
+ addChildFrame(result.entry);
128
+ removeChildFrame('h1', 'child-1');
129
+ expect(findChildFrame(['h1', 'child-1'])).toBeNull();
130
+ });
131
+ });
132
+
133
+ describe('childFrameAuthPropagationOptions', () => {
134
+ const session = {
135
+ accessToken: 'regional-token',
136
+ refreshToken: 'r',
137
+ expiresAt: 9999999999,
138
+ userId: 'u1',
139
+ userEmail: 'a@b.c',
140
+ userName: 'A',
141
+ } as AuthSession;
142
+
143
+ it('sends the regional session and backend, and no shared services', () => {
144
+ const result = validateChildFrameRegistration({
145
+ from: ['h1'],
146
+ hostSrc: host,
147
+ payload: good,
148
+ config,
149
+ });
150
+ if (!result.ok) throw new Error(result.reason);
151
+ const options = childFrameAuthPropagationOptions({
152
+ identity: result.entry.identity,
153
+ getAppSession: (key) => (key === result.entry.identity?.key ? session : null),
154
+ });
155
+ expect(options.accessToken).toBe('regional-token');
156
+ expect(options.authBackendBaseUrl).toBe('https://id.eu.example.com');
157
+ expect(options.settingsUser?.id).toBe('u1');
158
+ expect(options.storage).toBeNull();
159
+ expect(options.email).toBeNull();
160
+ expect(options.hosting).toBeNull();
161
+ });
162
+
163
+ it('sends no token when the child has no identity', () => {
164
+ const options = childFrameAuthPropagationOptions({
165
+ identity: null,
166
+ getAppSession: () => session,
167
+ });
168
+ expect(options.accessToken).toBeNull();
169
+ expect(options.includeAuthAccessToken).toBe(false);
170
+ expect(options.settingsUser).toBeNull();
171
+ });
172
+ });
173
+
174
+ describe('child frame service URLs', () => {
175
+ const withServices: ShellUIConfig = {
176
+ ...config,
177
+ navigation: [
178
+ {
179
+ label: 'Dashboard',
180
+ path: '',
181
+ url: 'https://dashboard.example.com/',
182
+ childFrames: {
183
+ origins: ['https://admin.example.com'],
184
+ backendOrigins: ['https://id.eu.example.com'],
185
+ serviceOrigins: [
186
+ 'https://email.eu.example.com',
187
+ 'https://storage.eu.example.com',
188
+ 'https://files.example.com',
189
+ 'https://*.example.com',
190
+ '*',
191
+ ],
192
+ },
193
+ },
194
+ ],
195
+ };
196
+ const register = (services: unknown, cfg: ShellUIConfig = withServices) =>
197
+ validateChildFrameRegistration({
198
+ from: ['h1'],
199
+ hostSrc: host,
200
+ payload: { ...good, services },
201
+ config: cfg,
202
+ });
203
+
204
+ it('forwards allowed service URLs to the child settings', () => {
205
+ const result = register({
206
+ email: 'https://email.eu.example.com/',
207
+ storage: 'https://storage.eu.example.com',
208
+ });
209
+ expect(result.ok).toBe(true);
210
+ if (!result.ok) return;
211
+ expect(result.entry.services).toEqual({
212
+ email: 'https://email.eu.example.com',
213
+ storage: 'https://storage.eu.example.com',
214
+ files: null,
215
+ hosting: null,
216
+ });
217
+ expect(result.entry.rejectedServices).toEqual([]);
218
+ const options = childFrameAuthPropagationOptions({
219
+ identity: result.entry.identity,
220
+ getAppSession: () => null,
221
+ services: result.entry.services,
222
+ });
223
+ expect(options.email).toEqual({ url: 'https://email.eu.example.com' });
224
+ expect(options.storage).toEqual({ url: 'https://storage.eu.example.com' });
225
+ expect(options.hosting).toBeNull();
226
+ });
227
+
228
+ it('drops a service URL whose origin is not allowed', () => {
229
+ const result = register({
230
+ storage: 'https://evil.example.org',
231
+ hosting: 'javascript:alert(1)',
232
+ });
233
+ expect(result.ok).toBe(true);
234
+ if (!result.ok) return;
235
+ expect(result.entry.services).toEqual({
236
+ email: null,
237
+ storage: null,
238
+ files: null,
239
+ hosting: null,
240
+ });
241
+ expect(result.entry.rejectedServices).toEqual(['storage', 'hosting']);
242
+ });
243
+
244
+ it('forwards an allowed files URL as storage.filesUrl', () => {
245
+ const result = register({
246
+ storage: 'https://storage.eu.example.com',
247
+ files: 'https://files.example.com/',
248
+ });
249
+ expect(result.ok).toBe(true);
250
+ if (!result.ok) return;
251
+ expect(result.entry.services.files).toBe('https://files.example.com');
252
+ const options = childFrameAuthPropagationOptions({
253
+ identity: result.entry.identity,
254
+ getAppSession: () => null,
255
+ services: result.entry.services,
256
+ });
257
+ expect(options.storage).toEqual({
258
+ url: 'https://storage.eu.example.com',
259
+ filesUrl: 'https://files.example.com',
260
+ });
261
+ });
262
+
263
+ it('drops a files URL whose origin is not allowed, or without storage', () => {
264
+ const rejected = register({
265
+ storage: 'https://storage.eu.example.com',
266
+ files: 'https://files.evil.example.org',
267
+ });
268
+ expect(rejected.ok).toBe(true);
269
+ if (!rejected.ok) return;
270
+ expect(rejected.entry.rejectedServices).toEqual(['files']);
271
+ expect(
272
+ childFrameAuthPropagationOptions({
273
+ identity: null,
274
+ getAppSession: () => null,
275
+ services: rejected.entry.services,
276
+ }).storage,
277
+ ).toEqual({ url: 'https://storage.eu.example.com' });
278
+ const alone = register({ files: 'https://files.example.com' });
279
+ if (!alone.ok) throw new Error('expected ok');
280
+ expect(
281
+ childFrameAuthPropagationOptions({
282
+ identity: null,
283
+ getAppSession: () => null,
284
+ services: alone.entry.services,
285
+ }).storage,
286
+ ).toBeNull();
287
+ });
288
+
289
+ it('never matches a wildcard entry', () => {
290
+ const result = register({ hosting: 'https://hosting.example.com' });
291
+ expect(result.ok).toBe(true);
292
+ if (!result.ok) return;
293
+ expect(result.entry.services.hosting).toBeNull();
294
+ expect(result.entry.rejectedServices).toEqual(['hosting']);
295
+ });
296
+
297
+ it('sends null for missing services, without falling back to the shell', () => {
298
+ const shellWithServices: ShellUIConfig = {
299
+ ...withServices,
300
+ email: { url: 'https://email.example.com' },
301
+ storage: { url: 'https://storage.example.com' },
302
+ hosting: { url: 'https://hosting.example.com' },
303
+ };
304
+ const result = register(undefined, shellWithServices);
305
+ expect(result.ok).toBe(true);
306
+ if (!result.ok) return;
307
+ expect(result.entry.services).toEqual({
308
+ email: null,
309
+ storage: null,
310
+ files: null,
311
+ hosting: null,
312
+ });
313
+ const options = childFrameAuthPropagationOptions({
314
+ identity: result.entry.identity,
315
+ getAppSession: () => null,
316
+ services: result.entry.services,
317
+ });
318
+ expect(options).toMatchObject({ email: null, storage: null, hosting: null });
319
+ });
320
+
321
+ it('drops every service URL when serviceOrigins is not configured', () => {
322
+ const result = register({ email: 'https://email.eu.example.com' }, config);
323
+ expect(result.ok).toBe(true);
324
+ if (!result.ok) return;
325
+ expect(result.entry.services.email).toBeNull();
326
+ expect(result.entry.rejectedServices).toEqual(['email']);
327
+ });
328
+ });