Skip to content

Commit

Permalink
feat(repo): add CAMUNDA_CUSTOM_ROOT_CERT_STRING parameter
Browse files Browse the repository at this point in the history
* fix(zeebe): fix waitForReady deadline (#151)

This fixes a bug in the grpc channel connection sensing

fixes #150

* feat(repo): add CAMUNDA_CUSTOM_ROOT_CERT_STRING parameter (#146)

* feat(repo): add CAMUNDA_CUSTOM_ROOT_CERT_STRING parameter

accept a custom certificate as a string argument to the configuration

fixes #142

* style(zeebe): lint generated zeebe grpc code

* test(zeebe): extend timeout to deal with SaaS connection delay

* fix(zeebe): fix waitForReady deadline (#151)

This fixes a bug in the grpc channel connection sensing

fixes #150

* feat(repo): add CAMUNDA_CUSTOM_ROOT_CERT_STRING parameter

accept a custom certificate as a string argument to the configuration

fixes #142

* style(zeebe): lint generated zeebe grpc code

* test(zeebe): extend timeout to deal with SaaS connection delay

* test(zeebe): refactor test

* chore(release): 8.5.2-alpha.1 [skip ci]

## [8.5.2-alpha.1](v8.5.1...v8.5.2-alpha.1) (2024-05-07)

### Bug Fixes

* **zeebe:** fix waitForReady deadline ([#151](#151)) ([a88ea2e](a88ea2e)), closes [#150](#150)

### Features

* **repo:** add CAMUNDA_CUSTOM_ROOT_CERT_STRING parameter ([#146](#146)) ([f828a95](f828a95)), closes [#142](#142) [#151](#151) [#150](#150) [#142](#142)

* chore(release): 8.5.2-alpha.1 [skip ci]

## [8.5.2-alpha.1](v8.5.1...v8.5.2-alpha.1) (2024-05-07)

### Bug Fixes

* **zeebe:** fix waitForReady deadline ([#151](#151)) ([a88ea2e](a88ea2e)), closes [#150](#150)

### Features

* **repo:** add CAMUNDA_CUSTOM_ROOT_CERT_STRING parameter ([#146](#146)) ([f828a95](f828a95)), closes [#142](#142) [#151](#151) [#150](#150) [#142](#142)

---------

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
  • Loading branch information
jwulf and semantic-release-bot committed May 7, 2024
1 parent f8c0c7d commit 7451a66
Show file tree
Hide file tree
Showing 17 changed files with 299 additions and 160 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ dist
*.env
!docker/.env

docs
docs
.nx/cache
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [8.5.2-alpha.1](https://github.com/camunda/camunda-8-js-sdk/compare/v8.5.1...v8.5.2-alpha.1) (2024-05-07)


### Bug Fixes

* **zeebe:** fix waitForReady deadline ([#151](https://github.com/camunda/camunda-8-js-sdk/issues/151)) ([a88ea2e](https://github.com/camunda/camunda-8-js-sdk/commit/a88ea2e48ab268890dae11917ef065ef4a451cec)), closes [#150](https://github.com/camunda/camunda-8-js-sdk/issues/150)


### Features

* **repo:** add CAMUNDA_CUSTOM_ROOT_CERT_STRING parameter ([#146](https://github.com/camunda/camunda-8-js-sdk/issues/146)) ([f828a95](https://github.com/camunda/camunda-8-js-sdk/commit/f828a95a992168a77d477ec987cd50a7c3b96112)), closes [#142](https://github.com/camunda/camunda-8-js-sdk/issues/142) [#151](https://github.com/camunda/camunda-8-js-sdk/issues/151) [#150](https://github.com/camunda/camunda-8-js-sdk/issues/150) [#142](https://github.com/camunda/camunda-8-js-sdk/issues/142)

## [8.5.1](https://github.com/camunda/camunda-8-js-sdk/compare/v8.5.0...v8.5.1) (2024-05-05)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@camunda8/sdk",
"version": "8.5.1",
"version": "8.5.2-alpha.1",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
124 changes: 112 additions & 12 deletions src/__tests__/lib/GetCustomCertificateBuffer.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ import {
import { OperateApiClient } from '../../operate'
import { ZeebeGrpcClient } from '../../zeebe'

let server
afterEach(() => {
;(server && server.close && server.close()) ||
(server &&
server.tryShutdown &&
server.tryShutdown((err) => {
if (err) {
throw err
}
}))
})

test('Can use a custom root certificate to connect to a REST API', async () => {
const app = express()

Expand All @@ -26,7 +38,7 @@ test('Can use a custom root certificate to connect to a REST API', async () => {
cert: fs.readFileSync(path.join(__dirname, 'localhost.crt')),
}

const server = https.createServer(options, app)
server = https.createServer(options, app)

server.listen(3012, () => {
// console.log('Server listening on port 3012')
Expand Down Expand Up @@ -81,7 +93,7 @@ test('gRPC server with self-signed certificate', (done) => {
) as unknown as { gateway_protocol: { Gateway: any } }

// Create the server
const server = new Server()
server = new Server()

// Add a service to the server
server.addService(zeebeProto.gateway_protocol.Gateway.service, {
Expand Down Expand Up @@ -140,16 +152,104 @@ test('gRPC server with self-signed certificate', (done) => {
done()
})
})
// const zbc2 = new ZeebeGrpcClient({
// config: {
// CAMUNDA_OAUTH_DISABLED: true,
// ZEEBE_ADDRESS: 'localhost:50051',
// },
// })
// zbc2.topology().catch((e) => {
// console.log(e)
// zbc2.close()
// })
}
)
})

test('gRPC server with self-signed certificate provided via string', (done) => {
// Load the protobuf definition
const packageDefinition = loadSync(
path.join(__dirname, '..', '..', 'proto', 'zeebe.proto'),
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
}
)

const zeebeProto = loadPackageDefinition(
packageDefinition
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) as unknown as { gateway_protocol: { Gateway: any } }

// Create the server
const server = new Server()

// Add a service to the server
server.addService(zeebeProto.gateway_protocol.Gateway.service, {
Topology: (_, callback) => {
const t = new TopologyResponse()
const b = new BrokerInfo()
b.setHost('localhost')
const partition = new Partition()
partition.setHealth(0)
partition.setPartitionid(0)
partition.setRole(0)
b.setPartitionsList([partition])
t.setBrokersList([b])
callback(null, t)
},
// Implement your service methods here
})

// Read the key and certificate
const key = fs.readFileSync(path.join(__dirname, 'localhost.key'))
const cert = fs.readFileSync(path.join(__dirname, 'localhost.crt'))

// Start the server
server.bindAsync(
'localhost:50051',
ServerCredentials.createSsl(null, [
{
private_key: key,
cert_chain: cert,
},
]),
(err) => {
if (err) {
console.error(err)
done()
return
}
const zbc = new ZeebeGrpcClient({
config: {
CAMUNDA_OAUTH_DISABLED: true,
ZEEBE_ADDRESS: 'localhost:50051',
CAMUNDA_CUSTOM_ROOT_CERT_STRING: `-----BEGIN CERTIFICATE-----
MIIC7TCCAdWgAwIBAgIUXlnuRfR2yE/v5t9A0ZoeVG4BvZowDQYJKoZIhvcNAQEL
BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI0MDUwMTAzMTIyNloXDTI1MDUw
MTAzMTIyNlowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF
AAOCAQ8AMIIBCgKCAQEA57iCfaiUmW74QUb0MtX5MOCOfhKJ8zw0i4Ep+nwST03w
Z/K5Z0W7OPmJDnPsko9DPC3bOeObriTcWgYg4zNaLNSKvDbkbLtDvpUyY8rdJAP3
6H7uTZWMoUQzdIGdSFZHa8HRO1HUZGFZT55bi7czyMPFnzSOtcaz4pCvlhLRk+QA
lsSG+4owhfDrpyPlFtEFNyeaE2fIsJtHxupkwGOmDNeh6iKV46lD8F0SGf2pl5qF
nbbMn6IZlpH7heQqMdPNs1ikGOuDybJISu07S72RSoClgdFzepzXFHoNWwhucdvN
UMJXWBnP/PoeNViI2+nBMrK/1Bwuhci0t5mjTujQNQIDAQABozcwNTAUBgNVHREE
DTALgglsb2NhbGhvc3QwHQYDVR0OBBYEFBuCDjLQbWjX7D+o9dt4nszcP3OIMA0G
CSqGSIb3DQEBCwUAA4IBAQASgexBeY7Nz9i0qREk1RzpQDIT+jM/QAgmnH3G6Ehx
tAYUMYLeDTmGhYhp3GJAU7/R3mbN6t5qg2d9Fa8b+JpBJRdxMY+CyjESoPvUHIE3
lkgNGphT+8QPnh7uO5KOUVnk7Jc9MTwBntDouLHfuzJJnHPlRko3IWnwaivZYVRn
VbnUoSMKKPzFaqqaY8uHPjvs4Gt4OGcYV8hHcjeI3fMHckmsXZclxb3pwF+x698o
Htg5+ydbmWkTspvbMuHx/280Ow0JPSSXFnwWGWpyH7kI0EAfq75W3iGMRR6yL7Je
ffZG7W8KARYx824nRlxbIN2rHo9VQwEBkbmoeg5nSkvi
-----END CERTIFICATE-----`,
CAMUNDA_SECURE_CONNECTION: true,
zeebeGrpcSettings: {
ZEEBE_CLIENT_LOG_LEVEL: 'NONE',
},
},
})
zbc.topology().then(() => {
expect(true).toBe(true)
zbc.close()
// Stop the server after the test
server.tryShutdown((err) => {
if (err) console.error(err)
done()
})
})
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ test('Calls the onConnectionError handler if there is no broker and eagerConnect
}, 7000)
}))

test('Sets connected:false if there is no broker and no setting of eagerConnection', () =>
test('Sets connected:undefined if there is no broker and no setting of eagerConnection', () =>
new Promise((done) => {
const zbc2 = new ZeebeGrpcClient({
config: { ZEEBE_ADDRESS: 'localtoast: 267890' },
}) // Broker doesn't exist!!!
setTimeout(async () => {
expect(zbc2.connected).toBe(false)
expect(zbc2.connected).toBe(undefined)
await zbc2.close()
done(null)
}, 5000)
Expand Down
41 changes: 21 additions & 20 deletions src/__tests__/zeebe/integration/Client-ThrowError.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,8 @@ jest.setTimeout(25000)
let bpmnProcessId: string
let processDefinitionKey: string

let zbc: ZeebeGrpcClient

beforeAll(async () => {
suppressZeebeLogging()
const zb = new ZeebeGrpcClient()
;({ bpmnProcessId, processDefinitionKey } = (
await zb.deployResource({
processFilename: './src/__tests__/testdata/Client-ThrowError.bpmn',
})
).deployments[0].process)
await cancelProcesses(processDefinitionKey)
await zb.close()
})

beforeEach(() => {
zbc = new ZeebeGrpcClient()
})

afterEach(async () => {
await zbc.close()
})

afterAll(async () => {
Expand All @@ -38,6 +20,13 @@ afterAll(async () => {
})

test('Throws a business error that is caught in the process', async () => {
const zbc = new ZeebeGrpcClient()
;({ bpmnProcessId, processDefinitionKey } = (
await zbc.deployResource({
processFilename: './src/__tests__/testdata/Client-ThrowError.bpmn',
})
).deployments[0].process)
await cancelProcesses(processDefinitionKey)
zbc.createWorker({
taskHandler: (job) =>
job.error('BUSINESS_ERROR', 'Well, that did not work'),
Expand All @@ -57,9 +46,18 @@ test('Throws a business error that is caught in the process', async () => {
variables: {},
})
expect(result.variables.bpmnErrorCaught).toBe(true)
await zbc.close()
})

test('Can set variables when throwing a BPMN Error', async () => {
const zbc = new ZeebeGrpcClient()
;({ bpmnProcessId, processDefinitionKey } = (
await zbc.deployResource({
processFilename: './src/__tests__/testdata/Client-ThrowError.bpmn',
})
).deployments[0].process)
await cancelProcesses(processDefinitionKey)
// This worker takes the first job and throws a BPMN error, setting a variable
zbc.createWorker({
taskHandler: (job) =>
job.error({
Expand All @@ -68,8 +66,8 @@ test('Can set variables when throwing a BPMN Error', async () => {
variables: { something: 'someValue' },
}),
taskType: 'throw-bpmn-error-task',
timeout: Duration.seconds.of(30),
})
// This worker is on the business error throw path
zbc.createWorker({
taskType: 'sad-flow',
taskHandler: (job) =>
Expand All @@ -83,5 +81,8 @@ test('Can set variables when throwing a BPMN Error', async () => {
variables: {},
})
expect(result.variables.bpmnErrorCaught).toBe(true)
// expect(result.variables.something).toBe("someValue")
// This is not working, the variable is not being set on 8.5
// this may be due to incremental implementation of the feature
// expect(result.variables.something).toBe('someValue')
await zbc.close()
})
16 changes: 8 additions & 8 deletions src/__tests__/zeebe/integration/Client-onReady.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ test('Does not call the onReady handler if there is no broker', (done) => {
expect(called).toBe(false)
await zbc2.close()
done(null)
}, 4000)
}, 8000)
})

test('Does call the onReady handler if there is a broker and eagerConnection is true', (done) => {
test('Calls the onReady handler if there is a broker and eagerConnection is true', (done) => {
let called = 0
const zbc2 = new ZeebeGrpcClient({
config: { zeebeGrpcSettings: { ZEEBE_GRPC_CLIENT_EAGER_CONNECT: true } },
Expand All @@ -32,10 +32,10 @@ test('Does call the onReady handler if there is a broker and eagerConnection is
expect(called).toBe(1)
await zbc2.close()
done()
}, 6000)
}, 8000)
})

test('Does set connected to true if there is a broker', (done) => {
test('Sets connected to true if there is a broker', (done) => {
const zbc2 = new ZeebeGrpcClient({
config: { zeebeGrpcSettings: { ZEEBE_GRPC_CLIENT_EAGER_CONNECT: true } },
})
Expand All @@ -44,21 +44,21 @@ test('Does set connected to true if there is a broker', (done) => {
expect(zbc2.connected).toBe(true)
await zbc2.close()
done()
}, 6000)
}, 8000)
})

test('Does emit the ready event if there is a broker and eagerConnection: true', (done) => {
test('emits the ready event if there is a broker and eagerConnection: true', (done) => {
let called = 0
const zbc2 = new ZeebeGrpcClient({
config: { zeebeGrpcSettings: { ZEEBE_GRPC_CLIENT_EAGER_CONNECT: true } },
}).on('ready', () => {
called++
called = called + 1
})

setTimeout(async () => {
expect(called).toBe(1)
expect(zbc2.connected).toBe(true)
await zbc2.close()
done()
}, 6000)
}, 8000)
})
4 changes: 2 additions & 2 deletions src/__tests__/zeebe/integration/Worker-onReady.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ test('Does set connected: true if there is a broker and eagerConnection: true',
}, 7000)
})

test('Does not set connected: true if there is a broker and eagerConnection: false', (done) => {
test('Sets connected: true if there is a broker and eagerConnection: false', (done) => {
const zbc2 = new ZeebeGrpcClient()
setTimeout(async () => {
expect(zbc2.connected).toBe(false)
expect(zbc2.connected).toBe(true)
await zbc2.close()
done()
}, 7000)
Expand Down
1 change: 1 addition & 0 deletions src/generated/zeebe_grpc_pb.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// GENERATED CODE -- DO NOT EDIT!

'use strict'
Expand Down
1 change: 1 addition & 0 deletions src/generated/zeebe_pb.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
// package: gateway_protocol
// file: zeebe.proto

Expand Down
5 changes: 5 additions & 0 deletions src/lib/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ const getMainEnv = () =>
type: 'string',
optional: true,
},
/** When using self-signed certificates, provide the root certificate as a string */
CAMUNDA_CUSTOM_ROOT_CERT_STRING: {
type: 'string',
optional: true,
},
/** When using custom or self-signed certificates, provide the path to the certificate chain */
CAMUNDA_CUSTOM_CERT_CHAIN_PATH: {
type: 'string',
Expand Down

0 comments on commit 7451a66

Please sign in to comment.