@webex/webex-core 3.13.0-next.4 → 3.13.0-next.6
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/.repo-context.json +1 -1
- package/.sdd/manifest.json +14 -4
- package/AGENTS.md +2 -2
- package/dist/interceptors/auth.js +10 -1
- package/dist/interceptors/auth.js.map +1 -1
- 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/interceptors/service.js +5 -1
- package/dist/lib/interceptors/service.js.map +1 -1
- package/dist/lib/services/catalog-auth.js +114 -0
- package/dist/lib/services/catalog-auth.js.map +1 -0
- package/dist/lib/services/services.js +46 -3
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/services-v2/services-v2.js +40 -3
- package/dist/lib/services-v2/services-v2.js.map +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/docs/getting-started.md +2 -2
- package/package.json +13 -13
- package/src/interceptors/auth.js +14 -1
- package/src/lib/interceptors/service.js +11 -3
- package/src/lib/services/catalog-auth.js +112 -0
- package/src/lib/services/docs/README.md +4 -4
- package/src/lib/services/services.js +54 -2
- package/src/lib/services-v2/docs/README.md +4 -4
- package/src/lib/services-v2/services-v2.ts +48 -2
- package/test/unit/spec/interceptors/auth.js +35 -0
- package/test/unit/spec/services/interceptors/service.js +35 -1
- package/test/unit/spec/services/services.js +309 -0
- package/test/unit/spec/services-v2/services-v2.ts +227 -0
package/package.json
CHANGED
|
@@ -33,16 +33,16 @@
|
|
|
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.13.0-next.
|
|
36
|
+
"@webex/internal-plugin-device": "3.13.0-next.6",
|
|
37
37
|
"@webex/jest-config-legacy": "0.0.0",
|
|
38
38
|
"@webex/legacy-tools": "0.0.0",
|
|
39
|
-
"@webex/plugin-logger": "3.13.0-next.
|
|
40
|
-
"@webex/test-helper-chai": "3.13.0-next.
|
|
41
|
-
"@webex/test-helper-make-local-url": "3.13.0-next.
|
|
42
|
-
"@webex/test-helper-mocha": "3.13.0-next.
|
|
43
|
-
"@webex/test-helper-mock-webex": "3.13.0-next.
|
|
44
|
-
"@webex/test-helper-refresh-callback": "3.13.0-next.
|
|
45
|
-
"@webex/test-helper-test-users": "3.13.0-next.
|
|
39
|
+
"@webex/plugin-logger": "3.13.0-next.6",
|
|
40
|
+
"@webex/test-helper-chai": "3.13.0-next.2",
|
|
41
|
+
"@webex/test-helper-make-local-url": "3.13.0-next.2",
|
|
42
|
+
"@webex/test-helper-mocha": "3.13.0-next.2",
|
|
43
|
+
"@webex/test-helper-mock-webex": "3.13.0-next.2",
|
|
44
|
+
"@webex/test-helper-refresh-callback": "3.13.0-next.2",
|
|
45
|
+
"@webex/test-helper-test-users": "3.13.0-next.2",
|
|
46
46
|
"chai": "^4.3.4",
|
|
47
47
|
"chai-as-promised": "^7.1.1",
|
|
48
48
|
"eslint": "^8.24.0",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"sinon": "^9.2.4"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@webex/common": "3.13.0-next.
|
|
54
|
-
"@webex/common-timers": "3.13.0-next.
|
|
55
|
-
"@webex/http-core": "3.13.0-next.
|
|
56
|
-
"@webex/storage-adapter-spec": "3.13.0-next.
|
|
53
|
+
"@webex/common": "3.13.0-next.2",
|
|
54
|
+
"@webex/common-timers": "3.13.0-next.2",
|
|
55
|
+
"@webex/http-core": "3.13.0-next.2",
|
|
56
|
+
"@webex/storage-adapter-spec": "3.13.0-next.2",
|
|
57
57
|
"ampersand-collection": "^2.0.2",
|
|
58
58
|
"ampersand-events": "^2.0.2",
|
|
59
59
|
"ampersand-state": "^5.0.3",
|
|
@@ -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.13.0-next.
|
|
76
|
+
"version": "3.13.0-next.6"
|
|
77
77
|
}
|
package/src/interceptors/auth.js
CHANGED
|
@@ -130,7 +130,20 @@ export default class AuthInterceptor extends Interceptor {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
if (this.webex.credentials.canRefresh) {
|
|
133
|
-
return this.webex.credentials
|
|
133
|
+
return this.webex.credentials
|
|
134
|
+
.refresh()
|
|
135
|
+
.catch((error) => {
|
|
136
|
+
const refreshStatus = error && (error.statusCode || error.status);
|
|
137
|
+
|
|
138
|
+
// A refresh 403 is not a catalog 403. Keep the original 401 for
|
|
139
|
+
// catalog auth reporting and leave statusCode unchanged.
|
|
140
|
+
if (reason.statusCode === 401 && refreshStatus === 403 && error) {
|
|
141
|
+
error.catalogAuthStatus = 401;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return Promise.reject(error);
|
|
145
|
+
})
|
|
146
|
+
.then(() => this.replay(options));
|
|
134
147
|
}
|
|
135
148
|
}
|
|
136
149
|
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import {Interceptor} from '@webex/http-core';
|
|
6
6
|
|
|
7
|
+
import {isCatalogAuthReason} from '../services/catalog-auth';
|
|
8
|
+
|
|
7
9
|
const trailingSlashes = /(?:^\/)|(?:\/$)/;
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -47,9 +49,15 @@ export default class ServiceInterceptor extends Interceptor {
|
|
|
47
49
|
|
|
48
50
|
return options;
|
|
49
51
|
})
|
|
50
|
-
.catch(() =>
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
.catch((error) => {
|
|
53
|
+
if (error && isCatalogAuthReason(error.reason)) {
|
|
54
|
+
return Promise.reject(error);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return Promise.reject(
|
|
58
|
+
new Error(`service-interceptor: '${service}' is not a known service`)
|
|
59
|
+
);
|
|
60
|
+
});
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
/* eslint-disable class-methods-use-this */
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {OAuthError} from '../credentials/grant-errors';
|
|
2
|
+
|
|
3
|
+
export const INVALID_ACCESS_TOKEN = 'invalid_access_token';
|
|
4
|
+
export const ACCESS_DENIED = 'access_denied';
|
|
5
|
+
|
|
6
|
+
const catalogAuthFailures = new WeakMap();
|
|
7
|
+
const catalogAuthReplayLimit = /^Failed after \d+ replay attempts$/;
|
|
8
|
+
const reasonByStatus = {
|
|
9
|
+
401: INVALID_ACCESS_TOKEN,
|
|
10
|
+
403: ACCESS_DENIED,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A catalog 401 can arrive as an OAuth refresh failure or the auth replay limit.
|
|
15
|
+
* @param {Error} error
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
export function isWrappedCatalogAuthFailure(error) {
|
|
19
|
+
return (
|
|
20
|
+
error instanceof OAuthError ||
|
|
21
|
+
(typeof error?.message === 'string' && catalogAuthReplayLimit.test(error.message))
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} reason
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
export function isCatalogAuthReason(reason) {
|
|
30
|
+
return reason === INVALID_ACCESS_TOKEN || reason === ACCESS_DENIED;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Classify a postauth catalog failure.
|
|
35
|
+
* A result is stored. Null means any previously stored failure should be cleared.
|
|
36
|
+
* Network errors and HTTP 5xx stay null.
|
|
37
|
+
* @param {Error} error
|
|
38
|
+
* @returns {{status: number, reason: string}|null}
|
|
39
|
+
*/
|
|
40
|
+
export function classifyCatalogAuthFailure(error) {
|
|
41
|
+
const status = error && (error.catalogAuthStatus || error.statusCode || error.status);
|
|
42
|
+
const reason = reasonByStatus[status];
|
|
43
|
+
|
|
44
|
+
if (reason) {
|
|
45
|
+
return {
|
|
46
|
+
status,
|
|
47
|
+
reason,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (isWrappedCatalogAuthFailure(error)) {
|
|
52
|
+
return {
|
|
53
|
+
status: 401,
|
|
54
|
+
reason: INVALID_ACCESS_TOKEN,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {object} services
|
|
63
|
+
* @param {Error} error
|
|
64
|
+
* @returns {void}
|
|
65
|
+
*/
|
|
66
|
+
export function recordCatalogAuthFailure(services, error) {
|
|
67
|
+
const authFailure = classifyCatalogAuthFailure(error);
|
|
68
|
+
|
|
69
|
+
if (authFailure) {
|
|
70
|
+
catalogAuthFailures.set(services, authFailure);
|
|
71
|
+
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
catalogAuthFailures.delete(services);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {object} services
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
export function clearCatalogAuthFailure(services) {
|
|
83
|
+
catalogAuthFailures.delete(services);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {object} services
|
|
88
|
+
* @returns {{status: number, reason: string}|null}
|
|
89
|
+
*/
|
|
90
|
+
export function getCatalogAuthFailure(services) {
|
|
91
|
+
return catalogAuthFailures.get(services) || null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {object} services
|
|
96
|
+
* @param {string} fallbackMessage
|
|
97
|
+
* @returns {Error}
|
|
98
|
+
*/
|
|
99
|
+
export function serviceLookupError(services, fallbackMessage) {
|
|
100
|
+
const authFailure = getCatalogAuthFailure(services);
|
|
101
|
+
|
|
102
|
+
if (authFailure && isCatalogAuthReason(authFailure.reason)) {
|
|
103
|
+
const authError = new Error(authFailure.reason);
|
|
104
|
+
|
|
105
|
+
authError.reason = authFailure.reason;
|
|
106
|
+
authError.statusCode = authFailure.status;
|
|
107
|
+
|
|
108
|
+
return authError;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return new Error(fallbackMessage);
|
|
112
|
+
}
|
|
@@ -187,7 +187,7 @@ Related context: [repository architecture](../../../../docs/architecture.md) ·
|
|
|
187
187
|
| `SVC-010` | `updateCredentialsConfig` copies the highest-priority `idbroker` and `identity` URLs (trailing slash removed) into credentials config, and sets `authorizeUrl` from idbroker unless an authorization string is configured | The OAuth endpoints must follow the discovered region, not the build-time default | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (idbroker, identity and authorize url cases) | Only one slash is stripped per string | Present |
|
|
188
188
|
| `SVC-011` | `waitForCatalog('postauth')` with a supertoken present and the group neither collecting nor ready starts collection itself (full init when preauth is not ready, otherwise `updateServices`) instead of waiting | A caller racing the init sequence must not wait for an event that has not been requested | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (initServiceCatalogs paths); `test/integration/spec/services/services.js` | The caller's timeout is ignored on this branch; no direct unit test of the branch | Weak |
|
|
189
189
|
| `SVC-012` | `ServiceCatalog.waitForCatalog` resolves immediately if the group is ready, otherwise resolves on the group's event or rejects after `timeout` seconds (60 when not a non-negative number) with `services: timeout occured while waiting for '<group>' catalog to populate` | Callers need bounded waiting with a consistent failure | `src/lib/services/service-catalog.js` | `test/integration/spec/services/service-catalog.js` (promise, timeout rejection, resolved once ready) | When already ready, the timer and listener are still created (see Pitfalls) | Present |
|
|
190
|
-
| `SVC-013` | `waitForService({name, url, timeout=5})` resolves in this order: the raw discovered link for names in `servicesNotNeedValidation`; the priority URL by name or by URL; when the catalog is ready, the given `url` as-is, else a rejection `services: service '<name>' was not found in any of the catalogs`; otherwise it waits on all three groups and resolves on the first hit, rejecting `services: service '<name>' was not found after waiting` only after all three settle; each not-found rejection reports a client metric | Request building must not fail merely because a catalog is still loading, yet unknown services must fail loudly | `src/lib/services/services.js` | `test/integration/spec/services/services.js` (name, url, name and url; existing, missing, becoming available) |
|
|
190
|
+
| `SVC-013` | `waitForService({name, url, timeout=5})` resolves in this order: the raw discovered link for names in `servicesNotNeedValidation`; the priority URL by name or by URL; when the catalog is ready, the given `url` as-is, else a rejection `services: service '<name>' was not found in any of the catalogs`; otherwise it waits on all three groups and resolves on the first hit, rejecting `services: service '<name>' was not found after waiting` only after all three settle; each not-found rejection reports a client metric. A stored postauth catalog auth failure replaces both not-found messages: `error.message` and `error.reason` are `invalid_access_token` with `error.statusCode` 401, or `access_denied` with `error.statusCode` 403. Every other missing service keeps the current text | Request building must not fail merely because a catalog is still loading, yet unknown services must fail loudly, and a catalog 401 or 403 must stay visible to the caller | `src/lib/services/services.js`, `src/lib/services/catalog-auth.js` | `test/unit/spec/services/services.js` (catalog auth failure), `test/integration/spec/services/services.js` (name, url, name and url; existing, missing, becoming available) | Generic not-found paths rely on live U2C | Present |
|
|
191
191
|
| `SVC-014` | `getServiceFromUrl` and `isServiceUrl` match a URL to a service when its origin (scheme, host, port) equals the service's default URL origin or an alternate-host URL, and its path equals or extends the service path at a `/` boundary; unparsable input matches nothing; groups are scanned discovery first, override last | A hostname that merely begins with a trusted host, a different port, scheme or path prefix must not be treated as a Webex service, because the result decides whether credentials are attached | `src/lib/services/service-catalog.js` | `test/unit/spec/services/service-catalog.js` (origin and path validation, SECURITY cases), `test/unit/spec/services/services.js`, `test/integration/spec/services/service-catalog.js` | Match result precedence differs from name precedence | Present |
|
|
192
192
|
| `SVC-015` | `isAllowedDomainUrl` is true only when the URL's hostname is an allowed domain or a subdomain of one, as decided by the domains helper; `hasAllowedDomains` reports whether any entry exists; `setAllowedDomains` and `addAllowedDomains` store canonicalized, de-duplicated entries | Allowed-domain checks gate whether the auth header is attached, so substring or parser-differential matches must not pass | `src/lib/services/service-catalog.js`, `src/lib/domains.ts`, `src/lib/services/services.js` | `test/unit/spec/services/service-catalog.js` (parametrized allowed-domain matching, set/add/get), `test/unit/spec/services/services.js` (isAllowedDomainUrl) | Matching rules themselves are owned by the helper in `src/lib/domains.ts` | Present |
|
|
193
193
|
| `SVC-016` | `get(name, true)` returns the URL of the best host: hosts with non-positive priority are ignored; without a cluster id only home-cluster hosts qualify; non-failed hosts are preferred; the lowest priority number wins; if every candidate has failed their `failed` flags are cleared and selection restarts; with no usable host the default URL is returned | Failover must degrade gracefully to the default URL and must never get stuck with every host disabled | `src/lib/services/service-url.js` | `test/unit/spec/services/service-url.js` (negative, zero, mixed priorities; reset when all failed; cluster id cases) | None | Present |
|
|
@@ -197,7 +197,7 @@ Related context: [repository architecture](../../../../docs/architecture.md) ·
|
|
|
197
197
|
| `SVC-020` | `replaceHostFromHostmap` replaces the host of a URI with the first host catalog entry of its host key, and returns the URI unchanged when the host catalog is unset or has no entry | Requests that already carry absolute URLs must still use the discovered host | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (four cases) | None | Present |
|
|
198
198
|
| `SVC-021` | `HostMapInterceptor.onRequest` rewrites `options.uri` through `replaceHostFromHostmap` when a URI exists and swallows any error, leaving the URI untouched | A malformed or relative URI must not abort the request | `src/lib/interceptors/hostmap.js` | `test/unit/spec/services/interceptors/hostmap.js` | None | Present |
|
|
199
199
|
| `SVC-022` | `ServiceInterceptor.onRequest` returns options unchanged when `uri` is set; otherwise it maps `api` to `service` (without overriding an explicit `service`), requires both `resource` and `service` (throwing `a \`resource\` parameter is required` or `a valid 'service' parameter is required`), waits for the service honoring `waitForServiceTimeout`, and sets `uri` to the service URL joined with the resource | Callers address services by logical name so that region, override and failover are applied centrally | `src/lib/interceptors/service.js` | `test/unit/spec/services/interceptors/service.js` | None | Present |
|
|
200
|
-
| `SVC-023` | When the service cannot be resolved `ServiceInterceptor`
|
|
200
|
+
| `SVC-023` | When the service cannot be resolved `ServiceInterceptor` rethrows the error unchanged when `error.reason` is `invalid_access_token` or `access_denied`. Every other failure is rejected as `service-interceptor: '<service>' is not a known service`, discarding the underlying cause | A catalog 401 or 403 must reach the request caller; other missing services stay a single recognizable failure | `src/lib/interceptors/service.js`, `src/lib/services/catalog-auth.js` | `test/unit/spec/services/interceptors/service.js` (rejected promise case, catalog auth reasons) | The underlying wait failure (timeout versus not found) is not surfaced | Present |
|
|
201
201
|
| `SVC-024` | `ServerErrorInterceptor.onResponseError` reacts only to `InternalServerError`, `BadGateway` and `ServiceUnavailable` with a URI and only when developer feature `web-high-availability` is present and truthy; it then submits a `web-ha` client metric, calls `markFailedUrl` and still rejects with the original error; every other case rejects with the original error unchanged | Subsequent retries should use the next host, but only for orgs that enabled high availability, and the error must still reach the caller | `src/lib/interceptors/server-error.js` | `test/unit/spec/services/interceptors/server-error.js` | The retry itself is not performed here; it belongs to the caller or another interceptor | Present |
|
|
202
202
|
| `SVC-025` | `initServiceCatalogs` resolves the org id, collects the preauth catalog for it, and, when `canAuthorize`, collects the postauth catalog then sets `catalog.isReady`; a postauth failure sets `initFailed` and is swallowed; a failed `getOrgId` or preauth collection rejects | Authenticated users need the full catalog; a failed postauth fetch must not break login | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (initServiceCatalogs, initFailed), `test/integration/spec/services/services.js` | None | Present |
|
|
203
203
|
| `SVC-026` | By default (`waitForCatalogInit` not true) `services.ready` is set true immediately, and catalog collection starts on the first webex `ready` event: load from cache and finish if warm; with a supertoken run `initServiceCatalogs`; otherwise collect preauth by configured email or by proximity unless `skipPreauthCatalogOnUnauthenticated` is true; failures set `initFailed` and are logged | The historical behavior must not block `webex.ready` on the network | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (initialize ungated cases, skip preauth) | None | Present |
|
|
@@ -635,8 +635,8 @@ and never becomes true for an unauthenticated user whose cache is cold.
|
|
|
635
635
|
| `validateUser` without email, or without client credentials | Rejection with the message | Fix input or config | Retry | `src/lib/services/services.js` |
|
|
636
636
|
| U2C request fails | Rejection with the request error; `collecting` cleared | Inspect error | Call again | `src/lib/services/services.js` |
|
|
637
637
|
| Catalog wait times out | Rejection `services: timeout occured while waiting for '<group>' catalog to populate` | Treat the service as unavailable | Retry later | `src/lib/services/service-catalog.js` |
|
|
638
|
-
| Service not found | Rejection `services: service '<name>' was not found in any of the catalogs` or `... after waiting` | Treat as unknown service | Retry after the catalog loads | `src/lib/services/services.js` |
|
|
639
|
-
| `ServiceInterceptor` cannot resolve | Rejection `service-interceptor: '<service>' is not a known service` | Check the service name | Retry later | `src/lib/interceptors/service.js` |
|
|
638
|
+
| Service not found | Rejection `services: service '<name>' was not found in any of the catalogs` or `... after waiting`. A stored postauth catalog auth failure instead rejects with `error.message` and `error.reason` `invalid_access_token` and `error.statusCode` 401, or `access_denied` and `error.statusCode` 403 | Treat a catalog 401 or 403 as an authorization failure; treat every other rejection as an unknown service | Retry after the catalog loads, or after the token is replaced | `src/lib/services/services.js`, `src/lib/services/catalog-auth.js` |
|
|
639
|
+
| `ServiceInterceptor` cannot resolve | Rejection `service-interceptor: '<service>' is not a known service`, unless `error.reason` is `invalid_access_token` or `access_denied`, which is rethrown with that message, reason, and statusCode | Check the service name, or handle the catalog auth reason | Retry later | `src/lib/interceptors/service.js`, `src/lib/services/catalog-auth.js` |
|
|
640
640
|
| `ServiceInterceptor` option error | Synchronous throw of the `resource` or `service` message | Fix the call | None | `src/lib/interceptors/service.js` |
|
|
641
641
|
| `convertUrlToPriorityHostUrl` or `getServiceUrlFromClusterId` on unknown input | Thrown error `No service associated with url: [...]` or `Could not find service for cluster [...]` | Guard with lookup methods | None | `src/lib/services/services.js` |
|
|
642
642
|
| Gated init fails or times out | `ready` still true; `initFailed` true; error logged | Check `initFailed` | Call `updateServices` | `src/lib/services/services.js` |
|
|
@@ -4,6 +4,12 @@ import {union, forEach} from 'lodash';
|
|
|
4
4
|
import WebexPlugin from '../webex-plugin';
|
|
5
5
|
|
|
6
6
|
import METRICS from '../metrics';
|
|
7
|
+
import {
|
|
8
|
+
clearCatalogAuthFailure,
|
|
9
|
+
getCatalogAuthFailure,
|
|
10
|
+
recordCatalogAuthFailure,
|
|
11
|
+
serviceLookupError,
|
|
12
|
+
} from './catalog-auth';
|
|
7
13
|
import ServiceCatalog from './service-catalog';
|
|
8
14
|
import ServiceRegistry from './service-registry';
|
|
9
15
|
import ServiceState from './service-state';
|
|
@@ -114,6 +120,42 @@ const Services = WebexPlugin.extend({
|
|
|
114
120
|
return this._catalogs.get(this.webex);
|
|
115
121
|
},
|
|
116
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Remember a postauth catalog failure caused by HTTP 401 or 403.
|
|
125
|
+
* 401 means the access token was rejected. 403 means the token can be
|
|
126
|
+
* valid and the caller still has no access. A refresh or replay failure
|
|
127
|
+
* that replaced a catalog 401 is recorded as invalid_access_token.
|
|
128
|
+
* A refresh 403 keeps that original 401 on error.catalogAuthStatus.
|
|
129
|
+
* Other failures clear any previously stored auth failure.
|
|
130
|
+
*
|
|
131
|
+
* @private
|
|
132
|
+
* @param {Error} error
|
|
133
|
+
* @returns {void}
|
|
134
|
+
*/
|
|
135
|
+
_recordCatalogAuthFailure(error) {
|
|
136
|
+
recordCatalogAuthFailure(this, error);
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @private
|
|
141
|
+
* @returns {{status: number, reason: string}|null}
|
|
142
|
+
*/
|
|
143
|
+
_getCatalogAuthFailure() {
|
|
144
|
+
return getCatalogAuthFailure(this);
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Build the rejection for a service that could not be resolved.
|
|
149
|
+
* A stored catalog auth failure replaces the generic not-found text.
|
|
150
|
+
*
|
|
151
|
+
* @private
|
|
152
|
+
* @param {string} fallbackMessage
|
|
153
|
+
* @returns {Error}
|
|
154
|
+
*/
|
|
155
|
+
_serviceLookupError(fallbackMessage) {
|
|
156
|
+
return serviceLookupError(this, fallbackMessage);
|
|
157
|
+
},
|
|
158
|
+
|
|
117
159
|
/**
|
|
118
160
|
* Safely access localStorage if available; returns the Storage or null.
|
|
119
161
|
* @returns {Storage|null}
|
|
@@ -401,10 +443,20 @@ const Services = WebexPlugin.extend({
|
|
|
401
443
|
catalog.updateServiceUrls(serviceGroup, formattedServiceHostMap);
|
|
402
444
|
this.updateCredentialsConfig();
|
|
403
445
|
catalog.status[serviceGroup].collecting = false;
|
|
446
|
+
|
|
447
|
+
// A successful postauth catalog replaces any remembered 401/403.
|
|
448
|
+
// Preauth and signin updates leave that marker alone.
|
|
449
|
+
if (serviceGroup === 'postauth') {
|
|
450
|
+
clearCatalogAuthFailure(this);
|
|
451
|
+
}
|
|
404
452
|
})
|
|
405
453
|
.catch((error) => {
|
|
406
454
|
catalog.status[serviceGroup].collecting = false;
|
|
407
455
|
|
|
456
|
+
if (serviceGroup === 'postauth') {
|
|
457
|
+
this._recordCatalogAuthFailure(error);
|
|
458
|
+
}
|
|
459
|
+
|
|
408
460
|
return Promise.reject(error);
|
|
409
461
|
});
|
|
410
462
|
},
|
|
@@ -820,7 +872,7 @@ const Services = WebexPlugin.extend({
|
|
|
820
872
|
});
|
|
821
873
|
|
|
822
874
|
return Promise.reject(
|
|
823
|
-
|
|
875
|
+
this._serviceLookupError(`services: service '${name}' was not found in any of the catalogs`)
|
|
824
876
|
);
|
|
825
877
|
}
|
|
826
878
|
|
|
@@ -843,7 +895,7 @@ const Services = WebexPlugin.extend({
|
|
|
843
895
|
this.webex.internal.metrics.submitClientMetrics(METRICS.JS_SDK_SERVICE_NOT_FOUND, {
|
|
844
896
|
fields: {service_name: name},
|
|
845
897
|
});
|
|
846
|
-
reject(
|
|
898
|
+
reject(this._serviceLookupError(`services: service '${name}' was not found after waiting`));
|
|
847
899
|
});
|
|
848
900
|
});
|
|
849
901
|
},
|
|
@@ -393,7 +393,7 @@ sequenceDiagram
|
|
|
393
393
|
Plugin-->>Caller: url unchanged
|
|
394
394
|
else
|
|
395
395
|
Plugin->>Metrics: submitClientMetrics(JS_SDK_SERVICE_NOT_FOUND)
|
|
396
|
-
Plugin-->>Caller: reject "service '<name>' was not found in any of the catalogs"
|
|
396
|
+
Plugin-->>Caller: reject stored catalog auth reason, else "service '<name>' was not found in any of the catalogs"
|
|
397
397
|
end
|
|
398
398
|
else not ready
|
|
399
399
|
par each of preauth, signin, postauth
|
|
@@ -404,7 +404,7 @@ sequenceDiagram
|
|
|
404
404
|
Plugin-->>Caller: resolve priority url
|
|
405
405
|
else all waits settled without a match
|
|
406
406
|
Plugin->>Metrics: submitClientMetrics(JS_SDK_SERVICE_NOT_FOUND)
|
|
407
|
-
Plugin-->>Caller: reject "service '<name>' was not found after waiting"
|
|
407
|
+
Plugin-->>Caller: reject stored catalog auth reason, else "service '<name>' was not found after waiting"
|
|
408
408
|
end
|
|
409
409
|
end
|
|
410
410
|
```
|
|
@@ -539,7 +539,7 @@ classDiagram
|
|
|
539
539
|
| `UC-001` Opt in to v2 | Integrator or test | Register `ServicesV2` as the `services` plugin with `replace: true` and the two interceptors, then construct the webex instance; `webex.internal.services` is v2 | Without `replace` the second registration is refused and v1 stays; without the interceptors, requests that use `service` are not resolved | `src/lib/webex-internal-core-plugin-mixin.js`, `test/integration/spec/services-v2/services-v2.js` |
|
|
540
540
|
| `UC-002` Start up with a token | SDK | Config change seeds discovery; on `ready` (or `loaded` when gated) warm from cache or fetch preauth by org then postauth; `isReady` becomes true; `ready` flips | Postauth failure sets `initFailed`; timeout (gated) finalizes anyway | `src/lib/services-v2/services-v2.ts`, `test/unit/spec/services-v2/services-v2.ts` |
|
|
541
541
|
| `UC-003` Start up unauthenticated | SDK | Preauth catalog by configured email hash or proximity mode; later sign-in triggers postauth | `skipPreauthCatalogOnUnauthenticated` skips the fetch; failure sets `initFailed` | `src/lib/services-v2/services-v2.ts`, `test/unit/spec/services-v2/services-v2.ts` |
|
|
542
|
-
| `UC-004` Send a request by service name | `ServiceInterceptor` | `waitForService` returns the priority URL; the interceptor appends the resource |
|
|
542
|
+
| `UC-004` Send a request by service name | `ServiceInterceptor` | `waitForService` returns the priority URL; the interceptor appends the resource | A stored postauth catalog auth failure rejects with `error.message` and `error.reason` `invalid_access_token` and `error.statusCode` 401, or `access_denied` and `error.statusCode` 403, and the interceptor rethrows that error. Every other missing service rejects with the not-found text, which the interceptor re-wraps as "is not a known service" | `src/lib/interceptors/service.js`, `src/lib/services/catalog-auth.js`, `src/lib/services-v2/services-v2.ts` |
|
|
543
543
|
| `UC-005` Decide whether to send a token to a URL | Auth interceptor | `getServiceFromUrl` match, else allowed-domain match when `validateDomains` is on | Similar-looking hosts and prefix paths are rejected by the matcher | `src/interceptors/auth.js`, `test/unit/spec/interceptors/auth.js`, `test/unit/spec/services-v2/service-catalog.ts` |
|
|
544
544
|
| `UC-006` Fail over after a server error | Error interceptor | `markFailedUrl` marks the host and returns the next base URL | Unknown URL returns `undefined`; reset behavior is in the Failover state diagram | `src/lib/interceptors/server-error.js`, `test/unit/spec/services-v2/service-detail.ts`, `test/integration/spec/services-v2/services-v2.js` |
|
|
545
545
|
| `UC-007` React to a cluster move | Mercury | `switchActiveClusterIds` or `invalidateCache` updates the active map or refetches | Missing cluster refetches; older timestamp is ignored | `src/lib/services-v2/services-v2.ts`, `test/unit/spec/services-v2/services-v2.ts` |
|
|
@@ -663,7 +663,7 @@ stateDiagram-v2
|
|
|
663
663
|
| `validateUser` without email or without client credentials | Rejection with the message | Fix input or config | Retry | `src/lib/services-v2/services-v2.ts` |
|
|
664
664
|
| U2C request fails | Rejection with the request error; `collecting` cleared | Inspect error | Call again | `src/lib/services-v2/services-v2.ts` |
|
|
665
665
|
| Catalog wait times out | Rejection `services: timeout occured while waiting for '<group>' catalog to populate` | Treat as unavailable | Retry later | `src/lib/services-v2/service-catalog.ts` |
|
|
666
|
-
| Service not found | Rejection `services: service '<name>' was not found in any of the catalogs` or `... after waiting`, plus a `JS_SDK_SERVICE_NOT_FOUND` metric | Treat as unknown | Retry after the catalog loads | `src/lib/services-v2/services-v2.ts` |
|
|
666
|
+
| Service not found | Rejection `services: service '<name>' was not found in any of the catalogs` or `... after waiting`, plus a `JS_SDK_SERVICE_NOT_FOUND` metric. A stored postauth catalog auth failure instead rejects with `error.message` and `error.reason` `invalid_access_token` and `error.statusCode` 401, or `access_denied` and `error.statusCode` 403 | Treat a catalog 401 or 403 as an authorization failure; treat every other rejection as an unknown service | Retry after the catalog loads, or after the token is replaced | `src/lib/services-v2/services-v2.ts`, `src/lib/services/catalog-auth.js` |
|
|
667
667
|
| `convertUrlToPriorityHostUrl` or `getServiceUrlFromClusterId` on unknown input | Thrown `No service associated with url: [...]` or `Could not find service for cluster [...]` | Guard with lookups; `replaceHostFromHostmap` already swallows | None | `src/lib/services-v2/services-v2.ts` |
|
|
668
668
|
| `markFailedUrl` with an unparsable URL | Thrown `TypeError` from `new URL` | Pass a full URL | None | `src/lib/services-v2/service-detail.ts` |
|
|
669
669
|
| Gated init fails or times out | `ready` still true; `initFailed` true; error logged | Check `initFailed` | Call `updateServices` | `src/lib/services-v2/services-v2.ts` |
|
|
@@ -7,6 +7,12 @@ import METRICS from '../metrics';
|
|
|
7
7
|
import ServiceCatalog from './service-catalog';
|
|
8
8
|
import fedRampServices from './service-fed-ramp';
|
|
9
9
|
import {COMMERCIAL_ALLOWED_DOMAINS} from '../constants';
|
|
10
|
+
import {
|
|
11
|
+
clearCatalogAuthFailure,
|
|
12
|
+
getCatalogAuthFailure,
|
|
13
|
+
recordCatalogAuthFailure,
|
|
14
|
+
serviceLookupError,
|
|
15
|
+
} from '../services/catalog-auth';
|
|
10
16
|
import {matchesCatalogUrl} from '../services/service-catalog';
|
|
11
17
|
import {
|
|
12
18
|
ActiveServices,
|
|
@@ -78,6 +84,36 @@ const Services = WebexPlugin.extend({
|
|
|
78
84
|
return this._catalogs.get(this.webex);
|
|
79
85
|
},
|
|
80
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Remember a postauth catalog failure caused by HTTP 401 or 403.
|
|
89
|
+
* Other failures clear any previously stored auth failure.
|
|
90
|
+
* @private
|
|
91
|
+
* @param {Error} error
|
|
92
|
+
* @returns {void}
|
|
93
|
+
*/
|
|
94
|
+
_recordCatalogAuthFailure(error) {
|
|
95
|
+
recordCatalogAuthFailure(this, error);
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @private
|
|
100
|
+
* @returns {{status: number, reason: string}|null}
|
|
101
|
+
*/
|
|
102
|
+
_getCatalogAuthFailure() {
|
|
103
|
+
return getCatalogAuthFailure(this);
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Build the rejection for a service that could not be resolved.
|
|
108
|
+
* A stored catalog auth failure replaces the generic not-found text.
|
|
109
|
+
* @private
|
|
110
|
+
* @param {string} fallbackMessage
|
|
111
|
+
* @returns {Error}
|
|
112
|
+
*/
|
|
113
|
+
_serviceLookupError(fallbackMessage: string) {
|
|
114
|
+
return serviceLookupError(this, fallbackMessage);
|
|
115
|
+
},
|
|
116
|
+
|
|
81
117
|
/**
|
|
82
118
|
* Safely access localStorage if available; returns the Storage or null.
|
|
83
119
|
* @returns {Storage | null}
|
|
@@ -357,10 +393,20 @@ const Services = WebexPlugin.extend({
|
|
|
357
393
|
this._cacheCatalog(serviceGroup, serviceHostMap, selectionMeta);
|
|
358
394
|
this.updateCredentialsConfig();
|
|
359
395
|
catalog.status[serviceGroup].collecting = false;
|
|
396
|
+
|
|
397
|
+
// A successful postauth catalog replaces any remembered 401/403.
|
|
398
|
+
// Preauth and signin updates leave that marker alone.
|
|
399
|
+
if (serviceGroup === 'postauth') {
|
|
400
|
+
clearCatalogAuthFailure(this);
|
|
401
|
+
}
|
|
360
402
|
})
|
|
361
403
|
.catch((error) => {
|
|
362
404
|
catalog.status[serviceGroup].collecting = false;
|
|
363
405
|
|
|
406
|
+
if (serviceGroup === 'postauth') {
|
|
407
|
+
this._recordCatalogAuthFailure(error);
|
|
408
|
+
}
|
|
409
|
+
|
|
364
410
|
return Promise.reject(error);
|
|
365
411
|
});
|
|
366
412
|
},
|
|
@@ -842,7 +888,7 @@ const Services = WebexPlugin.extend({
|
|
|
842
888
|
});
|
|
843
889
|
|
|
844
890
|
return Promise.reject(
|
|
845
|
-
|
|
891
|
+
this._serviceLookupError(`services: service '${name}' was not found in any of the catalogs`)
|
|
846
892
|
);
|
|
847
893
|
}
|
|
848
894
|
|
|
@@ -865,7 +911,7 @@ const Services = WebexPlugin.extend({
|
|
|
865
911
|
this.webex.internal.metrics.submitClientMetrics(METRICS.JS_SDK_SERVICE_NOT_FOUND, {
|
|
866
912
|
fields: {service_name: name},
|
|
867
913
|
});
|
|
868
|
-
reject(
|
|
914
|
+
reject(this._serviceLookupError(`services: service '${name}' was not found after waiting`));
|
|
869
915
|
});
|
|
870
916
|
});
|
|
871
917
|
},
|
|
@@ -547,6 +547,41 @@ describe('webex-core', () => {
|
|
|
547
547
|
});
|
|
548
548
|
});
|
|
549
549
|
|
|
550
|
+
it('marks a refresh 403 after a 401 with the original catalog status', () => {
|
|
551
|
+
webex.config.credentials.refreshCallback = sinon.stub();
|
|
552
|
+
webex.credentials.supertoken = new Token(
|
|
553
|
+
{
|
|
554
|
+
access_token: 'ST1',
|
|
555
|
+
refresh_token: 'RT1',
|
|
556
|
+
},
|
|
557
|
+
{parent: webex}
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
const refreshError = new Error('forbidden');
|
|
561
|
+
|
|
562
|
+
refreshError.statusCode = 403;
|
|
563
|
+
sinon.stub(webex.credentials, 'refresh').rejects(refreshError);
|
|
564
|
+
|
|
565
|
+
const err = new WebexHttpError.Unauthorized({
|
|
566
|
+
statusCode: 401,
|
|
567
|
+
options: {
|
|
568
|
+
headers: {
|
|
569
|
+
trackingid: 'blarg',
|
|
570
|
+
},
|
|
571
|
+
uri: `${config.services.discovery.hydra}/ping`,
|
|
572
|
+
},
|
|
573
|
+
body: {
|
|
574
|
+
error: 'fake error',
|
|
575
|
+
},
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
return assert.isRejected(interceptor.onResponseError(err.options, err)).then((err2) => {
|
|
579
|
+
assert.equal(err2, refreshError);
|
|
580
|
+
assert.equal(err2.statusCode, 403);
|
|
581
|
+
assert.equal(err2.catalogAuthStatus, 401);
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
|
|
550
585
|
it('does not refresh if shouldRefreshAccessToken was false', () => {
|
|
551
586
|
webex.config.credentials.refreshCallback = sinon.stub().returns(
|
|
552
587
|
Promise.resolve({
|
|
@@ -152,7 +152,41 @@ describe('webex-core', () => {
|
|
|
152
152
|
it('should return a rejected promise', () => {
|
|
153
153
|
const promise = interceptor.onRequest(options);
|
|
154
154
|
|
|
155
|
-
assert.isRejected(
|
|
155
|
+
return assert.isRejected(
|
|
156
|
+
promise,
|
|
157
|
+
Error,
|
|
158
|
+
"service-interceptor: 'example' is not a known service"
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('when the service lookup failed because the token was rejected', () => {
|
|
164
|
+
beforeEach(() => {
|
|
165
|
+
const authError = new Error('invalid_access_token');
|
|
166
|
+
|
|
167
|
+
authError.reason = 'invalid_access_token';
|
|
168
|
+
waitForService.rejects(authError);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('should reject with invalid_access_token', () => {
|
|
172
|
+
const promise = interceptor.onRequest(options);
|
|
173
|
+
|
|
174
|
+
return assert.isRejected(promise, Error, 'invalid_access_token');
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('when the service lookup failed because access was denied', () => {
|
|
179
|
+
beforeEach(() => {
|
|
180
|
+
const authError = new Error('access_denied');
|
|
181
|
+
|
|
182
|
+
authError.reason = 'access_denied';
|
|
183
|
+
waitForService.rejects(authError);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should reject with access_denied', () => {
|
|
187
|
+
const promise = interceptor.onRequest(options);
|
|
188
|
+
|
|
189
|
+
return assert.isRejected(promise, Error, 'access_denied');
|
|
156
190
|
});
|
|
157
191
|
});
|
|
158
192
|
});
|