Skip to content

Commit

Permalink
test: server test
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jul 13, 2015
1 parent 0f687a7 commit ca39881
Show file tree
Hide file tree
Showing 10 changed files with 361 additions and 56 deletions.
45 changes: 45 additions & 0 deletions .jscsrc
@@ -0,0 +1,45 @@
{
"disallowKeywordsOnNewLine": [ "else" ],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineStrings": true,
"disallowMultipleVarDecl": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpacesInCallExpression": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,

"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterKeywords": [ "if", "for", "while", "else", "try", "catch" ],
"requireSpaceAfterLineComment": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeKeywords": [ "else", "catch" ],
"requireSpaceBeforeObjectValues": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInConditionalExpression": true,
"requireSpacesInForStatement": true,
"requireSpacesInsideArrayBrackets": "all",
"requireSpacesInsideObjectBrackets": "all",
"requireDotNotation": true,

"maximumLineLength": 80,
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateParameterSeparator": ", ",
"validateQuoteMarks": "'"
}
89 changes: 89 additions & 0 deletions .jshintrc
@@ -0,0 +1,89 @@
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details

"maxerr" : 50, // {int} Maximum error before stopping

// Enforcing
"bitwise" : false, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : false, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent" : 2, // {int} Number of spaces to use for indentation
"latedef" : true, // true: Require variables/functions to be defined before being used
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : false, // true: Prohibit use of empty blocks
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : false, // true: Prohibit use of `++` & `--`
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // true: Require all defined variables be used
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : 4, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line

// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : false, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
"notypeof" : false, // true: Tolerate invalid typeof operator values
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"shadow" : true, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

// Environments
"browser" : true, // Web Browser (window, document, etc)
"browserify" : true, // Browserify (node.js code in the browser)
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jasmine" : false, // Jasmine
"jquery" : false, // jQuery
"mocha" : true, // Mocha
"mootools" : false, // MooTools
"node" : true, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"prototypejs" : false, // Prototype and Scriptaculous
"qunit" : false, // QUnit
"rhino" : false, // Rhino
"shelljs" : false, // ShellJS
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface

// Custom Globals
"globals" : {
"module": true
} // additional predefined global variables
}
2 changes: 2 additions & 0 deletions lib/spdy.js
@@ -1,3 +1,5 @@
'use strict';

var spdy = exports;

// Export tools
Expand Down
7 changes: 4 additions & 3 deletions lib/spdy/agent.js
@@ -1,3 +1,5 @@
'use strict';

var assert = require('assert');
var http = require('http');
var https = require('https');
Expand Down Expand Up @@ -29,7 +31,7 @@ function instantiate(base) {
return Agent;
}

