@onlineapps/service-validator-core 1.0.7 → 1.0.9
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 +24 -0
- package/coverage/clover.xml +0 -0
- package/coverage/coverage-final.json +0 -0
- package/coverage/lcov-report/base.css +0 -0
- package/coverage/lcov-report/block-navigation.js +0 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -0
- package/coverage/lcov-report/prettify.css +0 -0
- package/coverage/lcov-report/prettify.js +0 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -0
- package/coverage/lcov-report/src/index.html +0 -0
- package/coverage/lcov-report/src/index.js.html +0 -0
- package/coverage/lcov-report/src/security/certificateManager.js.html +0 -0
- package/coverage/lcov-report/src/security/index.html +0 -0
- package/coverage/lcov-report/src/security/tokenManager.js.html +0 -0
- package/coverage/lcov-report/src/validators/connectorValidator.js.html +0 -0
- package/coverage/lcov-report/src/validators/endpointValidator.js.html +0 -0
- package/coverage/lcov-report/src/validators/healthValidator.js.html +0 -0
- package/coverage/lcov-report/src/validators/index.html +0 -0
- package/coverage/lcov-report/src/validators/openApiValidator.js.html +0 -0
- package/coverage/lcov.info +0 -0
- package/jest.config.js +0 -0
- package/package.json +5 -1
- package/src/config.js +30 -0
- package/src/defaults.js +17 -0
- package/src/index.js +1 -1
- package/src/security/ValidationProofCodec.js +0 -0
- package/src/security/ValidationProofVerifier.js +0 -0
- package/src/security/certificateManager.js +0 -0
- package/src/security/tokenManager.js +17 -12
- package/src/types/ValidationProofSchema.js +0 -0
- package/src/utils/FingerprintUtils.js +0 -0
- package/src/validators/connectorValidator.js +0 -0
- package/src/validators/endpointValidator.js +0 -0
- package/src/validators/healthValidator.js +0 -0
- package/src/validators/openApiValidator.js +0 -0
- package/tests/component/validation-flow.test.js +10 -0
- package/tests/integration/real-validation.test.js +10 -0
- package/tests/unit/ValidationCore.test.js +10 -0
package/README.md
CHANGED
|
@@ -81,6 +81,30 @@ Validates health check configuration:
|
|
|
81
81
|
- **TokenManager** - Generates and verifies pre-validation tokens
|
|
82
82
|
- **CertificateManager** - Issues and verifies cryptographic certificates
|
|
83
83
|
|
|
84
|
+
### Validation Proof Structure
|
|
85
|
+
|
|
86
|
+
**Official format** (returned by `ValidationProofCodec.encode()`):
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"validationProof": "<SHA256-hash-64-chars>",
|
|
90
|
+
"validationData": {
|
|
91
|
+
"serviceName": "hello-service",
|
|
92
|
+
"version": "1.0.0",
|
|
93
|
+
"validator": "@onlineapps/conn-orch-validator",
|
|
94
|
+
"validatorVersion": "2.0.6",
|
|
95
|
+
"validatedAt": "2025-10-23T06:53:12.996Z",
|
|
96
|
+
"testsRun": 3,
|
|
97
|
+
"testsPassed": 3,
|
|
98
|
+
"testsFailed": 0,
|
|
99
|
+
"durationMs": 151
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**IMPORTANT:** Always use `validationProof` and `validationData` keys (NOT `hash`/`data`).
|
|
105
|
+
|
|
106
|
+
See [ValidationProofCodec.js](src/security/ValidationProofCodec.js) and [ValidationProofSchema.js](src/types/ValidationProofSchema.js) for complete specification.
|
|
107
|
+
|
|
84
108
|
## API
|
|
85
109
|
|
|
86
110
|
### ValidationCore(config)
|
package/coverage/clover.xml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/coverage/lcov.info
CHANGED
|
File without changes
|
package/jest.config.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/service-validator-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Core validation logic for microservices",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest",
|
|
8
|
+
"test:unit": "jest tests/unit",
|
|
9
|
+
"test:component": "jest tests/component",
|
|
10
|
+
"test:integration": "jest tests/integration",
|
|
8
11
|
"test:coverage": "jest --coverage",
|
|
9
12
|
"lint": "eslint src/"
|
|
10
13
|
},
|
|
@@ -17,6 +20,7 @@
|
|
|
17
20
|
"license": "MIT",
|
|
18
21
|
"dependencies": {
|
|
19
22
|
"ajv": "^8.12.0",
|
|
23
|
+
"@onlineapps/runtime-config": "1.0.2",
|
|
20
24
|
"jsonwebtoken": "^9.0.2",
|
|
21
25
|
"uuid": "^9.0.1"
|
|
22
26
|
},
|
package/src/config.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runtime configuration schema for @onlineapps/service-validator-core.
|
|
5
|
+
*
|
|
6
|
+
* Priority:
|
|
7
|
+
* 1) Explicit config
|
|
8
|
+
* 2) ENV
|
|
9
|
+
* 3) Module-owned defaults
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT:
|
|
12
|
+
* - Token secret is required (NO FALLBACKS).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { createRuntimeConfig } = require('@onlineapps/runtime-config');
|
|
16
|
+
const DEFAULTS = require('./defaults');
|
|
17
|
+
|
|
18
|
+
const runtimeCfg = createRuntimeConfig({
|
|
19
|
+
defaults: DEFAULTS,
|
|
20
|
+
schema: {
|
|
21
|
+
tokenSecret: { env: 'VALIDATION_TOKEN_SECRET', required: true },
|
|
22
|
+
tokenExpiresIn: { env: 'VALIDATION_TOKEN_EXPIRES_IN', defaultKey: 'tokenExpiresIn' },
|
|
23
|
+
tokenAlgorithm: { env: 'VALIDATION_TOKEN_ALGORITHM', defaultKey: 'tokenAlgorithm' },
|
|
24
|
+
tokenIssuer: { env: 'VALIDATION_TOKEN_ISSUER', defaultKey: 'tokenIssuer' },
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
module.exports = runtimeCfg;
|
|
29
|
+
|
|
30
|
+
|
package/src/defaults.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Module-owned defaults for @onlineapps/service-validator-core.
|
|
5
|
+
*
|
|
6
|
+
* Ownership rule:
|
|
7
|
+
* - This module owns token behavior defaults (expiry, algorithm, issuer).
|
|
8
|
+
* - Secret is NOT defaulted (must be provided via explicit config or ENV).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
tokenExpiresIn: '24h',
|
|
13
|
+
tokenAlgorithm: 'HS256',
|
|
14
|
+
tokenIssuer: 'validation-core',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
package/src/index.js
CHANGED
|
@@ -30,7 +30,7 @@ class ValidationCore {
|
|
|
30
30
|
health: new HealthValidator()
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
this.tokenManager = new TokenManager();
|
|
33
|
+
this.tokenManager = new TokenManager(this.config.token || {});
|
|
34
34
|
this.certificateManager = new CertificateManager();
|
|
35
35
|
this.proofVerifier = new ValidationProofVerifier({
|
|
36
36
|
maxProofAge: config.maxProofAge,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
const jwt = require('jsonwebtoken');
|
|
2
2
|
const crypto = require('crypto');
|
|
3
3
|
const FingerprintUtils = require('../utils/FingerprintUtils');
|
|
4
|
+
const runtimeCfg = require('../config');
|
|
4
5
|
|
|
5
6
|
class TokenManager {
|
|
6
7
|
constructor(config = {}) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
let resolved;
|
|
9
|
+
try {
|
|
10
|
+
resolved = runtimeCfg.resolve({
|
|
11
|
+
tokenSecret: config.secret,
|
|
12
|
+
tokenExpiresIn: config.expiresIn,
|
|
13
|
+
tokenAlgorithm: config.algorithm,
|
|
14
|
+
tokenIssuer: config.issuer,
|
|
15
|
+
});
|
|
16
|
+
} catch (err) {
|
|
17
|
+
throw new Error('[TokenManager] Missing configuration - tokenSecret is required (set VALIDATION_TOKEN_SECRET env or pass config.secret)');
|
|
18
|
+
}
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return crypto.randomBytes(64).toString('hex');
|
|
20
|
+
this.secret = resolved.tokenSecret;
|
|
21
|
+
this.expiresIn = resolved.tokenExpiresIn;
|
|
22
|
+
this.algorithm = resolved.tokenAlgorithm;
|
|
23
|
+
this.issuer = resolved.tokenIssuer;
|
|
24
|
+
this.usedTokens = new Set(); // Track used tokens for single-use enforcement
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/**
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -2,10 +2,20 @@ const ValidationCore = require('../../src/index');
|
|
|
2
2
|
|
|
3
3
|
describe('Validation Flow Component Tests @component', () => {
|
|
4
4
|
let validationCore;
|
|
5
|
+
let oldSecret;
|
|
5
6
|
|
|
6
7
|
beforeEach(() => {
|
|
8
|
+
oldSecret = process.env.VALIDATION_TOKEN_SECRET;
|
|
9
|
+
process.env.VALIDATION_TOKEN_SECRET = 'test-validation-secret';
|
|
7
10
|
validationCore = new ValidationCore();
|
|
8
11
|
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
if (oldSecret === undefined) {
|
|
14
|
+
delete process.env.VALIDATION_TOKEN_SECRET;
|
|
15
|
+
} else {
|
|
16
|
+
process.env.VALIDATION_TOKEN_SECRET = oldSecret;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
9
19
|
|
|
10
20
|
describe('Complete validation workflow', () => {
|
|
11
21
|
it('should perform full validation and generate token', async () => {
|
|
@@ -4,10 +4,20 @@ const path = require('path');
|
|
|
4
4
|
|
|
5
5
|
describe('ValidationCore Integration Tests @integration', () => {
|
|
6
6
|
let validationCore;
|
|
7
|
+
let oldSecret;
|
|
7
8
|
|
|
8
9
|
beforeEach(() => {
|
|
10
|
+
oldSecret = process.env.VALIDATION_TOKEN_SECRET;
|
|
11
|
+
process.env.VALIDATION_TOKEN_SECRET = 'test-validation-secret';
|
|
9
12
|
validationCore = new ValidationCore();
|
|
10
13
|
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
if (oldSecret === undefined) {
|
|
16
|
+
delete process.env.VALIDATION_TOKEN_SECRET;
|
|
17
|
+
} else {
|
|
18
|
+
process.env.VALIDATION_TOKEN_SECRET = oldSecret;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
11
21
|
|
|
12
22
|
describe('Real service validation', () => {
|
|
13
23
|
it('should validate a complete service configuration', async () => {
|
|
@@ -2,10 +2,20 @@ const ValidationCore = require('../../src/index');
|
|
|
2
2
|
|
|
3
3
|
describe('ValidationCore Unit Tests @unit', () => {
|
|
4
4
|
let validationCore;
|
|
5
|
+
let oldSecret;
|
|
5
6
|
|
|
6
7
|
beforeEach(() => {
|
|
8
|
+
oldSecret = process.env.VALIDATION_TOKEN_SECRET;
|
|
9
|
+
process.env.VALIDATION_TOKEN_SECRET = 'test-validation-secret';
|
|
7
10
|
validationCore = new ValidationCore();
|
|
8
11
|
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
if (oldSecret === undefined) {
|
|
14
|
+
delete process.env.VALIDATION_TOKEN_SECRET;
|
|
15
|
+
} else {
|
|
16
|
+
process.env.VALIDATION_TOKEN_SECRET = oldSecret;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
9
19
|
|
|
10
20
|
describe('constructor', () => {
|
|
11
21
|
it('should initialize with default config', () => {
|