@egen-civitas/esm-nextjs-utils 0.0.0-stage → 0.3.0
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/CHANGELOG.md +26 -0
- package/README.md +83 -2
- package/dist/client.d.ts +38 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +189 -0
- package/dist/host.d.ts +37 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +253 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/navigation-sync.test.js +931 -0
- package/dist/navigation.d.ts +51 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +153 -0
- package/dist/navigation.test.js +101 -0
- package/dist/nextjs-utils.test.js +956 -0
- package/dist/protocol.d.ts +79 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +83 -0
- package/package.json +84 -3
- package/src/client.ts +108 -0
- package/src/host.ts +215 -0
- package/src/index.ts +3 -0
- package/src/navigation.ts +163 -0
- package/src/protocol.ts +82 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
|
|
3
|
+
*
|
|
4
|
+
* L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
|
|
5
|
+
* Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
|
|
6
|
+
*/
|
|
7
|
+
import type { NavigationMode } from './protocol.js';
|
|
8
|
+
/** Paramètres jamais recopiés dans l'URL du Core (jetons, codes OAuth…). Comparaison insensible à la casse. */
|
|
9
|
+
export declare const DEFAULT_SENSITIVE_PARAMS: string[];
|
|
10
|
+
export declare const MAX_APP_PATH_LENGTH = 2000;
|
|
11
|
+
/** Mappage optionnel entre l'espace de chemins du Core et celui de l'application (flexibilité par app). */
|
|
12
|
+
export interface PathMap {
|
|
13
|
+
/** Chemin affiché dans le Core (`/dashboard/x`) → chemin interne de l'application. */
|
|
14
|
+
toApp?: (corePath: string) => string;
|
|
15
|
+
/** Chemin interne de l'application → chemin affiché dans le Core. */
|
|
16
|
+
toCore?: (appPath: string) => string;
|
|
17
|
+
}
|
|
18
|
+
export interface NavigationOptions {
|
|
19
|
+
/** Route de la page dans `routes.json` (`penpot`) : le Core est sur `<base>/<route>[/sous-chemin]`. */
|
|
20
|
+
route: string;
|
|
21
|
+
/** `history` (défaut), `hash`, ou `none` pour désactiver (comportement opaque d'origine). */
|
|
22
|
+
mode?: NavigationMode;
|
|
23
|
+
/** Paramètres supplémentaires à ne jamais recopier (s'ajoutent à `DEFAULT_SENSITIVE_PARAMS`). */
|
|
24
|
+
sensitiveParams?: string[];
|
|
25
|
+
pathMap?: PathMap;
|
|
26
|
+
/** Reçoit le titre annoncé par l'application (fil d'Ariane, titre de page). */
|
|
27
|
+
onTitle?: (title: string) => void;
|
|
28
|
+
}
|
|
29
|
+
/** Chemin interne sûr (`/x?y#z`), ou `null` : jamais d'URL absolue, de `//hôte`, d'espaces ni de caractères de contrôle. */
|
|
30
|
+
export declare function normalizeAppPath(input: unknown): string | null;
|
|
31
|
+
/** Retire les paramètres sensibles de la requête (et de la requête portée par le fragment `#/x?token=…`). */
|
|
32
|
+
export declare function stripSensitive(path: string, extra?: string[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Sous-chemin de l'application déduit de l'URL du Core, ou `null` si le Core n'est pas sur cette page.
|
|
35
|
+
* `pathname=/egen/spa/penpot/dashboard/x`, `spaBase=/egen/spa/`, `route=penpot` → `/dashboard/x` (`/` à la racine).
|
|
36
|
+
*/
|
|
37
|
+
export declare function coreSubpath(pathname: string, spaBase: string, route: string): string | null;
|
|
38
|
+
/** URL du Core (chemin seul) pour un chemin d'application : `<base>/<route><chemin>`, sans `/` final superflu. */
|
|
39
|
+
export declare function buildCoreUrl(spaBase: string, route: string, appPath: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* URL de chargement de l'iframe : l'adresse de base de l'application + le chemin interne.
|
|
42
|
+
* `history` : `<origine><chemin-de-base>/<chemin>?q#h` ; `hash` : `<base>#<chemin>`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildEmbedSrc(baseUrl: string, appPath: string, mode: NavigationMode): string;
|
|
45
|
+
/** Chemin d'application → chemin affiché par le Core (sans paramètres sensibles ; `pathMap.toCore` en dernier). */
|
|
46
|
+
export declare function toCorePath(appPath: unknown, opts: Pick<NavigationOptions, 'pathMap' | 'sensitiveParams'>): string | null;
|
|
47
|
+
/** Chemin lu dans l'URL du Core → chemin d'application (`pathMap.toApp` ; sans paramètres sensibles). */
|
|
48
|
+
export declare function toAppPath(corePath: string, opts: Pick<NavigationOptions, 'pathMap' | 'sensitiveParams'>): string | null;
|
|
49
|
+
/** Garde-fou de débit : au plus `max` messages par fenêtre `windowMs` (History API limitée par les navigateurs). */
|
|
50
|
+
export declare function createRateLimiter(max?: number, windowMs?: number, now?: () => number): () => boolean;
|
|
51
|
+
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,UAgBpC,CAAC;AAEF,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAIxC,2GAA2G;AAC3G,MAAM,WAAW,OAAO;IACtB,sFAAsF;IACtF,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IACrC,qEAAqE;IACrE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,uGAAuG;IACvG,KAAK,EAAE,MAAM,CAAC;IACd,6FAA6F;IAC7F,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,iGAAiG;IACjG,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAMD,4HAA4H;AAC5H,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG9D;AAED,6GAA6G;AAC7G,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,EAAO,GAAG,MAAM,CAqBzE;AAUD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM3F;AAED,kHAAkH;AAClH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,MAAM,CAe5F;AAED,mHAAmH;AACnH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,iBAAiB,CAAC,GAAG,MAAM,GAAG,IAAI,CAMxH;AAED,yGAAyG;AACzG,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,iBAAiB,CAAC,GAAG,MAAM,GAAG,IAAI,CAMvH;AAED,oHAAoH;AACpH,wBAAgB,iBAAiB,CAAC,GAAG,SAAK,EAAE,QAAQ,SAAO,EAAE,GAAG,GAAE,MAAM,MAAyB,SAEpF,OAAO,CAOnB"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
|
|
3
|
+
*
|
|
4
|
+
* L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
|
|
5
|
+
* Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
|
|
6
|
+
*/ function _array_like_to_array(arr, len) {
|
|
7
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
8
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
9
|
+
return arr2;
|
|
10
|
+
}
|
|
11
|
+
function _array_without_holes(arr) {
|
|
12
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
13
|
+
}
|
|
14
|
+
function _iterable_to_array(iter) {
|
|
15
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
16
|
+
}
|
|
17
|
+
function _non_iterable_spread() {
|
|
18
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
19
|
+
}
|
|
20
|
+
function _to_consumable_array(arr) {
|
|
21
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
22
|
+
}
|
|
23
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
24
|
+
if (!o) return;
|
|
25
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
26
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
27
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
28
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
29
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
30
|
+
}
|
|
31
|
+
/** Paramètres jamais recopiés dans l'URL du Core (jetons, codes OAuth…). Comparaison insensible à la casse. */ export var DEFAULT_SENSITIVE_PARAMS = [
|
|
32
|
+
'token',
|
|
33
|
+
'access_token',
|
|
34
|
+
'id_token',
|
|
35
|
+
'refresh_token',
|
|
36
|
+
'code',
|
|
37
|
+
'state',
|
|
38
|
+
'password',
|
|
39
|
+
'secret',
|
|
40
|
+
'otp',
|
|
41
|
+
'session',
|
|
42
|
+
'sessionid',
|
|
43
|
+
'auth',
|
|
44
|
+
'key',
|
|
45
|
+
'api_key',
|
|
46
|
+
'apikey'
|
|
47
|
+
];
|
|
48
|
+
export var MAX_APP_PATH_LENGTH = 2000;
|
|
49
|
+
// eslint-disable-next-line no-control-regex
|
|
50
|
+
var SAFE_APP_PATH = /^\/(?!\/)[^\s\\\u0000-\u001f]*$/;
|
|
51
|
+
function trimSlashes(s) {
|
|
52
|
+
return s.replace(/^\/+|\/+$/g, '');
|
|
53
|
+
}
|
|
54
|
+
/** Chemin interne sûr (`/x?y#z`), ou `null` : jamais d'URL absolue, de `//hôte`, d'espaces ni de caractères de contrôle. */ export function normalizeAppPath(input) {
|
|
55
|
+
if (typeof input !== 'string' || input.length > MAX_APP_PATH_LENGTH) return null;
|
|
56
|
+
return SAFE_APP_PATH.test(input) ? input : null;
|
|
57
|
+
}
|
|
58
|
+
/** Retire les paramètres sensibles de la requête (et de la requête portée par le fragment `#/x?token=…`). */ export function stripSensitive(path) {
|
|
59
|
+
var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
60
|
+
var blocked = new Set(_to_consumable_array(DEFAULT_SENSITIVE_PARAMS).concat(_to_consumable_array(extra)).map(function(p) {
|
|
61
|
+
return p.toLowerCase();
|
|
62
|
+
}));
|
|
63
|
+
var clean = function clean(query) {
|
|
64
|
+
var kept = query.split('&').filter(function(pair) {
|
|
65
|
+
return pair && !blocked.has(decodeSafe(pair.split('=')[0]).toLowerCase());
|
|
66
|
+
});
|
|
67
|
+
return kept.join('&');
|
|
68
|
+
};
|
|
69
|
+
var hashAt = path.indexOf('#');
|
|
70
|
+
var beforeHash = hashAt === -1 ? path : path.slice(0, hashAt);
|
|
71
|
+
var hash = hashAt === -1 ? '' : path.slice(hashAt);
|
|
72
|
+
var cleanHash = function() {
|
|
73
|
+
var q = hash.indexOf('?');
|
|
74
|
+
if (q === -1) return hash;
|
|
75
|
+
var kept = clean(hash.slice(q + 1));
|
|
76
|
+
return hash.slice(0, q) + (kept ? "?".concat(kept) : '');
|
|
77
|
+
}();
|
|
78
|
+
var qAt = beforeHash.indexOf('?');
|
|
79
|
+
if (qAt === -1) return beforeHash + cleanHash;
|
|
80
|
+
var kept = clean(beforeHash.slice(qAt + 1));
|
|
81
|
+
return beforeHash.slice(0, qAt) + (kept ? "?".concat(kept) : '') + cleanHash;
|
|
82
|
+
}
|
|
83
|
+
function decodeSafe(s) {
|
|
84
|
+
try {
|
|
85
|
+
return decodeURIComponent(s);
|
|
86
|
+
} catch (unused) {
|
|
87
|
+
return s;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Sous-chemin de l'application déduit de l'URL du Core, ou `null` si le Core n'est pas sur cette page.
|
|
92
|
+
* `pathname=/egen/spa/penpot/dashboard/x`, `spaBase=/egen/spa/`, `route=penpot` → `/dashboard/x` (`/` à la racine).
|
|
93
|
+
*/ export function coreSubpath(pathname, spaBase, route) {
|
|
94
|
+
var base = '/' + trimSlashes(spaBase);
|
|
95
|
+
var prefix = (base === '/' ? '' : base) + '/' + trimSlashes(route);
|
|
96
|
+
if (pathname !== prefix && !pathname.startsWith(prefix + '/')) return null;
|
|
97
|
+
var rest = pathname.slice(prefix.length);
|
|
98
|
+
return rest === '' ? '/' : rest;
|
|
99
|
+
}
|
|
100
|
+
/** URL du Core (chemin seul) pour un chemin d'application : `<base>/<route><chemin>`, sans `/` final superflu. */ export function buildCoreUrl(spaBase, route, appPath) {
|
|
101
|
+
var base = '/' + trimSlashes(spaBase);
|
|
102
|
+
var prefix = (base === '/' ? '' : base) + '/' + trimSlashes(route);
|
|
103
|
+
if (appPath === '/' || appPath === '') return prefix;
|
|
104
|
+
return prefix + (appPath.startsWith('/') ? appPath : '/' + appPath);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* URL de chargement de l'iframe : l'adresse de base de l'application + le chemin interne.
|
|
108
|
+
* `history` : `<origine><chemin-de-base>/<chemin>?q#h` ; `hash` : `<base>#<chemin>`.
|
|
109
|
+
*/ export function buildEmbedSrc(baseUrl, appPath, mode) {
|
|
110
|
+
if (mode === 'none' || appPath === '/' || appPath === '') return baseUrl;
|
|
111
|
+
var base = new URL(baseUrl);
|
|
112
|
+
if (mode === 'hash') {
|
|
113
|
+
base.hash = appPath;
|
|
114
|
+
return base.href;
|
|
115
|
+
}
|
|
116
|
+
var hashAt = appPath.indexOf('#');
|
|
117
|
+
var noHash = hashAt === -1 ? appPath : appPath.slice(0, hashAt);
|
|
118
|
+
var hash = hashAt === -1 ? '' : appPath.slice(hashAt);
|
|
119
|
+
var qAt = noHash.indexOf('?');
|
|
120
|
+
var pathname = qAt === -1 ? noHash : noHash.slice(0, qAt);
|
|
121
|
+
var search = qAt === -1 ? '' : noHash.slice(qAt);
|
|
122
|
+
var basePath = base.pathname.replace(/\/+$/, '');
|
|
123
|
+
return "".concat(base.origin).concat(basePath).concat(pathname).concat(search).concat(hash);
|
|
124
|
+
}
|
|
125
|
+
/** Chemin d'application → chemin affiché par le Core (sans paramètres sensibles ; `pathMap.toCore` en dernier). */ export function toCorePath(appPath, opts) {
|
|
126
|
+
var _opts_pathMap;
|
|
127
|
+
var safe = normalizeAppPath(appPath);
|
|
128
|
+
if (!safe) return null;
|
|
129
|
+
var clean = stripSensitive(safe, opts.sensitiveParams);
|
|
130
|
+
var mapped = ((_opts_pathMap = opts.pathMap) === null || _opts_pathMap === void 0 ? void 0 : _opts_pathMap.toCore) ? opts.pathMap.toCore(clean) : clean;
|
|
131
|
+
return normalizeAppPath(mapped);
|
|
132
|
+
}
|
|
133
|
+
/** Chemin lu dans l'URL du Core → chemin d'application (`pathMap.toApp` ; sans paramètres sensibles). */ export function toAppPath(corePath, opts) {
|
|
134
|
+
var _opts_pathMap;
|
|
135
|
+
var safe = normalizeAppPath(corePath);
|
|
136
|
+
if (!safe) return null;
|
|
137
|
+
var clean = stripSensitive(safe, opts.sensitiveParams);
|
|
138
|
+
var mapped = ((_opts_pathMap = opts.pathMap) === null || _opts_pathMap === void 0 ? void 0 : _opts_pathMap.toApp) ? opts.pathMap.toApp(clean) : clean;
|
|
139
|
+
return normalizeAppPath(mapped);
|
|
140
|
+
}
|
|
141
|
+
/** Garde-fou de débit : au plus `max` messages par fenêtre `windowMs` (History API limitée par les navigateurs). */ export function createRateLimiter() {
|
|
142
|
+
var max = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 40, windowMs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1000, now = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : function() {
|
|
143
|
+
return Date.now();
|
|
144
|
+
};
|
|
145
|
+
var stamps = [];
|
|
146
|
+
return function() {
|
|
147
|
+
var t = now();
|
|
148
|
+
while(stamps.length && t - stamps[0] > windowMs)stamps.shift();
|
|
149
|
+
if (stamps.length >= max) return false;
|
|
150
|
+
stamps.push(t);
|
|
151
|
+
return true;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, normalizeAppPath, stripSensitive, toAppPath, toCorePath } from './navigation.js';
|
|
3
|
+
describe('navigation partagée : fonctions pures', function() {
|
|
4
|
+
it('normalizeAppPath : chemins internes sûrs uniquement', function() {
|
|
5
|
+
for(var _i = 0, _iter = [
|
|
6
|
+
'/',
|
|
7
|
+
'/a/b?x=1#h',
|
|
8
|
+
'/dashboard/recent?team-id=1'
|
|
9
|
+
]; _i < _iter.length; _i++){
|
|
10
|
+
var ok = _iter[_i];
|
|
11
|
+
expect(normalizeAppPath(ok)).toBe(ok);
|
|
12
|
+
}
|
|
13
|
+
for(var _i1 = 0, _iter1 = [
|
|
14
|
+
'//evil.com',
|
|
15
|
+
'https://x.org',
|
|
16
|
+
'javascript:1',
|
|
17
|
+
'a',
|
|
18
|
+
'/a b',
|
|
19
|
+
'/a\\b',
|
|
20
|
+
'/a\u0000',
|
|
21
|
+
7,
|
|
22
|
+
undefined,
|
|
23
|
+
'/' + 'x'.repeat(2001)
|
|
24
|
+
]; _i1 < _iter1.length; _i1++){
|
|
25
|
+
var ko = _iter1[_i1];
|
|
26
|
+
expect(normalizeAppPath(ko)).toBeNull();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
it('stripSensitive : requête et fragment, insensible à la casse, ajouts configurables', function() {
|
|
30
|
+
expect(stripSensitive('/a?x=1&token=S&Code=C&y=2')).toBe('/a?x=1&y=2');
|
|
31
|
+
expect(stripSensitive('/a?token=S')).toBe('/a');
|
|
32
|
+
expect(stripSensitive('/#/invite?TOKEN=S&team=1')).toBe('/#/invite?team=1');
|
|
33
|
+
expect(stripSensitive('/a?invite=Z&x=1', [
|
|
34
|
+
'invite'
|
|
35
|
+
])).toBe('/a?x=1');
|
|
36
|
+
expect(stripSensitive('/a?%74oken=S&x=1')).toBe('/a?x=1');
|
|
37
|
+
expect(stripSensitive('/a?tokenize=1')).toBe('/a?tokenize=1');
|
|
38
|
+
});
|
|
39
|
+
it('coreSubpath / buildCoreUrl : aller-retour sur la route de la page', function() {
|
|
40
|
+
expect(coreSubpath('/egen/spa/penpot', '/egen/spa/', 'penpot')).toBe('/');
|
|
41
|
+
expect(coreSubpath('/egen/spa/penpot/', '/egen/spa/', 'penpot')).toBe('/');
|
|
42
|
+
expect(coreSubpath('/egen/spa/penpot/dash/x', '/egen/spa/', 'penpot')).toBe('/dash/x');
|
|
43
|
+
expect(coreSubpath('/egen/spa/penpotx', '/egen/spa/', 'penpot')).toBeNull();
|
|
44
|
+
expect(coreSubpath('/egen/spa/home', '/egen/spa/', 'penpot')).toBeNull();
|
|
45
|
+
expect(coreSubpath('/penpot/a', '/', 'penpot')).toBe('/a');
|
|
46
|
+
expect(buildCoreUrl('/egen/spa/', 'penpot', '/dash/x?q=1')).toBe('/egen/spa/penpot/dash/x?q=1');
|
|
47
|
+
expect(buildCoreUrl('/egen/spa/', 'penpot', '/')).toBe('/egen/spa/penpot');
|
|
48
|
+
expect(buildCoreUrl('/', 'penpot', '/a')).toBe('/penpot/a');
|
|
49
|
+
});
|
|
50
|
+
it('buildEmbedSrc : history, hash, none, racine, préfixe de base', function() {
|
|
51
|
+
expect(buildEmbedSrc('https://a.org', '/', 'history')).toBe('https://a.org');
|
|
52
|
+
expect(buildEmbedSrc('https://a.org/', '/x/y?q=1#h', 'history')).toBe('https://a.org/x/y?q=1#h');
|
|
53
|
+
expect(buildEmbedSrc('https://a.org/studio/', '/x?q=1', 'history')).toBe('https://a.org/studio/x?q=1');
|
|
54
|
+
expect(buildEmbedSrc('https://a.org/', '/dash/recent?t=1', 'hash')).toBe('https://a.org/#/dash/recent?t=1');
|
|
55
|
+
expect(buildEmbedSrc('https://a.org/', '/x', 'none')).toBe('https://a.org/');
|
|
56
|
+
});
|
|
57
|
+
it('toCorePath / toAppPath : filtrage, pathMap, rejet des chemins dangereux', function() {
|
|
58
|
+
expect(toCorePath('/a?token=S&x=1', {})).toBe('/a?x=1');
|
|
59
|
+
expect(toCorePath('//evil', {})).toBeNull();
|
|
60
|
+
var pathMap = {
|
|
61
|
+
toCore: function toCore(p) {
|
|
62
|
+
return p.replace(/^\/w/, '/workspace');
|
|
63
|
+
},
|
|
64
|
+
toApp: function toApp(p) {
|
|
65
|
+
return p.replace(/^\/workspace/, '/w');
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
expect(toCorePath('/w/1', {
|
|
69
|
+
pathMap: pathMap
|
|
70
|
+
})).toBe('/workspace/1');
|
|
71
|
+
expect(toAppPath('/workspace/1', {
|
|
72
|
+
pathMap: pathMap
|
|
73
|
+
})).toBe('/w/1');
|
|
74
|
+
expect(toCorePath('/a', {
|
|
75
|
+
pathMap: {
|
|
76
|
+
toCore: function toCore() {
|
|
77
|
+
return 'https://evil.org';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
it('createRateLimiter : plafonne les rafales puis reprend', function() {
|
|
83
|
+
var t = 0;
|
|
84
|
+
var allow = createRateLimiter(3, 1000, function() {
|
|
85
|
+
return t;
|
|
86
|
+
});
|
|
87
|
+
expect([
|
|
88
|
+
allow(),
|
|
89
|
+
allow(),
|
|
90
|
+
allow(),
|
|
91
|
+
allow()
|
|
92
|
+
]).toEqual([
|
|
93
|
+
true,
|
|
94
|
+
true,
|
|
95
|
+
true,
|
|
96
|
+
false
|
|
97
|
+
]);
|
|
98
|
+
t = 1500;
|
|
99
|
+
expect(allow()).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
});
|