Skip to content

Commit 671fbd5

Browse files
jbergstroemShigeki Ohtsu
authored and
Shigeki Ohtsu
committed
test: refactor all tests that depends on crypto
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 <[email protected]> Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent c7ad320 commit 671fbd5

File tree

128 files changed

+751
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+751
-445
lines changed

test/internet/test-http-https-default-ports.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
6+
process.exit();
7+
}
48
var https = require('https');
9+
510
var http = require('http');
611
var gotHttpsResp = false;
712
var gotHttpResp = false;

test/internet/test-tls-reuse-host-from-socket.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
6+
process.exit();
7+
}
48
var tls = require('tls');
9+
510
var net = require('net');
611
var connected = false;
712
var secure = false;

test/parallel/test-buffer.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -1108,16 +1108,20 @@ assert.throws(function () {
11081108
new SlowBuffer(smalloc.kMaxLength + 1);
11091109
}, RangeError);
11101110

1111-
// Test truncation after decode
1112-
var crypto = require('crypto');
1113-
1114-
var b1 = new Buffer('YW55=======', 'base64');
1115-
var b2 = new Buffer('YW55', 'base64');
1116-
1117-
assert.equal(
1118-
crypto.createHash('sha1').update(b1).digest('hex'),
1119-
crypto.createHash('sha1').update(b2).digest('hex')
1120-
);
1111+
if (common.hasCrypto) {
1112+
// Test truncation after decode
1113+
var crypto = require('crypto');
1114+
1115+
var b1 = new Buffer('YW55=======', 'base64');
1116+
var b2 = new Buffer('YW55', 'base64');
1117+
1118+
assert.equal(
1119+
crypto.createHash('sha1').update(b1).digest('hex'),
1120+
crypto.createHash('sha1').update(b2).digest('hex')
1121+
);
1122+
} else {
1123+
console.log('1..0 # Skipped: missing crypto');
1124+
}
11211125

11221126
// Test Compare
11231127
var b = new Buffer(1).fill('a');

test/parallel/test-crypto-authenticated.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
crypto.DEFAULT_ENCODING = 'buffer';
1211

test/parallel/test-crypto-binary-default.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ var common = require('../common');
66
var assert = require('assert');
77
var constants = require('constants');
88

9-
try {
10-
var crypto = require('crypto');
11-
var tls = require('tls');
12-
} catch (e) {
13-
console.log('Not compiled with OPENSSL support.');
9+
if (!common.hasCrypto) {
10+
console.log('1..0 # Skipped: missing crypto');
1411
process.exit();
1512
}
13+
var crypto = require('crypto');
1614

1715
crypto.DEFAULT_ENCODING = 'binary';
1816

test/parallel/test-crypto-certificate.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
6+
process.exit();
7+
}
48
var crypto = require('crypto');
59

610
crypto.DEFAULT_ENCODING = 'buffer';

test/parallel/test-crypto-cipher-decipher.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
function testCipher1(key) {
1211
// Test encryption and decryption

test/parallel/test-crypto-dh-odd-key.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
6+
process.exit();
7+
}
48
var crypto = require('crypto');
9+
510
var odd = new Buffer(39);
611
odd.fill('A');
712

test/parallel/test-crypto-dh.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ var common = require('../common');
22
var assert = require('assert');
33
var constants = require('constants');
44

5-
try {
6-
var crypto = require('crypto');
7-
} catch (e) {
8-
console.log('Not compiled with OPENSSL support.');
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
97
process.exit();
108
}
9+
var crypto = require('crypto');
1110

1211
// Test Diffie-Hellman with two parties sharing a secret,
1312
// using various encodings as we go along

test/parallel/test-crypto-domain.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ var common = require('../common');
22
var assert = require('assert');
33
var domain = require('domain');
44

5-
try {
6-
var crypto = require('crypto');
7-
} catch (e) {
8-
console.log('Skipping test, compiled without crypto support.');
9-
return;
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
7+
process.exit();
108
}
9+
var crypto = require('crypto');
1110

