Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Dec 17, 2024
1 parent 0664af6 commit 14be345
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
1 change: 0 additions & 1 deletion jest.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/(.+)': ['<rootDir>/../../packages/$1/src', '<rootDir>/../packages/$1/src', '<rootDir>/packages/$1/src'],
},
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import base from './jest.config.base'
const config: Config.InitialOptions = {
...base,
roots: ['<rootDir>'],
coverageReporters: ['text-summary', 'lcov'],
coveragePathIgnorePatterns: ['/build/', '/node_modules/', '/__tests__/', 'tests'],
coverageDirectory: '<rootDir>/coverage/',
projects: [
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/modules/x509/X509ModuleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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[]]) {
Expand Down
38 changes: 35 additions & 3 deletions packages/core/src/modules/x509/__tests__/X509ServiceModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 14be345

Please sign in to comment.