Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Added happy path cases for server #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ module.exports = function(grunt) {
mochaTest: {
options: {
reporter: 'dot',
timeout: 2000
timeout: 8000
},
client: {
src: ['./lib/client/index.js']
src: ['./lib/client/**/*.spec.js']
},
server: {
src: ['./lib/server/index.js']
Expand Down
115 changes: 115 additions & 0 deletions lib/client/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Copyright © Microsoft Open Technologies, Inc.
All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache 2 License for the specific language governing permissions and limitations under the License.
*/

/*
The MIT License

Copyright (C) 2013 Gábor Molnár <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/


var glob = require('glob').sync,
expect = require('chai').expect,
bunyan = require('bunyan'),
path = require('path'),
tls = require('tls'),
fs = require('fs'),
http2Protocol = require('http2-protocol'),
net = require('net'),
portfinder = require('portfinder');

var Browser = require('./browser');

var implementedVersion = 'HTTP-draft-07/2.0';

describe('HTTP/2 client', function() {


var tests = glob(__dirname + '/tests/**/*-test.js'),
port = 80,
testServer, log, browser;

function createLogger(name) {
return bunyan.createLogger({
name: name,
streams: [{
level: 'debug',
path: __dirname + '/../../test.log'
}],
serializers: http2Protocol.serializers,
level: 'info'
});
}

log = createLogger('test');
beforeEach(function() {
// Load the TCP Library


// Keep track of the chat clients
var clients = [];

// Start a TCP Server
testServer = net.createServer();

portfinder.getPort(function (err, newPort) {
port = newPort;
testServer.listen(port);
});

browser = new Browser(process.env.HTTP2_BROWSER);
});


tests.forEach(function(file) {
it(file, function(done) {

testServer.on('listening', function() {
browser.start('http://localhost:' + port);
});

testServer.on('connection', function(socket) {
testServer.close();
var startTest = require(file);
startTest(socket, log, function(error) {
done(error);
socket.destroy();
});
});

});
});

afterEach(function() {
browser.stop();
});

});
60 changes: 60 additions & 0 deletions lib/client/success_cases/goaway-unknown-error-code.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
describe('HTTP/2 client', function () {

var http2 = require('http2-protocol');
var testBootstrapper = require('../testBootstrapper');
var tlsSocket;

var testFunc = function (socket, log, callback, frame) {
tlsSocket = socket;
var endpoint = new http2.Endpoint(log, 'SERVER', {});
socket.pipe(endpoint).pipe(socket);
var commonError;

endpoint.on('stream', function (stream) {
frame = frame || {
type : 'GOAWAY',
flags : {},
last_stream : 1,
error : 'NO_ERROR'
};

frame.stream = 0;

testBootstrapper.withMethodSubstitution(Object.getPrototypeOf(endpoint._serializer).constructor, 'GOAWAY',
function (frame, buffers) {
var buffer = new Buffer(8);
var last_stream = frame.last_stream;
buffer.writeUInt32BE(last_stream, 0);
buffer.writeUInt32BE(30, 4);
buffers.push(buffer);
},
function () {
endpoint._compressor.write(frame);
}
);

setTimeout(function () {
// If there are no exception until this, then we're done
if (commonError === undefined) {
console.error('Sent without errors');
callback();
} else {
console.error(commonError);
callback(commonError);
}
}, 2000);
});

endpoint._connection.on('peerError', function (error) {
commonError = error;
});

};

it(__filename, function (done) {
testBootstrapper(testFunc, function (error) {
done(error);
});
});

});
58 changes: 58 additions & 0 deletions lib/client/success_cases/goaway-without-error-code.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
describe('HTTP/2 client', function () {

var http2 = require('http2-protocol');
var testBootstrapper = require('../testBootstrapper');
var tlsSocket;

var testFunc = function (socket, log, callback, frame) {
tlsSocket = socket;
var endpoint = new http2.Endpoint(log, 'SERVER', {});
socket.pipe(endpoint).pipe(socket);
var commonError;

endpoint.on('stream', function (stream) {
frame = frame || {
type : 'GOAWAY',
flags : {},
last_stream : 1
};

frame.stream = 0;

testBootstrapper.withMethodSubstitution(Object.getPrototypeOf(endpoint._serializer).constructor, 'GOAWAY',
function (frame, buffers) {
var buffer = new Buffer(8);
var last_stream = frame.last_stream;
buffer.writeUInt32BE(last_stream, 0);
buffers.push(buffer);
},
function () {
endpoint._compressor.write(frame);
}
);


setTimeout(function () {
// If there are no exception until this, then we're done
if (commonError === undefined) {
callback();
} else {
console.error(commonError);
callback(commonError);
}
}, 2000);
});

endpoint._connection.on('peerError', function (error) {
commonError = error;
});

};

it(__filename, function (done) {
testBootstrapper(testFunc, function (error) {
done(error);
});
});

});
57 changes: 57 additions & 0 deletions lib/client/success_cases/goaway-without-last-stream.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
describe('HTTP/2 client', function () {

var http2 = require('http2-protocol');
var testBootstrapper = require('../testBootstrapper');
var tlsSocket;

var testFunc = function (socket, log, callback, frame) {
tlsSocket = socket;
var endpoint = new http2.Endpoint(log, 'SERVER', {});
socket.pipe(endpoint).pipe(socket);
var commonError;

endpoint.on('stream', function (stream) {
frame = frame || {
type : 'GOAWAY',
flags : {},
error : 'NO_ERROR'
};

frame.stream = 0;

testBootstrapper.withMethodSubstitution(Object.getPrototypeOf(endpoint._serializer).constructor, 'GOAWAY',
function (frame, buffers) {
var buffer = new Buffer(8);
buffer.writeUInt32BE(0, 0);
buffer.writeUInt32BE(1, 4);
buffers.push(buffer);
},
function () {
endpoint._compressor.write(frame);
}
);

setTimeout(function () {
// If there are no exception until this, then we're done
if (commonError === undefined) {
callback();
} else {
console.error(commonError);
callback(commonError);
}
}, 2000);
});

endpoint._connection.on('peerError', function (error) {
commonError = error;
});

};

it(__filename, function (done) {
testBootstrapper(testFunc, function (error) {
done(error);
});
});

});
62 changes: 62 additions & 0 deletions lib/client/success_cases/invalid-settings-id.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
describe('HTTP/2 client', function () {

var http2 = require('http2-protocol');
var testBootstrapper = require('../testBootstrapper');
var tlsSocket;

var testFunc = function (socket, log, callback, frame) {
tlsSocket = socket;
var endpoint = new http2.Endpoint(log, 'SERVER', {});
socket.pipe(endpoint).pipe(socket);
var commonError;

testBootstrapper.withMethodSubstitution(Object.getPrototypeOf(endpoint._serializer).constructor, 'SETTINGS',
function (frame, buffers) {
var buffer = new Buffer(1 * 8);
for (var i = 0; i < 1; i++) {
//Write settings with undefined ID 13
buffer.writeUInt32BE(13 & 0xffffff, i * 8);
buffer.writeUInt32BE(13, i * 8 + 4);
}

buffers.push(buffer);
},
function (stream) {
frame = {
type : 'SETTINGS',
flags : {},
settings : {
SETTINGS_MAX_CONCURRENT_STREAMS : 100
}
};

frame.stream = 0;

endpoint._compressor.write(frame);

setTimeout(function () {
// If there are no exception until this, then we're done
if (commonError === undefined) {
console.error('Sent without errors');
callback();
} else {
console.error(commonError);
callback(commonError);
}
}, 2000);
}
);

endpoint._connection.on('peerError', function (error) {
commonError = error;
});

};

it(__filename, function (done) {
testBootstrapper(testFunc, function (error) {
done(error);
});
});

});
Loading