1211
function test(fn) {
1312
var ex = new Error('BAM');

test/parallel/test-crypto-domains.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
var crypto = require('crypto');
1+
var common = require('../common');
22
var domain = require('domain');
33
var assert = require('assert');
44
var d = domain.create();
55
var expect = ['pbkdf2', 'randomBytes', 'pseudoRandomBytes']
66
var errors = 0;
77

8+
if (!common.hasCrypto) {
9+
console.log('1..0 # Skipped: missing crypto');
10+
process.exit();
11+
}
12+
var crypto = require('crypto');
13+
814
process.on('exit', function() {
915
assert.equal(errors, 3);
1016
});

test/parallel/test-crypto-ecb.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
crypto.DEFAULT_ENCODING = 'buffer';
1211

test/parallel/test-crypto-from-binary.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
var common = require('../common');
66
var assert = require('assert');
77

8-
try {
9-
var crypto = require('crypto');
10-
} catch (e) {
11-
console.log('Not compiled with OPENSSL support.');
8+
if (!common.hasCrypto) {
9+
console.log('1..0 # Skipped: missing crypto');
1210
process.exit();
1311
}
12+
var crypto = require('crypto');
1413

1514
var EXTERN_APEX = 0xFBEE9;
1615

test/parallel/test-crypto-hash-stream-pipe.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
6+
process.exit();
7+
}
48
var crypto = require('crypto');
9+
510
var stream = require('stream')
611
var s = new stream.PassThrough();
712
var h = crypto.createHash('sha1');

test/parallel/test-crypto-hash.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ var assert = require('assert');
33
var fs = require('fs');
44
var path = require('path');
55

6-
try {
7-
var crypto = require('crypto');
8-
} catch (e) {
9-
console.log('Not compiled with OPENSSL support.');
6+
if (!common.hasCrypto) {
7+
console.log('1..0 # Skipped: missing crypto');
108
process.exit();
119
}
10+
var crypto = require('crypto');
1211

1312
// Test hashing
1413
var a0 = crypto.createHash('sha1').update('Test123').digest('hex');

test/parallel/test-crypto-hmac.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
// Test HMAC
1211
var h1 = crypto.createHmac('sha1', 'Node')

test/parallel/test-crypto-padding-aes256.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OpenSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
crypto.DEFAULT_ENCODING = 'buffer';
1211

test/parallel/test-crypto-padding.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
crypto.DEFAULT_ENCODING = 'buffer';
1211

test/parallel/test-crypto-pbkdf2.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
//
1211
// Test PBKDF2 with RFC 6070 test vectors (except #4)

test/parallel/test-crypto-random.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
} catch (e) {
7-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
86
process.exit();
97
}
8+
var crypto = require('crypto');
109

1110
crypto.DEFAULT_ENCODING = 'buffer';
1211

test/parallel/test-crypto-rsa-dsa.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ var assert = require('assert');
33
var fs = require('fs');
44
var constants = require('constants');
55

6-
try {
7-
var crypto = require('crypto');
8-
} catch (e) {
9-
console.log('Not compiled with OPENSSL support.');
6+
if (!common.hasCrypto) {
7+
console.log('1..0 # Skipped: missing crypto');
108
process.exit();
119
}
10+
var crypto = require('crypto');
1211

1312
// Test certificates
1413
var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');

test/parallel/test-crypto-sign-verify.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ var common = require('../common');
22
var assert = require('assert');
33
var fs = require('fs');
44

5-
try {
6-
var crypto = require('crypto');
7-
} catch (e) {
8-
console.log('Not compiled with OPENSSL support.');
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
97
process.exit();
108
}
9+
var crypto = require('crypto');
1110

1211
// Test certificates
1312
var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');

test/parallel/test-crypto-stream.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ var assert = require('assert');
33
var stream = require('stream');
44
var util = require('util');
55

6-
try {
7-
var crypto = require('crypto');
8-
} catch (e) {
9-
console.log('Not compiled with OPENSSL support.');
6+
if (!common.hasCrypto) {
7+
console.log('1..0 # Skipped: missing crypto');
108
process.exit();
119
}
10+
var crypto = require('crypto');
1211

1312
// Small stream to buffer converter
1413
function Stream2buffer(callback) {

test/parallel/test-crypto-verify-failure.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
var common = require('../common');
22
var assert = require('assert');
33

4-
try {
5-
var crypto = require('crypto');
6-
var tls = require('tls');
7-
} catch (e) {
8-
console.log('Not compiled with OPENSSL support.');
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
96
process.exit();
107
}
8+
var crypto = require('crypto');
9+
var tls = require('tls');
1110

1211
crypto.DEFAULT_ENCODING = 'buffer';
1312

0 commit comments

Comments
 (0)