@onlineapps/service-validator-core 1.0.2

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.
Files changed (35) hide show
  1. package/README.md +127 -0
  2. package/coverage/clover.xml +468 -0
  3. package/coverage/coverage-final.json +8 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +87 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +146 -0
  8. package/coverage/lcov-report/prettify.css +1 -0
  9. package/coverage/lcov-report/prettify.js +2 -0
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +210 -0
  12. package/coverage/lcov-report/src/index.html +116 -0
  13. package/coverage/lcov-report/src/index.js.html +643 -0
  14. package/coverage/lcov-report/src/security/certificateManager.js.html +799 -0
  15. package/coverage/lcov-report/src/security/index.html +131 -0
  16. package/coverage/lcov-report/src/security/tokenManager.js.html +622 -0
  17. package/coverage/lcov-report/src/validators/connectorValidator.js.html +787 -0
  18. package/coverage/lcov-report/src/validators/endpointValidator.js.html +577 -0
  19. package/coverage/lcov-report/src/validators/healthValidator.js.html +655 -0
  20. package/coverage/lcov-report/src/validators/index.html +161 -0
  21. package/coverage/lcov-report/src/validators/openApiValidator.js.html +517 -0
  22. package/coverage/lcov.info +982 -0
  23. package/jest.config.js +21 -0
  24. package/package.json +31 -0
  25. package/src/index.js +212 -0
  26. package/src/security/ValidationProofVerifier.js +178 -0
  27. package/src/security/certificateManager.js +239 -0
  28. package/src/security/tokenManager.js +194 -0
  29. package/src/validators/connectorValidator.js +235 -0
  30. package/src/validators/endpointValidator.js +165 -0
  31. package/src/validators/healthValidator.js +191 -0
  32. package/src/validators/openApiValidator.js +145 -0
  33. package/test/component/validation-flow.test.js +353 -0
  34. package/test/integration/real-validation.test.js +548 -0
  35. package/test/unit/ValidationCore.test.js +320 -0
