Skip to content

Commit

Permalink
fixup! add test
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Sep 20, 2024
1 parent 557d854 commit 2937599
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
44 changes: 34 additions & 10 deletions fixtures/nodejs-hybrid-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,51 @@ export default {
ctx: ExecutionContext
): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === "/test-random") {
return testGetRandomValues();
}

if (url.pathname === "/test-process") {
return testProcessBehaviour();
}

if (url.pathname === "/query") {
return testPostgresLibrary(env, ctx);
switch (url.pathname) {
case "/test-random":
return testGetRandomValues();
case "/test-process":
return testProcessBehaviour();
case "/query":
return testPostgresLibrary(env, ctx);
case "/test-x509-certificate":
return testX509Certificate();
}

return new Response(
'<a href="query">Postgres query</a> | ' +
'<a href="test-process">Test process global</a> | ' +
'<a href="test-random">Test getRandomValues()</a> | ',
'<a href="test-random">Test getRandomValues()</a> | ' +
'<a href="test-x509-certificate">Test X509Certificate</a>',
{ headers: { "Content-Type": "text/html; charset=utf-8" } }
);
},
};

function testX509Certificate() {
try {
new nodeCrypto.X509Certificate(`-----BEGIN CERTIFICATE-----
MIICZjCCAc+gAwIBAgIUOsv8Y+x40C+gdNuu40N50KpGUhEwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDA5MjAwOTA4MTNaFw0yNTA5
MjAwOTA4MTNaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwgZ8wDQYJKoZIhvcNAQEB
BQADgY0AMIGJAoGBALpJn3dUrNmZhZV02RbjZKTd5j3hpgTncF4lG4Y3sQA18k0l
7pt6xpZuXYSFH7v2zTAxYy+uYyYwX2NZur48dZc76FSzIeuQdoTCkT0NacwFRTR5
fEEqPvvB85ozYuyk8Bl3vSsonivOH3WftEDp9mjkHROQzS4wAZbIj7Cp+is/AgMB
AAGjUzBRMB0GA1UdDgQWBBSzFJSiPAw2tJOg8oUXrFBdqWI6zDAfBgNVHSMEGDAW
gBSzFJSiPAw2tJOg8oUXrFBdqWI6zDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3
DQEBCwUAA4GBACbto0+Ds40F7faRFFMwg5nPyh7gsiX+ZK3FYcrO3oxh5ejfzwow
DKOOje4Ncaw0rIkVpxacPyjg+wANuK2Nv/Z4CVAD3mneE4gwgRdn38q8IYN9AtSv
GzEf4UxiLBbUB6WRBgyVyquGfUMlKl/tnm4q0yeYQloYKSoHpGeHVJuN
-----END CERTIFICATE-----`);
return new Response(`"OK!"`);
} catch {
return new Response(`"KO!"`);
}
}

function testGetRandomValues() {
assert(
webcrypto.getRandomValues === getRandomValues,
Expand Down
17 changes: 16 additions & 1 deletion fixtures/nodejs-hybrid-app/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from "node:path";
import { fetch } from "undici";
import { describe, it } from "vitest";
import { describe, it, test } from "vitest";
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";

describe("nodejs compat", () => {
Expand Down Expand Up @@ -48,4 +48,19 @@ describe("nodejs compat", () => {
await stop();
}
});

test("crypto.X509Certificate is implemented", async ({ expect }) => {
const { ip, port, stop } = await runWranglerDev(
resolve(__dirname, "../src"),
["--port=0", "--inspector-port=0"]
);
try {
const response = await fetch(
`http://${ip}:${port}/test-x509-certificate`
);
await expect(response.text()).resolves.toBe(`"OK!"`);
} finally {
await stop();
}
});
});

0 comments on commit 2937599

Please sign in to comment.