Skip to content

Instantly share code, notes, and snippets.

@jbergstroem
Created March 3, 2015 05:25
Show Gist options
  • Save jbergstroem/eeec8cef7a37294ba580 to your computer and use it in GitHub Desktop.
Save jbergstroem/eeec8cef7a37294ba580 to your computer and use it in GitHub Desktop.
example of crypto skipping
diff --git test/common.js test/common.js
index 352f7b6..2efd987 100644
--- test/common.js
+++ test/common.js
@@ -10,6 +10,13 @@ exports.libDir = path.join(exports.testDir, '../lib');
exports.tmpDirName = 'tmp';
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
+exports.hasCrypto = true;
+try {
+ var crypto = require('crypto');
+} catch (e) {
+ exports.hasCrypto = false;
+}
+
if (process.env.TEST_THREAD_ID) {
// Distribute ports in parallel tests
if (!process.env.NODE_COMMON_PORT)
diff --git test/parallel/test-buffer.js test/parallel/test-buffer.js
index 1c2c425..509cb85 100644
--- test/parallel/test-buffer.js
+++ test/parallel/test-buffer.js
@@ -1108,16 +1108,21 @@ 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');
+if(common.hasCrypto) {
+ // Test truncation after decode
+ var crypto = require('crypto');
-assert.equal(
- crypto.createHash('sha1').update(b1).digest('hex'),
- crypto.createHash('sha1').update(b2).digest('hex')
-);
+ 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('cryptographic functions not available. skipping test');
+}
// Test Compare
var b = new Buffer(1).fill('a');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment