mirror of
https://github.com/hanzomsg/nats.js.git
synced 2026-10-30 20:31:36 +00:00
* feat(tests): increase coverage - fixed a validation in KV that was allowing keys with malformed keys like `a..b` - Introduced `sha_digest_test.ts` covering parsing and validation of SHA256 hashes in various formats. - Expanded Kv tests with codec validation, wildcard detection, and bucket options verification. - Updated workflows to include `unsafe` module in testing matrix. - Improved test coverage output handling in `deno.json`. Signed-off-by: Alberto Ricart <[email protected]> * run unsafe tests in ci Signed-off-by: Alberto Ricart <[email protected]> * run unsafe tests in ci Signed-off-by: Alberto Ricart <[email protected]> * run unsafe tests in ci Signed-off-by: Alberto Ricart <[email protected]> * debug unsafe Signed-off-by: Alberto Ricart <[email protected]> * skip tls unsafe test in CI environment Signed-off-by: Alberto Ricart <[email protected]> * more coverage Signed-off-by: Alberto Ricart <[email protected]> --------- Signed-off-by: Alberto Ricart <[email protected]>
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import { join, resolve } from "@std/path";
|
|
import { cleanup, connect, NatsServer, wsServerConf } from "test_helpers";
|
|
import { delay, wsconnect } from "../src/internal_mod.ts";
|
|
import type { NatsConnectionImpl } from "../src/internal_mod.ts";
|
|
import { assertEquals } from "@std/assert";
|
|
|
|
Deno.test("tls-unsafe - handshake first", async () => {
|
|
const cwd = Deno.cwd();
|
|
const config = {
|
|
host: "localhost",
|
|
tls: {
|
|
handshake_first: true,
|
|
cert_file: resolve(
|
|
join(cwd, "./core/tests/certs/localhost.crt"),
|
|
),
|
|
key_file: resolve(
|
|
join(cwd, "./core/tests/certs/localhost.key"),
|
|
),
|
|
ca_file: resolve(join(cwd, "./core/tests/certs/RootCA.crt")),
|
|
},
|
|
};
|
|
|
|
const ns = await NatsServer.start(config);
|
|
console.log("port", ns.port);
|
|
const nc = await connect({
|
|
debug: true,
|
|
servers: `localhost:${ns.port}`,
|
|
tls: {
|
|
handshakeFirst: true,
|
|
caFile: config.tls.ca_file,
|
|
},
|
|
});
|
|
nc.subscribe("foo", {
|
|
callback(_err, msg) {
|
|
msg.respond(msg.data);
|
|
},
|
|
});
|
|
|
|
await nc.request("foo", "hello");
|
|
await nc.close();
|
|
await ns.stop();
|
|
});
|
|
|
|
Deno.test({
|
|
name: "wss - wss connect default",
|
|
ignore: Deno.env.get("CI") === "true", // Skip in CI - requires binding to privileged port 443
|
|
async fn() {
|
|
const tlsConfig = await NatsServer.tlsConfig();
|
|
const tls = tlsConfig.tls;
|
|
const ns = await NatsServer.start(
|
|
wsServerConf(
|
|
{
|
|
websocket: {
|
|
port: 443,
|
|
tls,
|
|
},
|
|
},
|
|
),
|
|
true,
|
|
);
|
|
await delay(2000);
|
|
const nc = await wsconnect();
|
|
assertEquals(
|
|
(nc as NatsConnectionImpl).protocol.transport?.isEncrypted(),
|
|
true,
|
|
);
|
|
await nc.flush();
|
|
await cleanup(ns, nc);
|
|
},
|
|
sanitizeOps: false,
|
|
sanitizeResources: false,
|
|
});
|