-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPDY parser.js tests #3
Changes from 17 commits
794505d
989f6ed
9411d7d
3508cbe
834ea09
b7dec80
7200510
fb5d99b
dd45f9a
e1b09d8
c7dd3ee
02a0208
fd0ac34
b48a23d
162b215
6df5a91
85b50da
7ffadec
09f1d0d
7eba964
154b55a
fdd5ab0
278b374
5f51e5f
b6a2209
da89650
121d696
2f97dfb
a07500d
2482b3c
e411169
edbabd7
c6fd453
b4abe62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
.vimrc | ||
npm-debug.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
var assert = require('assert'); | ||
|
||
var transport = require('../../'); | ||
var spdy = transport.protocol.spdy; | ||
|
||
describe('SPDY Parser', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is SPDYv3-only test, let's rename the file to |
||
var parser; | ||
|
||
beforeEach(function() { | ||
var pool = spdy.compressionPool.create(); | ||
parser = spdy.parser.create({}); | ||
var comp = pool.get('3.1'); | ||
parser.setCompression(comp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be a good idea to skip preface here instead of duplicating the logic in |
||
}); | ||
|
||
function pass(data, expected, done) { | ||
parser.skipPreface(); | ||
parser.write(new Buffer(data, 'hex'), function (err) { | ||
if (err) { | ||
console.log('It should not err -> ', err) | ||
} | ||
}); | ||
|
||
parser.once('data', function(frame) { | ||
// console.log('THE FRAME \n', frame) | ||
// if (frame.data) { | ||
// console.log('hey ', frame.data.toString('hex')) | ||
// } | ||
assert.deepEqual(frame, expected); | ||
assert.equal(parser.buffer.size, 0); | ||
done(); | ||
}); | ||
} | ||
|
||
function fail(data, code, re, done) { | ||
parser.skipPreface(); | ||
parser.write(new Buffer(data, 'hex'), function(err) { | ||
console.log('err - ', err) | ||
assert(err); | ||
assert(err instanceof transport.protocol.base.utils.ProtocolError); | ||
assert.equal(err.code, spdy.constants.error[code]); | ||
assert(re.test(err.message), err.message); | ||
|
||
done(); | ||
}); | ||
} | ||
|
||
describe('SYN_STREAM', function() { | ||
// [x] pass with http header | ||
// [~] pass without http header (apparently it isn't supposed to - | ||
// github.com/indutny/spdy-transport/issues/1#issuecomment-116108202 | ||
// [~] fail on stream ID 0 | ||
// [X] pass on FIN flag | ||
// [ ] pass on UNIDIRECIONAL flag | ||
|
||
it('should parse frame with http header', function(done) { | ||
var hexFrame = '800300010000002c0000000100000000000078' + | ||
'f9e3c6a7c202e50e507ab442a45a77d7105006' + | ||
'b32a4804974d8cfa00000000ffff'; | ||
|
||
pass(hexFrame, { | ||
fin: false, | ||
headers: { | ||
':method': 'GET', | ||
':path': '/' | ||
}, | ||
id: 1, | ||
path: '/', | ||
priority: { | ||
exclusive: false, | ||
parent: 0, | ||
weight: 1. | ||
}, | ||
type: 'HEADERS' // by spec 'SYN_STREAM' | ||
}, done); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
|
||
/* | ||
it('should fail on stream ID 0', function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the parser doesn't fail with stream Id 0. Probably this validation is done in another place, could you confirm @indutny ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed too, thank you! |
||
var hexFrame = '800300010000002c0000000000000000000078' + | ||
'f9e3c6a7c202e50e507ab442a45a77d7105006' + | ||
'b32a4804974d8cfa00000000ffff'; | ||
|
||
fail(hexFrame, 'FRAME_SIZE_ERROR', /ACK.*non-zero/i, done); | ||
}); | ||
*/ | ||
|
||
it('should parse frame with http header and FIN flag', function(done) { | ||
var hexFrame = '800300010100002c0000000100000000000078' + | ||
'f9e3c6a7c202e50e507ab442a45a77d7105006' + | ||
'b32a4804974d8cfa00000000ffff'; | ||
|
||
pass(hexFrame, { | ||
fin: true, | ||
headers: { | ||
':method': 'GET', | ||
':path': '/' | ||
}, | ||
id: 1, | ||
path: '/', | ||
priority: { | ||
exclusive: false, | ||
parent: 0, | ||
weight: 1. | ||
}, | ||
type: 'HEADERS' // by spec 'SYN_STREAM' | ||
}, done); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
||
it('should parse frame with http header and Unidirectional flag', function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just fixed it, thanks for reminding! |
||
var hexFrame = '800300010200002c0000000100000000000078' + | ||
'f9e3c6a7c202e50e507ab442a45a77d7105006' + | ||
'b32a4804974d8cfa00000000ffff'; | ||
|
||
pass(hexFrame, { | ||
fin: false, | ||
headers: { | ||
':method': 'GET', | ||
':path': '/' | ||
}, | ||
id: 1, | ||
path: '/', | ||
priority: { | ||
exclusive: false, | ||
parent: 0, | ||
weight: 1. | ||
}, | ||
type: 'HEADERS' // by spec 'SYN_STREAM' | ||
}, done); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing semicolon |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Superfluous newline. |
||
|
||
}); | ||
|
||
describe('SYN_REPLY', function() { | ||
// [x] pass with frame without http headers | ||
// [ ] pass with frame with http headers | ||
// [ ] pass with frame with FLAG_FIN | ||
// [ ] fail with frame with invalid flag | ||
|
||
it('should parse a frame without headers', function(done) { | ||
var hexFrame = '80030002000000140000000178f9e3c6a7c202a6230600000000ffff' | ||
|
||
pass(hexFrame, { | ||
fin: false, | ||
headers: {}, | ||
id: 1, | ||
path: undefined, | ||
priority: { | ||
exclusive: false, | ||
parent: 0, | ||
weight: 16 | ||
}, | ||
type: 'HEADERS' // by spec SYN_REPLY | ||
} , done); | ||
}) | ||
}) | ||
|
||
describe('DATA_FRAME', function() { | ||
// [x] pass with no flags | ||
// [x] pass with flag fin | ||
|
||
it('should parse frame with no flags', function(done) { | ||
var hexFrame = '000000010000001157726974696e6720746f2073747265616d' | ||
|
||
pass(hexFrame, { | ||
data: new Buffer('57726974696e6720746f2073747265616d', 'hex'), | ||
fin: false, | ||
id: 1, | ||
type: 'DATA' | ||
}, done); | ||
}) | ||
|
||
it('should parse frame with FLAG_FIN', function(done) { | ||
var hexFrame = '000000010100001157726974696e6720746f2073747265616d' | ||
|
||
pass(hexFrame, { | ||
data: new Buffer('57726974696e6720746f2073747265616d', 'hex'), | ||
fin: true, | ||
id: 1, | ||
type: 'DATA' | ||
}, done); | ||
}) | ||
|
||
}) | ||
|
||
describe('RST_STREAM', function() { | ||
// [ ] pass with frame without flags and status code PROTOCOL_ERROR | ||
// [ ] pass with frame without flags and status code INVALID_STREAM | ||
// [ ] pass with frame without flags and status code REFUSED_STREAM | ||
// [ ] pass with frame without flags and status code UNSUPPORTED_VERSION | ||
// [ ] pass with frame without flags and status code CANCEL | ||
// [ ] pass with frame without flags and status code INTERNAL_ERROR | ||
// [ ] pass with frame without flags and status code FLOW_CONTROL_ERROR | ||
// [ ] pass with frame without flags and status code STREAM_IN_USE | ||
// [ ] pass with frame without flags and status code STREAM_ALREADY_CLOSED | ||
// [ ] pass with frame without flags and status code FRAME_TOO_LARGE | ||
// [ ] fail with frame without flags and status code 0 (unvalid) | ||
// [ ] fail with frame with flags (there should be none) | ||
}) | ||
|
||
|
||
describe('SETTINGS', function() { | ||
it('should parse frame', function(done) { | ||
var hexFrame = '800300040000000c000000010100000700000100' | ||
|
||
pass(hexFrame, { | ||
settings: { | ||
initial_window_size: 256 | ||
}, | ||
type: 'SETTINGS' | ||
}, done); | ||
}) | ||
|
||
}) | ||
|
||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous change.