@webex/webex-core 3.12.0-next.37 → 3.12.0-next.39
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 +5 -2
- package/dist/lib/batcher.js +1 -1
- package/dist/lib/credentials/credentials.js +1 -1
- package/dist/lib/credentials/token.js +1 -1
- package/dist/lib/domains.js +90 -0
- package/dist/lib/domains.js.map +1 -0
- package/dist/lib/services/service-catalog.js +6 -10
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/services.js +1 -1
- package/dist/lib/services-v2/service-catalog.js +6 -12
- package/dist/lib/services-v2/service-catalog.js.map +1 -1
- package/dist/lib/services-v2/services-v2.js +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/package.json +3 -3
- package/src/lib/domains.ts +94 -0
- package/src/lib/services/service-catalog.js +6 -10
- package/src/lib/services-v2/service-catalog.ts +6 -11
- package/test/unit/spec/interceptors/auth.js +56 -0
- package/test/unit/spec/services/service-catalog.js +93 -11
- package/test/unit/spec/services-v2/service-catalog.ts +93 -11
package/README.md
CHANGED
|
@@ -78,8 +78,11 @@ const webex = new WebexCore({
|
|
|
78
78
|
// Validate domains against the allowed domains
|
|
79
79
|
validateDomains: true,
|
|
80
80
|
|
|
81
|
-
// The allowed domains to validate domains against
|
|
82
|
-
|
|
81
|
+
// The allowed domains to validate domains against. Each entry is a
|
|
82
|
+
// hostname, matched on label boundaries: an entry allows that host and
|
|
83
|
+
// its subdomains, so 'example.com' covers 'api.example.com' but not
|
|
84
|
+
// 'notexample.com'.
|
|
85
|
+
allowedDomains: ['example.com']
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
});
|
package/dist/lib/batcher.js
CHANGED
|
@@ -302,7 +302,7 @@ var Batcher = _webexPlugin.default.extend({
|
|
|
302
302
|
fingerprintResponse: function fingerprintResponse(item) {
|
|
303
303
|
throw new Error('fingerprintResponse() must be implemented');
|
|
304
304
|
},
|
|
305
|
-
version: "3.12.0-next.
|
|
305
|
+
version: "3.12.0-next.39"
|
|
306
306
|
});
|
|
307
307
|
var _default2 = exports.default = Batcher;
|
|
308
308
|
//# sourceMappingURL=batcher.js.map
|
|
@@ -600,7 +600,7 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
600
600
|
this.refresh();
|
|
601
601
|
}
|
|
602
602
|
},
|
|
603
|
-
version: "3.12.0-next.
|
|
603
|
+
version: "3.12.0-next.39"
|
|
604
604
|
}, (0, _applyDecoratedDescriptor2.default)(_obj, "getUserToken", [_dec, _dec2], (0, _getOwnPropertyDescriptor.default)(_obj, "getUserToken"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "initialize", [_dec3], (0, _getOwnPropertyDescriptor.default)(_obj, "initialize"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "invalidate", [_common.oneFlight, _dec4], (0, _getOwnPropertyDescriptor.default)(_obj, "invalidate"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight, _dec5, _dec6], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), _obj));
|
|
605
605
|
var _default = exports.default = Credentials;
|
|
606
606
|
//# sourceMappingURL=credentials.js.map
|
|
@@ -532,7 +532,7 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
532
532
|
return res.body;
|
|
533
533
|
});
|
|
534
534
|
},
|
|
535
|
-
version: "3.12.0-next.
|
|
535
|
+
version: "3.12.0-next.39"
|
|
536
536
|
}, (0, _applyDecoratedDescriptor2.default)(_obj, "downscope", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "downscope"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "revoke", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "revoke"), _obj), _obj));
|
|
537
537
|
var _default = exports.default = Token;
|
|
538
538
|
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.normalizeAllowedDomains = exports.matchAllowedDomain = exports.default = void 0;
|
|
9
|
+
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));
|
|
10
|
+
var _url = _interopRequireDefault(require("url"));
|
|
11
|
+
var _lodash = require("lodash");
|
|
12
|
+
// Canonicalise a hostname for comparison: lowercase, drop the brackets around
|
|
13
|
+
// an IPv6 literal, and drop leading/trailing dots. DNS treats `Example.com`,
|
|
14
|
+
// `example.com.` and `example.com` as the same name.
|
|
15
|
+
//
|
|
16
|
+
// Node's `url.domainToASCII` looks like the standard way to do this, but the
|
|
17
|
+
// `url` polyfill this package bundles for the browser does not implement it,
|
|
18
|
+
// so it cannot be used here. It also leaves trailing dots in place.
|
|
19
|
+
var normalizeHostname = function normalizeHostname(value) {
|
|
20
|
+
return typeof value === 'string' ? value.toLowerCase().replace(/^\[|\]$/g, '').replace(/^\.+/, '').replace(/\.+$/, '') : '';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Canonicalise a list of configured allowed domains, discarding any entry that
|
|
25
|
+
* is not a usable hostname. Callers normalise on the way in so the stored list
|
|
26
|
+
* is already canonical, rather than re-deriving it on every request.
|
|
27
|
+
*
|
|
28
|
+
* @param {Array<string>} allowedDomains - The configured allowed domains.
|
|
29
|
+
* @returns {Array<string>} - Normalized, de-duplicated, non-empty entries.
|
|
30
|
+
*/
|
|
31
|
+
var normalizeAllowedDomains = exports.normalizeAllowedDomains = function normalizeAllowedDomains(allowedDomains) {
|
|
32
|
+
return (0, _lodash.uniq)(((0, _isArray.default)(allowedDomains) ? allowedDomains : []).map(normalizeHostname).filter(Boolean));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Determine if a hostname is covered by an allowed domain, matching only on DNS
|
|
37
|
+
* label boundaries, so that a hostname is allowed only when it is the domain
|
|
38
|
+
* itself or a subdomain of it. Matching on a substring instead would treat
|
|
39
|
+
* unrelated hostnames that merely contain the domain as allowed.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} hostname - Hostname to test. Must not include a port.
|
|
42
|
+
* @param {string} allowedDomain - The configured allowed domain.
|
|
43
|
+
* @returns {boolean} - True when the hostname is the domain or a subdomain of it.
|
|
44
|
+
*/
|
|
45
|
+
var hostnameMatchesDomain = function hostnameMatchesDomain(hostname, allowedDomain) {
|
|
46
|
+
// The stored list is normalized on write, but `allowedDomains` is a public
|
|
47
|
+
// property, so normalize again here rather than trust it.
|
|
48
|
+
var host = normalizeHostname(hostname);
|
|
49
|
+
var domain = normalizeHostname(allowedDomain);
|
|
50
|
+
return !!host && !!domain && (host === domain || host.endsWith(".".concat(domain)));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Find the allowed domain covering a url, or `undefined` if there is none.
|
|
55
|
+
*
|
|
56
|
+
* Parsing lives here rather than in the callers, and deliberately uses both url
|
|
57
|
+
* parsers, because this check gates an `Authorization` header. The two
|
|
58
|
+
* transports behind `@webex/http-core` do not use the same url parser: the
|
|
59
|
+
* browser transport parses per WHATWG, the node transport uses Node's legacy
|
|
60
|
+
* `Url.parse`, and for some inputs the two resolve different hosts.
|
|
61
|
+
*
|
|
62
|
+
* Rather than picking one, require both to agree and fail closed when they do
|
|
63
|
+
* not, so this check can never authorize a host that differs from the one a
|
|
64
|
+
* transport would actually connect to. Do not narrow this to a single parser.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} url - The url to match the allowed domains against.
|
|
67
|
+
* @param {Array<string>} allowedDomains - The configured allowed domains.
|
|
68
|
+
* @returns {string} - The matching allowed domain, or undefined if there is none.
|
|
69
|
+
*/
|
|
70
|
+
var matchAllowedDomain = exports.matchAllowedDomain = function matchAllowedDomain(url, allowedDomains) {
|
|
71
|
+
var hostname;
|
|
72
|
+
var legacyHostname;
|
|
73
|
+
try {
|
|
74
|
+
var _URL = new URL(url);
|
|
75
|
+
hostname = _URL.hostname;
|
|
76
|
+
var _Url$parse = _url.default.parse(url);
|
|
77
|
+
legacyHostname = _Url$parse.hostname;
|
|
78
|
+
} catch (_unused) {
|
|
79
|
+
// Not a parsable absolute url, so it cannot belong to an allowed domain.
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (normalizeHostname(hostname) !== normalizeHostname(legacyHostname)) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return (allowedDomains || []).find(function (allowedDomain) {
|
|
86
|
+
return hostnameMatchesDomain(hostname, allowedDomain);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
var _default = exports.default = matchAllowedDomain;
|
|
90
|
+
//# sourceMappingURL=domains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_url","_interopRequireDefault","require","_lodash","normalizeHostname","value","toLowerCase","replace","normalizeAllowedDomains","exports","allowedDomains","uniq","_isArray","default","map","filter","Boolean","hostnameMatchesDomain","hostname","allowedDomain","host","domain","endsWith","concat","matchAllowedDomain","url","legacyHostname","_URL","URL","_Url$parse","Url","parse","_unused","undefined","find","_default"],"sources":["domains.ts"],"sourcesContent":["import Url from 'url';\n\nimport {uniq} from 'lodash';\n\n// Canonicalise a hostname for comparison: lowercase, drop the brackets around\n// an IPv6 literal, and drop leading/trailing dots. DNS treats `Example.com`,\n// `example.com.` and `example.com` as the same name.\n//\n// Node's `url.domainToASCII` looks like the standard way to do this, but the\n// `url` polyfill this package bundles for the browser does not implement it,\n// so it cannot be used here. It also leaves trailing dots in place.\nconst normalizeHostname = (value: string): string =>\n typeof value === 'string'\n ? value\n .toLowerCase()\n .replace(/^\\[|\\]$/g, '')\n .replace(/^\\.+/, '')\n .replace(/\\.+$/, '')\n : '';\n\n/**\n * Canonicalise a list of configured allowed domains, discarding any entry that\n * is not a usable hostname. Callers normalise on the way in so the stored list\n * is already canonical, rather than re-deriving it on every request.\n *\n * @param {Array<string>} allowedDomains - The configured allowed domains.\n * @returns {Array<string>} - Normalized, de-duplicated, non-empty entries.\n */\nexport const normalizeAllowedDomains = (allowedDomains: Array<string>): Array<string> =>\n uniq(\n (Array.isArray(allowedDomains) ? allowedDomains : []).map(normalizeHostname).filter(Boolean)\n );\n\n/**\n * Determine if a hostname is covered by an allowed domain, matching only on DNS\n * label boundaries, so that a hostname is allowed only when it is the domain\n * itself or a subdomain of it. Matching on a substring instead would treat\n * unrelated hostnames that merely contain the domain as allowed.\n *\n * @param {string} hostname - Hostname to test. Must not include a port.\n * @param {string} allowedDomain - The configured allowed domain.\n * @returns {boolean} - True when the hostname is the domain or a subdomain of it.\n */\nconst hostnameMatchesDomain = (hostname: string, allowedDomain: string): boolean => {\n // The stored list is normalized on write, but `allowedDomains` is a public\n // property, so normalize again here rather than trust it.\n const host = normalizeHostname(hostname);\n const domain = normalizeHostname(allowedDomain);\n\n return !!host && !!domain && (host === domain || host.endsWith(`.${domain}`));\n};\n\n/**\n * Find the allowed domain covering a url, or `undefined` if there is none.\n *\n * Parsing lives here rather than in the callers, and deliberately uses both url\n * parsers, because this check gates an `Authorization` header. The two\n * transports behind `@webex/http-core` do not use the same url parser: the\n * browser transport parses per WHATWG, the node transport uses Node's legacy\n * `Url.parse`, and for some inputs the two resolve different hosts.\n *\n * Rather than picking one, require both to agree and fail closed when they do\n * not, so this check can never authorize a host that differs from the one a\n * transport would actually connect to. Do not narrow this to a single parser.\n *\n * @param {string} url - The url to match the allowed domains against.\n * @param {Array<string>} allowedDomains - The configured allowed domains.\n * @returns {string} - The matching allowed domain, or undefined if there is none.\n */\nexport const matchAllowedDomain = (\n url: string,\n allowedDomains: Array<string>\n): string | undefined => {\n let hostname: string;\n let legacyHostname: string;\n\n try {\n ({hostname} = new URL(url));\n ({hostname: legacyHostname} = Url.parse(url));\n } catch {\n // Not a parsable absolute url, so it cannot belong to an allowed domain.\n return undefined;\n }\n\n if (normalizeHostname(hostname) !== normalizeHostname(legacyHostname)) {\n return undefined;\n }\n\n return (allowedDomains || []).find((allowedDomain) =>\n hostnameMatchesDomain(hostname, allowedDomain)\n );\n};\n\nexport default matchAllowedDomain;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAME,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAIC,KAAa;EAAA,OACtC,OAAOA,KAAK,KAAK,QAAQ,GACrBA,KAAK,CACFC,WAAW,CAAC,CAAC,CACbC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CACvBA,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CACnBA,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GACtB,EAAE;AAAA;;AAER;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,SAA1BA,uBAAuBA,CAAIE,cAA6B;EAAA,OACnE,IAAAC,YAAI,EACF,CAAC,IAAAC,QAAA,CAAAC,OAAA,EAAcH,cAAc,CAAC,GAAGA,cAAc,GAAG,EAAE,EAAEI,GAAG,CAACV,iBAAiB,CAAC,CAACW,MAAM,CAACC,OAAO,CAC7F,CAAC;AAAA;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAqBA,CAAIC,QAAgB,EAAEC,aAAqB,EAAc;EAClF;EACA;EACA,IAAMC,IAAI,GAAGhB,iBAAiB,CAACc,QAAQ,CAAC;EACxC,IAAMG,MAAM,GAAGjB,iBAAiB,CAACe,aAAa,CAAC;EAE/C,OAAO,CAAC,CAACC,IAAI,IAAI,CAAC,CAACC,MAAM,KAAKD,IAAI,KAAKC,MAAM,IAAID,IAAI,CAACE,QAAQ,KAAAC,MAAA,CAAKF,MAAM,CAAE,CAAC,CAAC;AAC/E,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMG,kBAAkB,GAAAf,OAAA,CAAAe,kBAAA,GAAG,SAArBA,kBAAkBA,CAC7BC,GAAW,EACXf,cAA6B,EACN;EACvB,IAAIQ,QAAgB;EACpB,IAAIQ,cAAsB;EAE1B,IAAI;IAAA,IAAAC,IAAA,GACY,IAAIC,GAAG,CAACH,GAAG,CAAC;IAAxBP,QAAQ,GAAAS,IAAA,CAART,QAAQ;IAAA,IAAAW,UAAA,GACoBC,YAAG,CAACC,KAAK,CAACN,GAAG,CAAC;IAAhCC,cAAc,GAAAG,UAAA,CAAxBX,QAAQ;EACZ,CAAC,CAAC,OAAAc,OAAA,EAAM;IACN;IACA,OAAOC,SAAS;EAClB;EAEA,IAAI7B,iBAAiB,CAACc,QAAQ,CAAC,KAAKd,iBAAiB,CAACsB,cAAc,CAAC,EAAE;IACrE,OAAOO,SAAS;EAClB;EAEA,OAAO,CAACvB,cAAc,IAAI,EAAE,EAAEwB,IAAI,CAAC,UAACf,aAAa;IAAA,OAC/CF,qBAAqB,CAACC,QAAQ,EAAEC,aAAa,CAAC;EAAA,CAChD,CAAC;AACH,CAAC;AAAC,IAAAgB,QAAA,GAAA1B,OAAA,CAAAI,OAAA,GAEaW,kBAAkB","ignoreList":[]}
|
|
@@ -23,6 +23,7 @@ var _url = _interopRequireDefault(require("url"));
|
|
|
23
23
|
var _ampersandState = _interopRequireDefault(require("ampersand-state"));
|
|
24
24
|
var _lodash = require("lodash");
|
|
25
25
|
var _serviceUrl = _interopRequireDefault(require("./service-url"));
|
|
26
|
+
var _domains = require("../domains");
|
|
26
27
|
function ownKeys(e, r) { var t = _Object$keys3(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
27
28
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
28
29
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof _Symbol && r[_Symbol$iterator] || r["@@iterator"]; if (!t) { if (_Array$isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
@@ -283,19 +284,14 @@ var ServiceCatalog = _ampersandState.default.extend({
|
|
|
283
284
|
});
|
|
284
285
|
},
|
|
285
286
|
/**
|
|
286
|
-
* Finds an allowed domain that matches a specific url.
|
|
287
|
+
* Finds an allowed domain that matches a specific url. The url's hostname
|
|
288
|
+
* must be the allowed domain itself or a subdomain of it.
|
|
287
289
|
*
|
|
288
290
|
* @param {string} url - The url to match the allowed domains against.
|
|
289
291
|
* @returns {string} - The matching allowed domain.
|
|
290
292
|
*/
|
|
291
293
|
findAllowedDomain: function findAllowedDomain(url) {
|
|
292
|
-
|
|
293
|
-
if (!urlObj.host) {
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
296
|
-
return this.allowedDomains.find(function (allowedDomain) {
|
|
297
|
-
return urlObj.host.includes(allowedDomain);
|
|
298
|
-
});
|
|
294
|
+
return (0, _domains.matchAllowedDomain)(url, this.allowedDomains);
|
|
299
295
|
},
|
|
300
296
|
/**
|
|
301
297
|
* Get a service url from the current services list by name.
|
|
@@ -363,7 +359,7 @@ var ServiceCatalog = _ampersandState.default.extend({
|
|
|
363
359
|
* @returns {void}
|
|
364
360
|
*/
|
|
365
361
|
setAllowedDomains: function setAllowedDomains(allowedDomains) {
|
|
366
|
-
this.allowedDomains = (0,
|
|
362
|
+
this.allowedDomains = (0, _domains.normalizeAllowedDomains)(allowedDomains);
|
|
367
363
|
},
|
|
368
364
|
/**
|
|
369
365
|
*
|
|
@@ -371,7 +367,7 @@ var ServiceCatalog = _ampersandState.default.extend({
|
|
|
371
367
|
* @returns {void}
|
|
372
368
|
*/
|
|
373
369
|
addAllowedDomains: function addAllowedDomains(newAllowedDomains) {
|
|
374
|
-
this.allowedDomains = (0, _lodash.union)(this.allowedDomains, newAllowedDomains);
|
|
370
|
+
this.allowedDomains = (0, _lodash.union)(this.allowedDomains, (0, _domains.normalizeAllowedDomains)(newAllowedDomains));
|
|
375
371
|
},
|
|
376
372
|
/**
|
|
377
373
|
* Update the current list of `ServiceUrl`s against a provided
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_url","_interopRequireDefault","require","_ampersandState","_lodash","_serviceUrl","ownKeys","e","r","t","_Object$keys3","_Object$getOwnPropertySymbols","o","filter","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","Object","forEach","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","_createForOfIteratorHelper","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","_n","F","s","n","done","value","f","TypeError","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","_Array$from","test","Array","ServiceCatalog","AmpState","extend","namespace","props","serviceGroups","discovery","override","preauth","postauth","signin","status","ready","collecting","isReady","allowedDomains","_getUrl","serviceGroup","serviceUrls","concat","_toConsumableArray2","find","serviceUrl","_listServiceUrls","_loadServiceUrls","services","_this","existingService","service","_unloadServiceUrls","_this2","splice","indexOf","clean","findClusterId","url","incomingUrlObj","Url","parse","serviceUrlObj","_i","_Object$keys","_keys","key","_iterator","_step","defaultUrl","_iterator2","hosts","_step2","host","hostname","id","err","_iterator3","_step3","homeCluster","undefined","findServiceFromClusterId","_ref","clusterId","_ref$priorityHost","priorityHost","identifiedServiceUrl","get","findServiceUrlFromUrl","startsWith","_iterator4","_step4","alternateUrl","URL","findAllowedDomain","urlObj","allowedDomain","includes","getAllowedDomains","list","output","markFailedUrl","noPriorityHosts","_this3","failHost","setAllowedDomains","addAllowedDomains","newAllowedDomains","union","updateServiceUrls","serviceHostmap","_this4","currentServiceUrls","unusedUrls","every","item","serviceObj","ServiceUrl","trigger","waitForCatalog","timeout","_this5","_promise","resolve","reject","validatedTimeout","timeoutTimer","setTimeout","Error","once","clearTimeout","_default","exports"],"sources":["service-catalog.js"],"sourcesContent":["import Url from 'url';\n\nimport AmpState from 'ampersand-state';\n\nimport {union} from 'lodash';\nimport ServiceUrl from './service-url';\n\n/* eslint-disable no-underscore-dangle */\n/**\n * @class\n */\nconst ServiceCatalog = AmpState.extend({\n namespace: 'ServiceCatalog',\n\n props: {\n serviceGroups: [\n 'object',\n true,\n () => ({\n discovery: [],\n override: [],\n preauth: [],\n postauth: [],\n signin: [],\n }),\n ],\n status: [\n 'object',\n true,\n () => ({\n discovery: {\n ready: false,\n collecting: false,\n },\n override: {\n ready: false,\n collecting: false,\n },\n preauth: {\n ready: false,\n collecting: false,\n },\n postauth: {\n ready: false,\n collecting: false,\n },\n signin: {\n ready: false,\n collecting: false,\n },\n }),\n ],\n isReady: ['boolean', false, false],\n allowedDomains: ['array', false, () => []],\n },\n\n /**\n * @private\n * Search the service url array to locate a `ServiceUrl`\n * class object based on its name.\n * @param {string} name\n * @param {string} [serviceGroup]\n * @returns {ServiceUrl}\n */\n _getUrl(name, serviceGroup) {\n const serviceUrls =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n\n return serviceUrls.find((serviceUrl) => serviceUrl.name === name);\n },\n\n /**\n * @private\n * Generate an array of `ServiceUrl`s that is organized from highest auth\n * level to lowest auth level.\n * @returns {Array<ServiceUrl>} - array of `ServiceUrl`s\n */\n _listServiceUrls() {\n return [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n },\n\n /**\n * @private\n * Safely load one or more `ServiceUrl`s into this `Services` instance.\n * @param {string} serviceGroup\n * @param {Array<ServiceUrl>} services\n * @returns {Services}\n */\n _loadServiceUrls(serviceGroup, services) {\n // declare namespaces outside of loop\n let existingService;\n\n services.forEach((service) => {\n existingService = this._getUrl(service.name, serviceGroup);\n\n if (!existingService) {\n this.serviceGroups[serviceGroup].push(service);\n }\n });\n\n return this;\n },\n\n /**\n * @private\n * Safely unload one or more `ServiceUrl`s into this `Services` instance\n * @param {string} serviceGroup\n * @param {Array<ServiceUrl>} services\n * @returns {Services}\n */\n _unloadServiceUrls(serviceGroup, services) {\n // declare namespaces outside of loop\n let existingService;\n\n services.forEach((service) => {\n existingService = this._getUrl(service.name, serviceGroup);\n\n if (existingService) {\n this.serviceGroups[serviceGroup].splice(\n this.serviceGroups[serviceGroup].indexOf(existingService),\n 1\n );\n }\n });\n\n return this;\n },\n\n /**\n * Clear all collected catalog data and reset catalog status.\n *\n * @returns {void}\n */\n clean() {\n this.serviceGroups.preauth.length = 0;\n this.serviceGroups.signin.length = 0;\n this.serviceGroups.postauth.length = 0;\n this.status.preauth = {ready: false};\n this.status.signin = {ready: false};\n this.status.postauth = {ready: false};\n },\n\n /**\n * Search over all service groups to find a cluster id based\n * on a given url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {string} - ClusterId of a given url\n */\n findClusterId(url) {\n const incomingUrlObj = Url.parse(url);\n let serviceUrlObj;\n\n for (const key of Object.keys(this.serviceGroups)) {\n for (const service of this.serviceGroups[key]) {\n serviceUrlObj = Url.parse(service.defaultUrl);\n\n for (const host of service.hosts) {\n if (incomingUrlObj.hostname === host.host && host.id) {\n return host.id;\n }\n }\n\n if (serviceUrlObj.hostname === incomingUrlObj.hostname && service.hosts.length > 0) {\n // no exact match, so try to grab the first home cluster\n for (const host of service.hosts) {\n if (host.homeCluster) {\n return host.id;\n }\n }\n\n // no match found still, so return the first entry\n return service.hosts[0].id;\n }\n }\n }\n\n return undefined;\n },\n\n /**\n * Search over all service groups and return a service value from a provided\n * clusterId. Currently, this method will return either a service name, or a\n * service url depending on the `value` parameter. If the `value` parameter\n * is set to `name`, it will return a service name to be utilized within the\n * Services plugin methods.\n * @param {object} params\n * @param {string} params.clusterId - clusterId of found service\n * @param {boolean} [params.priorityHost = true] - returns priority host url if true\n * @param {string} [params.serviceGroup] - specify service group\n * @returns {object} service\n * @returns {string} service.name\n * @returns {string} service.url\n */\n findServiceFromClusterId({clusterId, priorityHost = true, serviceGroup} = {}) {\n const serviceUrls =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n\n const identifiedServiceUrl = serviceUrls.find((serviceUrl) =>\n serviceUrl.hosts.find((host) => host.id === clusterId)\n );\n\n if (identifiedServiceUrl) {\n return {\n name: identifiedServiceUrl.name,\n url: identifiedServiceUrl.get(priorityHost, clusterId),\n };\n }\n\n return undefined;\n },\n\n /**\n * Find a service based on the provided url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {serviceUrl} - ServiceUrl assocated with provided url\n */\n findServiceUrlFromUrl(url) {\n const serviceUrls = [\n ...this.serviceGroups.discovery,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.override,\n ];\n\n return serviceUrls.find((serviceUrl) => {\n // Check to see if the URL we are checking starts with the default URL\n if (url.startsWith(serviceUrl.defaultUrl)) {\n return true;\n }\n\n // If not, we check to see if the alternate URLs match\n // These are made by swapping the host of the default URL\n // with that of an alternate host\n for (const host of serviceUrl.hosts) {\n const alternateUrl = new URL(serviceUrl.defaultUrl);\n alternateUrl.host = host.host;\n\n if (url.startsWith(alternateUrl.toString())) {\n return true;\n }\n }\n\n return false;\n });\n },\n\n /**\n * Finds an allowed domain that matches a specific url.\n *\n * @param {string} url - The url to match the allowed domains against.\n * @returns {string} - The matching allowed domain.\n */\n findAllowedDomain(url) {\n const urlObj = Url.parse(url);\n\n if (!urlObj.host) {\n return undefined;\n }\n\n return this.allowedDomains.find((allowedDomain) => urlObj.host.includes(allowedDomain));\n },\n\n /**\n * Get a service url from the current services list by name.\n * @param {string} name\n * @param {boolean} priorityHost\n * @param {string} serviceGroup\n * @returns {string}\n */\n get(name, priorityHost, serviceGroup) {\n const serviceUrl = this._getUrl(name, serviceGroup);\n\n return serviceUrl ? serviceUrl.get(priorityHost) : undefined;\n },\n\n /**\n * Get the current allowed domains list.\n *\n * @returns {Array<string>} - the current allowed domains list.\n */\n getAllowedDomains() {\n return [...this.allowedDomains];\n },\n\n /**\n * Creates an object where the keys are the service names\n * and the values are the service urls.\n * @param {boolean} priorityHost - use the highest priority if set to `true`\n * @param {string} [serviceGroup]\n * @returns {Record<string, string>}\n */\n list(priorityHost, serviceGroup) {\n const output = {};\n\n const serviceUrls =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.discovery,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.override,\n ];\n\n if (serviceUrls) {\n serviceUrls.forEach((serviceUrl) => {\n output[serviceUrl.name] = serviceUrl.get(priorityHost);\n });\n }\n\n return output;\n },\n\n /**\n * Mark a priority host service url as failed.\n * This will mark the host associated with the\n * `ServiceUrl` to be removed from the its\n * respective host array, and then return the next\n * viable host from the `ServiceUrls` host array,\n * or the `ServiceUrls` default url if no other priority\n * hosts are available, or if `noPriorityHosts` is set to\n * `true`.\n * @param {string} url\n * @param {boolean} noPriorityHosts\n * @returns {string}\n */\n markFailedUrl(url, noPriorityHosts) {\n const serviceUrl = this._getUrl(\n Object.keys(this.list()).find((key) => this._getUrl(key).failHost(url))\n );\n\n if (!serviceUrl) {\n return undefined;\n }\n\n return noPriorityHosts ? serviceUrl.get(false) : serviceUrl.get(true);\n },\n\n /**\n * Set the allowed domains for the catalog.\n *\n * @param {Array<string>} allowedDomains - allowed domains to be assigned.\n * @returns {void}\n */\n setAllowedDomains(allowedDomains) {\n this.allowedDomains = [...allowedDomains];\n },\n\n /**\n *\n * @param {Array<string>} newAllowedDomains - new allowed domains to add to existing set of allowed domains\n * @returns {void}\n */\n addAllowedDomains(newAllowedDomains) {\n this.allowedDomains = union(this.allowedDomains, newAllowedDomains);\n },\n\n /**\n * Update the current list of `ServiceUrl`s against a provided\n * service hostmap.\n * @emits ServiceCatalog#preauthorized\n * @emits ServiceCatalog#postauthorized\n * @param {string} serviceGroup\n * @param {object} serviceHostmap\n * @returns {Services}\n */\n updateServiceUrls(serviceGroup, serviceHostmap) {\n const currentServiceUrls = this.serviceGroups[serviceGroup];\n\n const unusedUrls = currentServiceUrls.filter((serviceUrl) =>\n serviceHostmap.every((item) => item.name !== serviceUrl.name)\n );\n\n this._unloadServiceUrls(serviceGroup, unusedUrls);\n\n serviceHostmap.forEach((serviceObj) => {\n const service = this._getUrl(serviceObj.name, serviceGroup);\n\n if (service) {\n service.defaultUrl = serviceObj.defaultUrl;\n service.hosts = serviceObj.hosts || [];\n } else {\n this._loadServiceUrls(serviceGroup, [\n new ServiceUrl({\n ...serviceObj,\n }),\n ]);\n }\n });\n\n this.status[serviceGroup].ready = true;\n this.trigger(serviceGroup);\n\n return this;\n },\n\n /**\n * Wait until the service catalog is available,\n * or reject after a timeout of 60 seconds.\n * @param {string} serviceGroup\n * @param {number} [timeout] - in seconds\n * @returns {Promise<void>}\n */\n waitForCatalog(serviceGroup, timeout) {\n return new Promise((resolve, reject) => {\n if (this.status[serviceGroup].ready) {\n resolve();\n }\n\n const validatedTimeout = typeof timeout === 'number' && timeout >= 0 ? timeout : 60;\n\n const timeoutTimer = setTimeout(\n () =>\n reject(\n new Error(\n `services: timeout occured while waiting for '${serviceGroup}' catalog to populate`\n )\n ),\n validatedTimeout * 1000\n );\n\n this.once(serviceGroup, () => {\n clearTimeout(timeoutTimer);\n resolve();\n });\n });\n },\n});\n/* eslint-enable no-underscore-dangle */\n\nexport default ServiceCatalog;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAuC,SAAAI,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,aAAA,CAAAH,CAAA,OAAAI,6BAAA,QAAAC,CAAA,GAAAD,6BAAA,CAAAJ,CAAA,GAAAC,CAAA,KAAAI,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAL,CAAA,WAAAM,gCAAA,CAAAP,CAAA,EAAAC,CAAA,EAAAO,UAAA,OAAA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
+
{"version":3,"names":["_url","_interopRequireDefault","require","_ampersandState","_lodash","_serviceUrl","_domains","ownKeys","e","r","t","_Object$keys3","_Object$getOwnPropertySymbols","o","filter","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","Object","forEach","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","_createForOfIteratorHelper","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","_n","F","s","n","done","value","f","TypeError","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","_Array$from","test","Array","ServiceCatalog","AmpState","extend","namespace","props","serviceGroups","discovery","override","preauth","postauth","signin","status","ready","collecting","isReady","allowedDomains","_getUrl","serviceGroup","serviceUrls","concat","_toConsumableArray2","find","serviceUrl","_listServiceUrls","_loadServiceUrls","services","_this","existingService","service","_unloadServiceUrls","_this2","splice","indexOf","clean","findClusterId","url","incomingUrlObj","Url","parse","serviceUrlObj","_i","_Object$keys","_keys","key","_iterator","_step","defaultUrl","_iterator2","hosts","_step2","host","hostname","id","err","_iterator3","_step3","homeCluster","undefined","findServiceFromClusterId","_ref","clusterId","_ref$priorityHost","priorityHost","identifiedServiceUrl","get","findServiceUrlFromUrl","startsWith","_iterator4","_step4","alternateUrl","URL","findAllowedDomain","matchAllowedDomain","getAllowedDomains","list","output","markFailedUrl","noPriorityHosts","_this3","failHost","setAllowedDomains","normalizeAllowedDomains","addAllowedDomains","newAllowedDomains","union","updateServiceUrls","serviceHostmap","_this4","currentServiceUrls","unusedUrls","every","item","serviceObj","ServiceUrl","trigger","waitForCatalog","timeout","_this5","_promise","resolve","reject","validatedTimeout","timeoutTimer","setTimeout","Error","once","clearTimeout","_default","exports"],"sources":["service-catalog.js"],"sourcesContent":["import Url from 'url';\n\nimport AmpState from 'ampersand-state';\n\nimport {union} from 'lodash';\nimport ServiceUrl from './service-url';\nimport {matchAllowedDomain, normalizeAllowedDomains} from '../domains';\n\n/* eslint-disable no-underscore-dangle */\n/**\n * @class\n */\nconst ServiceCatalog = AmpState.extend({\n namespace: 'ServiceCatalog',\n\n props: {\n serviceGroups: [\n 'object',\n true,\n () => ({\n discovery: [],\n override: [],\n preauth: [],\n postauth: [],\n signin: [],\n }),\n ],\n status: [\n 'object',\n true,\n () => ({\n discovery: {\n ready: false,\n collecting: false,\n },\n override: {\n ready: false,\n collecting: false,\n },\n preauth: {\n ready: false,\n collecting: false,\n },\n postauth: {\n ready: false,\n collecting: false,\n },\n signin: {\n ready: false,\n collecting: false,\n },\n }),\n ],\n isReady: ['boolean', false, false],\n allowedDomains: ['array', false, () => []],\n },\n\n /**\n * @private\n * Search the service url array to locate a `ServiceUrl`\n * class object based on its name.\n * @param {string} name\n * @param {string} [serviceGroup]\n * @returns {ServiceUrl}\n */\n _getUrl(name, serviceGroup) {\n const serviceUrls =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n\n return serviceUrls.find((serviceUrl) => serviceUrl.name === name);\n },\n\n /**\n * @private\n * Generate an array of `ServiceUrl`s that is organized from highest auth\n * level to lowest auth level.\n * @returns {Array<ServiceUrl>} - array of `ServiceUrl`s\n */\n _listServiceUrls() {\n return [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n },\n\n /**\n * @private\n * Safely load one or more `ServiceUrl`s into this `Services` instance.\n * @param {string} serviceGroup\n * @param {Array<ServiceUrl>} services\n * @returns {Services}\n */\n _loadServiceUrls(serviceGroup, services) {\n // declare namespaces outside of loop\n let existingService;\n\n services.forEach((service) => {\n existingService = this._getUrl(service.name, serviceGroup);\n\n if (!existingService) {\n this.serviceGroups[serviceGroup].push(service);\n }\n });\n\n return this;\n },\n\n /**\n * @private\n * Safely unload one or more `ServiceUrl`s into this `Services` instance\n * @param {string} serviceGroup\n * @param {Array<ServiceUrl>} services\n * @returns {Services}\n */\n _unloadServiceUrls(serviceGroup, services) {\n // declare namespaces outside of loop\n let existingService;\n\n services.forEach((service) => {\n existingService = this._getUrl(service.name, serviceGroup);\n\n if (existingService) {\n this.serviceGroups[serviceGroup].splice(\n this.serviceGroups[serviceGroup].indexOf(existingService),\n 1\n );\n }\n });\n\n return this;\n },\n\n /**\n * Clear all collected catalog data and reset catalog status.\n *\n * @returns {void}\n */\n clean() {\n this.serviceGroups.preauth.length = 0;\n this.serviceGroups.signin.length = 0;\n this.serviceGroups.postauth.length = 0;\n this.status.preauth = {ready: false};\n this.status.signin = {ready: false};\n this.status.postauth = {ready: false};\n },\n\n /**\n * Search over all service groups to find a cluster id based\n * on a given url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {string} - ClusterId of a given url\n */\n findClusterId(url) {\n const incomingUrlObj = Url.parse(url);\n let serviceUrlObj;\n\n for (const key of Object.keys(this.serviceGroups)) {\n for (const service of this.serviceGroups[key]) {\n serviceUrlObj = Url.parse(service.defaultUrl);\n\n for (const host of service.hosts) {\n if (incomingUrlObj.hostname === host.host && host.id) {\n return host.id;\n }\n }\n\n if (serviceUrlObj.hostname === incomingUrlObj.hostname && service.hosts.length > 0) {\n // no exact match, so try to grab the first home cluster\n for (const host of service.hosts) {\n if (host.homeCluster) {\n return host.id;\n }\n }\n\n // no match found still, so return the first entry\n return service.hosts[0].id;\n }\n }\n }\n\n return undefined;\n },\n\n /**\n * Search over all service groups and return a service value from a provided\n * clusterId. Currently, this method will return either a service name, or a\n * service url depending on the `value` parameter. If the `value` parameter\n * is set to `name`, it will return a service name to be utilized within the\n * Services plugin methods.\n * @param {object} params\n * @param {string} params.clusterId - clusterId of found service\n * @param {boolean} [params.priorityHost = true] - returns priority host url if true\n * @param {string} [params.serviceGroup] - specify service group\n * @returns {object} service\n * @returns {string} service.name\n * @returns {string} service.url\n */\n findServiceFromClusterId({clusterId, priorityHost = true, serviceGroup} = {}) {\n const serviceUrls =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n\n const identifiedServiceUrl = serviceUrls.find((serviceUrl) =>\n serviceUrl.hosts.find((host) => host.id === clusterId)\n );\n\n if (identifiedServiceUrl) {\n return {\n name: identifiedServiceUrl.name,\n url: identifiedServiceUrl.get(priorityHost, clusterId),\n };\n }\n\n return undefined;\n },\n\n /**\n * Find a service based on the provided url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {serviceUrl} - ServiceUrl assocated with provided url\n */\n findServiceUrlFromUrl(url) {\n const serviceUrls = [\n ...this.serviceGroups.discovery,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.override,\n ];\n\n return serviceUrls.find((serviceUrl) => {\n // Check to see if the URL we are checking starts with the default URL\n if (url.startsWith(serviceUrl.defaultUrl)) {\n return true;\n }\n\n // If not, we check to see if the alternate URLs match\n // These are made by swapping the host of the default URL\n // with that of an alternate host\n for (const host of serviceUrl.hosts) {\n const alternateUrl = new URL(serviceUrl.defaultUrl);\n alternateUrl.host = host.host;\n\n if (url.startsWith(alternateUrl.toString())) {\n return true;\n }\n }\n\n return false;\n });\n },\n\n /**\n * Finds an allowed domain that matches a specific url. The url's hostname\n * must be the allowed domain itself or a subdomain of it.\n *\n * @param {string} url - The url to match the allowed domains against.\n * @returns {string} - The matching allowed domain.\n */\n findAllowedDomain(url) {\n return matchAllowedDomain(url, this.allowedDomains);\n },\n\n /**\n * Get a service url from the current services list by name.\n * @param {string} name\n * @param {boolean} priorityHost\n * @param {string} serviceGroup\n * @returns {string}\n */\n get(name, priorityHost, serviceGroup) {\n const serviceUrl = this._getUrl(name, serviceGroup);\n\n return serviceUrl ? serviceUrl.get(priorityHost) : undefined;\n },\n\n /**\n * Get the current allowed domains list.\n *\n * @returns {Array<string>} - the current allowed domains list.\n */\n getAllowedDomains() {\n return [...this.allowedDomains];\n },\n\n /**\n * Creates an object where the keys are the service names\n * and the values are the service urls.\n * @param {boolean} priorityHost - use the highest priority if set to `true`\n * @param {string} [serviceGroup]\n * @returns {Record<string, string>}\n */\n list(priorityHost, serviceGroup) {\n const output = {};\n\n const serviceUrls =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.discovery,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.override,\n ];\n\n if (serviceUrls) {\n serviceUrls.forEach((serviceUrl) => {\n output[serviceUrl.name] = serviceUrl.get(priorityHost);\n });\n }\n\n return output;\n },\n\n /**\n * Mark a priority host service url as failed.\n * This will mark the host associated with the\n * `ServiceUrl` to be removed from the its\n * respective host array, and then return the next\n * viable host from the `ServiceUrls` host array,\n * or the `ServiceUrls` default url if no other priority\n * hosts are available, or if `noPriorityHosts` is set to\n * `true`.\n * @param {string} url\n * @param {boolean} noPriorityHosts\n * @returns {string}\n */\n markFailedUrl(url, noPriorityHosts) {\n const serviceUrl = this._getUrl(\n Object.keys(this.list()).find((key) => this._getUrl(key).failHost(url))\n );\n\n if (!serviceUrl) {\n return undefined;\n }\n\n return noPriorityHosts ? serviceUrl.get(false) : serviceUrl.get(true);\n },\n\n /**\n * Set the allowed domains for the catalog.\n *\n * @param {Array<string>} allowedDomains - allowed domains to be assigned.\n * @returns {void}\n */\n setAllowedDomains(allowedDomains) {\n this.allowedDomains = normalizeAllowedDomains(allowedDomains);\n },\n\n /**\n *\n * @param {Array<string>} newAllowedDomains - new allowed domains to add to existing set of allowed domains\n * @returns {void}\n */\n addAllowedDomains(newAllowedDomains) {\n this.allowedDomains = union(this.allowedDomains, normalizeAllowedDomains(newAllowedDomains));\n },\n\n /**\n * Update the current list of `ServiceUrl`s against a provided\n * service hostmap.\n * @emits ServiceCatalog#preauthorized\n * @emits ServiceCatalog#postauthorized\n * @param {string} serviceGroup\n * @param {object} serviceHostmap\n * @returns {Services}\n */\n updateServiceUrls(serviceGroup, serviceHostmap) {\n const currentServiceUrls = this.serviceGroups[serviceGroup];\n\n const unusedUrls = currentServiceUrls.filter((serviceUrl) =>\n serviceHostmap.every((item) => item.name !== serviceUrl.name)\n );\n\n this._unloadServiceUrls(serviceGroup, unusedUrls);\n\n serviceHostmap.forEach((serviceObj) => {\n const service = this._getUrl(serviceObj.name, serviceGroup);\n\n if (service) {\n service.defaultUrl = serviceObj.defaultUrl;\n service.hosts = serviceObj.hosts || [];\n } else {\n this._loadServiceUrls(serviceGroup, [\n new ServiceUrl({\n ...serviceObj,\n }),\n ]);\n }\n });\n\n this.status[serviceGroup].ready = true;\n this.trigger(serviceGroup);\n\n return this;\n },\n\n /**\n * Wait until the service catalog is available,\n * or reject after a timeout of 60 seconds.\n * @param {string} serviceGroup\n * @param {number} [timeout] - in seconds\n * @returns {Promise<void>}\n */\n waitForCatalog(serviceGroup, timeout) {\n return new Promise((resolve, reject) => {\n if (this.status[serviceGroup].ready) {\n resolve();\n }\n\n const validatedTimeout = typeof timeout === 'number' && timeout >= 0 ? timeout : 60;\n\n const timeoutTimer = setTimeout(\n () =>\n reject(\n new Error(\n `services: timeout occured while waiting for '${serviceGroup}' catalog to populate`\n )\n ),\n validatedTimeout * 1000\n );\n\n this.once(serviceGroup, () => {\n clearTimeout(timeoutTimer);\n resolve();\n });\n });\n },\n});\n/* eslint-enable no-underscore-dangle */\n\nexport default ServiceCatalog;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,QAAA,G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CAAC,CAAC;AACF;AAAA,IAAAQ,QAAA,GAAAC,OAAA,CAAA1I,OAAA,GAEe8B,cAAc","ignoreList":[]}
|
|
@@ -1611,7 +1611,7 @@ var Services = _webexPlugin.default.extend({
|
|
|
1611
1611
|
}, _callee6);
|
|
1612
1612
|
})));
|
|
1613
1613
|
},
|
|
1614
|
-
version: "3.12.0-next.
|
|
1614
|
+
version: "3.12.0-next.39"
|
|
1615
1615
|
});
|
|
1616
1616
|
/* eslint-enable no-underscore-dangle */
|
|
1617
1617
|
var _default = exports.default = Services;
|
|
@@ -15,6 +15,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2
|
|
|
15
15
|
var _ampersandState = _interopRequireDefault(require("ampersand-state"));
|
|
16
16
|
var _lodash = require("lodash");
|
|
17
17
|
var _serviceDetail = _interopRequireDefault(require("./service-detail"));
|
|
18
|
+
var _domains = require("../domains");
|
|
18
19
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof _Symbol && r[_Symbol$iterator] || r["@@iterator"]; if (!t) { if (_Array$isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
19
20
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? _Array$from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
20
21
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -214,21 +215,14 @@ var ServiceCatalog = _ampersandState.default.extend({
|
|
|
214
215
|
});
|
|
215
216
|
},
|
|
216
217
|
/**
|
|
217
|
-
* Finds an allowed domain that matches a specific url.
|
|
218
|
+
* Finds an allowed domain that matches a specific url. The url's hostname
|
|
219
|
+
* must be the allowed domain itself or a subdomain of it.
|
|
218
220
|
*
|
|
219
221
|
* @param {string} url - The url to match the allowed domains against.
|
|
220
222
|
* @returns {string} - The matching allowed domain.
|
|
221
223
|
*/
|
|
222
224
|
findAllowedDomain: function findAllowedDomain(url) {
|
|
223
|
-
|
|
224
|
-
var urlObj = new URL(url);
|
|
225
|
-
return this.allowedDomains.find(function (allowedDomain) {
|
|
226
|
-
return urlObj.host.includes(allowedDomain);
|
|
227
|
-
});
|
|
228
|
-
} catch (_unused2) {
|
|
229
|
-
// If the URL is invalid or can't be found, return undefined
|
|
230
|
-
return undefined;
|
|
231
|
-
}
|
|
225
|
+
return (0, _domains.matchAllowedDomain)(url, this.allowedDomains);
|
|
232
226
|
},
|
|
233
227
|
/**
|
|
234
228
|
* Get a service url from the current services list by name. Return undefined
|
|
@@ -280,7 +274,7 @@ var ServiceCatalog = _ampersandState.default.extend({
|
|
|
280
274
|
* @returns {void}
|
|
281
275
|
*/
|
|
282
276
|
setAllowedDomains: function setAllowedDomains(allowedDomains) {
|
|
283
|
-
this.allowedDomains = (0,
|
|
277
|
+
this.allowedDomains = (0, _domains.normalizeAllowedDomains)(allowedDomains);
|
|
284
278
|
},
|
|
285
279
|
/**
|
|
286
280
|
*
|
|
@@ -288,7 +282,7 @@ var ServiceCatalog = _ampersandState.default.extend({
|
|
|
288
282
|
* @returns {void}
|
|
289
283
|
*/
|
|
290
284
|
addAllowedDomains: function addAllowedDomains(newAllowedDomains) {
|
|
291
|
-
this.allowedDomains = (0, _lodash.union)(this.allowedDomains, newAllowedDomains);
|
|
285
|
+
this.allowedDomains = (0, _lodash.union)(this.allowedDomains, (0, _domains.normalizeAllowedDomains)(newAllowedDomains));
|
|
292
286
|
},
|
|
293
287
|
/**
|
|
294
288
|
* Update the current list of `ServiceDetail`s against a provided
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_ampersandState","_interopRequireDefault","require","_lodash","_serviceDetail","_createForOfIteratorHelper","r","e","t","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","length","_n","F","s","n","done","value","f","TypeError","o","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","_Array$from","test","Array","ServiceCatalog","AmpState","extend","namespace","props","serviceGroups","discovery","override","preauth","postauth","signin","status","ready","collecting","isReady","timestamp","allowedDomains","_getAllServiceDetails","serviceGroup","serviceDetails","concat","_toConsumableArray2","default","_getServiceDetail","clusterId","find","serviceDetail","id","_loadServiceDetails","_this","existingService","forEach","service","push","_unloadServiceDetails","_this2","splice","indexOf","clean","findClusterId","url","_allServiceDetails$fi","incomingUrlObj","URL","allServiceDetails","serviceUrls","_ref","host","_unused","undefined","findServiceFromClusterId","_ref2","arguments","serviceName","get","findServiceDetailFromUrl","_ref3","_iterator","_step","serviceUrl","startsWith","baseUrl","err","findAllowedDomain","urlObj","allowedDomain","includes","_unused2","getAllowedDomains","markFailedServiceUrl","serviceDetailWithFailedHost","failHost","setAllowedDomains","addAllowedDomains","newAllowedDomains","union","updateServiceGroups","_this3","currentServiceDetails","unusedServicesDetails","filter","every","_ref4","serviceObj","_serviceObj$serviceUr","sort","b","priority","ServiceDetail","trigger","waitForCatalog","timeout","_this4","_promise","resolve","reject","validatedTimeout","timeoutTimer","setTimeout","Error","once","clearTimeout","_default","exports"],"sources":["service-catalog.ts"],"sourcesContent":["import AmpState from 'ampersand-state';\n\nimport {union} from 'lodash';\nimport ServiceDetail from './service-detail';\nimport {IServiceDetail, ServiceGroup} from './types';\n\n/**\n * @class\n */\nconst ServiceCatalog = AmpState.extend({\n namespace: 'ServiceCatalog',\n\n props: {\n serviceGroups: [\n 'object',\n true,\n () => ({\n discovery: [],\n override: [],\n preauth: [],\n postauth: [],\n signin: [],\n }),\n ],\n status: [\n 'object',\n true,\n () => ({\n discovery: {\n ready: false,\n collecting: false,\n },\n override: {\n ready: false,\n collecting: false,\n },\n preauth: {\n ready: false,\n collecting: false,\n },\n postauth: {\n ready: false,\n collecting: false,\n },\n signin: {\n ready: false,\n collecting: false,\n },\n }),\n ],\n isReady: ['boolean', false, false],\n timestamp: ['string', false, ''],\n allowedDomains: ['array', false, () => []],\n },\n\n /**\n * @private\n * Get all service details for a given service group or return all details if no group is specified.\n * @param {ServiceGroup} serviceGroup - The name of the service group to retrieve details for.\n * @returns {Array<IServiceDetail>} - An array of service details.\n */\n _getAllServiceDetails(serviceGroup?: ServiceGroup): Array<IServiceDetail> {\n const serviceDetails =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n\n return serviceDetails;\n },\n\n /**\n * @private\n * Search the service details array to locate a `ServiceDetails`\n * class object based on its id.\n * @param {string} clusterId\n * @param {ServiceGroup} [serviceGroup]\n * @returns {IServiceDetail}\n */\n _getServiceDetail(clusterId: string, serviceGroup?: ServiceGroup): IServiceDetail | undefined {\n const serviceDetails = this._getAllServiceDetails(serviceGroup);\n\n return serviceDetails.find((serviceDetail: IServiceDetail) => serviceDetail.id === clusterId);\n },\n\n /**\n * @private\n * Safely load one or more `ServiceDetail`s into this `ServiceCatalog` instance.\n * @param {ServiceGroup} serviceGroup\n * @param {Array<ServiceDetail>} serviceDetails\n * @returns {void}\n */\n _loadServiceDetails(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>): void {\n // declare namespaces outside of loop\n let existingService: IServiceDetail | undefined;\n\n serviceDetails.forEach((service) => {\n existingService = this._getServiceDetail(service.id, serviceGroup);\n\n if (!existingService) {\n this.serviceGroups[serviceGroup].push(service);\n }\n });\n },\n\n /**\n * @private\n * Safely unload one or more `ServiceDetail`s into this `Services` instance\n * @param {ServiceGroup} serviceGroup\n * @param {Array<ServiceDetail>} serviceDetails\n * @returns {void}\n */\n _unloadServiceDetails(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>): void {\n // declare namespaces outside of loop\n let existingService: IServiceDetail | undefined;\n\n serviceDetails?.forEach((service) => {\n existingService = this._getServiceDetail(service.id, serviceGroup);\n\n if (existingService) {\n this.serviceGroups[serviceGroup].splice(\n this.serviceGroups[serviceGroup].indexOf(existingService),\n 1\n );\n }\n });\n },\n\n /**\n * Clear all collected catalog data and reset catalog status.\n *\n * @returns {void}\n */\n clean(): void {\n this.serviceGroups.preauth.length = 0;\n this.serviceGroups.signin.length = 0;\n this.serviceGroups.postauth.length = 0;\n this.status.preauth = {ready: false};\n this.status.signin = {ready: false};\n this.status.postauth = {ready: false};\n },\n\n /**\n * Search over all service groups to find a cluster id based\n * on a given url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {string | undefined} - ClusterId of a given url\n */\n findClusterId(url: string): string | undefined {\n try {\n const incomingUrlObj = new URL(url);\n const allServiceDetails = this._getAllServiceDetails();\n\n return allServiceDetails.find((serviceDetail: IServiceDetail) =>\n serviceDetail.serviceUrls.find(({host}) => host === incomingUrlObj.host)\n )?.id;\n } catch {\n // If the URL is invalid or can't be found, return undefined\n return undefined;\n }\n },\n\n /**\n * Search over all service groups and return a service value from a provided\n * clusterId.\n * @param {object} params\n * @param {string} params.clusterId - clusterId of found service\n * @param {ServiceGroup} [params.serviceGroup] - specify service group\n * @returns {object} service\n * @returns {string} service.name\n * @returns {string} service.url\n */\n findServiceFromClusterId(\n {clusterId, serviceGroup} = {} as {clusterId: string; serviceGroup?: ServiceGroup}\n ): {name: string; url: string} | undefined {\n const serviceDetails = this._getServiceDetail(clusterId, serviceGroup);\n\n if (serviceDetails) {\n return {\n name: serviceDetails.serviceName,\n url: serviceDetails.get(),\n };\n }\n\n return undefined;\n },\n\n /**\n * Find a service based on the provided url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {IServiceDetail} - ServiceDetail assocated with provided url\n */\n findServiceDetailFromUrl(url: string): IServiceDetail | undefined {\n const serviceDetails = this._getAllServiceDetails();\n\n return serviceDetails.find(({serviceUrls}) => {\n for (const serviceUrl of serviceUrls) {\n if (url.startsWith(serviceUrl.baseUrl)) {\n return true;\n }\n }\n\n return false;\n });\n },\n\n /**\n * Finds an allowed domain that matches a specific url.\n *\n * @param {string} url - The url to match the allowed domains against.\n * @returns {string} - The matching allowed domain.\n */\n findAllowedDomain(url: string): string {\n try {\n const urlObj = new URL(url);\n\n return this.allowedDomains.find((allowedDomain) => urlObj.host.includes(allowedDomain));\n } catch {\n // If the URL is invalid or can't be found, return undefined\n return undefined;\n }\n },\n\n /**\n * Get a service url from the current services list by name. Return undefined\n * if the service is not found.\n * @param {string} clusterId\n * @param {ServiceGroup} serviceGroup\n * @returns {string | undefined}\n */\n get(clusterId: string, serviceGroup?: ServiceGroup): string | undefined {\n const serviceDetail = this._getServiceDetail(clusterId, serviceGroup);\n\n return serviceDetail ? serviceDetail.get() : undefined;\n },\n\n /**\n * Get the current allowed domains list.\n *\n * @returns {Array<string>} - the current allowed domains list.\n */\n getAllowedDomains(): Array<string> {\n return [...this.allowedDomains];\n },\n\n /**\n * Mark a priority host service url as failed.\n * This will mark the host associated with the\n * `ServiceDetail` to be removed from the its\n * respective host array, and then return the next\n * viable host from the `ServiceDetail` host array,\n * or the `ServiceDetail` default url if no other priority\n * hosts are available, or if `noPriorityHosts` is set to\n * `true`.\n * @param {string} url\n * @returns {string}\n */\n markFailedServiceUrl(url: string): string | undefined {\n const serviceDetails = this._getAllServiceDetails();\n\n const serviceDetailWithFailedHost = serviceDetails.find((serviceDetail: IServiceDetail) =>\n serviceDetail.failHost(url)\n );\n\n // if we couldn't find the url we wanted to fail, return undefined\n if (!serviceDetailWithFailedHost) {\n return undefined;\n }\n\n return serviceDetailWithFailedHost.get();\n },\n\n /**\n * Set the allowed domains for the catalog.\n *\n * @param {Array<string>} allowedDomains - allowed domains to be assigned.\n * @returns {void}\n */\n setAllowedDomains(allowedDomains: Array<string>): void {\n this.allowedDomains = [...allowedDomains];\n },\n\n /**\n *\n * @param {Array<string>} newAllowedDomains - new allowed domains to add to existing set of allowed domains\n * @returns {void}\n */\n addAllowedDomains(newAllowedDomains: Array<string>): void {\n this.allowedDomains = union(this.allowedDomains, newAllowedDomains);\n },\n\n /**\n * Update the current list of `ServiceDetail`s against a provided\n * service hostmap.\n * @emits ServiceCatalog#preauthorized\n * @emits ServiceCatalog#postauthorized\n * @param {ServiceGroup} serviceGroup\n * @param {Array<IServiceDetail>} serviceDetails\n * @param {timestamp<string>} timestamp of the catalog\n * @returns {void}\n */\n updateServiceGroups(\n serviceGroup: ServiceGroup,\n serviceDetails: Array<IServiceDetail>,\n timestamp?: string\n ) {\n const currentServiceDetails = this.serviceGroups[serviceGroup];\n\n const unusedServicesDetails = currentServiceDetails?.filter((serviceDetail) =>\n serviceDetails?.every(({id}) => id !== serviceDetail.id)\n );\n\n this._unloadServiceDetails(serviceGroup, unusedServicesDetails);\n\n serviceDetails?.forEach((serviceObj) => {\n const serviceDetail = this._getServiceDetail(serviceObj.id, serviceGroup);\n serviceObj?.serviceUrls?.sort((a, b) => {\n if (a.priority < 0 && b.priority < 0) return 0;\n if (a.priority < 0) return 1;\n if (b.priority < 0) return -1;\n\n return a.priority - b.priority;\n });\n if (serviceDetail) {\n serviceDetail.serviceUrls = serviceObj.serviceUrls || [];\n } else {\n this._loadServiceDetails(serviceGroup, [new ServiceDetail(serviceObj)]);\n }\n });\n\n this.timestamp = timestamp;\n this.status[serviceGroup].ready = true;\n this.trigger(serviceGroup);\n },\n\n /**\n * Wait until the service catalog is available,\n * or reject after a timeout of 60 seconds.\n * @param {ServiceGroup} serviceGroup\n * @param {number} [timeout] - in seconds\n * @returns {Promise<void>}\n */\n waitForCatalog(serviceGroup: ServiceGroup, timeout?: number): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (this.status[serviceGroup].ready) {\n resolve();\n }\n\n const validatedTimeout = typeof timeout === 'number' && timeout >= 0 ? timeout : 60;\n\n const timeoutTimer = setTimeout(\n () =>\n reject(\n new Error(\n `services: timeout occured while waiting for '${serviceGroup}' catalog to populate`\n )\n ),\n validatedTimeout * 1000\n );\n\n this.once(serviceGroup, () => {\n clearTimeout(timeoutTimer);\n resolve();\n });\n });\n },\n});\n\nexport default ServiceCatalog;\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AAA6C,SAAAG,2BAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,yBAAAC,OAAA,IAAAH,CAAA,CAAAI,gBAAA,KAAAJ,CAAA,qBAAAE,CAAA,QAAAG,cAAA,CAAAL,CAAA,MAAAE,CAAA,GAAAI,2BAAA,CAAAN,CAAA,MAAAC,CAAA,IAAAD,CAAA,uBAAAA,CAAA,CAAAO,MAAA,IAAAL,CAAA,KAAAF,CAAA,GAAAE,CAAA,OAAAM,EAAA,MAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,WAAAH,EAAA,IAAAR,CAAA,CAAAO,MAAA,KAAAK,IAAA,WAAAA,IAAA,MAAAC,KAAA,EAAAb,CAAA,CAAAQ,EAAA,UAAAP,CAAA,WAAAA,EAAAD,CAAA,UAAAA,CAAA,KAAAc,CAAA,EAAAL,CAAA,gBAAAM,SAAA,iJAAAC,CAAA,EAAAC,CAAA,OAAAC,CAAA,gBAAAR,CAAA,WAAAA,EAAA,IAAA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AMM,YAAY,GAAGC,UAAU,CAC7B;QAAA,OACEH,MAAM,CACJ,IAAII,KAAK,iDAAA/E,MAAA,CACyCF,YAAY,0BAC9D,CACF,CAAC;MAAA,GACH8E,gBAAgB,GAAG,IACrB,CAAC;MAEDJ,MAAI,CAACQ,IAAI,CAAClF,YAAY,EAAE,YAAM;QAC5BmF,YAAY,CAACJ,YAAY,CAAC;QAC1BH,OAAO,CAAC,CAAC;MACX,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;AACF,CAAC,CAAC;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAAjF,OAAA,GAEYtB,cAAc","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_ampersandState","_interopRequireDefault","require","_lodash","_serviceDetail","_domains","_createForOfIteratorHelper","r","e","t","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","length","_n","F","s","n","done","value","f","TypeError","o","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","_Array$from","test","Array","ServiceCatalog","AmpState","extend","namespace","props","serviceGroups","discovery","override","preauth","postauth","signin","status","ready","collecting","isReady","timestamp","allowedDomains","_getAllServiceDetails","serviceGroup","serviceDetails","concat","_toConsumableArray2","default","_getServiceDetail","clusterId","find","serviceDetail","id","_loadServiceDetails","_this","existingService","forEach","service","push","_unloadServiceDetails","_this2","splice","indexOf","clean","findClusterId","url","_allServiceDetails$fi","incomingUrlObj","URL","allServiceDetails","serviceUrls","_ref","host","_unused","undefined","findServiceFromClusterId","_ref2","arguments","serviceName","get","findServiceDetailFromUrl","_ref3","_iterator","_step","serviceUrl","startsWith","baseUrl","err","findAllowedDomain","matchAllowedDomain","getAllowedDomains","markFailedServiceUrl","serviceDetailWithFailedHost","failHost","setAllowedDomains","normalizeAllowedDomains","addAllowedDomains","newAllowedDomains","union","updateServiceGroups","_this3","currentServiceDetails","unusedServicesDetails","filter","every","_ref4","serviceObj","_serviceObj$serviceUr","sort","b","priority","ServiceDetail","trigger","waitForCatalog","timeout","_this4","_promise","resolve","reject","validatedTimeout","timeoutTimer","setTimeout","Error","once","clearTimeout","_default","exports"],"sources":["service-catalog.ts"],"sourcesContent":["import AmpState from 'ampersand-state';\n\nimport {union} from 'lodash';\nimport ServiceDetail from './service-detail';\nimport {IServiceDetail, ServiceGroup} from './types';\nimport {matchAllowedDomain, normalizeAllowedDomains} from '../domains';\n\n/**\n * @class\n */\nconst ServiceCatalog = AmpState.extend({\n namespace: 'ServiceCatalog',\n\n props: {\n serviceGroups: [\n 'object',\n true,\n () => ({\n discovery: [],\n override: [],\n preauth: [],\n postauth: [],\n signin: [],\n }),\n ],\n status: [\n 'object',\n true,\n () => ({\n discovery: {\n ready: false,\n collecting: false,\n },\n override: {\n ready: false,\n collecting: false,\n },\n preauth: {\n ready: false,\n collecting: false,\n },\n postauth: {\n ready: false,\n collecting: false,\n },\n signin: {\n ready: false,\n collecting: false,\n },\n }),\n ],\n isReady: ['boolean', false, false],\n timestamp: ['string', false, ''],\n allowedDomains: ['array', false, () => []],\n },\n\n /**\n * @private\n * Get all service details for a given service group or return all details if no group is specified.\n * @param {ServiceGroup} serviceGroup - The name of the service group to retrieve details for.\n * @returns {Array<IServiceDetail>} - An array of service details.\n */\n _getAllServiceDetails(serviceGroup?: ServiceGroup): Array<IServiceDetail> {\n const serviceDetails =\n typeof serviceGroup === 'string'\n ? this.serviceGroups[serviceGroup] || []\n : [\n ...this.serviceGroups.override,\n ...this.serviceGroups.postauth,\n ...this.serviceGroups.signin,\n ...this.serviceGroups.preauth,\n ...this.serviceGroups.discovery,\n ];\n\n return serviceDetails;\n },\n\n /**\n * @private\n * Search the service details array to locate a `ServiceDetails`\n * class object based on its id.\n * @param {string} clusterId\n * @param {ServiceGroup} [serviceGroup]\n * @returns {IServiceDetail}\n */\n _getServiceDetail(clusterId: string, serviceGroup?: ServiceGroup): IServiceDetail | undefined {\n const serviceDetails = this._getAllServiceDetails(serviceGroup);\n\n return serviceDetails.find((serviceDetail: IServiceDetail) => serviceDetail.id === clusterId);\n },\n\n /**\n * @private\n * Safely load one or more `ServiceDetail`s into this `ServiceCatalog` instance.\n * @param {ServiceGroup} serviceGroup\n * @param {Array<ServiceDetail>} serviceDetails\n * @returns {void}\n */\n _loadServiceDetails(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>): void {\n // declare namespaces outside of loop\n let existingService: IServiceDetail | undefined;\n\n serviceDetails.forEach((service) => {\n existingService = this._getServiceDetail(service.id, serviceGroup);\n\n if (!existingService) {\n this.serviceGroups[serviceGroup].push(service);\n }\n });\n },\n\n /**\n * @private\n * Safely unload one or more `ServiceDetail`s into this `Services` instance\n * @param {ServiceGroup} serviceGroup\n * @param {Array<ServiceDetail>} serviceDetails\n * @returns {void}\n */\n _unloadServiceDetails(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>): void {\n // declare namespaces outside of loop\n let existingService: IServiceDetail | undefined;\n\n serviceDetails?.forEach((service) => {\n existingService = this._getServiceDetail(service.id, serviceGroup);\n\n if (existingService) {\n this.serviceGroups[serviceGroup].splice(\n this.serviceGroups[serviceGroup].indexOf(existingService),\n 1\n );\n }\n });\n },\n\n /**\n * Clear all collected catalog data and reset catalog status.\n *\n * @returns {void}\n */\n clean(): void {\n this.serviceGroups.preauth.length = 0;\n this.serviceGroups.signin.length = 0;\n this.serviceGroups.postauth.length = 0;\n this.status.preauth = {ready: false};\n this.status.signin = {ready: false};\n this.status.postauth = {ready: false};\n },\n\n /**\n * Search over all service groups to find a cluster id based\n * on a given url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {string | undefined} - ClusterId of a given url\n */\n findClusterId(url: string): string | undefined {\n try {\n const incomingUrlObj = new URL(url);\n const allServiceDetails = this._getAllServiceDetails();\n\n return allServiceDetails.find((serviceDetail: IServiceDetail) =>\n serviceDetail.serviceUrls.find(({host}) => host === incomingUrlObj.host)\n )?.id;\n } catch {\n // If the URL is invalid or can't be found, return undefined\n return undefined;\n }\n },\n\n /**\n * Search over all service groups and return a service value from a provided\n * clusterId.\n * @param {object} params\n * @param {string} params.clusterId - clusterId of found service\n * @param {ServiceGroup} [params.serviceGroup] - specify service group\n * @returns {object} service\n * @returns {string} service.name\n * @returns {string} service.url\n */\n findServiceFromClusterId(\n {clusterId, serviceGroup} = {} as {clusterId: string; serviceGroup?: ServiceGroup}\n ): {name: string; url: string} | undefined {\n const serviceDetails = this._getServiceDetail(clusterId, serviceGroup);\n\n if (serviceDetails) {\n return {\n name: serviceDetails.serviceName,\n url: serviceDetails.get(),\n };\n }\n\n return undefined;\n },\n\n /**\n * Find a service based on the provided url.\n * @param {string} url - Must be parsable by `Url`\n * @returns {IServiceDetail} - ServiceDetail assocated with provided url\n */\n findServiceDetailFromUrl(url: string): IServiceDetail | undefined {\n const serviceDetails = this._getAllServiceDetails();\n\n return serviceDetails.find(({serviceUrls}) => {\n for (const serviceUrl of serviceUrls) {\n if (url.startsWith(serviceUrl.baseUrl)) {\n return true;\n }\n }\n\n return false;\n });\n },\n\n /**\n * Finds an allowed domain that matches a specific url. The url's hostname\n * must be the allowed domain itself or a subdomain of it.\n *\n * @param {string} url - The url to match the allowed domains against.\n * @returns {string} - The matching allowed domain.\n */\n findAllowedDomain(url: string): string {\n return matchAllowedDomain(url, this.allowedDomains);\n },\n\n /**\n * Get a service url from the current services list by name. Return undefined\n * if the service is not found.\n * @param {string} clusterId\n * @param {ServiceGroup} serviceGroup\n * @returns {string | undefined}\n */\n get(clusterId: string, serviceGroup?: ServiceGroup): string | undefined {\n const serviceDetail = this._getServiceDetail(clusterId, serviceGroup);\n\n return serviceDetail ? serviceDetail.get() : undefined;\n },\n\n /**\n * Get the current allowed domains list.\n *\n * @returns {Array<string>} - the current allowed domains list.\n */\n getAllowedDomains(): Array<string> {\n return [...this.allowedDomains];\n },\n\n /**\n * Mark a priority host service url as failed.\n * This will mark the host associated with the\n * `ServiceDetail` to be removed from the its\n * respective host array, and then return the next\n * viable host from the `ServiceDetail` host array,\n * or the `ServiceDetail` default url if no other priority\n * hosts are available, or if `noPriorityHosts` is set to\n * `true`.\n * @param {string} url\n * @returns {string}\n */\n markFailedServiceUrl(url: string): string | undefined {\n const serviceDetails = this._getAllServiceDetails();\n\n const serviceDetailWithFailedHost = serviceDetails.find((serviceDetail: IServiceDetail) =>\n serviceDetail.failHost(url)\n );\n\n // if we couldn't find the url we wanted to fail, return undefined\n if (!serviceDetailWithFailedHost) {\n return undefined;\n }\n\n return serviceDetailWithFailedHost.get();\n },\n\n /**\n * Set the allowed domains for the catalog.\n *\n * @param {Array<string>} allowedDomains - allowed domains to be assigned.\n * @returns {void}\n */\n setAllowedDomains(allowedDomains: Array<string>): void {\n this.allowedDomains = normalizeAllowedDomains(allowedDomains);\n },\n\n /**\n *\n * @param {Array<string>} newAllowedDomains - new allowed domains to add to existing set of allowed domains\n * @returns {void}\n */\n addAllowedDomains(newAllowedDomains: Array<string>): void {\n this.allowedDomains = union(this.allowedDomains, normalizeAllowedDomains(newAllowedDomains));\n },\n\n /**\n * Update the current list of `ServiceDetail`s against a provided\n * service hostmap.\n * @emits ServiceCatalog#preauthorized\n * @emits ServiceCatalog#postauthorized\n * @param {ServiceGroup} serviceGroup\n * @param {Array<IServiceDetail>} serviceDetails\n * @param {timestamp<string>} timestamp of the catalog\n * @returns {void}\n */\n updateServiceGroups(\n serviceGroup: ServiceGroup,\n serviceDetails: Array<IServiceDetail>,\n timestamp?: string\n ) {\n const currentServiceDetails = this.serviceGroups[serviceGroup];\n\n const unusedServicesDetails = currentServiceDetails?.filter((serviceDetail) =>\n serviceDetails?.every(({id}) => id !== serviceDetail.id)\n );\n\n this._unloadServiceDetails(serviceGroup, unusedServicesDetails);\n\n serviceDetails?.forEach((serviceObj) => {\n const serviceDetail = this._getServiceDetail(serviceObj.id, serviceGroup);\n serviceObj?.serviceUrls?.sort((a, b) => {\n if (a.priority < 0 && b.priority < 0) return 0;\n if (a.priority < 0) return 1;\n if (b.priority < 0) return -1;\n\n return a.priority - b.priority;\n });\n if (serviceDetail) {\n serviceDetail.serviceUrls = serviceObj.serviceUrls || [];\n } else {\n this._loadServiceDetails(serviceGroup, [new ServiceDetail(serviceObj)]);\n }\n });\n\n this.timestamp = timestamp;\n this.status[serviceGroup].ready = true;\n this.trigger(serviceGroup);\n },\n\n /**\n * Wait until the service catalog is available,\n * or reject after a timeout of 60 seconds.\n * @param {ServiceGroup} serviceGroup\n * @param {number} [timeout] - in seconds\n * @returns {Promise<void>}\n */\n waitForCatalog(serviceGroup: ServiceGroup, timeout?: number): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (this.status[serviceGroup].ready) {\n resolve();\n }\n\n const validatedTimeout = typeof timeout === 'number' && timeout >= 0 ? timeout : 60;\n\n const timeoutTimer = setTimeout(\n () =>\n reject(\n new Error(\n `services: timeout occured while waiting for '${serviceGroup}' catalog to populate`\n )\n ),\n validatedTimeout * 1000\n );\n\n this.once(serviceGroup, () => {\n clearTimeout(timeoutTimer);\n resolve();\n });\n });\n },\n});\n\nexport default ServiceCatalog;\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,QAAA,GAAAH,OAAA;AAAuE,SAAAI,2BAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,yBAAAC,OAAA,IAAAH,CAAA,CAAAI,gBAAA,KAAAJ,CAAA,qBAAAE,CAAA,QAAAG,cAAA,CAAAL,CAAA,MAAAE,CAAA,GAAAI,2BAAA,CAAAN,CAAA,MAAAC,CAAA,IAAAD,CAAA,uBAAAA,CAAA,CAAAO,MAAA,IAAAL,CAAA,KAAAF,CAAA,GAAAE,CAAA,OAAAM,EAAA,MAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,WAAAH,EAAA,IAAAR,CAAA,CAAAO,MAAA,KAAAK,IAAA,WAAA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AAGA,OAAO,GAAG,EAAE;MAEnF,IAAMM,YAAY,GAAGC,UAAU,CAC7B;QAAA,OACEH,MAAM,CACJ,IAAII,KAAK,iDAAA7E,MAAA,CACyCF,YAAY,0BAC9D,CACF,CAAC;MAAA,GACH4E,gBAAgB,GAAG,IACrB,CAAC;MAEDJ,MAAI,CAACQ,IAAI,CAAChF,YAAY,EAAE,YAAM;QAC5BiF,YAAY,CAACJ,YAAY,CAAC;QAC1BH,OAAO,CAAC,CAAC;MACX,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;AACF,CAAC,CAAC;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAA/E,OAAA,GAEYtB,cAAc","ignoreList":[]}
|
|
@@ -1546,7 +1546,7 @@ var Services = _webexPlugin.default.extend({
|
|
|
1546
1546
|
}, _callee5);
|
|
1547
1547
|
})));
|
|
1548
1548
|
},
|
|
1549
|
-
version: "3.12.0-next.
|
|
1549
|
+
version: "3.12.0-next.39"
|
|
1550
1550
|
});
|
|
1551
1551
|
/* eslint-enable no-underscore-dangle */
|
|
1552
1552
|
var _default = exports.default = Services;
|
package/dist/plugins/logger.js
CHANGED
|
@@ -57,7 +57,7 @@ var Logger = _webexPlugin.default.extend({
|
|
|
57
57
|
info: wrapConsoleMethod('info'),
|
|
58
58
|
debug: wrapConsoleMethod('debug'),
|
|
59
59
|
trace: wrapConsoleMethod('trace'),
|
|
60
|
-
version: "3.12.0-next.
|
|
60
|
+
version: "3.12.0-next.39"
|
|
61
61
|
});
|
|
62
62
|
(0, _webexCore.registerPlugin)('logger', Logger);
|
|
63
63
|
var _default = exports.default = Logger;
|
package/dist/webex-core.js
CHANGED
|
@@ -96,7 +96,7 @@ var MAX_FILE_SIZE_IN_MB = 2048;
|
|
|
96
96
|
* @class
|
|
97
97
|
*/
|
|
98
98
|
var WebexCore = _ampersandState.default.extend((_obj = {
|
|
99
|
-
version: "3.12.0-next.
|
|
99
|
+
version: "3.12.0-next.39",
|
|
100
100
|
children: {
|
|
101
101
|
internal: _webexInternalCore.default
|
|
102
102
|
},
|
|
@@ -634,7 +634,7 @@ var WebexCore = _ampersandState.default.extend((_obj = {
|
|
|
634
634
|
});
|
|
635
635
|
}
|
|
636
636
|
}, (0, _applyDecoratedDescriptor2.default)(_obj, "_uploadPhaseUpload", [_common.retry], (0, _getOwnPropertyDescriptor.default)(_obj, "_uploadPhaseUpload"), _obj), _obj));
|
|
637
|
-
WebexCore.version = "3.12.0-next.
|
|
637
|
+
WebexCore.version = "3.12.0-next.39";
|
|
638
638
|
(0, _webexInternalCorePluginMixin.default)(_webexInternalCore.default, _config.default, interceptors);
|
|
639
639
|
(0, _webexCorePluginMixin.default)(WebexCore, _config.default, interceptors);
|
|
640
640
|
var _default = exports.default = WebexCore;
|
package/package.json
CHANGED
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"@sinonjs/fake-timers": "^6.0.1",
|
|
34
34
|
"@webex/babel-config-legacy": "0.0.0",
|
|
35
35
|
"@webex/eslint-config-legacy": "0.0.0",
|
|
36
|
-
"@webex/internal-plugin-device": "3.12.0-next.
|
|
36
|
+
"@webex/internal-plugin-device": "3.12.0-next.39",
|
|
37
37
|
"@webex/jest-config-legacy": "0.0.0",
|
|
38
38
|
"@webex/legacy-tools": "0.0.0",
|
|
39
|
-
"@webex/plugin-logger": "3.12.0-next.
|
|
39
|
+
"@webex/plugin-logger": "3.12.0-next.39",
|
|
40
40
|
"@webex/test-helper-chai": "3.12.0-next.5",
|
|
41
41
|
"@webex/test-helper-make-local-url": "3.12.0-next.5",
|
|
42
42
|
"@webex/test-helper-mocha": "3.12.0-next.5",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"test:style": "eslint ./src/**/*.*",
|
|
74
74
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
75
75
|
},
|
|
76
|
-
"version": "3.12.0-next.
|
|
76
|
+
"version": "3.12.0-next.39"
|
|
77
77
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import Url from 'url';
|
|
2
|
+
|
|
3
|
+
import {uniq} from 'lodash';
|
|
4
|
+
|
|
5
|
+
// Canonicalise a hostname for comparison: lowercase, drop the brackets around
|
|
6
|
+
// an IPv6 literal, and drop leading/trailing dots. DNS treats `Example.com`,
|
|
7
|
+
// `example.com.` and `example.com` as the same name.
|
|
8
|
+
//
|
|
9
|
+
// Node's `url.domainToASCII` looks like the standard way to do this, but the
|
|
10
|
+
// `url` polyfill this package bundles for the browser does not implement it,
|
|
11
|
+
// so it cannot be used here. It also leaves trailing dots in place.
|
|
12
|
+
const normalizeHostname = (value: string): string =>
|
|
13
|
+
typeof value === 'string'
|
|
14
|
+
? value
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/^\[|\]$/g, '')
|
|
17
|
+
.replace(/^\.+/, '')
|
|
18
|
+
.replace(/\.+$/, '')
|
|
19
|
+
: '';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Canonicalise a list of configured allowed domains, discarding any entry that
|
|
23
|
+
* is not a usable hostname. Callers normalise on the way in so the stored list
|
|
24
|
+
* is already canonical, rather than re-deriving it on every request.
|
|
25
|
+
*
|
|
26
|
+
* @param {Array<string>} allowedDomains - The configured allowed domains.
|
|
27
|
+
* @returns {Array<string>} - Normalized, de-duplicated, non-empty entries.
|
|
28
|
+
*/
|
|
29
|
+
export const normalizeAllowedDomains = (allowedDomains: Array<string>): Array<string> =>
|
|
30
|
+
uniq(
|
|
31
|
+
(Array.isArray(allowedDomains) ? allowedDomains : []).map(normalizeHostname).filter(Boolean)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Determine if a hostname is covered by an allowed domain, matching only on DNS
|
|
36
|
+
* label boundaries, so that a hostname is allowed only when it is the domain
|
|
37
|
+
* itself or a subdomain of it. Matching on a substring instead would treat
|
|
38
|
+
* unrelated hostnames that merely contain the domain as allowed.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} hostname - Hostname to test. Must not include a port.
|
|
41
|
+
* @param {string} allowedDomain - The configured allowed domain.
|
|
42
|
+
* @returns {boolean} - True when the hostname is the domain or a subdomain of it.
|
|
43
|
+
*/
|
|
44
|
+
const hostnameMatchesDomain = (hostname: string, allowedDomain: string): boolean => {
|
|
45
|
+
// The stored list is normalized on write, but `allowedDomains` is a public
|
|
46
|
+
// property, so normalize again here rather than trust it.
|
|
47
|
+
const host = normalizeHostname(hostname);
|
|
48
|
+
const domain = normalizeHostname(allowedDomain);
|
|
49
|
+
|
|
50
|
+
return !!host && !!domain && (host === domain || host.endsWith(`.${domain}`));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Find the allowed domain covering a url, or `undefined` if there is none.
|
|
55
|
+
*
|
|
56
|
+
* Parsing lives here rather than in the callers, and deliberately uses both url
|
|
57
|
+
* parsers, because this check gates an `Authorization` header. The two
|
|
58
|
+
* transports behind `@webex/http-core` do not use the same url parser: the
|
|
59
|
+
* browser transport parses per WHATWG, the node transport uses Node's legacy
|
|
60
|
+
* `Url.parse`, and for some inputs the two resolve different hosts.
|
|
61
|
+
*
|
|
62
|
+
* Rather than picking one, require both to agree and fail closed when they do
|
|
63
|
+
* not, so this check can never authorize a host that differs from the one a
|
|
64
|
+
* transport would actually connect to. Do not narrow this to a single parser.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} url - The url to match the allowed domains against.
|
|
67
|
+
* @param {Array<string>} allowedDomains - The configured allowed domains.
|
|
68
|
+
* @returns {string} - The matching allowed domain, or undefined if there is none.
|
|
69
|
+
*/
|
|
70
|
+
export const matchAllowedDomain = (
|
|
71
|
+
url: string,
|
|
72
|
+
allowedDomains: Array<string>
|
|
73
|
+
): string | undefined => {
|
|
74
|
+
let hostname: string;
|
|
75
|
+
let legacyHostname: string;
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
({hostname} = new URL(url));
|
|
79
|
+
({hostname: legacyHostname} = Url.parse(url));
|
|
80
|
+
} catch {
|
|
81
|
+
// Not a parsable absolute url, so it cannot belong to an allowed domain.
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (normalizeHostname(hostname) !== normalizeHostname(legacyHostname)) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (allowedDomains || []).find((allowedDomain) =>
|
|
90
|
+
hostnameMatchesDomain(hostname, allowedDomain)
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default matchAllowedDomain;
|
|
@@ -4,6 +4,7 @@ import AmpState from 'ampersand-state';
|
|
|
4
4
|
|
|
5
5
|
import {union} from 'lodash';
|
|
6
6
|
import ServiceUrl from './service-url';
|
|
7
|
+
import {matchAllowedDomain, normalizeAllowedDomains} from '../domains';
|
|
7
8
|
|
|
8
9
|
/* eslint-disable no-underscore-dangle */
|
|
9
10
|
/**
|
|
@@ -268,19 +269,14 @@ const ServiceCatalog = AmpState.extend({
|
|
|
268
269
|
},
|
|
269
270
|
|
|
270
271
|
/**
|
|
271
|
-
* Finds an allowed domain that matches a specific url.
|
|
272
|
+
* Finds an allowed domain that matches a specific url. The url's hostname
|
|
273
|
+
* must be the allowed domain itself or a subdomain of it.
|
|
272
274
|
*
|
|
273
275
|
* @param {string} url - The url to match the allowed domains against.
|
|
274
276
|
* @returns {string} - The matching allowed domain.
|
|
275
277
|
*/
|
|
276
278
|
findAllowedDomain(url) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (!urlObj.host) {
|
|
280
|
-
return undefined;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return this.allowedDomains.find((allowedDomain) => urlObj.host.includes(allowedDomain));
|
|
279
|
+
return matchAllowedDomain(url, this.allowedDomains);
|
|
284
280
|
},
|
|
285
281
|
|
|
286
282
|
/**
|
|
@@ -367,7 +363,7 @@ const ServiceCatalog = AmpState.extend({
|
|
|
367
363
|
* @returns {void}
|
|
368
364
|
*/
|
|
369
365
|
setAllowedDomains(allowedDomains) {
|
|
370
|
-
this.allowedDomains =
|
|
366
|
+
this.allowedDomains = normalizeAllowedDomains(allowedDomains);
|
|
371
367
|
},
|
|
372
368
|
|
|
373
369
|
/**
|
|
@@ -376,7 +372,7 @@ const ServiceCatalog = AmpState.extend({
|
|
|
376
372
|
* @returns {void}
|
|
377
373
|
*/
|
|
378
374
|
addAllowedDomains(newAllowedDomains) {
|
|
379
|
-
this.allowedDomains = union(this.allowedDomains, newAllowedDomains);
|
|
375
|
+
this.allowedDomains = union(this.allowedDomains, normalizeAllowedDomains(newAllowedDomains));
|
|
380
376
|
},
|
|
381
377
|
|
|
382
378
|
/**
|
|
@@ -3,6 +3,7 @@ import AmpState from 'ampersand-state';
|
|
|
3
3
|
import {union} from 'lodash';
|
|
4
4
|
import ServiceDetail from './service-detail';
|
|
5
5
|
import {IServiceDetail, ServiceGroup} from './types';
|
|
6
|
+
import {matchAllowedDomain, normalizeAllowedDomains} from '../domains';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @class
|
|
@@ -210,20 +211,14 @@ const ServiceCatalog = AmpState.extend({
|
|
|
210
211
|
},
|
|
211
212
|
|
|
212
213
|
/**
|
|
213
|
-
* Finds an allowed domain that matches a specific url.
|
|
214
|
+
* Finds an allowed domain that matches a specific url. The url's hostname
|
|
215
|
+
* must be the allowed domain itself or a subdomain of it.
|
|
214
216
|
*
|
|
215
217
|
* @param {string} url - The url to match the allowed domains against.
|
|
216
218
|
* @returns {string} - The matching allowed domain.
|
|
217
219
|
*/
|
|
218
220
|
findAllowedDomain(url: string): string {
|
|
219
|
-
|
|
220
|
-
const urlObj = new URL(url);
|
|
221
|
-
|
|
222
|
-
return this.allowedDomains.find((allowedDomain) => urlObj.host.includes(allowedDomain));
|
|
223
|
-
} catch {
|
|
224
|
-
// If the URL is invalid or can't be found, return undefined
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
221
|
+
return matchAllowedDomain(url, this.allowedDomains);
|
|
227
222
|
},
|
|
228
223
|
|
|
229
224
|
/**
|
|
@@ -282,7 +277,7 @@ const ServiceCatalog = AmpState.extend({
|
|
|
282
277
|
* @returns {void}
|
|
283
278
|
*/
|
|
284
279
|
setAllowedDomains(allowedDomains: Array<string>): void {
|
|
285
|
-
this.allowedDomains =
|
|
280
|
+
this.allowedDomains = normalizeAllowedDomains(allowedDomains);
|
|
286
281
|
},
|
|
287
282
|
|
|
288
283
|
/**
|
|
@@ -291,7 +286,7 @@ const ServiceCatalog = AmpState.extend({
|
|
|
291
286
|
* @returns {void}
|
|
292
287
|
*/
|
|
293
288
|
addAllowedDomains(newAllowedDomains: Array<string>): void {
|
|
294
|
-
this.allowedDomains = union(this.allowedDomains, newAllowedDomains);
|
|
289
|
+
this.allowedDomains = union(this.allowedDomains, normalizeAllowedDomains(newAllowedDomains));
|
|
295
290
|
},
|
|
296
291
|
|
|
297
292
|
/**
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
AuthInterceptor,
|
|
15
15
|
config,
|
|
16
16
|
Credentials,
|
|
17
|
+
Services,
|
|
18
|
+
ServicesV2,
|
|
17
19
|
WebexHttpError,
|
|
18
20
|
Token,
|
|
19
21
|
serviceConstants,
|
|
@@ -380,6 +382,60 @@ describe('webex-core', () => {
|
|
|
380
382
|
});
|
|
381
383
|
});
|
|
382
384
|
|
|
385
|
+
describe('#onRequest() against a real service catalog', () => {
|
|
386
|
+
// The cases above stub `isAllowedDomainUrl`, so they answer the
|
|
387
|
+
// allowed-domain question themselves and cannot show that the catalog
|
|
388
|
+
// matcher is reached by the code that attaches the token. These use a
|
|
389
|
+
// real catalog and real allowed-domain methods.
|
|
390
|
+
[
|
|
391
|
+
{name: 'Services', Constructor: Services},
|
|
392
|
+
{name: 'ServicesV2', Constructor: ServicesV2},
|
|
393
|
+
].forEach(({name, Constructor}) => {
|
|
394
|
+
describe(name, () => {
|
|
395
|
+
let getUserToken;
|
|
396
|
+
|
|
397
|
+
beforeEach(() => {
|
|
398
|
+
const services = new Constructor(undefined, {parent: webex});
|
|
399
|
+
|
|
400
|
+
services._getCatalog().setAllowedDomains(['webex.com']);
|
|
401
|
+
// the catalog holds no services, so a url that is not covered by
|
|
402
|
+
// an allowed domain has nothing else to authorize it
|
|
403
|
+
services.waitForService = sinon.stub().rejects(new Error('no such service'));
|
|
404
|
+
|
|
405
|
+
webex.internal.services = services;
|
|
406
|
+
getUserToken = sinon.spy(webex.credentials, 'getUserToken');
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
afterEach(() => {
|
|
410
|
+
getUserToken.restore();
|
|
411
|
+
delete webex.internal.services;
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('adds the authorization header for a url under an allowed domain', () =>
|
|
415
|
+
interceptor
|
|
416
|
+
.onRequest({uri: 'https://api.webex.com/resource', headers: {}})
|
|
417
|
+
.then((options) => {
|
|
418
|
+
assert.equal(
|
|
419
|
+
options.headers.authorization,
|
|
420
|
+
webex.credentials.supertoken.toString()
|
|
421
|
+
);
|
|
422
|
+
assert.calledOnce(getUserToken);
|
|
423
|
+
}));
|
|
424
|
+
|
|
425
|
+
[
|
|
426
|
+
'https://notwebex.com/resource',
|
|
427
|
+
'https://webex.com.unrelated.example/resource',
|
|
428
|
+
].forEach((uri) => {
|
|
429
|
+
it(`does not add the authorization header for ${uri}`, () =>
|
|
430
|
+
interceptor.onRequest({uri, headers: {}}).then((options) => {
|
|
431
|
+
assert.notProperty(options.headers, 'authorization');
|
|
432
|
+
assert.notCalled(getUserToken);
|
|
433
|
+
}));
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
383
439
|
describe('#onResponseError()', () => {
|
|
384
440
|
describe('when the server responds with 401', () => {
|
|
385
441
|
nodeOnly(it)('refreshes the access token and replays the request', () => {
|
|
@@ -101,7 +101,24 @@ describe('webex-core', () => {
|
|
|
101
101
|
const domains = [];
|
|
102
102
|
|
|
103
103
|
beforeEach(() => {
|
|
104
|
-
|
|
104
|
+
// Shaped like a real catalog rather than a tidy list: the commercial
|
|
105
|
+
// domains the sdk ships with, a multi-part suffix, sites added at
|
|
106
|
+
// runtime from meeting preferences, an entry that overlaps another,
|
|
107
|
+
// and an unset entry, which callers can add and which must match
|
|
108
|
+
// nothing.
|
|
109
|
+
domains.push(
|
|
110
|
+
'wbx2.com',
|
|
111
|
+
'ciscospark.com',
|
|
112
|
+
'webex.com',
|
|
113
|
+
'webexapis.com',
|
|
114
|
+
'broadcloud.com.au',
|
|
115
|
+
'webexgov.us',
|
|
116
|
+
'example-a.com',
|
|
117
|
+
'example-b.com',
|
|
118
|
+
'example-c.com',
|
|
119
|
+
'go.example-a.com',
|
|
120
|
+
''
|
|
121
|
+
);
|
|
105
122
|
|
|
106
123
|
catalog.setAllowedDomains(domains);
|
|
107
124
|
});
|
|
@@ -110,10 +127,60 @@ describe('webex-core', () => {
|
|
|
110
127
|
domains.length = 0;
|
|
111
128
|
});
|
|
112
129
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
[
|
|
131
|
+
// real service hosts resolve to the entry that covers them
|
|
132
|
+
['https://u2c-a.wbx2.com/u2c/api/v1/limited/catalog', 'wbx2.com'],
|
|
133
|
+
['https://conv-a.wbx2.com/conversation/api/v1/conversations', 'wbx2.com'],
|
|
134
|
+
['https://foobar.ciscospark.com/resource/id', 'ciscospark.com'],
|
|
135
|
+
['https://idbroker.webex.com/idb/token', 'webex.com'],
|
|
136
|
+
['https://webexapis.com/v1/people/me', 'webexapis.com'],
|
|
137
|
+
// an entry is not required to be a bare registrable domain
|
|
138
|
+
['https://foo.broadcloud.com.au/resource/id', 'broadcloud.com.au'],
|
|
139
|
+
['https://a.b.webexgov.us/resource/id', 'webexgov.us'],
|
|
140
|
+
// the domain itself and its subdomains match
|
|
141
|
+
['https://example-a.com/resource/id', 'example-a.com'],
|
|
142
|
+
['https://sub.example-b.com/resource/id', 'example-b.com'],
|
|
143
|
+
['https://deep.sub.example-c.com/resource/id', 'example-c.com'],
|
|
144
|
+
// overlapping entries resolve to the first covering entry in the list
|
|
145
|
+
['https://go.example-a.com/resource/id', 'example-a.com'],
|
|
146
|
+
// an explicit port must not defeat the match
|
|
147
|
+
['https://example-a.com:8443/resource/id', 'example-a.com'],
|
|
148
|
+
['https://u2c-a.wbx2.com:8000/resource/id', 'wbx2.com'],
|
|
149
|
+
// hostname comparison is case insensitive
|
|
150
|
+
['https://U2C-A.WBX2.COM/resource/id', 'wbx2.com'],
|
|
151
|
+
// a trailing dot is the same name
|
|
152
|
+
['https://u2c-a.wbx2.com./resource/id', 'wbx2.com'],
|
|
153
|
+
// a sibling registrable domain must not match
|
|
154
|
+
['https://notwebex.com/resource/id', undefined],
|
|
155
|
+
['https://mywebexgov.us/resource/id', undefined],
|
|
156
|
+
['https://webex.company/resource/id', undefined],
|
|
157
|
+
['https://webex.com-unrelated.example/resource/id', undefined],
|
|
158
|
+
['https://example-a.community/resource/id', undefined],
|
|
159
|
+
// a partial label must not match, even against a multi-part entry
|
|
160
|
+
['https://broadcloud.com/resource/id', undefined],
|
|
161
|
+
// the domain matches only as a suffix, on a label boundary
|
|
162
|
+
['https://webex.com.unrelated.example/resource/id', undefined],
|
|
163
|
+
['https://unrelated.example/webex.com/resource/id', undefined],
|
|
164
|
+
['https://unrelated.example/?next=https://webex.com', undefined],
|
|
165
|
+
// userinfo is not the host
|
|
166
|
+
['https://webex.com@unrelated.example/resource/id', undefined],
|
|
167
|
+
// an encoded or unusual separator is not a label boundary, and the url
|
|
168
|
+
// parsers used by the transports do not agree on where these end the
|
|
169
|
+
// host, so they must not resolve to an allowed domain
|
|
170
|
+
['https://webex.com%2eunrelated.example/resource/id', undefined],
|
|
171
|
+
['https://webex.com%2Eunrelated.example/resource/id', undefined],
|
|
172
|
+
['https://unrelated.example%2ewebex.com/resource/id', undefined],
|
|
173
|
+
['https://unrelated.example%2Ewebex.com/resource/id', undefined],
|
|
174
|
+
['https://unrelated.example;.webex.com/resource/id', undefined],
|
|
175
|
+
// an empty allowed domain entry matches nothing
|
|
176
|
+
['https://unrelated.example/resource/id', undefined],
|
|
177
|
+
// unparseable urls
|
|
178
|
+
['', undefined],
|
|
179
|
+
['not a url', undefined],
|
|
180
|
+
].forEach(([url, expected]) => {
|
|
181
|
+
it(`returns ${expected} for ${url || '<empty>'}`, () => {
|
|
182
|
+
assert.equal(catalog.findAllowedDomain(url), expected);
|
|
183
|
+
});
|
|
117
184
|
});
|
|
118
185
|
});
|
|
119
186
|
|
|
@@ -121,7 +188,7 @@ describe('webex-core', () => {
|
|
|
121
188
|
const domains = [];
|
|
122
189
|
|
|
123
190
|
beforeEach(() => {
|
|
124
|
-
domains.push('example-a', 'example-b', 'example-c');
|
|
191
|
+
domains.push('example-a.com', 'example-b.com', 'example-c.com');
|
|
125
192
|
|
|
126
193
|
catalog.setAllowedDomains(domains);
|
|
127
194
|
});
|
|
@@ -160,7 +227,7 @@ describe('webex-core', () => {
|
|
|
160
227
|
const domains = [];
|
|
161
228
|
|
|
162
229
|
beforeEach(() => {
|
|
163
|
-
domains.push('example-a', 'example-b', 'example-c');
|
|
230
|
+
domains.push('example-a.com', 'example-b.com', 'example-c.com');
|
|
164
231
|
|
|
165
232
|
catalog.setAllowedDomains(domains);
|
|
166
233
|
});
|
|
@@ -170,19 +237,31 @@ describe('webex-core', () => {
|
|
|
170
237
|
});
|
|
171
238
|
|
|
172
239
|
it('sets the allowed domain entries to new values', () => {
|
|
173
|
-
const newValues = ['example-d', 'example-e', 'example-f'];
|
|
240
|
+
const newValues = ['example-d.com', 'example-e.com', 'example-f.com'];
|
|
174
241
|
|
|
175
242
|
catalog.setAllowedDomains(newValues);
|
|
176
243
|
|
|
177
244
|
assert.notDeepInclude(domains, newValues);
|
|
178
245
|
});
|
|
246
|
+
|
|
247
|
+
it('canonicalizes entries and discards those that are not usable', () => {
|
|
248
|
+
catalog.setAllowedDomains([
|
|
249
|
+
'Example-D.COM',
|
|
250
|
+
'example-d.com',
|
|
251
|
+
'example-e.com.',
|
|
252
|
+
'',
|
|
253
|
+
undefined,
|
|
254
|
+
]);
|
|
255
|
+
|
|
256
|
+
assert.deepEqual(catalog.getAllowedDomains(), ['example-d.com', 'example-e.com']);
|
|
257
|
+
});
|
|
179
258
|
});
|
|
180
259
|
|
|
181
260
|
describe('#addAllowedDomains()', () => {
|
|
182
261
|
const domains = [];
|
|
183
262
|
|
|
184
263
|
beforeEach(() => {
|
|
185
|
-
domains.push('example-a', 'example-b', 'example-c');
|
|
264
|
+
domains.push('example-a.com', 'example-b.com', 'example-c.com');
|
|
186
265
|
|
|
187
266
|
catalog.setAllowedDomains(domains);
|
|
188
267
|
});
|
|
@@ -192,13 +271,16 @@ describe('webex-core', () => {
|
|
|
192
271
|
});
|
|
193
272
|
|
|
194
273
|
it('merge the allowed domain entries with new values', () => {
|
|
195
|
-
const newValues = ['example-c', 'example-e', 'example-f'];
|
|
274
|
+
const newValues = ['example-c.com', 'example-e.com', 'example-f.com'];
|
|
196
275
|
|
|
197
276
|
catalog.addAllowedDomains(newValues);
|
|
198
277
|
|
|
199
278
|
const list = catalog.getAllowedDomains();
|
|
200
279
|
|
|
201
|
-
assert.match(
|
|
280
|
+
assert.match(
|
|
281
|
+
['example-a.com', 'example-b.com', 'example-c.com', 'example-e.com', 'example-f.com'],
|
|
282
|
+
list
|
|
283
|
+
);
|
|
202
284
|
});
|
|
203
285
|
});
|
|
204
286
|
|
|
@@ -101,7 +101,24 @@ describe('webex-core', () => {
|
|
|
101
101
|
const domains = [];
|
|
102
102
|
|
|
103
103
|
beforeEach(() => {
|
|
104
|
-
|
|
104
|
+
// Shaped like a real catalog rather than a tidy list: the commercial
|
|
105
|
+
// domains the sdk ships with, a multi-part suffix, sites added at
|
|
106
|
+
// runtime from meeting preferences, an entry that overlaps another,
|
|
107
|
+
// and an unset entry, which callers can add and which must match
|
|
108
|
+
// nothing.
|
|
109
|
+
domains.push(
|
|
110
|
+
'wbx2.com',
|
|
111
|
+
'ciscospark.com',
|
|
112
|
+
'webex.com',
|
|
113
|
+
'webexapis.com',
|
|
114
|
+
'broadcloud.com.au',
|
|
115
|
+
'webexgov.us',
|
|
116
|
+
'example-a.com',
|
|
117
|
+
'example-b.com',
|
|
118
|
+
'example-c.com',
|
|
119
|
+
'go.example-a.com',
|
|
120
|
+
''
|
|
121
|
+
);
|
|
105
122
|
|
|
106
123
|
catalog.setAllowedDomains(domains);
|
|
107
124
|
});
|
|
@@ -110,10 +127,60 @@ describe('webex-core', () => {
|
|
|
110
127
|
domains.length = 0;
|
|
111
128
|
});
|
|
112
129
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
[
|
|
131
|
+
// real service hosts resolve to the entry that covers them
|
|
132
|
+
['https://u2c-a.wbx2.com/u2c/api/v1/limited/catalog', 'wbx2.com'],
|
|
133
|
+
['https://conv-a.wbx2.com/conversation/api/v1/conversations', 'wbx2.com'],
|
|
134
|
+
['https://foobar.ciscospark.com/resource/id', 'ciscospark.com'],
|
|
135
|
+
['https://idbroker.webex.com/idb/token', 'webex.com'],
|
|
136
|
+
['https://webexapis.com/v1/people/me', 'webexapis.com'],
|
|
137
|
+
// an entry is not required to be a bare registrable domain
|
|
138
|
+
['https://foo.broadcloud.com.au/resource/id', 'broadcloud.com.au'],
|
|
139
|
+
['https://a.b.webexgov.us/resource/id', 'webexgov.us'],
|
|
140
|
+
// the domain itself and its subdomains match
|
|
141
|
+
['https://example-a.com/resource/id', 'example-a.com'],
|
|
142
|
+
['https://sub.example-b.com/resource/id', 'example-b.com'],
|
|
143
|
+
['https://deep.sub.example-c.com/resource/id', 'example-c.com'],
|
|
144
|
+
// overlapping entries resolve to the first covering entry in the list
|
|
145
|
+
['https://go.example-a.com/resource/id', 'example-a.com'],
|
|
146
|
+
// an explicit port must not defeat the match
|
|
147
|
+
['https://example-a.com:8443/resource/id', 'example-a.com'],
|
|
148
|
+
['https://u2c-a.wbx2.com:8000/resource/id', 'wbx2.com'],
|
|
149
|
+
// hostname comparison is case insensitive
|
|
150
|
+
['https://U2C-A.WBX2.COM/resource/id', 'wbx2.com'],
|
|
151
|
+
// a trailing dot is the same name
|
|
152
|
+
['https://u2c-a.wbx2.com./resource/id', 'wbx2.com'],
|
|
153
|
+
// a sibling registrable domain must not match
|
|
154
|
+
['https://notwebex.com/resource/id', undefined],
|
|
155
|
+
['https://mywebexgov.us/resource/id', undefined],
|
|
156
|
+
['https://webex.company/resource/id', undefined],
|
|
157
|
+
['https://webex.com-unrelated.example/resource/id', undefined],
|
|
158
|
+
['https://example-a.community/resource/id', undefined],
|
|
159
|
+
// a partial label must not match, even against a multi-part entry
|
|
160
|
+
['https://broadcloud.com/resource/id', undefined],
|
|
161
|
+
// the domain matches only as a suffix, on a label boundary
|
|
162
|
+
['https://webex.com.unrelated.example/resource/id', undefined],
|
|
163
|
+
['https://unrelated.example/webex.com/resource/id', undefined],
|
|
164
|
+
['https://unrelated.example/?next=https://webex.com', undefined],
|
|
165
|
+
// userinfo is not the host
|
|
166
|
+
['https://webex.com@unrelated.example/resource/id', undefined],
|
|
167
|
+
// an encoded or unusual separator is not a label boundary, and the url
|
|
168
|
+
// parsers used by the transports do not agree on where these end the
|
|
169
|
+
// host, so they must not resolve to an allowed domain
|
|
170
|
+
['https://webex.com%2eunrelated.example/resource/id', undefined],
|
|
171
|
+
['https://webex.com%2Eunrelated.example/resource/id', undefined],
|
|
172
|
+
['https://unrelated.example%2ewebex.com/resource/id', undefined],
|
|
173
|
+
['https://unrelated.example%2Ewebex.com/resource/id', undefined],
|
|
174
|
+
['https://unrelated.example;.webex.com/resource/id', undefined],
|
|
175
|
+
// an empty allowed domain entry matches nothing
|
|
176
|
+
['https://unrelated.example/resource/id', undefined],
|
|
177
|
+
// unparseable urls
|
|
178
|
+
['', undefined],
|
|
179
|
+
['not a url', undefined],
|
|
180
|
+
].forEach(([url, expected]) => {
|
|
181
|
+
it(`returns ${expected} for ${url || '<empty>'}`, () => {
|
|
182
|
+
assert.equal(catalog.findAllowedDomain(url), expected);
|
|
183
|
+
});
|
|
117
184
|
});
|
|
118
185
|
});
|
|
119
186
|
|
|
@@ -121,7 +188,7 @@ describe('webex-core', () => {
|
|
|
121
188
|
const domains = [];
|
|
122
189
|
|
|
123
190
|
beforeEach(() => {
|
|
124
|
-
domains.push('example-a', 'example-b', 'example-c');
|
|
191
|
+
domains.push('example-a.com', 'example-b.com', 'example-c.com');
|
|
125
192
|
|
|
126
193
|
catalog.setAllowedDomains(domains);
|
|
127
194
|
});
|
|
@@ -141,7 +208,7 @@ describe('webex-core', () => {
|
|
|
141
208
|
const domains = [];
|
|
142
209
|
|
|
143
210
|
beforeEach(() => {
|
|
144
|
-
domains.push('example-a', 'example-b', 'example-c');
|
|
211
|
+
domains.push('example-a.com', 'example-b.com', 'example-c.com');
|
|
145
212
|
|
|
146
213
|
catalog.setAllowedDomains(domains);
|
|
147
214
|
});
|
|
@@ -151,19 +218,31 @@ describe('webex-core', () => {
|
|
|
151
218
|
});
|
|
152
219
|
|
|
153
220
|
it('sets the allowed domain entries to new values', () => {
|
|
154
|
-
const newValues = ['example-d', 'example-e', 'example-f'];
|
|
221
|
+
const newValues = ['example-d.com', 'example-e.com', 'example-f.com'];
|
|
155
222
|
|
|
156
223
|
catalog.setAllowedDomains(newValues);
|
|
157
224
|
|
|
158
225
|
assert.notDeepInclude(domains, newValues);
|
|
159
226
|
});
|
|
227
|
+
|
|
228
|
+
it('canonicalizes entries and discards those that are not usable', () => {
|
|
229
|
+
catalog.setAllowedDomains([
|
|
230
|
+
'Example-D.COM',
|
|
231
|
+
'example-d.com',
|
|
232
|
+
'example-e.com.',
|
|
233
|
+
'',
|
|
234
|
+
undefined,
|
|
235
|
+
]);
|
|
236
|
+
|
|
237
|
+
assert.deepEqual(catalog.getAllowedDomains(), ['example-d.com', 'example-e.com']);
|
|
238
|
+
});
|
|
160
239
|
});
|
|
161
240
|
|
|
162
241
|
describe('#addAllowedDomains()', () => {
|
|
163
242
|
const domains = [];
|
|
164
243
|
|
|
165
244
|
beforeEach(() => {
|
|
166
|
-
domains.push('example-a', 'example-b', 'example-c');
|
|
245
|
+
domains.push('example-a.com', 'example-b.com', 'example-c.com');
|
|
167
246
|
|
|
168
247
|
catalog.setAllowedDomains(domains);
|
|
169
248
|
});
|
|
@@ -173,13 +252,16 @@ describe('webex-core', () => {
|
|
|
173
252
|
});
|
|
174
253
|
|
|
175
254
|
it('merge the allowed domain entries with new values', () => {
|
|
176
|
-
const newValues = ['example-c', 'example-e', 'example-f'];
|
|
255
|
+
const newValues = ['example-c.com', 'example-e.com', 'example-f.com'];
|
|
177
256
|
|
|
178
257
|
catalog.addAllowedDomains(newValues);
|
|
179
258
|
|
|
180
259
|
const list = catalog.getAllowedDomains();
|
|
181
260
|
|
|
182
|
-
assert.match(
|
|
261
|
+
assert.match(
|
|
262
|
+
['example-a.com', 'example-b.com', 'example-c.com', 'example-e.com', 'example-f.com'],
|
|
263
|
+
list
|
|
264
|
+
);
|
|
183
265
|
});
|
|
184
266
|
});
|
|
185
267
|
|