@cryptexlabs/codex-nodejs-common 0.10.37 → 0.11.1
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/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptexlabs/codex-nodejs-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Common code for Codex framework",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
|
|
@@ -21,9 +21,13 @@
|
|
|
21
21
|
"@nestjs/platform-ws": "8.0.6",
|
|
22
22
|
"@nestjs/swagger": "5.0.9",
|
|
23
23
|
"@nestjs/websockets": "8.0.6",
|
|
24
|
-
"axios": "
|
|
24
|
+
"axios": "^1.7.7",
|
|
25
25
|
"rxjs": "^7.1.0"
|
|
26
26
|
},
|
|
27
|
+
"resolutions": {
|
|
28
|
+
"**/string-width": "4.2.3",
|
|
29
|
+
"**/wrap-ansi": "7.0.0"
|
|
30
|
+
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"@cryptexlabs/authf-data-model": "^0.9.15",
|
|
29
33
|
"@cryptexlabs/codex-data-model": "0.1.9",
|
|
@@ -84,10 +88,6 @@
|
|
|
84
88
|
"test": "jest",
|
|
85
89
|
"postinstall": "install-peers || true"
|
|
86
90
|
},
|
|
87
|
-
"resolutions": {
|
|
88
|
-
"axios": "0.19.0",
|
|
89
|
-
"**/undici": "5.0.0"
|
|
90
|
-
},
|
|
91
91
|
"husky": {
|
|
92
92
|
"hooks": {
|
|
93
93
|
"pre-commit": "yarn prettier && yarn lint && yarn test && yarn build"
|
|
@@ -24,8 +24,10 @@ let AuthfGuard = class AuthfGuard {
|
|
|
24
24
|
constructor(config, contextBuilder) {
|
|
25
25
|
this.config = config;
|
|
26
26
|
this.contextBuilder = contextBuilder;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (config.authEnabled) {
|
|
28
|
+
this._ensurePem().then();
|
|
29
|
+
this._watchBlacklist().then();
|
|
30
|
+
}
|
|
29
31
|
this._blacklistedSubjects = [];
|
|
30
32
|
}
|
|
31
33
|
canActivate(context) {
|
|
@@ -72,7 +74,7 @@ let AuthfGuard = class AuthfGuard {
|
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
76
|
async _ensurePem() {
|
|
75
|
-
if (this._pem
|
|
77
|
+
if (this._pem) {
|
|
76
78
|
return;
|
|
77
79
|
}
|
|
78
80
|
const context = this.contextBuilder.build().getResult();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authf.guard.js","sourceRoot":"","sources":["../../../src/auth/authf.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAA0C;AAC1C,2CAMwB;AAKxB,iCAA0B;AAC1B,+BAAoC;AACpC,wCAAqD;AACrD,uCAAuC;AACvC,oCAAoC;AAI7B,IAAM,UAAU,GAAhB,MAAM,UAAU;IAKrB,YACqC,MAAqB,EACZ,cAA8B;QADvC,WAAM,GAAN,MAAM,CAAe;QACZ,mBAAc,GAAd,cAAc,CAAgB;QAE1E,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"authf.guard.js","sourceRoot":"","sources":["../../../src/auth/authf.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAA0C;AAC1C,2CAMwB;AAKxB,iCAA0B;AAC1B,+BAAoC;AACpC,wCAAqD;AACrD,uCAAuC;AACvC,oCAAoC;AAI7B,IAAM,UAAU,GAAhB,MAAM,UAAU;IAKrB,YACqC,MAAqB,EACZ,cAA8B;QADvC,WAAM,GAAN,MAAM,CAAe;QACZ,mBAAc,GAAd,cAAc,CAAgB;QAE1E,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,EA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Aa;QACI,wBAAc;GAPjE,UAAU,CAuHtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptexlabs/codex-nodejs-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Common code for Codex framework",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
|
|
@@ -21,9 +21,13 @@
|
|
|
21
21
|
"@nestjs/platform-ws": "8.0.6",
|
|
22
22
|
"@nestjs/swagger": "5.0.9",
|
|
23
23
|
"@nestjs/websockets": "8.0.6",
|
|
24
|
-
"axios": "
|
|
24
|
+
"axios": "^1.7.7",
|
|
25
25
|
"rxjs": "^7.1.0"
|
|
26
26
|
},
|
|
27
|
+
"resolutions": {
|
|
28
|
+
"**/string-width": "4.2.3",
|
|
29
|
+
"**/wrap-ansi": "7.0.0"
|
|
30
|
+
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"@cryptexlabs/authf-data-model": "^0.9.15",
|
|
29
33
|
"@cryptexlabs/codex-data-model": "0.1.9",
|
|
@@ -84,10 +88,6 @@
|
|
|
84
88
|
"test": "jest",
|
|
85
89
|
"postinstall": "install-peers || true"
|
|
86
90
|
},
|
|
87
|
-
"resolutions": {
|
|
88
|
-
"axios": "0.19.0",
|
|
89
|
-
"**/undici": "5.0.0"
|
|
90
|
-
},
|
|
91
91
|
"husky": {
|
|
92
92
|
"hooks": {
|
|
93
93
|
"pre-commit": "yarn prettier && yarn lint && yarn test && yarn build"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuthfGuard } from "./authf.guard";
|
|
2
|
+
import { DefaultConfig } from "../config";
|
|
3
|
+
import { instance, mock, when } from "ts-mockito";
|
|
4
|
+
import { Context, ContextBuilder } from "../context";
|
|
5
|
+
|
|
6
|
+
describe("AuthGuard", () => {
|
|
7
|
+
let authGuard: AuthfGuard;
|
|
8
|
+
let ConfigMock: DefaultConfig;
|
|
9
|
+
let ContextBuilderMock: ContextBuilder;
|
|
10
|
+
let ContextMock: Context;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
ConfigMock = mock(DefaultConfig);
|
|
14
|
+
ContextBuilderMock = mock(ContextBuilder);
|
|
15
|
+
ContextMock = mock(Context);
|
|
16
|
+
|
|
17
|
+
when(ConfigMock.authEnabled).thenReturn(false);
|
|
18
|
+
when(ContextBuilderMock.build()).thenReturn(instance(ContextBuilderMock));
|
|
19
|
+
when(ContextBuilderMock.getResult()).thenReturn(instance(ContextMock));
|
|
20
|
+
when(ContextMock.logger).thenReturn({
|
|
21
|
+
debug: () => {},
|
|
22
|
+
warn: () => {},
|
|
23
|
+
} as any);
|
|
24
|
+
|
|
25
|
+
authGuard = new AuthfGuard(
|
|
26
|
+
instance(ConfigMock),
|
|
27
|
+
instance(ContextBuilderMock)
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should be defined", () => {
|
|
32
|
+
expect(true).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/src/auth/authf.guard.ts
CHANGED
|
@@ -27,8 +27,10 @@ export class AuthfGuard implements CanActivate {
|
|
|
27
27
|
@Inject("CONFIG") private readonly config: DefaultConfig,
|
|
28
28
|
@Inject("CONTEXT_BUILDER") private readonly contextBuilder: ContextBuilder
|
|
29
29
|
) {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if (config.authEnabled) {
|
|
31
|
+
this._ensurePem().then();
|
|
32
|
+
this._watchBlacklist().then();
|
|
33
|
+
}
|
|
32
34
|
this._blacklistedSubjects = [];
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -84,14 +86,14 @@ export class AuthfGuard implements CanActivate {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
private async _ensurePem(): Promise<void> {
|
|
87
|
-
if (this._pem
|
|
89
|
+
if (this._pem) {
|
|
88
90
|
return;
|
|
89
91
|
}
|
|
90
92
|
const context = this.contextBuilder.build().getResult();
|
|
91
93
|
|
|
92
94
|
const keysHttpResponse = await axios.get(`/api/v1/key`, {
|
|
93
|
-
baseURL: this.config.authfUrl,
|
|
94
|
-
headers: this._getApiHeaders(context),
|
|
95
|
+
baseURL: this.config.authfUrl as string,
|
|
96
|
+
headers: this._getApiHeaders(context) as any,
|
|
95
97
|
});
|
|
96
98
|
|
|
97
99
|
const response: JwtKeyResponseInterface = keysHttpResponse.data;
|