Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fix(configuration-hydrator): use custom SSL configuration from env
Browse files Browse the repository at this point in the history
This makes sure we use configuration provided via env variables. Previously, it would be assigned
incorrectly.
  • Loading branch information
barmac committed Jul 18, 2022
1 parent dccde0d commit be737ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/__mocks__/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
readFileSync() {
return 'file-contents'
}
};
20 changes: 20 additions & 0 deletions src/__tests__/ConfigurationHydrator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ConfigurationHydrator } from '../lib/ConfigurationHydrator'

jest.mock('fs');

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
// const gatewayAddress = process.env.ZEEBE_GATEWAY_ADDRESS || '0.0.0.0:26500'

Expand All @@ -15,6 +17,9 @@ const ENV_VARS_TO_STORE = [
'ZEEBE_CLIENT_MAX_RETRIES',
'ZEEBE_CLIENT_RETRY',
'ZEEBE_CLIENT_MAX_RETRY_TIMEOUT',
'ZEEBE_CLIENT_SSL_ROOT_CERTS_PATH',
'ZEEBE_CLIENT_SSL_PRIVATE_KEY_PATH',
'ZEEBE_CLIENT_SSL_CERT_CHAIN_PATH',
]

beforeAll(() => {
Expand Down Expand Up @@ -370,6 +375,21 @@ test('Can be unsecured via the environment', () => {
const conf = ConfigurationHydrator.configure('localhost:26600', {})
expect(conf.useTLS).toBe(true)
})
test('Cert chain path can be configured via the environment', () => {
process.env.ZEEBE_CLIENT_SSL_CERT_CHAIN_PATH = '/my/path'
const conf = ConfigurationHydrator.configure('localhost:26600', {})
expect(conf.customSSL?.certChain).toBe('file-contents')
})
test('Private key path can be configured via the environment', () => {
process.env.ZEEBE_CLIENT_SSL_PRIVATE_KEY_PATH = '/my/path'
const conf = ConfigurationHydrator.configure('localhost:26600', {})
expect(conf.customSSL?.privateKey).toBe('file-contents')
})
test('Root certs path can be configured via the environment', () => {
process.env.ZEEBE_CLIENT_SSL_ROOT_CERTS_PATH = '/my/path'
const conf = ConfigurationHydrator.configure('localhost:26600', {})
expect(conf.customSSL?.rootCerts).toBe('file-contents')
})
test('Retry can be configured via the environment', () => {
process.env.ZEEBE_CLIENT_RETRY = 'false'
const conf = ConfigurationHydrator.configure('localhost:26600', {})
Expand Down
9 changes: 7 additions & 2 deletions src/lib/ConfigurationHydrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,23 @@ export class ConfigurationHydrator {
}
}

private static readCustomSSLFromEnvironment(): Partial<CustomSSL> {
private static readCustomSSLFromEnvironment(): { customSSL: Partial<CustomSSL> } {
const rootCerts = ConfigurationHydrator.ENV()
.ZEEBE_CLIENT_SSL_ROOT_CERTS_PATH
const certChain = ConfigurationHydrator.ENV()
.ZEEBE_CLIENT_SSL_CERT_CHAIN_PATH
const privateKey = ConfigurationHydrator.ENV()
.ZEEBE_CLIENT_SSL_PRIVATE_KEY_PATH
return {

const customSSL = {
certChain: certChain ? fs.readFileSync(certChain) : undefined,
privateKey: privateKey ? fs.readFileSync(privateKey) : undefined,
rootCerts: rootCerts ? fs.readFileSync(rootCerts) : undefined,
}

return {
customSSL,
}
}

private static readOAuthFromEnvironment(
Expand Down

0 comments on commit be737ff

Please sign in to comment.