Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 6f71f41

Browse files
committed
test: remove 0.10ism in Digest.update()
It turns out that updating a crypto digest barfs if you pass it a string and the encoding `base64`, but it's probably faster just to use Buffers except when you need to actually compare as base64-encoded strings anyway.
1 parent 50bbb3b commit 6f71f41

7 files changed

+18
-18
lines changed

test/publish-again-scoped.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tap.test('publish again', function (t) {
1717
// not really a tarball, but doesn't matter
1818
var bodyPath = require.resolve('../package.json')
1919
var tarball = fs.createReadStream(bodyPath)
20-
var pd = fs.readFileSync(bodyPath, 'base64')
20+
var pd = fs.readFileSync(bodyPath)
2121
var pkg = require('../package.json')
2222
var lastTime = null
2323

@@ -36,7 +36,7 @@ tap.test('publish again', function (t) {
3636
t.has(o.versions[pkg.version], pkg)
3737
t.same(o.maintainers, [ { name: 'username', email: '[email protected]' } ])
3838
var att = o._attachments[ pkg.name + '-' + pkg.version + '.tgz' ]
39-
t.same(att.data, pd)
39+
t.same(att.data, pd.toString('base64'))
4040
res.statusCode = 409
4141
res.json({reason: 'must supply latest _rev to update existing package'})
4242
})

test/publish-again.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tap.test('publish again', function (t) {
1717
// not really a tarball, but doesn't matter
1818
var bodyPath = require.resolve('../package.json')
1919
var tarball = fs.createReadStream(bodyPath)
20-
var pd = fs.readFileSync(bodyPath, 'base64')
20+
var pd = fs.readFileSync(bodyPath)
2121
var pkg = require('../package.json')
2222
var lastTime = null
2323

@@ -36,7 +36,7 @@ tap.test('publish again', function (t) {
3636
t.has(o.versions[pkg.version], pkg)
3737
t.same(o.maintainers, [ { name: 'username', email: '[email protected]' } ])
3838
var att = o._attachments[ pkg.name + '-' + pkg.version + '.tgz' ]
39-
t.same(att.data, pd)
39+
t.same(att.data, pd.toString('base64'))
4040
res.statusCode = 409
4141
res.json({reason: 'must supply latest _rev to update existing package'})
4242
})

test/publish-mixcase-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tap.test('publish mixcase name', function (t) {
1717
// not really a tarball, but doesn't matter
1818
var bodyPath = require.resolve('../package.json')
1919
var tarball = fs.createReadStream(bodyPath)
20-
var pd = fs.readFileSync(bodyPath, 'base64')
20+
var pd = fs.readFileSync(bodyPath)
2121
var pkg = require('../package.json')
2222
var lastTime = null
2323

@@ -39,7 +39,7 @@ tap.test('publish mixcase name', function (t) {
3939
t.has(o.versions[pkg.version], pkg)
4040
t.same(o.maintainers, [ { name: 'username', email: '[email protected]' } ])
4141
var att = o._attachments[ pkg.name + '-' + pkg.version + '.tgz' ]
42-
t.same(att.data, pd)
42+
t.same(att.data, pd.toString('base64'))
4343
res.statusCode = 409
4444
res.json({reason: 'must supply latest _rev to update existing package'})
4545
})

test/publish-new-mixcase-name.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var PARAMS = {
2828
}
2929

3030
test('publish-new-mixcase-name', function (t) {
31-
var pd = fs.readFileSync(BODY_PATH, 'base64')
31+
var pd = fs.readFileSync(BODY_PATH)
3232

3333
// change to mixed-case name
3434
METADATA.name = 'npm-Registry-Client'
@@ -51,9 +51,9 @@ test('publish-new-mixcase-name', function (t) {
5151
t.same(o.maintainers, o.versions[METADATA.version].maintainers)
5252

5353
var att = o._attachments[METADATA.name + '-' + METADATA.version + '.tgz']
54-
t.same(att.data, pd)
54+
t.same(att.data, pd.toString('base64'))
5555

56-
var hash = crypto.createHash('sha1').update(pd, 'base64').digest('hex')
56+
var hash = crypto.createHash('sha1').update(pd).digest('hex')
5757
t.equal(o.versions[METADATA.version].dist.shasum, hash)
5858

5959
res.statusCode = 403

test/publish-scoped-auth-token.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ tap.test('publish', function (t) {
1313
// not really a tarball, but doesn't matter
1414
var bodyPath = require.resolve('../package.json')
1515
var tarball = fs.createReadStream(bodyPath)
16-
var pd = fs.readFileSync(bodyPath, 'base64')
16+
var pd = fs.readFileSync(bodyPath)
1717
var pkg = require('../package.json')
1818
pkg.name = '@npm/npm-registry-client'
1919

@@ -34,8 +34,8 @@ tap.test('publish', function (t) {
3434
t.has(o.versions[pkg.version], pkg)
3535
t.same(o.maintainers, o.versions[pkg.version].maintainers)
3636
var att = o._attachments[ pkg.name + '-' + pkg.version + '.tgz' ]
37-
t.same(att.data, pd)
38-
var hash = crypto.createHash('sha1').update(pd, 'base64').digest('hex')
37+
t.same(att.data, pd.toString('base64'))
38+
var hash = crypto.createHash('sha1').update(pd).digest('hex')
3939
t.equal(o.versions[pkg.version].dist.shasum, hash)
4040
res.statusCode = 201
4141
res.json({ created: true })

test/publish-scoped.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tap.test('publish', function (t) {
1919
// not really a tarball, but doesn't matter
2020
var bodyPath = require.resolve('../package.json')
2121
var tarball = fs.createReadStream(bodyPath)
22-
var pd = fs.readFileSync(bodyPath, 'base64')
22+
var pd = fs.readFileSync(bodyPath)
2323
var pkg = require('../package.json')
2424
pkg.name = '@npm/npm-registry-client'
2525

@@ -41,8 +41,8 @@ tap.test('publish', function (t) {
4141
t.same(o.maintainers, [ { name: 'username', email: '[email protected]' } ])
4242
t.same(o.maintainers, o.versions[pkg.version].maintainers)
4343
var att = o._attachments[ pkg.name + '-' + pkg.version + '.tgz' ]
44-
t.same(att.data, pd)
45-
var hash = crypto.createHash('sha1').update(pd, 'base64').digest('hex')
44+
t.same(att.data, pd.toString('base64'))
45+
var hash = crypto.createHash('sha1').update(pd).digest('hex')
4646
t.equal(o.versions[pkg.version].dist.shasum, hash)
4747
res.statusCode = 201
4848
res.json({ created: true })

test/publish.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ test('publish call contract', function (t) {
164164
})
165165

166166
test('publish', function (t) {
167-
var pd = fs.readFileSync(BODY_PATH, 'base64')
167+
var pd = fs.readFileSync(BODY_PATH)
168168

169169
server.expect('/npm-registry-client', function (req, res) {
170170
t.equal(req.method, 'PUT')
@@ -184,9 +184,9 @@ test('publish', function (t) {
184184
t.same(o.maintainers, o.versions[METADATA.version].maintainers)
185185

186186
var att = o._attachments[METADATA.name + '-' + METADATA.version + '.tgz']
187-
t.same(att.data, pd)
187+
t.same(att.data, pd.toString('base64'))
188188

189-
var hash = crypto.createHash('sha1').update(pd, 'base64').digest('hex')
189+
var hash = crypto.createHash('sha1').update(pd).digest('hex')
190190
t.equal(o.versions[METADATA.version].dist.shasum, hash)
191191

192192
res.statusCode = 201

0 commit comments

Comments
 (0)