Skip to content

Commit

Permalink
test(repo): use string for custom certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed May 9, 2024
1 parent 0b121a3 commit 6bc2bfa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"compile": "tsc --project tsconfig.json",
"docs": "rm -rf ./docs && typedoc",
"generate:grpc": "grpc_tools_node_protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --js_out=import_style=commonjs,binary:./src/generated --grpc_out=./src/generated --ts_out=./src/generated -I ./src/proto ./src/proto/*.proto",
"test": "cross-env CAMUNDA_UNIT_TEST=true jest '.*unit.*' -u --detectOpenHandles --testPathIgnorePatterns integration --testPathIgnorePatterns local-integration --testPathIgnorePatterns disconnection --testPathIgnorePatterns multitenancy --testPathIgnorePatterns __tests__/config",
"test": "cross-env CAMUNDA_UNIT_TEST=true jest '.*unit.*' -u --detectOpenHandles --runInBand --testPathIgnorePatterns integration --testPathIgnorePatterns local-integration --testPathIgnorePatterns disconnection --testPathIgnorePatterns multitenancy --testPathIgnorePatterns __tests__/config",
"test:integration": "jest --runInBand --testPathIgnorePatterns disconnection --testPathIgnorePatterns '.unit.*' --testPathIgnorePatterns __tests__/config --testPathIgnorePatterns multitenancy --detectOpenHandles --verbose true -u",
"test:multitenancy": "jest --runInBand --testPathIgnorePatterns disconnection --testPathIgnorePatterns admin --testPathIgnorePatterns '.unit.*' --testPathIgnorePatterns __tests__/config - --detectOpenHandles --verbose true -u",
"test:local": "jest --runInBand --verbose true --detectOpenHandles local-integration -u",
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/lib/GetCustomCertificateBuffer.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ test('Can use a custom root certificate to connect to a REST API', async () => {
CAMUNDA_OPERATE_BASE_URL: 'https://localhost:3012',
},
})

console.log('Trying to get process instance with certificate')
const res = await c.getProcessInstance('1')
console.log(
`Got response from self-signed secured server: ${res.bpmnProcessId}`
)
expect(res.bpmnProcessId).toBe('test')
const c1 = new OperateApiClient({
config: {
Expand All @@ -65,6 +68,7 @@ test('Can use a custom root certificate to connect to a REST API', async () => {

let threw = false
try {
console.log('Trying to get process instance without certificate')
await c1.getProcessInstance('1')
} catch (e) {
threw = true
Expand Down
8 changes: 4 additions & 4 deletions src/lib/GetCustomCertificateBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const trace = debug('camunda:certificate')

export async function GetCustomCertificateBuffer(
config: CamundaPlatform8Configuration
): Promise<Buffer | undefined> {
trace(config)
): Promise<string | undefined> {
const customRootCertPath = config.CAMUNDA_CUSTOM_ROOT_CERT_PATH
const customRootCert = config.CAMUNDA_CUSTOM_ROOT_CERT_STRING

Expand Down Expand Up @@ -42,8 +41,9 @@ export async function GetCustomCertificateBuffer(
trace(`No custom root certificates found`)
return undefined
}

return Buffer.from(rootCerts.join('\n'))
const output = rootCerts.join('\n')
trace(`Custom root certificates:\n${output}`)
return output
}

function readRootCertificate(certPath) {
Expand Down
2 changes: 1 addition & 1 deletion src/zeebe/zb/ZeebeGrpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class ZeebeGrpcClient extends TypedEmitter<
const customSSL = {
certChain: certChainPath ? readFileSync(certChainPath) : undefined,
privateKey: privateKeyPath ? readFileSync(privateKeyPath) : undefined,
rootCerts,
rootCerts: rootCerts ? Buffer.from(rootCerts) : undefined,
}

this.customSSL = customSSL
Expand Down

0 comments on commit 6bc2bfa

Please sign in to comment.