Skip to content

Commit

Permalink
test: refactor all tests that depends on crypto
Browse files Browse the repository at this point in the history
we had a few ways versions of looking for support before executing a test. this
commit unifies them as well as add the check for all tests that previously
lacked them. found by running `./configure --without-ssl && make test`. also,
produce tap skip output if the test is skipped.

PR-URL: #1049
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
  • Loading branch information
jbergstroem authored and Shigeki Ohtsu committed Mar 5, 2015
1 parent c7ad320 commit 671fbd5
Show file tree
Hide file tree
Showing 128 changed files with 751 additions and 445 deletions.
5 changes: 5 additions & 0 deletions test/internet/test-http-https-default-ports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var common = require('../common');
var assert = require('assert');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var https = require('https');

var http = require('http');
var gotHttpsResp = false;
var gotHttpResp = false;
Expand Down
5 changes: 5 additions & 0 deletions test/internet/test-tls-reuse-host-from-socket.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var common = require('../common');
var assert = require('assert');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var tls = require('tls');

var net = require('net');
var connected = false;
var secure = false;
Expand Down
24 changes: 14 additions & 10 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,16 +1108,20 @@ assert.throws(function () {
new SlowBuffer(smalloc.kMaxLength + 1);
}, RangeError);

// Test truncation after decode
var crypto = require('crypto');

var b1 = new Buffer('YW55=======', 'base64');
var b2 = new Buffer('YW55', 'base64');

assert.equal(
crypto.createHash('sha1').update(b1).digest('hex'),
crypto.createHash('sha1').update(b2).digest('hex')
);
if (common.hasCrypto) {
// Test truncation after decode
var crypto = require('crypto');

var b1 = new Buffer('YW55=======', 'base64');
var b2 = new Buffer('YW55', 'base64');

assert.equal(
crypto.createHash('sha1').update(b1).digest('hex'),
crypto.createHash('sha1').update(b2).digest('hex')
);
} else {
console.log('1..0 # Skipped: missing crypto');
}

// Test Compare
var b = new Buffer(1).fill('a');
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-authenticated.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

crypto.DEFAULT_ENCODING = 'buffer';

Expand Down
8 changes: 3 additions & 5 deletions test/parallel/test-crypto-binary-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ var common = require('../common');
var assert = require('assert');
var constants = require('constants');

try {
var crypto = require('crypto');
var tls = require('tls');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

crypto.DEFAULT_ENCODING = 'binary';

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-crypto-certificate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var common = require('../common');
var assert = require('assert');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

crypto.DEFAULT_ENCODING = 'buffer';
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-cipher-decipher.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

function testCipher1(key) {
// Test encryption and decryption
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-crypto-dh-odd-key.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var common = require('../common');
var assert = require('assert');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

var odd = new Buffer(39);
odd.fill('A');

Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-dh.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ var common = require('../common');
var assert = require('assert');
var constants = require('constants');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

// Test Diffie-Hellman with two parties sharing a secret,
// using various encodings as we go along
Expand Down
9 changes: 4 additions & 5 deletions test/parallel/test-crypto-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ var common = require('../common');
var assert = require('assert');
var domain = require('domain');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Skipping test, compiled without crypto support.');
return;
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

function test(fn) {
var ex = new Error('BAM');
Expand Down
8 changes: 7 additions & 1 deletion test/parallel/test-crypto-domains.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
var crypto = require('crypto');
var common = require('../common');
var domain = require('domain');
var assert = require('assert');
var d = domain.create();
var expect = ['pbkdf2', 'randomBytes', 'pseudoRandomBytes']
var errors = 0;

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

process.on('exit', function() {
assert.equal(errors, 3);
});
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-ecb.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

crypto.DEFAULT_ENCODING = 'buffer';

Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-from-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

var EXTERN_APEX = 0xFBEE9;

Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-crypto-hash-stream-pipe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var common = require('../common');
var assert = require('assert');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

var stream = require('stream')
var s = new stream.PassThrough();
var h = crypto.createHash('sha1');
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ var assert = require('assert');
var fs = require('fs');
var path = require('path');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

// Test hashing
var a0 = crypto.createHash('sha1').update('Test123').digest('hex');
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-hmac.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

// Test HMAC
var h1 = crypto.createHmac('sha1', 'Node')
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-padding-aes256.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OpenSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

crypto.DEFAULT_ENCODING = 'buffer';

Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-padding.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

crypto.DEFAULT_ENCODING = 'buffer';

Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-pbkdf2.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

//
// Test PBKDF2 with RFC 6070 test vectors (except #4)
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

crypto.DEFAULT_ENCODING = 'buffer';

Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-rsa-dsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ var assert = require('assert');
var fs = require('fs');
var constants = require('constants');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

// Test certificates
var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-sign-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ var common = require('../common');
var assert = require('assert');
var fs = require('fs');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

// Test certificates
var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-crypto-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ var assert = require('assert');
var stream = require('stream');
var util = require('util');

try {
var crypto = require('crypto');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');

// Small stream to buffer converter
function Stream2buffer(callback) {
Expand Down
9 changes: 4 additions & 5 deletions test/parallel/test-crypto-verify-failure.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var common = require('../common');
var assert = require('assert');

try {
var crypto = require('crypto');
var tls = require('tls');
} catch (e) {
console.log('Not compiled with OPENSSL support.');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var crypto = require('crypto');
var tls = require('tls');

crypto.DEFAULT_ENCODING = 'buffer';

Expand Down
Loading

0 comments on commit 671fbd5

Please sign in to comment.