Skip to content
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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
794505d
spdy-tests 1
daviddias Jun 25, 2015
989f6ed
testing
daviddias Jun 26, 2015
9411d7d
pass full frame
daviddias Jun 27, 2015
3508cbe
pull master
daviddias Jun 28, 2015
834ea09
Merge branch 'master' of github.com:indutny/spdy-transport into spdy-…
daviddias Jun 28, 2015
b7dec80
with sniffed frame
daviddias Jun 28, 2015
7200510
add SYN_STREAM frame parse to spdy + fix parser.js to write the right…
daviddias Jun 28, 2015
fb5d99b
remove non necessary line feed
daviddias Jun 28, 2015
dd45f9a
add SYN_REPLY frame parser test, add clause to return the right frame…
daviddias Jun 29, 2015
e1b09d8
change back type of SYN_STREAM and SYN_REPLY to headers, so that it c…
daviddias Jun 29, 2015
c7dd3ee
list more tests
daviddias Jun 29, 2015
02a0208
add DATA_FRAME tests
daviddias Jun 29, 2015
fd0ac34
fix codestyle
daviddias Jun 29, 2015
b48a23d
fix codestyle
daviddias Jun 29, 2015
162b215
add SETTINGS spdy parser test, also hit 200 tests mark wohoo
daviddias Jun 29, 2015
6df5a91
add SETTINGS test
daviddias Jun 29, 2015
85b50da
more SYN_STREAM tests
daviddias Jul 2, 2015
7ffadec
Merge branch 'master' of github.com:indutny/spdy-transport into spdy-…
daviddias Jul 2, 2015
09f1d0d
add option writable, following #8b4fe5dals
daviddias Jul 2, 2015
7eba964
SYN_REPLY tests
daviddias Jul 2, 2015
154b55a
RST_STREAM tests
daviddias Jul 2, 2015
fdd5ab0
ping test
daviddias Jul 2, 2015
278b374
add GOAWAY parser tests
daviddias Jul 2, 2015
5f51e5f
WINDOW_UPDATE TEST
daviddias Jul 2, 2015
b6a2209
fix codestyle
daviddias Jul 2, 2015
da89650
failing HEADERS test
daviddias Jul 2, 2015
121d696
one more ping test
daviddias Jul 2, 2015
2f97dfb
one more ping test
daviddias Jul 2, 2015
a07500d
add SYN_REPLY for context on the HEADERS frame test
daviddias Jul 5, 2015
2482b3c
remove unnecessary comment
daviddias Jul 7, 2015
e411169
add missing semicolons
daviddias Jul 7, 2015
edbabd7
remove superfluous newlines
daviddias Jul 7, 2015
c6fd453
change spdy/parser-test to spdy/v3-parser-test to respect the correct…
daviddias Jul 7, 2015
b4abe62
remove unnecessary logging and moved skipPreface up
daviddias Jul 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.vimrc
npm-debug.log
2 changes: 1 addition & 1 deletion lib/spdy-transport/protocol/spdy/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Parser.prototype.onSynHeadFrame = function onSynHeadFrame(type,

if (!isPush) {
callback(null, {
type: 'HEADERS',
type: 'HEADERS', // type === 0x01 ? 'SYN_STREAM': 'SYN_REPLY',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous change.

id: id,
priority: priorityInfo,
fin: fin,
Expand Down
217 changes: 217 additions & 0 deletions test/spdy/parser-test.js
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 v3-parser-test.js.

var parser;

beforeEach(function() {
var pool = spdy.compressionPool.create();
parser = spdy.parser.create({});
var comp = pool.get('3.1');
parser.setCompression(comp);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 pass/fail.

});

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);
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.


/*
it('should fail on stream ID 0', function(done) {
Copy link
Member Author

Choose a reason for hiding this comment

The 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 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
})
Copy link
Collaborator

Choose a reason for hiding this comment

The 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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When 0x02 = FLAG_UNIDIRECTIONAL is passed, nothing is declared on the frame parsed. Is this intended @indutny ?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon


Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
})

})

})