Files
jsowell-charger-web/jsowell-ui/node_modules/object-hash/test/old-crypto.js
Lemon f5e6e29f00 Merge branch 'dev-zza' into dev
# Conflicts:
#	jsowell-ui/.env.development
#	jsowell-ui/.env.staging
#	jsowell-ui/bin/build-sit.bat
#	jsowell-ui/bin/build.bat
#	jsowell-ui/src/api/adapayMember/adapayMember.js
#	jsowell-ui/src/api/pile/merchant.js
#	jsowell-ui/src/router/index.js
#	jsowell-ui/src/views/financial/financeDetail.vue
#	jsowell-ui/src/views/financial/merchant.vue
#	jsowell-ui/src/views/homeIndex/homeIndex.vue
#	jsowell-ui/src/views/login.vue
#	jsowell-ui/src/views/pile/basic/detail.vue
#	jsowell-ui/src/views/pile/station/components/SiteInfo.vue
#	jsowell-ui/src/views/pile/station/detail.vue
#	jsowell-ui/src/views/pile/station/orderReport.vue
2025-06-03 14:26:37 +08:00

61 lines
1.8 KiB
JavaScript

'use strict';
var assert = require('assert');
var crypto = require('crypto');
var hash = require('../index');
var validSha1 = /^[0-9a-f]{40}$/i;
var validBase64 = /^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/==]{4})$/;
describe('hash() without crypto.getHashes', function() {
var getHashes_;
beforeEach(function() {
getHashes_ = crypto.getHashes;
delete crypto.getHashes;
});
afterEach(function() {
crypto.getHashes = getHashes_;
});
it('should work fine for SHA1', function() {
assert.ok(validSha1.test(hash(42)), 'hash some value');
assert.ok(validSha1.test(hash(NaN)), 'hash some value');
});
});
describe('hash() without Duplex streams', function() {
var createHash_;
beforeEach(function() {
createHash_ = crypto.createHash;
crypto.createHash = function(algorithm) {
var strm = createHash_(algorithm);
return {
update: strm.write.bind(strm),
digest: strm.digest.bind(strm)
};
};
});
afterEach(function() {
crypto.createHash = createHash_;
});
it('should work fine for SHA1 without .write()/.read()', function() {
assert.ok(validSha1.test(hash(42)), 'hash some value');
assert.ok(validSha1.test(hash(NaN)), 'hash some value');
});
it('should work fine for SHA1 without .write()/.read() with base64', function() {
assert.ok(validBase64.test(hash(42, {encoding: 'base64'})), 'hash some value');
assert.ok(validBase64.test(hash(NaN, {encoding: 'base64'})), 'hash some value');
});
if (typeof Buffer !== 'undefined') {
it('should work fine for SHA1 without .write()/.read() with buffer', function() {
assert.ok(Buffer.isBuffer(hash(42, {encoding: 'buffer'})), 'hash some value');
assert.ok(Buffer.isBuffer(hash(NaN, {encoding: 'buffer'})), 'hash some value');
});
}
});