@abyss-project/main 42.5.0 → 42.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/oauth-app.constants.d.ts +3 -0
- package/dist/constants/oauth-app.constants.js +16 -7
- package/dist/constants/oauth-app.constants.js.map +1 -1
- package/dist/constants/tests/oauth-app.constants.spec.js +30 -8
- package/dist/constants/tests/oauth-app.constants.spec.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/oauth-no-app-token.util.d.ts +7 -0
- package/dist/server/oauth-no-app-token.util.js +14 -0
- package/dist/server/oauth-no-app-token.util.js.map +1 -0
- package/dist/server/oauth-request-guard.util.d.ts +0 -12
- package/dist/server/oauth-request-guard.util.js +6 -50
- package/dist/server/oauth-request-guard.util.js.map +1 -1
- package/dist/server/tests/oauth-no-app-token.util.spec.d.ts +1 -0
- package/dist/server/tests/oauth-no-app-token.util.spec.js +40 -0
- package/dist/server/tests/oauth-no-app-token.util.spec.js.map +1 -0
- package/dist/server/tests/oauth-request-guard.util.spec.js +27 -102
- package/dist/server/tests/oauth-request-guard.util.spec.js.map +1 -1
- package/dist/types/enum/oauth-app.enum.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,10 +13,13 @@ export declare const OAUTH_APP_MAX_ORIGINS = 10;
|
|
|
13
13
|
export declare const OAUTH_APP_NAME_MAX_LENGTH = 100;
|
|
14
14
|
export declare const OAUTH_APP_DESCRIPTION_MAX_LENGTH = 500;
|
|
15
15
|
export declare const OAUTH_APP_PRODUCT_AUDIENCE: Record<OAuthAppProduct, OAuthAudience>;
|
|
16
|
+
export declare const OAUTH_APP_READ_ONLY_PRODUCTS: readonly OAuthAppProduct[];
|
|
17
|
+
export declare const isOAuthAppProductReadOnly: (product: OAuthAppProduct) => boolean;
|
|
16
18
|
export declare const oauthAppScopeOf: (product: OAuthAppProduct, access: OAuthAppAccess) => `${OAuthAppProduct}:${OAuthAppAccess}`;
|
|
17
19
|
export declare const OAUTH_APP_OPENID_SCOPE = "openid";
|
|
18
20
|
export declare const OAUTH_APP_IDENTITY_SCOPES: readonly ["openid", "profile", "email"];
|
|
19
21
|
export declare const OAUTH_ID_TOKEN_TTL_SECONDS = 900;
|
|
20
22
|
export declare const OAUTH_NONCE_MAX_LENGTH = 512;
|
|
23
|
+
export declare const isOAuthAppProductScope: (scope: string) => boolean;
|
|
21
24
|
export declare const OAUTH_APP_SCOPES_SUPPORTED: ReadonlyArray<string>;
|
|
22
25
|
export declare const audiencesOfScopes: (scopes: readonly string[]) => OAuthAudience[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.audiencesOfScopes = exports.OAUTH_APP_SCOPES_SUPPORTED = exports.OAUTH_NONCE_MAX_LENGTH = exports.OAUTH_ID_TOKEN_TTL_SECONDS = exports.OAUTH_APP_IDENTITY_SCOPES = exports.OAUTH_APP_OPENID_SCOPE = exports.oauthAppScopeOf = exports.OAUTH_APP_PRODUCT_AUDIENCE = exports.OAUTH_APP_DESCRIPTION_MAX_LENGTH = exports.OAUTH_APP_NAME_MAX_LENGTH = exports.OAUTH_APP_MAX_ORIGINS = exports.OAUTH_APP_MAX_REDIRECT_URIS = exports.OAUTH_APP_MAX_PER_PROJECT = exports.OAUTH_APP_REQUEST_TTL_SECONDS = exports.OAUTH_APP_CODE_TTL_SECONDS = exports.OAUTH_APP_REFRESH_TOKEN_TTL_SECONDS = exports.OAUTH_APP_ACCESS_TOKEN_TTL_SECONDS = exports.OAUTH_APP_ACCESS_TOKEN_TYPE = exports.OAUTH_APP_REFRESH_TOKEN_PREFIX = exports.OAUTH_APP_CLIENT_SECRET_PREFIX = exports.OAUTH_APP_CLIENT_ID_PREFIX = void 0;
|
|
3
|
+
exports.audiencesOfScopes = exports.OAUTH_APP_SCOPES_SUPPORTED = exports.isOAuthAppProductScope = exports.OAUTH_NONCE_MAX_LENGTH = exports.OAUTH_ID_TOKEN_TTL_SECONDS = exports.OAUTH_APP_IDENTITY_SCOPES = exports.OAUTH_APP_OPENID_SCOPE = exports.oauthAppScopeOf = exports.isOAuthAppProductReadOnly = exports.OAUTH_APP_READ_ONLY_PRODUCTS = exports.OAUTH_APP_PRODUCT_AUDIENCE = exports.OAUTH_APP_DESCRIPTION_MAX_LENGTH = exports.OAUTH_APP_NAME_MAX_LENGTH = exports.OAUTH_APP_MAX_ORIGINS = exports.OAUTH_APP_MAX_REDIRECT_URIS = exports.OAUTH_APP_MAX_PER_PROJECT = exports.OAUTH_APP_REQUEST_TTL_SECONDS = exports.OAUTH_APP_CODE_TTL_SECONDS = exports.OAUTH_APP_REFRESH_TOKEN_TTL_SECONDS = exports.OAUTH_APP_ACCESS_TOKEN_TTL_SECONDS = exports.OAUTH_APP_ACCESS_TOKEN_TYPE = exports.OAUTH_APP_REFRESH_TOKEN_PREFIX = exports.OAUTH_APP_CLIENT_SECRET_PREFIX = exports.OAUTH_APP_CLIENT_ID_PREFIX = void 0;
|
|
4
4
|
const oauth_app_enum_1 = require("../types/enum/oauth-app.enum");
|
|
5
5
|
exports.OAUTH_APP_CLIENT_ID_PREFIX = 'abys_app_';
|
|
6
6
|
exports.OAUTH_APP_CLIENT_SECRET_PREFIX = 'abys_apsec_';
|
|
@@ -32,6 +32,12 @@ exports.OAUTH_APP_PRODUCT_AUDIENCE = {
|
|
|
32
32
|
[oauth_app_enum_1.OAuthAppProduct.CONSOLE]: oauth_app_enum_1.OAuthAudience.ABYSS_CONSOLE,
|
|
33
33
|
[oauth_app_enum_1.OAuthAppProduct.REFLEX]: oauth_app_enum_1.OAuthAudience.ABYSS_REFLEX,
|
|
34
34
|
};
|
|
35
|
+
exports.OAUTH_APP_READ_ONLY_PRODUCTS = [
|
|
36
|
+
oauth_app_enum_1.OAuthAppProduct.REFLEX,
|
|
37
|
+
oauth_app_enum_1.OAuthAppProduct.CONSOLE,
|
|
38
|
+
];
|
|
39
|
+
const isOAuthAppProductReadOnly = (product) => exports.OAUTH_APP_READ_ONLY_PRODUCTS.includes(product);
|
|
40
|
+
exports.isOAuthAppProductReadOnly = isOAuthAppProductReadOnly;
|
|
35
41
|
const oauthAppScopeOf = (product, access) => `${product}:${access}`;
|
|
36
42
|
exports.oauthAppScopeOf = oauthAppScopeOf;
|
|
37
43
|
exports.OAUTH_APP_OPENID_SCOPE = 'openid';
|
|
@@ -39,13 +45,17 @@ exports.OAUTH_APP_IDENTITY_SCOPES = [exports.OAUTH_APP_OPENID_SCOPE, 'profile',
|
|
|
39
45
|
exports.OAUTH_ID_TOKEN_TTL_SECONDS = 900;
|
|
40
46
|
exports.OAUTH_NONCE_MAX_LENGTH = 512;
|
|
41
47
|
const OAUTH_APP_OFFLINE_ACCESS_SCOPE = 'offline_access';
|
|
48
|
+
const PRODUCT_SCOPES = Object.values(oauth_app_enum_1.OAuthAppProduct).flatMap((product) => Object.values(oauth_app_enum_1.OAuthAppAccess)
|
|
49
|
+
.filter((access) => access === oauth_app_enum_1.OAuthAppAccess.READ || !(0, exports.isOAuthAppProductReadOnly)(product))
|
|
50
|
+
.map((access) => ({ scope: (0, exports.oauthAppScopeOf)(product, access), product })));
|
|
51
|
+
const PRODUCT_BY_SCOPE = new Map(PRODUCT_SCOPES.map(({ scope, product }) => [scope, product]));
|
|
52
|
+
const isOAuthAppProductScope = (scope) => PRODUCT_BY_SCOPE.has(scope);
|
|
53
|
+
exports.isOAuthAppProductScope = isOAuthAppProductScope;
|
|
42
54
|
exports.OAUTH_APP_SCOPES_SUPPORTED = [
|
|
43
|
-
...
|
|
55
|
+
...PRODUCT_SCOPES.map(({ scope }) => scope),
|
|
44
56
|
...exports.OAUTH_APP_IDENTITY_SCOPES,
|
|
45
57
|
OAUTH_APP_OFFLINE_ACCESS_SCOPE,
|
|
46
58
|
];
|
|
47
|
-
const PRODUCT_BY_VALUE = new Map(Object.values(oauth_app_enum_1.OAuthAppProduct).map((product) => [product, product]));
|
|
48
|
-
const ACCESS_VALUES = new Set(Object.values(oauth_app_enum_1.OAuthAppAccess));
|
|
49
59
|
const IDENTITY_SCOPES = new Set(exports.OAUTH_APP_IDENTITY_SCOPES);
|
|
50
60
|
const audiencesOfScopes = (scopes) => {
|
|
51
61
|
const audiences = new Set();
|
|
@@ -54,9 +64,8 @@ const audiencesOfScopes = (scopes) => {
|
|
|
54
64
|
audiences.add(oauth_app_enum_1.OAuthAudience.ABYSS_MAIN);
|
|
55
65
|
continue;
|
|
56
66
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
if (product !== undefined && rest.length === 0 && ACCESS_VALUES.has(accessPart ?? '')) {
|
|
67
|
+
const product = PRODUCT_BY_SCOPE.get(scope);
|
|
68
|
+
if (product !== undefined) {
|
|
60
69
|
audiences.add(exports.OAUTH_APP_PRODUCT_AUDIENCE[product]);
|
|
61
70
|
}
|
|
62
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-app.constants.js","sourceRoot":"","sources":["../../src/constants/oauth-app.constants.ts"],"names":[],"mappings":";;;AAAA,iEAA8F;AAGjF,QAAA,0BAA0B,GAAG,WAAW,CAAC;AAGzC,QAAA,8BAA8B,GAAG,aAAa,CAAC;AAG/C,QAAA,8BAA8B,GAAG,YAAY,CAAC;AAG9C,QAAA,2BAA2B,GAAG,QAAQ,CAAC;AAGvC,QAAA,kCAAkC,GAAG,GAAG,CAAC;AAGzC,QAAA,mCAAmC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAGrD,QAAA,0BAA0B,GAAG,EAAE,CAAC;AAGhC,QAAA,6BAA6B,GAAG,GAAG,CAAC;AAGpC,QAAA,yBAAyB,GAAG,EAAE,CAAC;AAG/B,QAAA,2BAA2B,GAAG,EAAE,CAAC;AAGjC,QAAA,qBAAqB,GAAG,EAAE,CAAC;AAE3B,QAAA,yBAAyB,GAAG,GAAG,CAAC;AAEhC,QAAA,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AAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,SAAS,CAAC,GAAG,CAAC,kCAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;AACxB,CAAC,CAAC;AAbW,QAAA,iBAAiB,qBAa5B"}
|
|
@@ -31,13 +31,15 @@ describe('oauth-app.constants', () => {
|
|
|
31
31
|
describe('scopes', () => {
|
|
32
32
|
it('oauthAppScopeOf joins the product and the access', () => {
|
|
33
33
|
expect((0, oauth_app_constants_1.oauthAppScopeOf)(oauth_app_enum_1.OAuthAppProduct.CLOUD, oauth_app_enum_1.OAuthAppAccess.READ)).toBe('cloud:read');
|
|
34
|
-
expect((0, oauth_app_constants_1.oauthAppScopeOf)(oauth_app_enum_1.OAuthAppProduct.
|
|
34
|
+
expect((0, oauth_app_constants_1.oauthAppScopeOf)(oauth_app_enum_1.OAuthAppProduct.CLOUD, oauth_app_enum_1.OAuthAppAccess.WRITE)).toBe('cloud:write');
|
|
35
35
|
});
|
|
36
|
-
it('
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
it('keeps console and reflex read-only for this batch', () => {
|
|
37
|
+
expect([...oauth_app_constants_1.OAUTH_APP_READ_ONLY_PRODUCTS].sort()).toEqual(['console', 'reflex']);
|
|
38
|
+
});
|
|
39
|
+
it('supports every product read, write too except for a read-only product, then openid, profile, email and offline_access', () => {
|
|
40
|
+
const productScopes = Object.values(oauth_app_enum_1.OAuthAppProduct).flatMap((product) => oauth_app_constants_1.OAUTH_APP_READ_ONLY_PRODUCTS.includes(product)
|
|
41
|
+
? [`${product}:read`]
|
|
42
|
+
: [`${product}:read`, `${product}:write`]);
|
|
41
43
|
expect(oauth_app_constants_1.OAUTH_APP_SCOPES_SUPPORTED).toEqual([
|
|
42
44
|
...productScopes,
|
|
43
45
|
'openid',
|
|
@@ -45,9 +47,21 @@ describe('oauth-app.constants', () => {
|
|
|
45
47
|
'email',
|
|
46
48
|
'offline_access',
|
|
47
49
|
]);
|
|
48
|
-
expect(productScopes).toHaveLength(
|
|
50
|
+
expect(productScopes).toHaveLength(28);
|
|
51
|
+
expect(oauth_app_constants_1.OAUTH_APP_SCOPES_SUPPORTED).toContain('reflex:read');
|
|
52
|
+
expect(oauth_app_constants_1.OAUTH_APP_SCOPES_SUPPORTED).toContain('console:read');
|
|
53
|
+
expect(oauth_app_constants_1.OAUTH_APP_SCOPES_SUPPORTED).not.toContain('reflex:write');
|
|
54
|
+
expect(oauth_app_constants_1.OAUTH_APP_SCOPES_SUPPORTED).not.toContain('console:write');
|
|
49
55
|
expect(oauth_app_constants_1.OAUTH_APP_IDENTITY_SCOPES).toEqual(['openid', 'profile', 'email']);
|
|
50
56
|
});
|
|
57
|
+
it('isOAuthAppProductScope accepts exactly the product scopes that are supported', () => {
|
|
58
|
+
expect((0, oauth_app_constants_1.isOAuthAppProductScope)('cloud:write')).toBe(true);
|
|
59
|
+
expect((0, oauth_app_constants_1.isOAuthAppProductScope)('reflex:read')).toBe(true);
|
|
60
|
+
expect((0, oauth_app_constants_1.isOAuthAppProductScope)('reflex:write')).toBe(false);
|
|
61
|
+
expect((0, oauth_app_constants_1.isOAuthAppProductScope)('console:write')).toBe(false);
|
|
62
|
+
expect((0, oauth_app_constants_1.isOAuthAppProductScope)('openid')).toBe(false);
|
|
63
|
+
expect((0, oauth_app_constants_1.isOAuthAppProductScope)('cloud:admin')).toBe(false);
|
|
64
|
+
});
|
|
51
65
|
it('maps every product to its own audience, never abyss-main', () => {
|
|
52
66
|
const audiences = Object.values(oauth_app_constants_1.OAUTH_APP_PRODUCT_AUDIENCE);
|
|
53
67
|
expect(Object.keys(oauth_app_constants_1.OAUTH_APP_PRODUCT_AUDIENCE).sort()).toEqual(Object.values(oauth_app_enum_1.OAuthAppProduct).sort());
|
|
@@ -74,7 +88,13 @@ describe('oauth-app.constants', () => {
|
|
|
74
88
|
oauth_app_enum_1.OAuthAudience.ABYSS_WORKSPACE,
|
|
75
89
|
]);
|
|
76
90
|
});
|
|
77
|
-
it('
|
|
91
|
+
it('gives the audience of a read-only product for its read scope only', () => {
|
|
92
|
+
expect((0, oauth_app_constants_1.audiencesOfScopes)(['reflex:read', 'console:read'])).toEqual([
|
|
93
|
+
oauth_app_enum_1.OAuthAudience.ABYSS_REFLEX,
|
|
94
|
+
oauth_app_enum_1.OAuthAudience.ABYSS_CONSOLE,
|
|
95
|
+
]);
|
|
96
|
+
});
|
|
97
|
+
it('adds nothing for offline_access, an unknown scope or a malformed one, nor for a write scope that does not exist', () => {
|
|
78
98
|
expect((0, oauth_app_constants_1.audiencesOfScopes)([
|
|
79
99
|
'offline_access',
|
|
80
100
|
'abyss:read',
|
|
@@ -82,6 +102,8 @@ describe('oauth-app.constants', () => {
|
|
|
82
102
|
'cloud',
|
|
83
103
|
'cloud:read:extra',
|
|
84
104
|
'monitor:read',
|
|
105
|
+
'reflex:write',
|
|
106
|
+
'console:write',
|
|
85
107
|
])).toEqual([oauth_app_enum_1.OAuthAudience.ABYSS_MONITOR]);
|
|
86
108
|
expect((0, oauth_app_constants_1.audiencesOfScopes)([])).toEqual([]);
|
|
87
109
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-app.constants.spec.js","sourceRoot":"","sources":["../../../src/constants/tests/oauth-app.constants.spec.ts"],"names":[],"mappings":";;AAAA,oDAI0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"oauth-app.constants.spec.js","sourceRoot":"","sources":["../../../src/constants/tests/oauth-app.constants.spec.ts"],"names":[],"mappings":";;AAAA,oDAI0B;AAC1B,gEAWgC;AAChC,oEAAiG;AAGjG,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAExC,MAAM,wBAAwB,GAAG,WAAW,CAAC;AAE7C,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAA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OAAO;gBACP,kBAAkB;gBAClB,cAAc;gBACd,cAAc;gBACd,eAAe;aAChB,CAAC,CACH,CAAC,OAAO,CAAC,CAAC,8BAAa,CAAC,aAAa,CAAC,CAAC,CAAC;YACzC,MAAM,CAAC,IAAA,uCAAiB,EAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './safe-url.util';
|
|
2
2
|
export * from './api-cors.util';
|
|
3
3
|
export * from './oauth-access-token.util';
|
|
4
|
+
export * from './oauth-no-app-token.util';
|
|
4
5
|
export * from './oauth-request-guard.util';
|
|
5
6
|
export * from './after-commit-emit.util';
|
|
6
7
|
export * from './encrypt-secret.util';
|
package/dist/server/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./safe-url.util"), exports);
|
|
18
18
|
__exportStar(require("./api-cors.util"), exports);
|
|
19
19
|
__exportStar(require("./oauth-access-token.util"), exports);
|
|
20
|
+
__exportStar(require("./oauth-no-app-token.util"), exports);
|
|
20
21
|
__exportStar(require("./oauth-request-guard.util"), exports);
|
|
21
22
|
__exportStar(require("./after-commit-emit.util"), exports);
|
|
22
23
|
__exportStar(require("./encrypt-secret.util"), exports);
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAgBA,kDAAgC;AAIhC,kDAAgC;AAIhC,4DAA0C;AAC1C,6DAA2C;AAG3C,2DAAyC;AAKzC,wDAAsC;AAGtC,yCAAuB;AAIvB,gEAA8C;AAC9C,2DAAyC;AACzC,wDAAsC;AAGtC,yDAAuC;AAGvC,sDAAoC;AAKpC,4CAA0B;AAK1B,iDAA+B;AAI/B,+DAA6C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAgBA,kDAAgC;AAIhC,kDAAgC;AAIhC,4DAA0C;AAC1C,4DAA0C;AAC1C,6DAA2C;AAG3C,2DAAyC;AAKzC,wDAAsC;AAGtC,yCAAuB;AAIvB,gEAA8C;AAC9C,2DAAyC;AACzC,wDAAsC;AAGtC,yDAAuC;AAGvC,sDAAoC;AAKpC,4CAA0B;AAK1B,iDAA+B;AAI/B,+DAA6C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface OAuthAppLocals {
|
|
2
|
+
oauth?: unknown;
|
|
3
|
+
}
|
|
4
|
+
export declare const isOAuthAppRequest: (locals: OAuthAppLocals) => boolean;
|
|
5
|
+
export declare const createNoAppTokenMiddleware: <Req, Res extends {
|
|
6
|
+
locals: OAuthAppLocals;
|
|
7
|
+
}>(refuse: (req: Req, res: Res) => void) => (req: Req, res: Res, next: () => void) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNoAppTokenMiddleware = exports.isOAuthAppRequest = void 0;
|
|
4
|
+
const isOAuthAppRequest = (locals) => locals.oauth !== undefined && locals.oauth !== null;
|
|
5
|
+
exports.isOAuthAppRequest = isOAuthAppRequest;
|
|
6
|
+
const createNoAppTokenMiddleware = (refuse) => (req, res, next) => {
|
|
7
|
+
if ((0, exports.isOAuthAppRequest)(res.locals)) {
|
|
8
|
+
refuse(req, res);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
next();
|
|
12
|
+
};
|
|
13
|
+
exports.createNoAppTokenMiddleware = createNoAppTokenMiddleware;
|
|
14
|
+
//# sourceMappingURL=oauth-no-app-token.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-no-app-token.util.js","sourceRoot":"","sources":["../../src/server/oauth-no-app-token.util.ts"],"names":[],"mappings":";;;AAsBO,MAAM,iBAAiB,GAAG,CAAC,MAAsB,EAAW,EAAE,CACnE,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC;AADzC,QAAA,iBAAiB,qBACwB;AAM/C,MAAM,0BAA0B,GACrC,CAA8C,MAAoC,EAAE,EAAE,CACtF,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAgB,EAAQ,EAAE;IAC7C,IAAI,IAAA,yBAAiB,EAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjB,OAAO;IACT,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AARS,QAAA,0BAA0B,8BAQnC"}
|
|
@@ -2,8 +2,6 @@ import { OAuthAppAccess, OAuthAppProduct } from '../types/enum/oauth-app.enum';
|
|
|
2
2
|
import type { OAuthAccessTokenClaims } from './oauth-access-token.util';
|
|
3
3
|
export interface OAuthGuardRequest {
|
|
4
4
|
method: string;
|
|
5
|
-
path?: string;
|
|
6
|
-
originalUrl?: string;
|
|
7
5
|
}
|
|
8
6
|
export declare enum OAuthGuardRefusalCode {
|
|
9
7
|
INSUFFICIENT_SCOPE = "insufficient_scope",
|
|
@@ -21,19 +19,9 @@ export type OAuthGuardOutcome = {
|
|
|
21
19
|
status: 403;
|
|
22
20
|
code: OAuthGuardRefusalCode.OAUTH_TOKEN_NOT_ALLOWED;
|
|
23
21
|
};
|
|
24
|
-
export declare enum OAuthCredentialMethods {
|
|
25
|
-
ANY = "ANY",
|
|
26
|
-
ANY_WRITE = "ANY_WRITE"
|
|
27
|
-
}
|
|
28
|
-
export interface OAuthCredentialRoute {
|
|
29
|
-
methods: OAuthCredentialMethods | readonly string[];
|
|
30
|
-
path: RegExp;
|
|
31
|
-
}
|
|
32
22
|
export interface OAuthRequestGuardOptions {
|
|
33
23
|
product: OAuthAppProduct;
|
|
34
|
-
credentialRoutes?: readonly OAuthCredentialRoute[];
|
|
35
24
|
}
|
|
36
25
|
export type OAuthRequestGuard = (req: OAuthGuardRequest, claims: Pick<OAuthAccessTokenClaims, 'scopes'>) => OAuthGuardOutcome;
|
|
37
26
|
export declare const requiredOAuthAccessFor: (method: string) => OAuthAppAccess;
|
|
38
|
-
export declare const canonicalOAuthRoutePath: (url: string) => string;
|
|
39
27
|
export declare const createOAuthRequestGuard: (options: OAuthRequestGuardOptions) => OAuthRequestGuard;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOAuthRequestGuard = exports.
|
|
3
|
+
exports.createOAuthRequestGuard = exports.requiredOAuthAccessFor = exports.OAuthGuardRefusalCode = void 0;
|
|
4
4
|
const oauth_app_constants_1 = require("../constants/oauth-app.constants");
|
|
5
5
|
const oauth_app_enum_1 = require("../types/enum/oauth-app.enum");
|
|
6
6
|
var OAuthGuardRefusalCode;
|
|
@@ -8,61 +8,17 @@ var OAuthGuardRefusalCode;
|
|
|
8
8
|
OAuthGuardRefusalCode["INSUFFICIENT_SCOPE"] = "insufficient_scope";
|
|
9
9
|
OAuthGuardRefusalCode["OAUTH_TOKEN_NOT_ALLOWED"] = "oauthTokenNotAllowed";
|
|
10
10
|
})(OAuthGuardRefusalCode || (exports.OAuthGuardRefusalCode = OAuthGuardRefusalCode = {}));
|
|
11
|
-
var OAuthCredentialMethods;
|
|
12
|
-
(function (OAuthCredentialMethods) {
|
|
13
|
-
OAuthCredentialMethods["ANY"] = "ANY";
|
|
14
|
-
OAuthCredentialMethods["ANY_WRITE"] = "ANY_WRITE";
|
|
15
|
-
})(OAuthCredentialMethods || (exports.OAuthCredentialMethods = OAuthCredentialMethods = {}));
|
|
16
11
|
const READ_METHODS = new Set(['GET', 'HEAD']);
|
|
17
12
|
const requiredOAuthAccessFor = (method) => READ_METHODS.has(method.toUpperCase()) ? oauth_app_enum_1.OAuthAppAccess.READ : oauth_app_enum_1.OAuthAppAccess.WRITE;
|
|
18
13
|
exports.requiredOAuthAccessFor = requiredOAuthAccessFor;
|
|
19
|
-
const ABSOLUTE_FORM_PREFIX = /^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i;
|
|
20
|
-
const API_PREFIX = /^\/api(?=\/|$)/;
|
|
21
|
-
const canonicalOAuthRoutePath = (url) => {
|
|
22
|
-
const withoutQuery = url.split('#')[0].split('?')[0].replace(ABSOLUTE_FORM_PREFIX, '');
|
|
23
|
-
const merged = withoutQuery.replace(/\/+/g, '/').replace(/\/$/, '').toLowerCase();
|
|
24
|
-
return merged.replace(API_PREFIX, '') || '/';
|
|
25
|
-
};
|
|
26
|
-
exports.canonicalOAuthRoutePath = canonicalOAuthRoutePath;
|
|
27
|
-
const withoutEscapes = (source) => source.replace(/\\./g, '');
|
|
28
|
-
const assertWellWrittenCredentialRoute = (route) => {
|
|
29
|
-
const { source, flags } = route.path;
|
|
30
|
-
const refuse = (reason) => {
|
|
31
|
-
throw new Error(`OAuth credential route ${route.path}: ${reason}`);
|
|
32
|
-
};
|
|
33
|
-
if (/[igy]/.test(flags)) {
|
|
34
|
-
refuse('flags i, g and y are refused (the path is already lowercase, g and y make test() stateful)');
|
|
35
|
-
}
|
|
36
|
-
if (/[A-Z]/.test(withoutEscapes(source))) {
|
|
37
|
-
refuse('write the pattern in lowercase: it is compared with a lowercased path');
|
|
38
|
-
}
|
|
39
|
-
if (!source.startsWith('^') || !source.endsWith('$')) {
|
|
40
|
-
refuse('anchor the pattern with ^ and $');
|
|
41
|
-
}
|
|
42
|
-
if (/^\^(?:\(\?:)?\\\/api(?:\\\/|\)|\$)/.test(source)) {
|
|
43
|
-
refuse('leave the /api mount prefix out: the canonical path has none');
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const methodsMatch = (methods, method) => {
|
|
47
|
-
const upper = method.toUpperCase();
|
|
48
|
-
if (typeof methods === 'string') {
|
|
49
|
-
return methods === OAuthCredentialMethods.ANY || !READ_METHODS.has(upper);
|
|
50
|
-
}
|
|
51
|
-
return methods.some((name) => name.toUpperCase() === upper || (upper === 'HEAD' && name.toUpperCase() === 'GET'));
|
|
52
|
-
};
|
|
53
14
|
const createOAuthRequestGuard = (options) => {
|
|
54
|
-
const
|
|
55
|
-
credentialRoutes.forEach(assertWellWrittenCredentialRoute);
|
|
15
|
+
const readOnly = (0, oauth_app_constants_1.isOAuthAppProductReadOnly)(options.product);
|
|
56
16
|
return (req, claims) => {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
return {
|
|
60
|
-
allowed: false,
|
|
61
|
-
status: 403,
|
|
62
|
-
code: OAuthGuardRefusalCode.OAUTH_TOKEN_NOT_ALLOWED,
|
|
63
|
-
};
|
|
17
|
+
const access = (0, exports.requiredOAuthAccessFor)(req.method);
|
|
18
|
+
if (readOnly && access === oauth_app_enum_1.OAuthAppAccess.WRITE) {
|
|
19
|
+
return { allowed: false, status: 403, code: OAuthGuardRefusalCode.OAUTH_TOKEN_NOT_ALLOWED };
|
|
64
20
|
}
|
|
65
|
-
const requiredScope = (0, oauth_app_constants_1.oauthAppScopeOf)(options.product,
|
|
21
|
+
const requiredScope = (0, oauth_app_constants_1.oauthAppScopeOf)(options.product, access);
|
|
66
22
|
if (!claims.scopes.includes(requiredScope)) {
|
|
67
23
|
return {
|
|
68
24
|
allowed: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-request-guard.util.js","sourceRoot":"","sources":["../../src/server/oauth-request-guard.util.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"oauth-request-guard.util.js","sourceRoot":"","sources":["../../src/server/oauth-request-guard.util.ts"],"names":[],"mappings":";;;AAaA,0EAA8F;AAC9F,iEAA+E;AAQ/E,IAAY,qBAKX;AALD,WAAY,qBAAqB;I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AAC;AAlBW,QAAA,uBAAuB,2BAkBlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const oauth_no_app_token_util_1 = require("../oauth-no-app-token.util");
|
|
4
|
+
describe('oauth-no-app-token.util', () => {
|
|
5
|
+
describe('isOAuthAppRequest', () => {
|
|
6
|
+
it('is true when the authentication of an app token set res.locals.oauth', () => {
|
|
7
|
+
expect((0, oauth_no_app_token_util_1.isOAuthAppRequest)({ oauth: { clientId: 'abys_app_x', scopes: ['cloud:read'] } })).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it('is true whatever the scopes: an empty scope list is still an app token', () => {
|
|
10
|
+
expect((0, oauth_no_app_token_util_1.isOAuthAppRequest)({ oauth: { clientId: 'abys_app_x', scopes: [] } })).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it('is false for a session, which never sets res.locals.oauth', () => {
|
|
13
|
+
expect((0, oauth_no_app_token_util_1.isOAuthAppRequest)({})).toBe(false);
|
|
14
|
+
expect((0, oauth_no_app_token_util_1.isOAuthAppRequest)({ oauth: undefined })).toBe(false);
|
|
15
|
+
expect((0, oauth_no_app_token_util_1.isOAuthAppRequest)({ oauth: null })).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe('createNoAppTokenMiddleware', () => {
|
|
19
|
+
it('calls refuse and never next for a request carried by an app token', () => {
|
|
20
|
+
const refuse = jest.fn();
|
|
21
|
+
const next = jest.fn();
|
|
22
|
+
const req = { method: 'GET' };
|
|
23
|
+
const res = {
|
|
24
|
+
locals: { oauth: { clientId: 'abys_app_x', scopes: ['console:read'] } },
|
|
25
|
+
};
|
|
26
|
+
(0, oauth_no_app_token_util_1.createNoAppTokenMiddleware)(refuse)(req, res, next);
|
|
27
|
+
expect(refuse).toHaveBeenCalledTimes(1);
|
|
28
|
+
expect(refuse).toHaveBeenCalledWith(req, res);
|
|
29
|
+
expect(next).not.toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
it('calls next and never refuse for a session', () => {
|
|
32
|
+
const refuse = jest.fn();
|
|
33
|
+
const next = jest.fn();
|
|
34
|
+
(0, oauth_no_app_token_util_1.createNoAppTokenMiddleware)(refuse)({ method: 'GET' }, { locals: {} }, next);
|
|
35
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
36
|
+
expect(refuse).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=oauth-no-app-token.util.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-no-app-token.util.spec.js","sourceRoot":"","sources":["../../../src/server/tests/oauth-no-app-token.util.spec.ts"],"names":[],"mappings":";;AAAA,wEAA2F;AAM3F,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,sEAAsE,EAAE,GAAG,EAAE;YAC9E,MAAM,CAAC,IAAA,2CAAiB,EAAC,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC3F,IAAI,CACL,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;YAChF,MAAM,CAAC,IAAA,2CAAiB,EAAC,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;YACnE,MAAM,CAAC,IAAA,2CAAiB,EAAC,EAAE,CAAC,CAAC,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,EAA8B,MAAM,CAAC,CAC7D,EAAE,MAAM,EAAE,KAAK,EAAE,EACjB,EAAE,MAAM,EAAE,EAAE,EAAE,EACd,IAAI,CACL,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YACtC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const oauth_app_enum_1 = require("../../types/enum/oauth-app.enum");
|
|
4
4
|
const oauth_request_guard_util_1 = require("../oauth-request-guard.util");
|
|
5
|
-
const
|
|
5
|
+
const NOT_ALLOWED = {
|
|
6
6
|
allowed: false,
|
|
7
7
|
status: 403,
|
|
8
8
|
code: oauth_request_guard_util_1.OAuthGuardRefusalCode.OAUTH_TOKEN_NOT_ALLOWED,
|
|
@@ -22,18 +22,13 @@ describe('oauth-request-guard.util', () => {
|
|
|
22
22
|
expect((0, oauth_request_guard_util_1.requiredOAuthAccessFor)(method)).toBe(access);
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
-
describe('createOAuthRequestGuard', () => {
|
|
26
|
-
const guard = (0, oauth_request_guard_util_1.createOAuthRequestGuard)({
|
|
27
|
-
product: oauth_app_enum_1.OAuthAppProduct.CLOUD,
|
|
28
|
-
credentialRoutes: [{ methods: oauth_request_guard_util_1.OAuthCredentialMethods.ANY, path: /^\/personal-api-key$/ }],
|
|
29
|
-
});
|
|
25
|
+
describe('createOAuthRequestGuard on a product with both accesses', () => {
|
|
26
|
+
const guard = (0, oauth_request_guard_util_1.createOAuthRequestGuard)({ product: oauth_app_enum_1.OAuthAppProduct.CLOUD });
|
|
30
27
|
it.each(['GET', 'HEAD'])('lets %s through with cloud:read', (method) => {
|
|
31
|
-
expect(guard({ method
|
|
32
|
-
allowed: true,
|
|
33
|
-
});
|
|
28
|
+
expect(guard({ method }, { scopes: ['cloud:read'] })).toEqual({ allowed: true });
|
|
34
29
|
});
|
|
35
30
|
it.each(['GET', 'HEAD'])('refuses %s with cloud:write alone: write is not read', (method) => {
|
|
36
|
-
expect(guard({ method
|
|
31
|
+
expect(guard({ method }, { scopes: ['cloud:write'] })).toEqual({
|
|
37
32
|
allowed: false,
|
|
38
33
|
status: 403,
|
|
39
34
|
code: oauth_request_guard_util_1.OAuthGuardRefusalCode.INSUFFICIENT_SCOPE,
|
|
@@ -41,114 +36,44 @@ describe('oauth-request-guard.util', () => {
|
|
|
41
36
|
});
|
|
42
37
|
});
|
|
43
38
|
it.each(['POST', 'PUT', 'PATCH', 'DELETE'])('refuses %s with cloud:read, lets it through with cloud:write', (method) => {
|
|
44
|
-
expect(guard({ method
|
|
39
|
+
expect(guard({ method }, { scopes: ['cloud:read'] })).toEqual({
|
|
45
40
|
allowed: false,
|
|
46
41
|
status: 403,
|
|
47
42
|
code: oauth_request_guard_util_1.OAuthGuardRefusalCode.INSUFFICIENT_SCOPE,
|
|
48
43
|
requiredScope: 'cloud:write',
|
|
49
44
|
});
|
|
50
|
-
expect(guard({ method
|
|
51
|
-
allowed: true,
|
|
52
|
-
});
|
|
45
|
+
expect(guard({ method }, { scopes: ['cloud:write'] })).toEqual({ allowed: true });
|
|
53
46
|
});
|
|
54
47
|
it('refuses the scope of another product', () => {
|
|
55
|
-
expect(guard({ method: 'GET'
|
|
48
|
+
expect(guard({ method: 'GET' }, { scopes: ['form:read'] })).toMatchObject({
|
|
56
49
|
allowed: false,
|
|
57
50
|
code: oauth_request_guard_util_1.OAuthGuardRefusalCode.INSUFFICIENT_SCOPE,
|
|
58
51
|
});
|
|
59
52
|
});
|
|
60
|
-
it('
|
|
61
|
-
expect(guard({ method: '
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
'/personal-api-key/',
|
|
65
|
-
'/PERSONAL-API-KEY',
|
|
66
|
-
'/api/personal-api-key',
|
|
67
|
-
'/API/Personal-Api-Key/',
|
|
68
|
-
'/api//personal-api-key',
|
|
69
|
-
'//api///personal-api-key//',
|
|
70
|
-
'/api/personal-api-key?x=1#frag',
|
|
71
|
-
'http://host:3000/API//personal-api-key',
|
|
72
|
-
])('refuses the variant %s of a credential route', (url) => {
|
|
73
|
-
expect(guard({ method: 'GET', path: '/x', originalUrl: url }, { scopes: ['cloud:read'] })).toEqual(REFUSED);
|
|
74
|
-
});
|
|
75
|
-
it('reads the path when there is no original URL', () => {
|
|
76
|
-
expect(guard({ method: 'GET', path: '/PERSONAL-API-KEY' }, { scopes: ['cloud:read'] })).toEqual(REFUSED);
|
|
77
|
-
});
|
|
78
|
-
it('has no credential route when none is declared', () => {
|
|
79
|
-
const bare = (0, oauth_request_guard_util_1.createOAuthRequestGuard)({ product: oauth_app_enum_1.OAuthAppProduct.CLOUD });
|
|
80
|
-
expect(bare({ method: 'GET', path: '/personal-api-key' }, { scopes: ['cloud:read'] })).toEqual({ allowed: true });
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe('credential route methods', () => {
|
|
84
|
-
const scopes = { scopes: ['cloud:read', 'cloud:write'] };
|
|
85
|
-
const url = '/api/secret/a/value';
|
|
86
|
-
const guardOf = (methods) => (0, oauth_request_guard_util_1.createOAuthRequestGuard)({
|
|
87
|
-
product: oauth_app_enum_1.OAuthAppProduct.CLOUD,
|
|
88
|
-
credentialRoutes: [{ methods, path: /^\/secret\/[^/]+\/value$/ }],
|
|
89
|
-
});
|
|
90
|
-
it.each(['GET', 'HEAD', 'POST', 'put', 'DELETE'])('ANY refuses %s', (method) => {
|
|
91
|
-
expect(guardOf(oauth_request_guard_util_1.OAuthCredentialMethods.ANY)({ method, originalUrl: url }, scopes)).toEqual(REFUSED);
|
|
92
|
-
});
|
|
93
|
-
it.each(['POST', 'PUT', 'PATCH', 'DELETE', 'put'])('ANY_WRITE refuses %s', (method) => {
|
|
94
|
-
expect(guardOf(oauth_request_guard_util_1.OAuthCredentialMethods.ANY_WRITE)({ method, originalUrl: url }, scopes)).toEqual(REFUSED);
|
|
95
|
-
});
|
|
96
|
-
it.each(['GET', 'HEAD'])('ANY_WRITE lets %s through', (method) => {
|
|
97
|
-
expect(guardOf(oauth_request_guard_util_1.OAuthCredentialMethods.ANY_WRITE)({ method, originalUrl: url }, scopes)).toEqual({ allowed: true });
|
|
98
|
-
});
|
|
99
|
-
it.each(['GET', 'get', 'HEAD'])('an explicit [get] list refuses %s (GET covers HEAD)', (m) => {
|
|
100
|
-
expect(guardOf(['get'])({ method: m, originalUrl: url }, scopes)).toEqual(REFUSED);
|
|
101
|
-
});
|
|
102
|
-
it('an explicit list lets another method through', () => {
|
|
103
|
-
expect(guardOf(['GET'])({ method: 'POST', originalUrl: url }, scopes)).toEqual({
|
|
104
|
-
allowed: true,
|
|
53
|
+
it('compares the method in any case', () => {
|
|
54
|
+
expect(guard({ method: 'post' }, { scopes: ['cloud:read'] })).toMatchObject({
|
|
55
|
+
allowed: false,
|
|
56
|
+
requiredScope: 'cloud:write',
|
|
105
57
|
});
|
|
106
58
|
});
|
|
107
|
-
it.each(['/api/secret/a/value/b', '/api/secret/a', '/api/secret//value'])('does not refuse the other path %s', (other) => {
|
|
108
|
-
expect(guardOf(oauth_request_guard_util_1.OAuthCredentialMethods.ANY)({ method: 'GET', originalUrl: other }, scopes)).toEqual({ allowed: true });
|
|
109
|
-
});
|
|
110
59
|
});
|
|
111
|
-
describe('
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
it.each([
|
|
117
|
-
['the i flag', /^\/secret$/i],
|
|
118
|
-
['the g flag', /^\/secret$/g],
|
|
119
|
-
['the y flag', /^\/secret$/y],
|
|
120
|
-
['an upper-case literal', /^\/Secret$/],
|
|
121
|
-
['an upper-case literal in a class', /^\/[A-Z]+$/],
|
|
122
|
-
['no start anchor', /\/secret$/],
|
|
123
|
-
['no end anchor', /^\/secret/],
|
|
124
|
-
['the /api prefix', /^\/api\/secret$/],
|
|
125
|
-
['the optional /api prefix', /^(?:\/api)?\/secret$/],
|
|
126
|
-
])('refuses a pattern with %s', (_name, path) => {
|
|
127
|
-
expect(build(path)).toThrow(/OAuth credential route/);
|
|
60
|
+
describe.each([oauth_app_enum_1.OAuthAppProduct.REFLEX, oauth_app_enum_1.OAuthAppProduct.CONSOLE])('createOAuthRequestGuard on %s, a read-only product', (product) => {
|
|
61
|
+
const guard = (0, oauth_request_guard_util_1.createOAuthRequestGuard)({ product });
|
|
62
|
+
it.each(['GET', 'HEAD'])('lets %s through with the read scope', (method) => {
|
|
63
|
+
expect(guard({ method }, { scopes: [`${product}:read`] })).toEqual({ allowed: true });
|
|
128
64
|
});
|
|
129
|
-
it('
|
|
130
|
-
expect(
|
|
65
|
+
it.each(['GET', 'HEAD'])('still asks for the read scope on %s', (method) => {
|
|
66
|
+
expect(guard({ method }, { scopes: [] })).toEqual({
|
|
67
|
+
allowed: false,
|
|
68
|
+
status: 403,
|
|
69
|
+
code: oauth_request_guard_util_1.OAuthGuardRefusalCode.INSUFFICIENT_SCOPE,
|
|
70
|
+
requiredScope: `${product}:read`,
|
|
71
|
+
});
|
|
131
72
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
['/API/Secret/P/S/VALUE', '/secret/p/s/value'],
|
|
137
|
-
['/api//secret///p/s/value', '/secret/p/s/value'],
|
|
138
|
-
['//api/secret/p/s/value/', '/secret/p/s/value'],
|
|
139
|
-
['/api/secret/p/s/value?a=b/c', '/secret/p/s/value'],
|
|
140
|
-
['/api/secret/p/s/value#frag/x', '/secret/p/s/value'],
|
|
141
|
-
['/api/secret/p/s/value?a=1#f', '/secret/p/s/value'],
|
|
142
|
-
['https://host:10112/api/secret/p', '/secret/p'],
|
|
143
|
-
['/api', '/'],
|
|
144
|
-
['/', '/'],
|
|
145
|
-
['', '/'],
|
|
146
|
-
['/apix/secret', '/apix/secret'],
|
|
147
|
-
['/api/api/secret', '/api/secret'],
|
|
148
|
-
['/secret/%76alue', '/secret/%76alue'],
|
|
149
|
-
['/secret/a%2Fb', '/secret/a%2fb'],
|
|
150
|
-
])('%s -> %s', (url, canonical) => {
|
|
151
|
-
expect((0, oauth_request_guard_util_1.canonicalOAuthRoutePath)(url)).toBe(canonical);
|
|
73
|
+
it.each(['POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'])('refuses %s with oauthTokenNotAllowed, not insufficient_scope, whatever the scopes', (method) => {
|
|
74
|
+
expect(guard({ method }, { scopes: [`${product}:read`] })).toEqual(NOT_ALLOWED);
|
|
75
|
+
expect(guard({ method }, { scopes: [`${product}:read`, `${product}:write`] })).toEqual(NOT_ALLOWED);
|
|
76
|
+
expect(guard({ method }, { scopes: [] })).toEqual(NOT_ALLOWED);
|
|
152
77
|
});
|
|
153
78
|
});
|
|
154
79
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-request-guard.util.spec.js","sourceRoot":"","sources":["../../../src/server/tests/oauth-request-guard.util.spec.ts"],"names":[],"mappings":";;AAAA,oEAAkF;AAClF,
|
|
1
|
+
{"version":3,"file":"oauth-request-guard.util.spec.js","sourceRoot":"","sources":["../../../src/server/tests/oauth-request-guard.util.spec.ts"],"names":[],"mappings":";;AAAA,oEAAkF;AAClF,0EAIqC;AAErC,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,gDAAqB,CAAC,uBAAuB;CACpD,CAAC;AAEF,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,IAAI,CAAC;YACN,CAAC,KAAK,EAAE,+BAAc,CAAC,IAAI,CAAC;YAC5B,CAAC,MAAM,EAAE,+BAAc,CAAC,IAAI,CAAC;YAC7B,CAAC,KAAK,EAAE,+BAAc,CAAC,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