|
| 1 | +import { describe, expect, test } from "vitest" |
| 2 | +import { createEnvironment, Environment } from "../../src/environment.js" |
| 3 | +import { host, username, eventually, numberOfConnections, password } from "../support/util.js" |
| 4 | +import { Connection } from "../../src/connection.js" |
| 5 | +import { readFile } from "fs/promises" |
| 6 | + |
| 7 | +describe("TLS Connection", () => { |
| 8 | + const LOCAL_TEST_CN = "rabbitmq" |
| 9 | + |
| 10 | + let environment: Environment |
| 11 | + let connection: Connection |
| 12 | + |
| 13 | + test("creating a TLS connection", async () => { |
| 14 | + const cn = process.env.CN ?? LOCAL_TEST_CN |
| 15 | + const tls = { |
| 16 | + ca: await readFile("./tls-gen/basic/result/ca_certificate.pem", "utf8"), |
| 17 | + cert: await readFile(`./tls-gen/basic/result/client_${cn}_certificate.pem`, "utf8"), |
| 18 | + key: await readFile(`./tls-gen/basic/result/client_${cn}_key.pem`, "utf8"), |
| 19 | + rejectUnauthorized: true, |
| 20 | + } |
| 21 | + |
| 22 | + environment = createEnvironment({ host, port: 5671, username, password, tls }) |
| 23 | + |
| 24 | + connection = await environment.createConnection() |
| 25 | + |
| 26 | + await eventually(async () => { |
| 27 | + expect(await numberOfConnections()).to.eql(1) |
| 28 | + }) |
| 29 | + await connection.close() |
| 30 | + await environment.close() |
| 31 | + }) |
| 32 | +}) |
0 commit comments