Welcome! Log In Create A New Profile

Advanced

[njs] Tests: allowing to define own test function per test suite.

Dmitry Volyntsev
November 01, 2021 11:58AM
details: https://hg.nginx.org/njs/rev/8dd6868a8748
branches:
changeset: 1733:8dd6868a8748
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Nov 01 15:53:30 2021 +0000
description:
Tests: allowing to define own test function per test suite.

diffstat:

test/webcrypto/aes.js | 8 +++++---
test/webcrypto/aes_decoding.js | 8 +++++---
test/webcrypto/derive.js | 8 +++++---
test/webcrypto/digest.js | 8 +++++---
test/webcrypto/rsa.js | 8 +++++---
test/webcrypto/rsa_decoding.js | 8 +++++---
test/webcrypto/sign.js | 14 +++++++++++---
test/webcrypto/verify.js | 14 +++++++++++---
8 files changed, 52 insertions(+), 24 deletions(-)

diffs (342 lines):

diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/aes.js
--- a/test/webcrypto/aes.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/aes.js Mon Nov 01 15:53:30 2021 +0000
@@ -2,7 +2,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -22,7 +22,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -77,6 +77,8 @@ async function test(params) {

let aes_tsuite = {
name: "AES encoding/decoding",
+ T: test,
+ prepare_args: p,
opts: {
iv: "44556677445566774455667744556677",
key: "00112233001122330011223300112233",
@@ -120,4 +122,4 @@ let aes_tsuite = {
{ name: "AES-CBC", data: "aabbccdd".repeat(5), iv: "ffffffffffffffffffffffffffffffff" },
]};

-run([aes_tsuite], test, p);
+run([aes_tsuite]);
diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/aes_decoding.js
--- a/test/webcrypto/aes_decoding.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/aes_decoding.js Mon Nov 01 15:53:30 2021 +0000
@@ -4,7 +4,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -24,7 +24,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -79,6 +79,8 @@ async function test(params) {

let aes_tsuite = {
name: "AES decoding",
+ T: test,
+ prepare_args: p,
opts: {
key: "00112233001122330011223300112233",
iv: "44556677445566774455667744556677",
@@ -113,4 +115,4 @@ let aes_tsuite = {
expected: "AES-CBC-256-SECRET-TEXT" },
]};

-run([aes_tsuite], test, p);
+run([aes_tsuite]);
diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/derive.js
--- a/test/webcrypto/derive.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/derive.js Mon Nov 01 15:53:30 2021 +0000
@@ -2,7 +2,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -26,7 +26,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -96,6 +96,8 @@ async function test(params) {

let derive_tsuite = {
name: "derive",
+ T: test,
+ prepare_args: p,
opts: {
text: "secReT",
pass: "passW0rd",
@@ -146,4 +148,4 @@ let derive_tsuite = {
expected: "e089c7491711306c69e077aa19fae6bfd2d4a6d240b0d37317d50472d7291a3e" },
]};

-run([derive_tsuite], test, p);
+run([derive_tsuite]);
diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/digest.js
--- a/test/webcrypto/digest.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/digest.js Mon Nov 01 15:53:30 2021 +0000
@@ -2,7 +2,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -22,7 +22,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -54,6 +54,8 @@ async function test(params) {

let digest_tsuite = {
name: "SHA digest",
+ T: test,
+ prepare_args: p,
opts: { },

tests: [
@@ -85,4 +87,4 @@ let digest_tsuite = {
expected: "cdea58919606ea9ae078f7595b192b84446f2189" },
]};

-run([digest_tsuite], test, p);
+run([digest_tsuite]);
diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/rsa.js
--- a/test/webcrypto/rsa.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/rsa.js Mon Nov 01 15:53:30 2021 +0000
@@ -4,7 +4,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -24,7 +24,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -79,6 +79,8 @@ async function test(params) {

let rsa_tsuite = {
name: "RSA-OAEP encoding/decoding",
+ T: test,
+ prepare_args: p,
opts: {
spki: "rsa.spki",
spki_hash: "SHA-256",
@@ -103,4 +105,4 @@ let rsa_tsuite = {
{ data: "aabbcc", spki: "rsa2.spki", exception: "Error: EVP_PKEY_decrypt() failed" },
]};

-run([rsa_tsuite], test, p);
+run([rsa_tsuite]);
diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/rsa_decoding.js
--- a/test/webcrypto/rsa_decoding.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/rsa_decoding.js Mon Nov 01 15:53:30 2021 +0000
@@ -4,7 +4,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -24,7 +24,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -70,6 +70,8 @@ async function test(params) {

let rsa_tsuite = {
name: "RSA-OAEP decoding",
+ T: test,
+ prepare_args: (v) => v,
opts: { },

tests: [
@@ -78,4 +80,4 @@ let rsa_tsuite = {
{ pem: "rsa.pkcs8.broken", src: "text.base64.rsa-oaep.enc", exception: "Error: d2i_PKCS8_PRIV_KEY_INFO_bio() failed" },
]};

-run([rsa_tsuite], test, (v) => v);
+run([rsa_tsuite]);
diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/sign.js
--- a/test/webcrypto/sign.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/sign.js Mon Nov 01 15:53:30 2021 +0000
@@ -3,7 +3,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -23,7 +23,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -160,6 +160,8 @@ async function test(params) {

let hmac_tsuite = {
name: "HMAC sign",
+ T: test,
+ prepare_args: p,
opts: {
text: "TExt-T0-SiGN",
sign_key: { key: "secretKEY", fmt: "raw" },
@@ -193,6 +195,8 @@ let hmac_tsuite = {

let rsassa_pkcs1_v1_5_tsuite = {
name: "RSASSA-PKCS1-v1_5 sign",
+ T: test,
+ prepare_args: p,
opts: {
text: "TExt-T0-SiGN",
sign_key: { key: "rsa.pkcs8", fmt: "pkcs8" },
@@ -221,6 +225,8 @@ let rsassa_pkcs1_v1_5_tsuite = {

let rsa_pss_tsuite = {
name: "RSA-PSS sign",
+ T: test,
+ prepare_args: p,
opts: {
text: "TExt-T0-SiGN",
sign_key: { key: "rsa.pkcs8", fmt: "pkcs8" },
@@ -250,6 +256,8 @@ let rsa_pss_tsuite = {

let ecdsa_tsuite = {
name: "ECDSA sign",
+ T: test,
+ prepare_args: p,
opts: {
text: "TExt-T0-SiGN",
sign_key: { key: "ec.pkcs8", fmt: "pkcs8" },
@@ -279,4 +287,4 @@ run([
rsassa_pkcs1_v1_5_tsuite,
rsa_pss_tsuite,
ecdsa_tsuite
-], test, p);
+]);
diff -r 360384498060 -r 8dd6868a8748 test/webcrypto/verify.js
--- a/test/webcrypto/verify.js Mon Nov 01 18:32:48 2021 +0300
+++ b/test/webcrypto/verify.js Mon Nov 01 15:53:30 2021 +0000
@@ -4,7 +4,7 @@ if (typeof crypto == 'undefined') {
crypto = require('crypto').webcrypto;
}

-async function run(tlist, T, prepare_args) {
+async function run(tlist) {
function validate(t, r, i) {
if (r.status == "fulfilled" && !t[i].exception) {
return r.value === "SUCCESS";
@@ -24,7 +24,7 @@ async function run(tlist, T, prepare_arg

for (let k = 0; k < tlist.length; k++) {
let ts = tlist[k];
- let results = await Promise.allSettled(ts.tests.map(t => T(prepare_args(t, ts.opts))));
+ let results = await Promise.allSettled(ts.tests.map(t => ts.T(ts.prepare_args(t, ts.opts))));
let r = results.map((r, i) => validate(ts.tests, r, i));

console.log(`${ts.name} ${r.every(v=>v == true) ? "SUCCESS" : "FAILED"}`);
@@ -108,6 +108,8 @@ async function test(params) {

let hmac_tsuite = {
name: "HMAC verify",
+ T: test,
+ prepare_args: p,
opts: {
text: "SigneD-TExt",
key: { fmt: "raw", file: "aabbcc" },
@@ -130,6 +132,8 @@ let hmac_tsuite = {

let rsassa_pkcs1_v1_5_tsuite = {
name: "RSASSA-PKCS1-v1_5 verify",
+ T: test,
+ prepare_args: p,
opts: {
text: "SigneD-TExt",
key: { fmt: "spki", file: "rsa.spki" },
@@ -152,6 +156,8 @@ let rsassa_pkcs1_v1_5_tsuite = {

let rsa_pss_tsuite = {
name: "RSA-PSS verify",
+ T: test,
+ prepare_args: p,
opts: {
text: "SigneD-TExt",
key: { fmt: "spki", file: "rsa.spki" },
@@ -179,6 +185,8 @@ let rsa_pss_tsuite = {

let ecdsa_tsuite = {
name: "ECDSA verify",
+ T: test,
+ prepare_args: p,
opts: {
text: "SigneD-TExt",
key: { fmt: "spki", file: "ec.spki" },
@@ -204,4 +212,4 @@ run([
rsassa_pkcs1_v1_5_tsuite,
rsa_pss_tsuite,
ecdsa_tsuite,
-], test, p);
+]);
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Tests: allowing to define own test function per test suite.

Dmitry Volyntsev 365 November 01, 2021 11:58AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 57
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready