-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow '0' as a valid header value, for content-length
Also add test to prevent regressions on this bug Fixes #39
- Loading branch information
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2015 Joyent, Inc. All rights reserved. | ||
|
||
var crypto = require('crypto'); | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
|
||
var test = require('tap').test; | ||
var uuid = require('node-uuid'); | ||
|
||
var httpSignature = require('../lib/index'); | ||
|
||
|
||
|
||
///--- Globals | ||
|
||
var hmacKey = null; | ||
var httpOptions = null; | ||
var rsaPrivate = null; | ||
var signOptions = null; | ||
var server = null; | ||
var socket = null; | ||
|
||
|
||
|
||
///--- Tests | ||
|
||
|
||
test('setup', function(t) { | ||
rsaPrivate = fs.readFileSync(__dirname + '/rsa_private.pem', 'ascii'); | ||
t.ok(rsaPrivate); | ||
|
||
socket = '/tmp/.' + uuid(); | ||
|
||
server = http.createServer(function(req, res) { | ||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
|
||
server.listen(socket, function() { | ||
hmacKey = uuid(); | ||
httpOptions = { | ||
socketPath: socket, | ||
path: '/', | ||
method: 'HEAD', | ||
headers: { | ||
'content-length': '0', | ||
'x-foo': 'false' | ||
} | ||
}; | ||
|
||
signOptions = { | ||
key: rsaPrivate, | ||
keyId: 'unitTest', | ||
}; | ||
|
||
t.end(); | ||
}); | ||
}); | ||
|
||
|
||
|
||
test('header with 0 value', function(t) { | ||
var req = http.request(httpOptions, function(res) { | ||
t.end(); | ||
}); | ||
var opts = { | ||
keyId: 'unit', | ||
key: rsaPrivate, | ||
headers: ['date', 'request-line', 'content-length'] | ||
}; | ||
|
||
t.ok(httpSignature.sign(req, opts)); | ||
t.ok(req.getHeader('Authorization')); | ||
console.log('> ' + req.getHeader('Authorization')); | ||
req.end(); | ||
}); | ||
|
||
test('header with boolean-mungable value', function(t) { | ||
var req = http.request(httpOptions, function(res) { | ||
t.end(); | ||
}); | ||
var opts = { | ||
keyId: 'unit', | ||
key: rsaPrivate, | ||
headers: ['date', 'x-foo'] | ||
}; | ||
|
||
t.ok(httpSignature.sign(req, opts)); | ||
t.ok(req.getHeader('Authorization')); | ||
console.log('> ' + req.getHeader('Authorization')); | ||
req.end(); | ||
}); | ||
|
||
test('tear down', function(t) { | ||
server.on('close', function() { | ||
t.end(); | ||
}); | ||
server.close(); | ||
}); |