Skip to content

Commit 671fbd5

Browse files
jbergstroemShigeki Ohtsu
authored andcommitted
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 <info@bnoordhuis.nl> Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 14 additions & 10 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 4 additions & 5 deletions
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');

0 commit comments

Comments
 (0)