diff options
author | James M Snell <jasnell@gmail.com> | 2017-07-17 15:33:46 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-08-07 18:00:57 -0700 |
commit | 7535a94c8a54bb6346c8e60dbae1c32d6f508212 (patch) | |
tree | e455c85470c3256bb064516a8fa8e2c4c059532b /test/parallel/test-crypto-binary-default.js | |
parent | 7192e913f703c96eddff697c4ba0daef87930776 (diff) | |
download | android-node-v8-7535a94c8a54bb6346c8e60dbae1c32d6f508212.tar.gz android-node-v8-7535a94c8a54bb6346c8e60dbae1c32d6f508212.tar.bz2 android-node-v8-7535a94c8a54bb6346c8e60dbae1c32d6f508212.zip |
test: begin normalizing fixtures use
Adds a new `../common/fixtures' module to begin normalizing
`test/fixtures` use. Our test code is a bit inconsistent with
regards to use of the fixtures directory. Some code uses
`path.join()`, some code uses string concats, some other
code uses template strings, etc. In mnay cases, significant
duplication of code is seen when accessing fixture files, etc.
This updates many (but by no means all) of the tests in the
test suite to use the new consistent API. There are still
many more to update, which would make an excelent Code-n-Learn
exercise.
PR-URL: https://github.com/nodejs/node/pull/14332
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Diffstat (limited to 'test/parallel/test-crypto-binary-default.js')
-rw-r--r-- | test/parallel/test-crypto-binary-default.js | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js index 4a31f76865..932db932d7 100644 --- a/test/parallel/test-crypto-binary-default.js +++ b/test/parallel/test-crypto-binary-default.js @@ -32,19 +32,18 @@ if (!common.hasCrypto) const assert = require('assert'); const crypto = require('crypto'); const fs = require('fs'); -const path = require('path'); const tls = require('tls'); +const fixtures = require('../common/fixtures'); const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR; -const fixtDir = common.fixturesDir; crypto.DEFAULT_ENCODING = 'latin1'; // Test Certificates -const certPem = fs.readFileSync(`${fixtDir}/test_cert.pem`, 'ascii'); -const certPfx = fs.readFileSync(`${fixtDir}/test_cert.pfx`); -const keyPem = fs.readFileSync(`${fixtDir}/test_key.pem`, 'ascii'); -const rsaPubPem = fs.readFileSync(`${fixtDir}/test_rsa_pubkey.pem`, 'ascii'); -const rsaKeyPem = fs.readFileSync(`${fixtDir}/test_rsa_privkey.pem`, 'ascii'); +const certPem = fixtures.readSync('test_cert.pem', 'ascii'); +const certPfx = fixtures.readSync('test_cert.pfx'); +const keyPem = fixtures.readSync('test_key.pem', 'ascii'); +const rsaPubPem = fixtures.readSync('test_rsa_pubkey.pem', 'ascii'); +const rsaKeyPem = fixtures.readSync('test_rsa_privkey.pem', 'ascii'); // PFX tests assert.doesNotThrow(function() { @@ -405,7 +404,7 @@ const h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex'); assert.strictEqual(h1, h2, 'multipled updates'); // Test hashing for binary files -const fn = path.join(fixtDir, 'sample.png'); +const fn = fixtures.path('sample.png'); const sha1Hash = crypto.createHash('sha1'); const fileStream = fs.createReadStream(fn); fileStream.on('data', function(data) { @@ -614,9 +613,8 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); // Test RSA signing and verification // { - const privateKey = fs.readFileSync(`${fixtDir}/test_rsa_privkey_2.pem`); - - const publicKey = fs.readFileSync(`${fixtDir}/test_rsa_pubkey_2.pem`); + const privateKey = fixtures.readSync('test_rsa_privkey_2.pem'); + const publicKey = fixtures.readSync('test_rsa_pubkey_2.pem'); const input = 'I AM THE WALRUS'; @@ -644,9 +642,8 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); // Test DSA signing and verification // { - const privateKey = fs.readFileSync(`${fixtDir}/test_dsa_privkey.pem`); - - const publicKey = fs.readFileSync(`${fixtDir}/test_dsa_pubkey.pem`); + const privateKey = fixtures.readSync('test_dsa_privkey.pem'); + const publicKey = fixtures.readSync('test_dsa_pubkey.pem'); const input = 'I AM THE WALRUS'; |