aboutsummaryrefslogtreecommitdiff
path: root/test/js/third_party/jsonwebtoken/rsa-public-key.test.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
commit7458b969c5d9971e89d187b687e1924e78da427e (patch)
treeee3dbf95c728cf407bf49a27826b541e9264a8bd /test/js/third_party/jsonwebtoken/rsa-public-key.test.js
parentd4a2c29131ec154f5e4db897d4deedab2002cbc4 (diff)
parente91436e5248d947b50f90b4a7402690be8a41f39 (diff)
downloadbun-7458b969c5d9971e89d187b687e1924e78da427e.tar.gz
bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.zst
bun-7458b969c5d9971e89d187b687e1924e78da427e.zip
Merge branch 'main' into postinstall_3
Diffstat (limited to 'test/js/third_party/jsonwebtoken/rsa-public-key.test.js')
-rw-r--r--test/js/third_party/jsonwebtoken/rsa-public-key.test.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/js/third_party/jsonwebtoken/rsa-public-key.test.js b/test/js/third_party/jsonwebtoken/rsa-public-key.test.js
new file mode 100644
index 000000000..c343cb0a9
--- /dev/null
+++ b/test/js/third_party/jsonwebtoken/rsa-public-key.test.js
@@ -0,0 +1,44 @@
+const PS_SUPPORTED = true;
+import jwt from "jsonwebtoken";
+import { expect, describe, it } from "bun:test";
+import { generateKeyPairSync } from "crypto";
+
+describe("public key start with BEGIN RSA PUBLIC KEY", function () {
+ it("should work for RS family of algorithms", function (done) {
+ var fs = require("fs");
+ var cert_pub = fs.readFileSync(__dirname + "/rsa-public-key.pem");
+ var cert_priv = fs.readFileSync(__dirname + "/rsa-private.pem");
+
+ var token = jwt.sign({ foo: "bar" }, cert_priv, { algorithm: "RS256" });
+
+ jwt.verify(token, cert_pub, done);
+ });
+
+ it("should not work for RS algorithms when modulus length is less than 2048 when allowInsecureKeySizes is false or not set", function (done) {
+ const { privateKey } = generateKeyPairSync("rsa", { modulusLength: 1024 });
+
+ expect(function () {
+ jwt.sign({ foo: "bar" }, privateKey, { algorithm: "RS256" });
+ }).toThrow("minimum key size");
+
+ done();
+ });
+
+ it("should work for RS algorithms when modulus length is less than 2048 when allowInsecureKeySizes is true", function (done) {
+ const { privateKey } = generateKeyPairSync("rsa", { modulusLength: 1024 });
+
+ jwt.sign({ foo: "bar" }, privateKey, { algorithm: "RS256", allowInsecureKeySizes: true }, done);
+ });
+
+ if (PS_SUPPORTED) {
+ it("should work for PS family of algorithms", function (done) {
+ var fs = require("fs");
+ var cert_pub = fs.readFileSync(__dirname + "/rsa-public-key.pem");
+ var cert_priv = fs.readFileSync(__dirname + "/rsa-private.pem");
+
+ var token = jwt.sign({ foo: "bar" }, cert_priv, { algorithm: "PS256" });
+
+ jwt.verify(token, cert_pub, done);
+ });
+ }
+});