test.js 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*jshint node:true */
  2. 'use strict';
  3. var bufferEq = require('./index');
  4. var assert = require('assert');
  5. describe('buffer-equal-constant-time', function() {
  6. var a = new Buffer('asdfasdf123456');
  7. var b = new Buffer('asdfasdf123456');
  8. var c = new Buffer('asdfasdf');
  9. describe('bufferEq', function() {
  10. it('says a == b', function() {
  11. assert.strictEqual(bufferEq(a, b), true);
  12. });
  13. it('says a != c', function() {
  14. assert.strictEqual(bufferEq(a, c), false);
  15. });
  16. });
  17. describe('install/restore', function() {
  18. before(function() {
  19. bufferEq.install();
  20. });
  21. after(function() {
  22. bufferEq.restore();
  23. });
  24. it('installed an .equal method', function() {
  25. var SlowBuffer = require('buffer').SlowBuffer;
  26. assert.ok(Buffer.prototype.equal);
  27. assert.ok(SlowBuffer.prototype.equal);
  28. });
  29. it('infected existing Buffers', function() {
  30. assert.strictEqual(a.equal(b), true);
  31. assert.strictEqual(a.equal(c), false);
  32. });
  33. });
  34. });