@@ -0,0 +1,320 @@
1
+ const ValidationCore = require('../../src/index');
2
+
3
+ describe('ValidationCore Unit Tests', () => {
4
+ let validationCore;
5
+
6
+ beforeEach(() => {
7
+ validationCore = new ValidationCore();
8
+ });
9
+
10
+ describe('constructor', () => {
11
+ it('should initialize with default config', () => {
12
+ expect(validationCore.config.strictMode).toBe(false);
13
+ expect(validationCore.config.requiredConnectors).toHaveLength(5);
14
+ });
15
+
16
+ it('should accept custom config', () => {
17
+ const customCore = new ValidationCore({ strictMode: true });
18
+ expect(customCore.config.strictMode).toBe(true);
19
+ });
20
+
21
+ it('should initialize all validators', () => {
22
+ expect(validationCore.validators.openApi).toBeDefined();
23
+ expect(validationCore.validators.endpoints).toBeDefined();
24
+ expect(validationCore.validators.connectors).toBeDefined();
25
+ expect(validationCore.validators.health).toBeDefined();
26
+ });
27
+
28
+ it('should initialize token and certificate managers', () => {
29
+ expect(validationCore.tokenManager).toBeDefined();
30
+ expect(validationCore.certificateManager).toBeDefined();
31
+ });
32
+ });
33
+
34
+ describe('validate', () => {
35
+ it('should return success for valid service data', async () => {
36
+ const serviceData = {
37
+ metadata: {
38
+ connectors: [
39
+ 'connector-logger',
40
+ 'connector-storage',
41
+ 'connector-registry-client',
42
+ 'connector-mq-client',
43
+ 'connector-cookbook'
44
+ ]
45
+ }
46
+ };
47
+
48
+ // Mock validator responses
49
+ validationCore.validators.connectors.validate = jest.fn().mockResolvedValue({
50
+ valid: true,
51
+ warnings: []
52
+ });
53
+
54
+ const result = await validationCore.validate(serviceData);
55
+ expect(result.success).toBe(true);
56
+ expect(result.validated).toBe(true);
57
+ expect(result.errors).toHaveLength(0);
58
+ });
59
+
60
+ it('should handle OpenAPI validation', async () => {
61
+ const serviceData = {
62
+ openApiSpec: {
63
+ openapi: '3.0.0',
64
+ info: { title: 'Test API', version: '1.0.0' },
65
+ paths: {}
66
+ }
67
+ };
68
+
69
+ validationCore.validators.openApi.validate = jest.fn().mockResolvedValue({
70
+ valid: true,
71
+ errors: []
72
+ });
73
+
74
+ const result = await validationCore.validate(serviceData);
75
+ expect(result.checks.openApi).toBeDefined();
76
+ expect(validationCore.validators.openApi.validate).toHaveBeenCalled();
77
+ });
78
+
79
+ it('should handle endpoint validation', async () => {
80
+ const serviceData = {
81
+ endpoints: [
82
+ { path: '/health', method: 'GET' },
83
+ { path: '/api/test', method: 'POST' }
84
+ ]
85
+ };
86
+
87
+ validationCore.validators.endpoints.validate = jest.fn().mockResolvedValue({
88
+ valid: true,
89
+ errors: []
90
+ });
91
+
92
+ const result = await validationCore.validate(serviceData);
93
+ expect(result.checks.endpoints).toBeDefined();
94
+ expect(validationCore.validators.endpoints.validate).toHaveBeenCalled();
95
+ });
96
+
97
+ it('should handle health validation', async () => {
98
+ const serviceData = {
99
+ health: {
100
+ status: 'healthy',
101
+ uptime: 12345
102
+ }
103
+ };
104
+
105
+ validationCore.validators.health.validate = jest.fn().mockResolvedValue({
106
+ valid: true,
107
+ warnings: []
108
+ });
109
+
110
+ const result = await validationCore.validate(serviceData);
111
+ expect(result.checks.health).toBeDefined();
112
+ expect(validationCore.validators.health.validate).toHaveBeenCalled();
113
+ });
114
+
115
+ it('should collect errors from validators', async () => {
116
+ const serviceData = {
117
+ openApiSpec: {}
118
+ };
119
+
120
+ validationCore.validators.openApi.validate = jest.fn().mockResolvedValue({
121
+ valid: false,
122
+ errors: ['Invalid OpenAPI spec']
123
+ });
124
+
125
+ const result = await validationCore.validate(serviceData);
126
+ expect(result.success).toBe(false);
127
+ expect(result.errors).toContain('Invalid OpenAPI spec');
128
+ });
129
+
130
+ it('should handle validation exceptions', async () => {
131
+ const serviceData = {
132
+ openApiSpec: {}
133
+ };
134
+
135
+ validationCore.validators.openApi.validate = jest.fn().mockRejectedValue(
136
+ new Error('Validation failed')
137
+ );
138
+
139
+ const result = await validationCore.validate(serviceData);
140
+ expect(result.success).toBe(false);
141
+ expect(result.errors[0]).toContain('Validation error');
142
+ });
143
+
144
+ it('should handle strict mode for connector warnings', async () => {
145
+ const strictCore = new ValidationCore({ strictMode: true });
146
+ const serviceData = {
147
+ metadata: {
148
+ connectors: ['connector-logger']
149
+ }
150
+ };
151
+
152
+ strictCore.validators.connectors.validate = jest.fn().mockResolvedValue({
153
+ valid: false,
154
+ warnings: ['Missing required connectors']
155
+ });
156
+
157
+ const result = await strictCore.validate(serviceData);
158
+ expect(result.errors).toContain('Missing required connectors');
159
+ expect(result.warnings).toContain('Missing required connectors');
160
+ });
161
+ });
162
+
163
+ describe('generatePreValidationToken', () => {
164
+ beforeEach(() => {
165
+ validationCore.tokenManager.generateToken = jest.fn().mockResolvedValue({
166
+ token: 'test-token',
167
+ secret: 'test-secret',
168
+ tokenId: 'test-id'
169
+ });
170
+ });
171
+
172
+ it('should generate token for successful validation', async () => {
173
+ const validationResults = {
174
+ success: true,
175
+ validated: true
176
+ };
177
+
178
+ const tokenData = await validationCore.generatePreValidationToken(
179
+ validationResults,
180
+ 'test-service'
181
+ );
182
+
183
+ expect(tokenData.token).toBe('test-token');
184
+ expect(tokenData.secret).toBe('test-secret');
185
+ expect(tokenData.tokenId).toBe('test-id');
186
+ expect(validationCore.tokenManager.generateToken).toHaveBeenCalledWith({
187
+ serviceName: 'test-service',
188
+ validationResults,
189
+ type: 'pre-validation'
190
+ });
191
+ });
192
+
193
+ it('should throw error for failed validation', async () => {
194
+ const validationResults = {
195
+ success: false,
196
+ errors: ['Validation failed']
197
+ };
198
+
199
+ await expect(
200
+ validationCore.generatePreValidationToken(validationResults, 'test-service')
201
+ ).rejects.toThrow('Cannot generate token for failed validation');
202
+ });
203
+ });
204
+
205
+ describe('verifyPreValidationToken', () => {
206
+ it('should verify token', async () => {
207
+ const mockPayload = {
208
+ serviceName: 'test-service',
209
+ type: 'pre-validation'
210
+ };
211
+
212
+ validationCore.tokenManager.verifyToken = jest.fn().mockResolvedValue(mockPayload);
213
+
214
+ const result = await validationCore.verifyPreValidationToken('test-token');
215
+ expect(result).toEqual(mockPayload);
216
+ expect(validationCore.tokenManager.verifyToken).toHaveBeenCalledWith('test-token', null);
217
+ });
218
+ });
219
+
220
+ describe('generateCertificate', () => {
221
+ beforeEach(() => {
222
+ validationCore.certificateManager.generateCertificate = jest.fn().mockResolvedValue({
223
+ certificate: 'test-cert',
224
+ signature: 'test-signature'
225
+ });
226
+ });
227
+
228
+ it('should generate certificate for successful validation', async () => {
229
+ const validationResults = {
230
+ success: true,
231
+ validated: true
232
+ };
233
+
234
+ const cert = await validationCore.generateCertificate(
235
+ validationResults,
236
+ 'test-service',
237
+ '1.0.0'
238
+ );
239
+
240
+ expect(cert).toHaveProperty('certificate');
241
+ expect(cert).toHaveProperty('signature');
242
+ });
243
+
244
+ it('should throw error for failed validation', async () => {
245
+ const validationResults = {
246
+ success: false,
247
+ errors: ['Validation failed']
248
+ };
249
+
250
+ await expect(
251
+ validationCore.generateCertificate(validationResults, 'test-service', '1.0.0')
252
+ ).rejects.toThrow('Cannot generate certificate for failed validation');
253
+ });
254
+ });
255
+
256
+ describe('verifyCertificate', () => {
257
+ it('should verify certificate', async () => {
258
+ validationCore.certificateManager.verifyCertificate = jest.fn().mockResolvedValue(true);
259
+
260
+ const result = await validationCore.verifyCertificate({
261
+ certificate: 'test-cert',
262
+ signature: 'test-signature'
263
+ });
264
+
265
+ expect(result).toBe(true);
266
+ });
267
+ });
268
+
269
+ describe('generateFunctionalTests', () => {
270
+ it('should generate tests from OpenAPI spec', async () => {
271
+ const openApiSpec = {
272
+ paths: {
273
+ '/users': {
274
+ get: {
275
+ summary: 'Get users',
276
+ responses: {
277
+ '200': { description: 'Success' }
278
+ }
279
+ },
280
+ post: {
281
+ summary: 'Create user',
282
+ responses: {
283
+ '201': { description: 'Created' }
284
+ }
285
+ }
286
+ },
287
+ '/users/{id}': {
288
+ get: {
289
+ summary: 'Get user by ID',
290
+ parameters: [
291
+ { name: 'id', in: 'path', required: true }
292
+ ],
293
+ responses: {
294
+ '200': { description: 'Success' }
295
+ }
296
+ }
297
+ }
298
+ }
299
+ };
300
+
301
+ const tests = await validationCore.generateFunctionalTests(openApiSpec);
302
+
303
+ expect(tests).toHaveLength(3);
304
+ expect(tests[0].method).toBe('GET');
305
+ expect(tests[0].path).toBe('/users');
306
+ expect(tests[1].method).toBe('POST');
307
+ expect(tests[2].parameters).toHaveLength(1);
308
+ });
309
+
310
+ it('should handle empty spec', async () => {
311
+ const tests = await validationCore.generateFunctionalTests({});
312
+ expect(tests).toEqual([]);
313
+ });
314
+
315
+ it('should handle null spec', async () => {
316
+ const tests = await validationCore.generateFunctionalTests(null);
317
+ expect(tests).toEqual([]);
318
+ });
319
+ });
320
+ });