proto._init = function _init(base, options, handler) {
proto._init = function _init(base, options) {
base.call(this, options);

var state = {};
Expand Down Expand Up @@ -86,7 +88,7 @@ proto._connect = function _connect(options, callback) {

var socket = this.createConnection(util._extend({
NPNProtocols: protocols,
ALPNProtocols: protocols,
ALPNProtocols: protocols
}, options));
state.socket = socket;

Expand All @@ -95,7 +97,6 @@ proto._connect = function _connect(options, callback) {
}
socket.on('error', onError);

var self = this;
socket.on(state.secure ? 'secureConnect' : 'connect', function() {
socket.removeListener('error', onError);

Expand Down
5 changes: 3 additions & 2 deletions lib/spdy/handle.js
@@ -1,3 +1,5 @@
'use strict';

var thing = require('handle-thing');
var httpDeceiver = require('http-deceiver');
var util = require('util');
Expand Down Expand Up @@ -92,7 +94,7 @@ Handle.prototype.assignClientRequest = function assignClientRequest(req) {
stream.sendHeaders(headers);
});
} else {
stream.sendHeaders(headers);
state.stream.sendHeaders(headers);
}

req._send = oldSend;
Expand All @@ -113,7 +115,6 @@ Handle.prototype.emitRequest = function emitRequest() {

Handle.prototype.emitResponse = function emitResponse(status, headers) {
var state = this._spdyState;
var stream = state.stream;

state.deceiver.emitResponse({
status: status,
Expand Down
4 changes: 3 additions & 1 deletion lib/spdy/response.js
@@ -1,3 +1,5 @@
'use strict';

// NOTE: Mostly copy paste from node
exports.writeHead = function writeHead(statusCode, reason, obj) {
var headers;
Expand Down Expand Up @@ -73,5 +75,5 @@ exports.push = function push(path, headers, callback) {
};

var stream = this.socket._handle._spdyState.stream;
stream.pushPromise(frame, callback);
return stream.pushPromise(frame, callback);
};
4 changes: 3 additions & 1 deletion lib/spdy/server.js
@@ -1,3 +1,5 @@
'use strict';

var assert = require('assert');
var https = require('https');
var net = require('net');
Expand Down Expand Up @@ -99,7 +101,7 @@ proto._onConnection = function _onConnection(socket) {
else if (protocol === 'spdy/2')
connection.start(2);

connection.on('error', function(err) {
connection.on('error', function() {
socket.destroy();
});

Expand Down
10 changes: 6 additions & 4 deletions package.json
Expand Up @@ -27,14 +27,16 @@
"dependencies": {
"debug": "^2.2.0",
"handle-thing": "^1.2.0",
"http-deceiver": "^1.1.0",
"spdy-transport": "^1.0.0-rc5"
"http-deceiver": "^1.2.0",
"spdy-transport": "^1.0.0-rc6"
},
"devDependencies": {
"mocha": "1.3.x"
"jscs": "^1.13.1",
"jshint": "^2.8.0",
"mocha": "^2.2.x"
},
"scripts": {
"test": "mocha --ui tdd --growl --reporter spec test/unit/*-test.js"
"test": "jscs lib/**/*.js test/*.js && jshint lib/**/*.js && mocha --reporter=spec test/*-test.js"
},
"engines": [
"node >= 0.7.0"
Expand Down
107 changes: 63 additions & 44 deletions test/fixtures.js
@@ -1,46 +1,65 @@
'use strict';

var assert = require('assert');

exports.port = 23433;

exports.keys = {
key: "-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIEogIBAAKCAQEA1ARXSoyizYSnHDYickxX4x2UG/8uNWnQWKlWR97NAwRsspN6\n" +
"aFF1+LnyN9bvLNnhxIowcYy68+LpZ7pYAQgBZSyAhnF1S4qz2w/rxH4CNn96B/je\n" +
"vQGo3e8vIQ8ChhfuYvGAtTEYJzW8aRoxWSPcukZZdxPQ1Wgbhd9DSXhgkUnkEEET\n" +
"owyn8ufQFRnQHfc9Fn5DrJilI7vD+ZyRU3gZoBj2GVMQuxJLqQEHy2XsJ6ZWTea/\n" +
"EfK93XfDyY7ZxyeK0ZdWCVoTqw9QNJSkGjesCBkcY4Rjxi9LbLJwW3Es4wgW4N4Y\n" +
"cltfygjltSis+RVKJyGeDqTWAxceih3mlkdGIQIDAQABAoIBAB6akc8dBdMMtuKH\n" +
"nelJw9XwyxRPfWgQYhaqOt4c9xLcbKRKTX0JZTIGBUSyLcwXl1M7b0q0ubfCpVZn\n" +
"u5RKh4kHJ3ZAomHJH7UbUzkFx2P+eqrz7ZLyzmFayT7IX+DjS3HU0nNVJttiElRJ\n" +
"h54KYy4wQXHC1n43jOGCHMBaM/ZEpO3xA7PLfVD/B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yi\n' +
'zYSnHDYickxX4x2UG/8uNWnQWKlWR97NAwRsspN6aFF1+LnyN9bvLNnhxIowcYy6\n' +
'8+LpZ7pYAQgBZSyAhnF1S4qz2w/rxH4CNn96B/jevQGo3e8vIQ8ChhfuYvGAtTEY\n' +
'JzW8aRoxWSPcukZZdxPQ1Wgbhd9DSXhgkUnkEEETowyn8ufQFRnQHfc9Fn5DrJil\n' +
'I7vD+ZyRU3gZoBj2GVMQuxJLqQEHy2XsJ6ZWTea/EfK93XfDyY7ZxyeK0ZdWCVoT\n' +
'qw9QNJSkGjesCBkcY4Rjxi9LbLJwW3Es4wgW4N4YcltfygjltSis+RVKJyGeDqTW\n' +
'Axceih3mlkdGIQIDAQABoxowGDAWBgNVHREEDzANggsqLm5vZGUuc3BkeTALBgkq\n' +
'hkiG9w0BAQsDggEBALn2FQSDMsyu+oqUnJgTVdGpnzKmfXoBPlQuznRdibri8ABO\n' +
'kOo8FC72Iy6leVSsB26KtAdhpURZ3mv1Oyt4cGeeyQln2Olzp5flIos+GqYSztAq\n' +
'5ZnrzTLLlip7KHkmastYRXhEwTLmo2JCU8RkRP1X/m1xONF/YkURxmqj6cQTahPY\n' +
'FzzLP1clW3arJwPlUcKKby6WpxO5MihYEliheBr7fL2TDUA96eG+B/SKxvwaGF2v\n' +
'gWF8rg5prjPaLW8HH3Efq59AimFqUVQ4HtcJApjLJDYUKlvsMNMvBqh/pQRRPafj\n' +
'0Cp8dyS45sbZ2RgXdyfl6gNEj+DiPbaFliIuFmM=\n' +
'-----END CERTIFICATE-----'
};

function expectData(stream, expected, callback) {
var actual = '';

stream.on('data', function(chunk) {
actual += chunk;
});
stream.on('end', function() {
assert.equal(actual, expected);
callback();
});
}
exports.expectData = expectData;

0 comments on commit ca39881

Please sign in to comment.