Skip to content

Commit

Permalink
Skip native Crypto tests if native lib is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Feb 20, 2023
1 parent dcd28fa commit 6684482
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/crypto/eax.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function testAESEAX() {
});
}

/* eslint-disable no-invalid-this */
module.exports = () => describe('Symmetric AES-EAX', function() {
let sinonSandbox;
let getWebCryptoStub;
Expand All @@ -142,6 +143,11 @@ module.exports = () => describe('Symmetric AES-EAX', function() {
};

describe('Symmetric AES-EAX (native)', function() {
before(function () {
const detectNative = () => !!(util.getWebCrypto() || util.getNodeCrypto());
if (!detectNative()) { this.skip(); }
});

beforeEach(function () {
sinonSandbox = sandbox.create();
enableNative();
Expand Down
6 changes: 6 additions & 0 deletions test/crypto/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module.exports = () => describe('basic RSA cryptography', function () {
sinonSandbox.restore();
});

const detectNative = () => !!(util.getWebCrypto() || util.getNodeCrypto());

const disableNative = () => {
enableNative();
// stubbed functions return undefined
Expand Down Expand Up @@ -105,6 +107,8 @@ module.exports = () => describe('basic RSA cryptography', function () {
});

it('compare native crypto and bnSign', async function() {
if (!detectNative()) { this.skip(); }

const bits = 1024;
const { publicParams, privateParams } = await crypto.generateParams(openpgp.enums.publicKey.rsaSign, bits);
const { n, e, d, p, q, u } = { ...publicParams, ...privateParams };
Expand All @@ -120,6 +124,8 @@ module.exports = () => describe('basic RSA cryptography', function () {
});

it('compare native crypto and bnVerify', async function() {
if (!detectNative()) { this.skip(); }

const bits = 1024;
const { publicParams, privateParams } = await crypto.generateParams(openpgp.enums.publicKey.rsaSign, bits);
const { n, e, d, p, q, u } = { ...publicParams, ...privateParams };
Expand Down

0 comments on commit 6684482

Please sign in to comment.