mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-06-06 14:16:42 +00:00
Tests: explicitly share openpgp instance used in tests
Also, init config before any code is run in tests
This commit is contained in:
parent
d49d92e5cb
commit
ae4ed1fbf3
@ -96,6 +96,7 @@ module.exports = {
|
||||
// eslint-plugin-import rules:
|
||||
'import/named': 'error',
|
||||
'import/extensions': 'error',
|
||||
'import/first': 'off',
|
||||
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true, 'optionalDependencies': false, 'peerDependencies': false }],
|
||||
'import/no-unassigned-import': 'error',
|
||||
'import/prefer-default-export': 'off',
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import sandbox from 'sinon/lib/sinon/sandbox';
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import crypto from '../../src/crypto';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
// Adapted from https://github.com/artjomb/cryptojs-extension/blob/8c61d159/test/eax.js
|
||||
import sandbox from 'sinon/lib/sinon/sandbox';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import EAX from '../../src/crypto/mode/eax.js';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import sandbox from 'sinon/lib/sinon/sandbox';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import OID from '../../src/type/oid.js';
|
||||
import KDFParams from '../../src/type/kdf_params.js';
|
||||
import * as elliptic_curves from '../../src/crypto/public_key/elliptic';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import sandbox from 'sinon/lib/sinon/sandbox';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import * as elliptic_curves from '../../src/crypto/public_key/elliptic';
|
||||
import hashMod from '../../src/crypto/hash';
|
||||
import config from '../../src/config';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import sandbox from 'sinon/lib/sinon/sandbox';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import crypto from '../../src/crypto';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
// Adapted from https://github.com/artjomb/cryptojs-extension/blob/8c61d159/test/eax.js
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import OCB from '../../src/crypto/mode/ocb.js';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import sandbox from 'sinon/lib/sinon/sandbox';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import crypto from '../../src/crypto';
|
||||
import * as random from '../../src/crypto/random.js';
|
||||
import util from '../../src/util.js';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import BN from 'bn.js';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
const armoredDSAKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
export default () => describe('ASCII armor', function() {
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* globals tryTests */
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
import * as input from './testInputs.js';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
export default () => describe('Custom configuration', function() {
|
||||
it('openpgp.readMessage', async function() {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
const password = 'I am a password';
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
export default () => describe('Elliptic Curve Cryptography for secp256k1 curve @lightweight', function () {
|
||||
|
@ -1,10 +1,10 @@
|
||||
/* eslint-disable max-lines */
|
||||
/* globals tryTests */
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import util from '../../src/util.js';
|
||||
import { isAEADSupported, getPreferredAlgo } from '../../src/key';
|
||||
import KeyID from '../../src/type/keyid.js';
|
||||
|
@ -3,10 +3,10 @@
|
||||
import spy from 'sinon/lib/sinon/spy';
|
||||
import * as stream from '@openpgp/web-stream-tools';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import crypto from '../../src/crypto';
|
||||
import * as random from '../../src/crypto/random.js';
|
||||
import util from '../../src/util.js';
|
||||
|
@ -2,10 +2,10 @@
|
||||
import * as stream from '@openpgp/web-stream-tools';
|
||||
import stub from 'sinon/lib/sinon/stub';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import crypto from '../../src/crypto';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
/* globals tryTests, loadStreamsPolyfill */
|
||||
import * as stream from '@openpgp/web-stream-tools';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
import * as stream from '@openpgp/web-stream-tools';
|
||||
import stub from 'sinon/lib/sinon/stub';
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import * as random from '../../src/crypto/random.js';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
|
||||
import nacl from '@openpgp/tweetnacl';
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
import * as elliptic from '../../src/crypto/public_key/elliptic';
|
||||
import * as signature from '../../src/crypto/signature';
|
||||
|
14
test/initOpenpgp.js
Normal file
14
test/initOpenpgp.js
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* This module centralises the openpgp import and ensures that the module is initialised
|
||||
* at the top of the test bundle, and that the config is initialised before the tests code runs (incl. that outside of `describe`).
|
||||
*/
|
||||
|
||||
import * as openpgp from 'openpgp';
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.openpgp = openpgp;
|
||||
}
|
||||
|
||||
openpgp.config.s2kIterationCountByte = 0;
|
||||
|
||||
export default openpgp;
|
@ -1,8 +1,8 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
import util from '../../src/util.js';
|
||||
|
||||
const { readKey, readCleartextMessage, SignaturePacket } = openpgp;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
const armoredMessage = `-----BEGIN PGP MESSAGE-----
|
||||
Version: OpenPGP.js VERSION
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
const { readKey, PublicKey, readCleartextMessage, createCleartextMessage, enums, PacketList, SignaturePacket } = openpgp;
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { use as chaiUse, expect } from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
|
||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||
chaiUse(chaiAsPromised);
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : await import('openpgp');
|
||||
import openpgp from '../initOpenpgp.js';
|
||||
|
||||
const { readKey, PrivateKey, createMessage, enums, PacketList, SignaturePacket } = openpgp;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
import * as openpgp from 'openpgp';
|
||||
if (typeof window !== 'undefined' && !window.openpgp) { window.openpgp = openpgp }
|
||||
|
||||
import openpgp from './initOpenpgp.js';
|
||||
|
||||
(typeof window !== 'undefined' ? window : global).globalThis = (typeof window !== 'undefined' ? window : global);
|
||||
|
||||
@ -38,9 +36,6 @@ import runGeneralTests from './general';
|
||||
import runSecurityTests from './security';
|
||||
|
||||
describe('Unit Tests', function () {
|
||||
|
||||
openpgp.config.s2kIterationCountByte = 0;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
// Safari 14.1.*, 15.* and 16.* seem to have issues handling rejections when their native TransformStream implementation is involved,
|
||||
// so for now we ignore unhandled rejections for those browser versions.
|
||||
|
Loading…
x
Reference in New Issue
Block a user