From 14be345d907716da5862950f595ebe209a18b94f Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 17 Dec 2024 20:29:49 +0100 Subject: [PATCH] fix: tests Signed-off-by: Timo Glastra --- jest.config.base.ts | 1 - jest.config.ts | 1 + .../core/src/modules/x509/X509ModuleConfig.ts | 12 +++--- .../x509/__tests__/X509ServiceModule.test.ts | 38 +++++++++++++++++-- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/jest.config.base.ts b/jest.config.base.ts index 6fea81e953..43b6b40302 100644 --- a/jest.config.base.ts +++ b/jest.config.base.ts @@ -6,7 +6,6 @@ const config: Config.InitialOptions = { // NOTE: overridden in e2e test. Make sure to // update that match as well when changing this one testMatch: ['**/?(*.)test.ts'], - coverageReporters: ['text-summary', 'lcov'], moduleNameMapper: { '@credo-ts/(.+)': ['/../../packages/$1/src', '/../packages/$1/src', '/packages/$1/src'], }, diff --git a/jest.config.ts b/jest.config.ts index 286a152f79..2bd545eda8 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -5,6 +5,7 @@ import base from './jest.config.base' const config: Config.InitialOptions = { ...base, roots: [''], + coverageReporters: ['text-summary', 'lcov'], coveragePathIgnorePatterns: ['/build/', '/node_modules/', '/__tests__/', 'tests'], coverageDirectory: '/coverage/', projects: [ diff --git a/packages/core/src/modules/x509/X509ModuleConfig.ts b/packages/core/src/modules/x509/X509ModuleConfig.ts index db5fa6f91f..fff632092f 100644 --- a/packages/core/src/modules/x509/X509ModuleConfig.ts +++ b/packages/core/src/modules/x509/X509ModuleConfig.ts @@ -67,13 +67,13 @@ export interface X509ModuleConfigOptions { } export class X509ModuleConfig { - private options: X509ModuleConfigOptions #trustedCertificates?: X509Certificate[] + #getTrustedCertificatesForVerification?: X509ModuleConfigOptions['getTrustedCertificatesForVerification'] public constructor(options?: X509ModuleConfigOptions) { - this.options = { - getTrustedCertificatesForVerification: options?.getTrustedCertificatesForVerification, - trustedCertificates: options?.trustedCertificates ? [...options.trustedCertificates] : undefined, + this.setTrustedCertificates(options?.trustedCertificates) + if (options?.getTrustedCertificatesForVerification) { + this.setTrustedCertificatesForVerification(options.getTrustedCertificatesForVerification) } } @@ -84,11 +84,11 @@ export class X509ModuleConfig { } public get getTrustedCertificatesForVerification() { - return this.options.getTrustedCertificatesForVerification + return this.#getTrustedCertificatesForVerification } public setTrustedCertificatesForVerification(fn: X509ModuleConfigOptions['getTrustedCertificatesForVerification']) { - this.options.getTrustedCertificatesForVerification = fn + this.#getTrustedCertificatesForVerification = fn } public setTrustedCertificates(trustedCertificates?: [string, ...string[]]) { diff --git a/packages/core/src/modules/x509/__tests__/X509ServiceModule.test.ts b/packages/core/src/modules/x509/__tests__/X509ServiceModule.test.ts index 7649c6a3cf..f54e224d94 100644 --- a/packages/core/src/modules/x509/__tests__/X509ServiceModule.test.ts +++ b/packages/core/src/modules/x509/__tests__/X509ServiceModule.test.ts @@ -11,7 +11,24 @@ const dependencyManager = { describe('X509ServiceModule', () => { test('registers dependencies on the dependency manager', async () => { - const options: X509ModuleConfigOptions = { trustedCertificates: ['certificate'] } + const options: X509ModuleConfigOptions = { + trustedCertificates: [ + `-----BEGIN CERTIFICATE----- +MIICKjCCAdCgAwIBAgIUV8bM0wi95D7KN0TyqHE42ru4hOgwCgYIKoZIzj0EAwIw +UzELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5ldyBZb3JrMQ8wDQYDVQQHDAZBbGJh +bnkxDzANBgNVBAoMBk5ZIERNVjEPMA0GA1UECwwGTlkgRE1WMB4XDTIzMDkxNDE0 +NTUxOFoXDTMzMDkxMTE0NTUxOFowUzELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5l +dyBZb3JrMQ8wDQYDVQQHDAZBbGJhbnkxDzANBgNVBAoMBk5ZIERNVjEPMA0GA1UE +CwwGTlkgRE1WMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiTwtg0eQbcbNabf2 +Nq9L/VM/lhhPCq2s0Qgw2kRx29tgrBcNHPxTT64tnc1Ij3dH/fl42SXqMenpCDw4 +K6ntU6OBgTB/MB0GA1UdDgQWBBSrbS4DuR1JIkAzj7zK3v2TM+r2xzAfBgNVHSME +GDAWgBSrbS4DuR1JIkAzj7zK3v2TM+r2xzAPBgNVHRMBAf8EBTADAQH/MCwGCWCG +SAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAKBggqhkjO +PQQDAgNIADBFAiAJ/Qyrl7A+ePZOdNfc7ohmjEdqCvxaos6//gfTvncuqQIhANo4 +q8mKCA9J8k/+zh//yKbN1bLAtdqPx7dnrDqV3Lg+ +-----END CERTIFICATE-----`, + ], + } const x509Module = new X509Module(options) x509Module.register(dependencyManager) @@ -24,9 +41,24 @@ describe('X509ServiceModule', () => { expect(x509Module.config.trustedCertificates).toBeDefined() expect(x509Module.config.trustedCertificates).toHaveLength(1) - expect(x509Module.config.trustedCertificates).toContain('certificate') + expect(x509Module.config.trustedCertificates).toContain(`-----BEGIN CERTIFICATE----- +MIICKjCCAdCgAwIBAgIUV8bM0wi95D7KN0TyqHE42ru4hOgwCgYIKoZIzj0EAwIw +UzELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5ldyBZb3JrMQ8wDQYDVQQHDAZBbGJh +bnkxDzANBgNVBAoMBk5ZIERNVjEPMA0GA1UECwwGTlkgRE1WMB4XDTIzMDkxNDE0 +NTUxOFoXDTMzMDkxMTE0NTUxOFowUzELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5l +dyBZb3JrMQ8wDQYDVQQHDAZBbGJhbnkxDzANBgNVBAoMBk5ZIERNVjEPMA0GA1UE +CwwGTlkgRE1WMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiTwtg0eQbcbNabf2 +Nq9L/VM/lhhPCq2s0Qgw2kRx29tgrBcNHPxTT64tnc1Ij3dH/fl42SXqMenpCDw4 +K6ntU6OBgTB/MB0GA1UdDgQWBBSrbS4DuR1JIkAzj7zK3v2TM+r2xzAfBgNVHSME +GDAWgBSrbS4DuR1JIkAzj7zK3v2TM+r2xzAPBgNVHRMBAf8EBTADAQH/MCwGCWCG +SAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAKBggqhkjO +PQQDAgNIADBFAiAJ/Qyrl7A+ePZOdNfc7ohmjEdqCvxaos6//gfTvncuqQIhANo4 +q8mKCA9J8k/+zh//yKbN1bLAtdqPx7dnrDqV3Lg+ +-----END CERTIFICATE-----`) - x509Module.config.addTrustedCertificate('certificate2') + x509Module.config.addTrustedCertificate( + 'MIIBEzCBu6ADAgECAhBwnaR5jboQ4R7Ne/k+sfhCMAoGCCqGSM49BAMCMA0xCzAJBgNVBAYTAk5MMB4XDTcwMDEwMTAwMDAwMFoXDTI1MTEyMjA4MjIxMlowDTELMAkGA1UEBhMCTkwwOTATBgcqhkjOPQIBBggqhkjOPQMBBwMiAALcD1XzKepFxWMAOqV+ln1fybBt7DRO5CV0f9A6mRp2xaMdMBswGQYDVR0RBBIwEIIOZnVua2UuYW5pbW8uaWQwCgYIKoZIzj0EAwIDRwAwRAIgPM5ITfUD6VWLgRm8Eu1gw53Of+SUdjS+yRClR68m//4CIDxnng7NnJyGnpsKDuUqSIl/A0rRQCwTLBZw9Hx3MZnZ' + ) expect(x509Module.config.trustedCertificates).toHaveLength(2) x509Module.config.setTrustedCertificates(undefined)