|
1 |
| -import { |
2 |
| - CaCertDto, |
3 |
| - ClientCertPairDto, |
4 |
| -} from 'src/modules/instances/dto/database-instance.dto'; |
5 |
| -import { CaCertificateEntity } from 'src/modules/core/models/ca-certificate.entity'; |
6 |
| -import { ClientCertificateEntity } from 'src/modules/core/models/client-certificate.entity'; |
7 |
| - |
8 |
| -export const mockCaCertDto: CaCertDto = { |
| 1 | +import { pick, omit } from 'lodash'; |
| 2 | +import { CaCertificateEntity } from 'src/modules/certificate/entities/ca-certificate.entity'; |
| 3 | +import { ClientCertificateEntity } from 'src/modules/certificate/entities/client-certificate.entity'; |
| 4 | +import { CreateCaCertificateDto } from 'src/modules/certificate/dto/create.ca-certificate.dto'; |
| 5 | +import { CreateClientCertificateDto } from 'src/modules/certificate/dto/create.client-certificate.dto'; |
| 6 | +import { CaCertificate } from 'src/modules/certificate/models/ca-certificate'; |
| 7 | +import { EncryptionStrategy } from 'src/modules/encryption/models'; |
| 8 | +import { ClientCertificate } from 'src/modules/certificate/models/client-certificate'; |
| 9 | + |
| 10 | +// ================== CA Certificate ================== |
| 11 | +export const mockCaCertificateId = 'a77b23c1-7816-4ea4-b61f-d37795a0f805'; |
| 12 | + |
| 13 | +export const mockCaCertificateCertificateEncrypted = 'caCertificate.certificate_ENCRYPTED'; |
| 14 | + |
| 15 | +export const mockCaCertificateCertificatePlain = '-----BEGIN CERTIFICATE-----\nMIIDejCCAmKgAwIBAgIUehUr5AHdJM'; |
| 16 | + |
| 17 | +export const mockCaCertificate = Object.assign(new CaCertificate(), { |
| 18 | + id: mockCaCertificateId, |
9 | 19 | name: 'ca-cert',
|
10 |
| - cert: '-----BEGIN CERTIFICATE-----\nMIIDejCCAmKgAwIBAgIUehUr5AHdJM', |
11 |
| -}; |
| 20 | + certificate: mockCaCertificateCertificatePlain, |
| 21 | +}); |
12 | 22 |
|
13 |
| -export const mockClientCertDto: ClientCertPairDto = { |
14 |
| - name: 'client-cert', |
15 |
| - cert: '-----BEGIN CERTIFICATE-----\nMIIDejCCAmKgAwIBAgIUehUr5AHdJM', |
16 |
| - key: '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAAM', |
17 |
| -}; |
18 |
| - |
19 |
| -export const mockCaCertEntity: CaCertificateEntity = { |
20 |
| - id: 'a77b23c1-7816-4ea4-b61f-d37795a0f805', |
21 |
| - name: mockCaCertDto.name, |
22 |
| - encryption: null, |
23 |
| - certificate: mockCaCertDto.cert, |
24 |
| - databases: [], |
25 |
| -}; |
26 |
| - |
27 |
| -export const mockClientCertEntity: ClientCertificateEntity = { |
28 |
| - id: 'a77b23c1-7816-4ea4-b61f-d37795a0f809', |
29 |
| - name: mockClientCertDto.name, |
30 |
| - encryption: null, |
31 |
| - certificate: mockClientCertDto.cert, |
32 |
| - key: mockClientCertDto.key, |
33 |
| - databases: [], |
34 |
| -}; |
35 |
| - |
36 |
| -export const mockCaCertificatesService = () => ({ |
| 23 | +export const mockCreateCaCertificateDto = Object.assign(new CreateCaCertificateDto(), { |
| 24 | + ...omit(mockCaCertificate, 'id'), |
| 25 | +}); |
| 26 | + |
| 27 | +export const mockCaCertificateEntity = Object.assign(new CaCertificateEntity(), { |
| 28 | + ...mockCaCertificate, |
| 29 | + certificate: mockCaCertificateCertificateEncrypted, |
| 30 | + encryption: EncryptionStrategy.KEYTAR, |
| 31 | +}); |
| 32 | + |
| 33 | +export const mockCaCertificateRepository = jest.fn(() => ({ |
| 34 | + get: jest.fn().mockResolvedValue(mockCaCertificate), |
| 35 | + list: jest.fn().mockResolvedValueOnce([ |
| 36 | + pick(mockCaCertificate, 'id', 'name'), |
| 37 | + pick(mockCaCertificate, 'id', 'name'), |
| 38 | + ]), |
| 39 | + create: jest.fn().mockResolvedValue(mockCaCertificate), |
| 40 | + delete: jest.fn().mockResolvedValue(undefined), |
| 41 | +})); |
| 42 | + |
| 43 | +export const mockCaCertificateService = jest.fn(() => ({ |
37 | 44 | getAll: jest.fn(),
|
38 | 45 | getOneById: jest.fn(),
|
| 46 | +})); |
| 47 | + |
| 48 | +// ================== Client Certificate ================== |
| 49 | +export const mockClientCertificateId = 'a77b23c1-7816-4ea4-b61f-d37f2915f805'; |
| 50 | + |
| 51 | +export const mockClientCertificateCertificateEncrypted = 'clientCertificate.certificate_ENCRYPTED'; |
| 52 | + |
| 53 | +export const mockClientCertificateCertificatePlain = '-----BEGIN CERTIFICATE-----\nMICLIENTCERTIDejCCAmKgAwIB'; |
| 54 | + |
| 55 | +export const mockClientCertificateKeyEncrypted = 'clientCertificate.key_ENCRYPTED'; |
| 56 | + |
| 57 | +export const mockClientCertificateKeyPlain = '-----BEGIN PRIVATE KEY-----\nMICLIENTCERTIDejCCAmKgAwIB'; |
| 58 | + |
| 59 | +export const mockClientCertificate = Object.assign(new ClientCertificate(), { |
| 60 | + id: mockClientCertificateId, |
| 61 | + name: 'client-cert', |
| 62 | + certificate: mockClientCertificateCertificatePlain, |
| 63 | + key: mockClientCertificateKeyPlain, |
39 | 64 | });
|
40 | 65 |
|
41 |
| -export const mockClientCertificatesService = () => ({ |
| 66 | +export const mockCreateClientCertificateDto = Object.assign(new CreateClientCertificateDto(), { |
| 67 | + ...omit(mockClientCertificate, 'id'), |
| 68 | +}); |
| 69 | + |
| 70 | +export const mockClientCertificateEntity = Object.assign(new ClientCertificateEntity(), { |
| 71 | + ...mockClientCertificate, |
| 72 | + certificate: mockClientCertificateCertificateEncrypted, |
| 73 | + key: mockClientCertificateKeyEncrypted, |
| 74 | + encryption: EncryptionStrategy.KEYTAR, |
| 75 | +}); |
| 76 | + |
| 77 | +export const mockClientCertificateRepository = jest.fn(() => ({ |
| 78 | + get: jest.fn().mockResolvedValue(mockClientCertificate), |
| 79 | + list: jest.fn().mockResolvedValueOnce([ |
| 80 | + pick(mockClientCertificate, 'id', 'name'), |
| 81 | + pick(mockClientCertificate, 'id', 'name'), |
| 82 | + ]), |
| 83 | + create: jest.fn().mockResolvedValue(mockClientCertificate), |
| 84 | + delete: jest.fn().mockResolvedValue(undefined), |
| 85 | +})); |
| 86 | + |
| 87 | +export const mockClientCertificateService = jest.fn(() => ({ |
42 | 88 | getAll: jest.fn(),
|
43 | 89 | getOneById: jest.fn(),
|
44 |
| -}); |
| 90 | +})); |
0 commit comments