Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug-certs #158

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/__tests__/lib/GetCustomCertificateBuffer.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { OperateApiClient } from '../../operate'
import { ZeebeGrpcClient } from '../../zeebe'

let DEBUG
let server
afterEach(() => {
;(server && server.close && server.close()) ||
Expand All @@ -26,35 +27,55 @@ afterEach(() => {
}))
})

beforeAll(() => {
DEBUG = process.env.DEBUG
})

afterAll(() => {
process.env.DEBUG = DEBUG
})

test('Can use a custom root certificate to connect to a REST API', async () => {
process.env.DEBUG = 'camunda:certificate'
const app = express()

app.get('/v1/process-instances/:processInstanceKey', (_, res) => {
res.json({ bpmnProcessId: 'test' })
})

const options = {
key: fs.readFileSync(path.join(__dirname, 'localhost.key')),
cert: fs.readFileSync(path.join(__dirname, 'localhost.crt')),
// key: fs.readFileSync(path.join(__dirname, 'localhost.key')),
// cert: fs.readFileSync(path.join(__dirname, 'localhost.crt')),
// The above certificate works on Linux and Mac, and intermittently fails on Windows
// Using this cert/key pair to see if it can address intermittent failures on Windows
// See: https://github.com/camunda/camunda-8-js-sdk/issues/145
key: fs.readFileSync(path.join(__dirname, 'ryans-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'ryans-cert.pem')),
}

server = https.createServer(options, app)

server.listen(3012, () => {
// console.log('Server listening on port 3012')
// console.log('Server listening on port 3012')DB
// server.close()
// done()
})

const c = new OperateApiClient({
config: {
CAMUNDA_CUSTOM_ROOT_CERT_PATH: path.join(__dirname, 'localhost.crt'),
CAMUNDA_CUSTOM_ROOT_CERT_PATH: path.join(__dirname, 'ryans-cert.pem'), //'localhost.crt'),
CAMUNDA_OAUTH_DISABLED: true,
CAMUNDA_OPERATE_BASE_URL: 'https://localhost:3012',
},
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// ;(c as any).rest.then((r) => console.log(r.defaults.options.https))

console.log('Trying to get process instance with certificate')
const res = await c.getProcessInstance('1')
const res = await c.getProcessInstance('1').catch((e) => {
console.error(e)
throw e
})
console.log(
`Got response from self-signed secured server: ${res.bpmnProcessId}`
)
Expand Down Expand Up @@ -83,6 +104,8 @@ test('Can use a custom root certificate to connect to a REST API', async () => {
})

test('gRPC server with self-signed certificate', (done) => {
process.env.DEBUG = ''

// Load the protobuf definition
const packageDefinition = loadSync(
path.join(__dirname, '..', '..', 'proto', 'zeebe.proto'),
Expand Down
21 changes: 21 additions & 0 deletions src/__tests__/lib/ryans-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDYTCCAkmgAwIBAgIUeU0a2u+zLyQkjVc7e4/1zxmBTGowDQYJKoZIhvcNAQEL
BQAwWTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJbG9jYWxob3N0MB4X
DTI0MDUxMDA1MTUwOFoXDTI0MDYwOTA1MTUwOFowWTELMAkGA1UEBhMCQVUxEzAR
BgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5
IEx0ZDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
MIIBCgKCAQEAs0r7JftoOeBVnK0nwRyQ+LYS0I7LxLFB+AJ9DLf9ubTiWXO2ftap
YroHQlimumuXImrAgqh1UU8j6huLVoy43IBqEQ/v5LNCSzpTEdH+LcstHR/oO+rE
Guflx2wplZO73I6tR1XpsEudKY7legpoFyR+WwoRNhQsqMbpFoQ3IsUl3KQrFhF1
x5eReb9IusrPAu4JSrIaeiVohZ/NqVgF4mxwnkUSXn2/2OyQm7GnnaGseOoqC+4Y
I0FgoKE/1YWGI4E3Em1Zj0aToX4aGZIreYT51R8M0kbBjJiQaPXU79oWdKt6Frdn
6Ld+kdurOGLDz3y+4O9cVXxcXi9BBg9l1QIDAQABoyEwHzAdBgNVHQ4EFgQUcvSH
8wJFC3kb6u4uTMNQw+wDj40wDQYJKoZIhvcNAQELBQADggEBAIwwX6xCq+nJ1A06
PMK0GWchtnaiD8VXZwD9ur7im/x5iNKY5VC1P+EwLHS5D6YuRCxpg4Ec3j4N1xBX
8GzeEW5qoc9Upi6XNZiM90EQnNGEZ4uq316ifZjUCms6WT5QijRAMjEbiUu5pvU4
eiUcNgyjlvAQJhntbeb4xlZDlMheTF+02PZffAPKijU3IEvRLx1FUmSFAgigFqJe
KPPSoKA4Op+d2p7iM0pb8M9jJXTzm0dgYl3sphIob7wyDMfa551pB9HJaTahKB5/
yS6UDAt7A6qsO0TyuPprjYiXzahHBplA6cAsP4S22iNcrFZpb3FW/EMgBVKzqn4G
KRQix4A=
-----END CERTIFICATE-----
17 changes: 17 additions & 0 deletions src/__tests__/lib/ryans-csr.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE REQUEST-----
MIICnjCCAYYCAQAwWTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx
ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJbG9j
YWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs0r7JftoOeBV
nK0nwRyQ+LYS0I7LxLFB+AJ9DLf9ubTiWXO2ftapYroHQlimumuXImrAgqh1UU8j
6huLVoy43IBqEQ/v5LNCSzpTEdH+LcstHR/oO+rEGuflx2wplZO73I6tR1XpsEud
KY7legpoFyR+WwoRNhQsqMbpFoQ3IsUl3KQrFhF1x5eReb9IusrPAu4JSrIaeiVo
hZ/NqVgF4mxwnkUSXn2/2OyQm7GnnaGseOoqC+4YI0FgoKE/1YWGI4E3Em1Zj0aT
oX4aGZIreYT51R8M0kbBjJiQaPXU79oWdKt6Frdn6Ld+kdurOGLDz3y+4O9cVXxc
Xi9BBg9l1QIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAAaTBW7DGvC61WWeRMRK
iobIwlOMLA0+1T7SwjuhX/j7DZUxbm5o9uj+XvpvRcL3OLVxaO97Y+ki891AEaAr
wuVY4gu3aerrLYvoRonr8aSju6TqXRJrD6Pss7cL5JNut4/kNZmM6zhJyF+Fe0zN
TE53CCd6WOTQCG8DB/V7Ut9zF4AboU/K2RgVa0b6YK3OOje7ongYNdzEnbgmtxDR
mSO7F0dzKIwNxtyAIDJHHyx4OMA1A2Q4Py8E11MuABdpU+wJSJMj5BL7L6s1oUQk
/yNAMveBSYB29pLx7HpjK+SAuAsF8IUkMvYyNoffxoSEKpMIF4wCwA6L4w+mVOAV
Cfk=
-----END CERTIFICATE REQUEST-----
28 changes: 28 additions & 0 deletions src/__tests__/lib/ryans-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCzSvsl+2g54FWc
rSfBHJD4thLQjsvEsUH4An0Mt/25tOJZc7Z+1qliugdCWKa6a5ciasCCqHVRTyPq
G4tWjLjcgGoRD+/ks0JLOlMR0f4tyy0dH+g76sQa5+XHbCmVk7vcjq1HVemwS50p
juV6CmgXJH5bChE2FCyoxukWhDcixSXcpCsWEXXHl5F5v0i6ys8C7glKshp6JWiF
n82pWAXibHCeRRJefb/Y7JCbsaedoax46ioL7hgjQWCgoT/VhYYjgTcSbVmPRpOh
fhoZkit5hPnVHwzSRsGMmJBo9dTv2hZ0q3oWt2fot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