From 37730eb8bfba02d92574a1ffae63767916dcdf91 Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Thu, 2 Apr 2020 21:41:56 +0200 Subject: [PATCH] move crypto to server utils (#62344) * move crypto to server utils * fix mocks --- .../elasticsearch_config.test.mocks.ts | 2 +- .../elasticsearch/elasticsearch_config.test.ts | 2 +- .../server/elasticsearch/elasticsearch_config.ts | 2 +- src/core/server/http/ssl_config.test.mocks.ts | 2 +- src/core/server/http/ssl_config.test.ts | 2 +- src/core/server/http/ssl_config.ts | 2 +- .../utils/crypto/__fixtures__/README.md | 0 .../{ => server}/utils/crypto/__fixtures__/index.ts | 0 .../utils/crypto/__fixtures__/no_ca.p12 | Bin .../utils/crypto/__fixtures__/no_cert.p12 | Bin .../utils/crypto/__fixtures__/no_key.p12 | Bin .../utils/crypto/__fixtures__/two_cas.p12 | Bin .../utils/crypto/__fixtures__/two_keys.p12 | Bin src/core/{ => server}/utils/crypto/index.ts | 0 src/core/{ => server}/utils/crypto/pkcs12.test.ts | 2 +- src/core/{ => server}/utils/crypto/pkcs12.ts | 0 src/core/server/utils/index.ts | 1 + src/core/utils/index.ts | 1 - 18 files changed, 8 insertions(+), 8 deletions(-) rename src/core/{ => server}/utils/crypto/__fixtures__/README.md (100%) rename src/core/{ => server}/utils/crypto/__fixtures__/index.ts (100%) rename src/core/{ => server}/utils/crypto/__fixtures__/no_ca.p12 (100%) rename src/core/{ => server}/utils/crypto/__fixtures__/no_cert.p12 (100%) rename src/core/{ => server}/utils/crypto/__fixtures__/no_key.p12 (100%) rename src/core/{ => server}/utils/crypto/__fixtures__/two_cas.p12 (100%) rename src/core/{ => server}/utils/crypto/__fixtures__/two_keys.p12 (100%) rename src/core/{ => server}/utils/crypto/index.ts (100%) rename src/core/{ => server}/utils/crypto/pkcs12.test.ts (99%) rename src/core/{ => server}/utils/crypto/pkcs12.ts (100%) diff --git a/src/core/server/elasticsearch/elasticsearch_config.test.mocks.ts b/src/core/server/elasticsearch/elasticsearch_config.test.mocks.ts index d908fdbfd2e80..df8566746eaf9 100644 --- a/src/core/server/elasticsearch/elasticsearch_config.test.mocks.ts +++ b/src/core/server/elasticsearch/elasticsearch_config.test.mocks.ts @@ -22,7 +22,7 @@ jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); export const mockReadPkcs12Keystore = jest.fn(); export const mockReadPkcs12Truststore = jest.fn(); -jest.mock('../../utils', () => ({ +jest.mock('../utils', () => ({ readPkcs12Keystore: mockReadPkcs12Keystore, readPkcs12Truststore: mockReadPkcs12Truststore, })); diff --git a/src/core/server/elasticsearch/elasticsearch_config.test.ts b/src/core/server/elasticsearch/elasticsearch_config.test.ts index 913bd542fd6e6..9059db28c9b29 100644 --- a/src/core/server/elasticsearch/elasticsearch_config.test.ts +++ b/src/core/server/elasticsearch/elasticsearch_config.test.ts @@ -227,7 +227,7 @@ describe('throws when config is invalid', () => { beforeAll(() => { const realFs = jest.requireActual('fs'); mockReadFileSync.mockImplementation((path: string) => realFs.readFileSync(path)); - const utils = jest.requireActual('../../utils'); + const utils = jest.requireActual('../utils'); mockReadPkcs12Keystore.mockImplementation((path: string, password?: string) => utils.readPkcs12Keystore(path, password) ); diff --git a/src/core/server/elasticsearch/elasticsearch_config.ts b/src/core/server/elasticsearch/elasticsearch_config.ts index df31f51361c19..cd1b919d3dfe9 100644 --- a/src/core/server/elasticsearch/elasticsearch_config.ts +++ b/src/core/server/elasticsearch/elasticsearch_config.ts @@ -21,7 +21,7 @@ import { schema, TypeOf } from '@kbn/config-schema'; import { Duration } from 'moment'; import { readFileSync } from 'fs'; import { ConfigDeprecationProvider } from 'src/core/server'; -import { readPkcs12Keystore, readPkcs12Truststore } from '../../utils'; +import { readPkcs12Keystore, readPkcs12Truststore } from '../utils'; import { ServiceConfigDescriptor } from '../internal_types'; const hostURISchema = schema.uri({ scheme: ['http', 'https'] }); diff --git a/src/core/server/http/ssl_config.test.mocks.ts b/src/core/server/http/ssl_config.test.mocks.ts index ab98c3a27920c..50e34c7c8f678 100644 --- a/src/core/server/http/ssl_config.test.mocks.ts +++ b/src/core/server/http/ssl_config.test.mocks.ts @@ -24,7 +24,7 @@ jest.mock('fs', () => { export const mockReadPkcs12Keystore = jest.fn(); export const mockReadPkcs12Truststore = jest.fn(); -jest.mock('../../utils', () => ({ +jest.mock('../utils', () => ({ readPkcs12Keystore: mockReadPkcs12Keystore, readPkcs12Truststore: mockReadPkcs12Truststore, })); diff --git a/src/core/server/http/ssl_config.test.ts b/src/core/server/http/ssl_config.test.ts index 3980b9c247fa3..5d0bed601f540 100644 --- a/src/core/server/http/ssl_config.test.ts +++ b/src/core/server/http/ssl_config.test.ts @@ -45,7 +45,7 @@ describe('#SslConfig', () => { beforeEach(() => { const realFs = jest.requireActual('fs'); mockReadFileSync.mockImplementation((path: string) => realFs.readFileSync(path)); - const utils = jest.requireActual('../../utils'); + const utils = jest.requireActual('../utils'); mockReadPkcs12Keystore.mockImplementation((path: string, password?: string) => utils.readPkcs12Keystore(path, password) ); diff --git a/src/core/server/http/ssl_config.ts b/src/core/server/http/ssl_config.ts index 0096eeb092565..4eb0c50e72362 100644 --- a/src/core/server/http/ssl_config.ts +++ b/src/core/server/http/ssl_config.ts @@ -20,7 +20,7 @@ import { schema, TypeOf } from '@kbn/config-schema'; import crypto from 'crypto'; import { readFileSync } from 'fs'; -import { readPkcs12Keystore, readPkcs12Truststore } from '../../utils'; +import { readPkcs12Keystore, readPkcs12Truststore } from '../utils'; // `crypto` type definitions doesn't currently include `crypto.constants`, see // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/fa5baf1733f49cf26228a4e509914572c1b74adf/types/node/v6/index.d.ts#L3412 diff --git a/src/core/utils/crypto/__fixtures__/README.md b/src/core/server/utils/crypto/__fixtures__/README.md similarity index 100% rename from src/core/utils/crypto/__fixtures__/README.md rename to src/core/server/utils/crypto/__fixtures__/README.md diff --git a/src/core/utils/crypto/__fixtures__/index.ts b/src/core/server/utils/crypto/__fixtures__/index.ts similarity index 100% rename from src/core/utils/crypto/__fixtures__/index.ts rename to src/core/server/utils/crypto/__fixtures__/index.ts diff --git a/src/core/utils/crypto/__fixtures__/no_ca.p12 b/src/core/server/utils/crypto/__fixtures__/no_ca.p12 similarity index 100% rename from src/core/utils/crypto/__fixtures__/no_ca.p12 rename to src/core/server/utils/crypto/__fixtures__/no_ca.p12 diff --git a/src/core/utils/crypto/__fixtures__/no_cert.p12 b/src/core/server/utils/crypto/__fixtures__/no_cert.p12 similarity index 100% rename from src/core/utils/crypto/__fixtures__/no_cert.p12 rename to src/core/server/utils/crypto/__fixtures__/no_cert.p12 diff --git a/src/core/utils/crypto/__fixtures__/no_key.p12 b/src/core/server/utils/crypto/__fixtures__/no_key.p12 similarity index 100% rename from src/core/utils/crypto/__fixtures__/no_key.p12 rename to src/core/server/utils/crypto/__fixtures__/no_key.p12 diff --git a/src/core/utils/crypto/__fixtures__/two_cas.p12 b/src/core/server/utils/crypto/__fixtures__/two_cas.p12 similarity index 100% rename from src/core/utils/crypto/__fixtures__/two_cas.p12 rename to src/core/server/utils/crypto/__fixtures__/two_cas.p12 diff --git a/src/core/utils/crypto/__fixtures__/two_keys.p12 b/src/core/server/utils/crypto/__fixtures__/two_keys.p12 similarity index 100% rename from src/core/utils/crypto/__fixtures__/two_keys.p12 rename to src/core/server/utils/crypto/__fixtures__/two_keys.p12 diff --git a/src/core/utils/crypto/index.ts b/src/core/server/utils/crypto/index.ts similarity index 100% rename from src/core/utils/crypto/index.ts rename to src/core/server/utils/crypto/index.ts diff --git a/src/core/utils/crypto/pkcs12.test.ts b/src/core/server/utils/crypto/pkcs12.test.ts similarity index 99% rename from src/core/utils/crypto/pkcs12.test.ts rename to src/core/server/utils/crypto/pkcs12.test.ts index c6c28697c4bcc..e9eb72fe395ff 100644 --- a/src/core/utils/crypto/pkcs12.test.ts +++ b/src/core/server/utils/crypto/pkcs12.test.ts @@ -29,7 +29,7 @@ import { import { NO_CA_PATH, NO_CERT_PATH, NO_KEY_PATH, TWO_CAS_PATH, TWO_KEYS_PATH } from './__fixtures__'; import { readFileSync } from 'fs'; -import { readPkcs12Keystore, Pkcs12ReadResult, readPkcs12Truststore } from '.'; +import { readPkcs12Keystore, Pkcs12ReadResult, readPkcs12Truststore } from './index'; const reformatPem = (pem: string) => { // ensure consistency in line endings when comparing two PEM files diff --git a/src/core/utils/crypto/pkcs12.ts b/src/core/server/utils/crypto/pkcs12.ts similarity index 100% rename from src/core/utils/crypto/pkcs12.ts rename to src/core/server/utils/crypto/pkcs12.ts diff --git a/src/core/server/utils/index.ts b/src/core/server/utils/index.ts index 86924c559e5fa..b01a4c4e04899 100644 --- a/src/core/server/utils/index.ts +++ b/src/core/server/utils/index.ts @@ -17,5 +17,6 @@ * under the License. */ +export * from './crypto'; export * from './from_root'; export * from './package_json'; diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index e35356343cfe2..a6df0992f6cc6 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -19,7 +19,6 @@ export * from './assert_never'; export * from './context'; -export * from './crypto'; export * from './deep_freeze'; export * from './get'; export * from './map_to_object';