FlashPolicyFileServer-0.0.6/ 0000775 0000000 0000000 00000000000 13073465515 0015732 5 ustar 00root root 0000000 0000000 FlashPolicyFileServer-0.0.6/.gitignore 0000664 0000000 0000000 00000000014 13073465515 0017715 0 ustar 00root root 0000000 0000000 node_modules FlashPolicyFileServer-0.0.6/LICENSE 0000664 0000000 0000000 00000002053 13073465515 0016737 0 ustar 00root root 0000000 0000000 Copyright (c) 2011 Arnout Kazemier,3rd-Eden
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. FlashPolicyFileServer-0.0.6/Makefile 0000664 0000000 0000000 00000000207 13073465515 0017371 0 ustar 00root root 0000000 0000000 doc:
dox --title "FlashPolicyFileServer" lib/* > doc/index.html
test:
expresso -I lib $(TESTFLAGS) tests/*.test.js
.PHONY: test doc FlashPolicyFileServer-0.0.6/README.md 0000664 0000000 0000000 00000005730 13073465515 0017216 0 ustar 00root root 0000000 0000000 ## LOL, WUT?
It basically allows you to allow or disallow Flash Player sockets from accessing your site.
## Installation
```bash
npm install policyfile
```
## Usage
The server is based on the regular and know `net` and `http` server patterns. So it you can just listen
for all the events that a `net` based server emits etc. But there is one extra event, the `connect_failed`
event. This event is triggered when we are unable to listen on the supplied port number.
### createServer
Creates a new server instance and accepts 2 optional arguments:
- `options` **Object** Options to configure the server instance
- `log` **Boolean** Enable logging to STDOUT and STDERR (defaults to true)
- `origins` **Array** An Array of origins that are allowed by the server (defaults to *:*)
```js
var pf = require('policyfile').createServer();
pf.listen();
```
#### server.listen
Start listening on the server and it takes 3 optional arguments
- `port` **Number** On which port number should we listen? (defaults to 843, which is the first port number the FlashPlayer checks)
- `server` **Server** A http server, if we are unable to accept requests or run the server we can also answer the policy requests inline over the supplied HTTP server.
- `callback` **Function** A callback function that is called when listening to the server was successful.
```js
var pf = require('policyfile').createServer();
pf.listen(1337, function(){
console.log(':3 yay')
});
```
Changing port numbers can be handy if you do not want to run your server as root and have port 843 forward to a non root port number (aka a number above 1024).
```js
var pf = require('policyfile').createServer()
, http = require('http');
server = http.createServer(function(q,r){r.writeHead(200);r.end('hello world')});
server.listen(80);
pf.listen(1337, server, function(){
console.log(':3 yay')
});
```
Support for serving inline requests over a existing HTTP connection as the FlashPlayer will first check port 843, but if it's unable to get a response there it will send a policy file request over port 80, which is usually your http server.
#### server.add
Adds more origins to the policy file you can add as many arguments as you like.
```js
var pf = require('policyfile').createServer(['google.com:80']);
pf.listen();
pf.add('blog.3rd-Eden.com:80', 'blog.3rd-Eden.com:8080'); // now has 3 origins
```
#### server.remove
Removes added origins from the policy file - you can add as many arguments as you like.
```js
var pf = require('policyfile').createServer(['blog.3rd-Eden.com:80', 'blog.3rd-Eden.com:8080']);
pf.listen();
pf.remove('blog.3rd-Eden.com:8080'); // only contains the :80 version now
```
#### server.close
Shuts down the server
```js
var pf = require('policyfile').createServer();
pf.listen();
pf.close(); // OH NVM.
```
## API
http://3rd-eden.com/FlashPolicyFileServer/
## Examples
See https://github.com/3rd-Eden/FlashPolicyFileServer/tree/master/examples for examples
## Licence
MIT see LICENSE file in the repository FlashPolicyFileServer-0.0.6/examples/ 0000775 0000000 0000000 00000000000 13073465515 0017550 5 ustar 00root root 0000000 0000000 FlashPolicyFileServer-0.0.6/examples/basic.fallback.js 0000664 0000000 0000000 00000000332 13073465515 0022723 0 ustar 00root root 0000000 0000000 var http = require('http')
, fspfs = require('../');
var server = http.createServer(function(q,r){ r.writeHead(200); r.end(':3') })
, flash = fspfs.createServer();
server.listen(8080);
flash.listen(8081,server); FlashPolicyFileServer-0.0.6/examples/basic.js 0000664 0000000 0000000 00000000151 13073465515 0021164 0 ustar 00root root 0000000 0000000 var http = require('http')
, fspfs = require('../');
var flash = fspfs.createServer();
flash.listen(); FlashPolicyFileServer-0.0.6/index.js 0000664 0000000 0000000 00000017405 13073465515 0017406 0 ustar 00root root 0000000 0000000 /**
* Module dependencies and cached references.
*/
var slice = Array.prototype.slice
, EventEmitter = require('events')
, net = require('net');
/**
* The server that does the Policy File severing
*
* Options:
* - `log` false or a function that can output log information, defaults to console.log?
*
* @param {Object} options Options to customize the servers functionality.
* @param {Array} origins The origins that are allowed on this server, defaults to `*:*`.
* @api public
*/
function Server (options, origins) {
var me = this;
this.origins = origins || ['*:*'];
this.port = 843;
this.log = console.log;
// merge `this` with the options
Object.keys(options).forEach(function (key) {
me[key] && (me[key] = options[key])
});
// create the net server
this.socket = net.createServer(function createServer (socket) {
socket.on('error', function socketError () {
me.responder.call(me, socket);
});
me.responder.call(me, socket);
});
// Listen for errors as the port might be blocked because we do not have root priv.
this.socket.on('error', function serverError (err) {
// Special and common case error handling
if (err.errno == 13) {
me.log && me.log(
'Unable to listen to port `' + me.port + '` as your Node.js instance does not have root privileges. ' +
(
me.server
? 'The Flash Policy File requests will only be served inline over the supplied HTTP server. Inline serving is slower than a dedicated server instance.'
: 'No fallback server supplied, we will be unable to answer Flash Policy File requests.'
)
);
me.emit('connect_failed', err);
me.socket.removeAllListeners();
delete me.socket;
} else {
me.log && me.log('FlashPolicyFileServer received an error event:\n' + (err.message ? err.message : err));
}
});
this.socket.on('timeout', function serverTimeout () {});
this.socket.on('close', function serverClosed (err) {
err && me.log && me.log('Server closing due to an error: \n' + (err.message ? err.message : err));
if (me.server) {
// Remove the inline policy listener if we close down
// but only when the server was `online` (see listen prototype)
if (me.server['@'] && me.server.online) {
me.server.removeListener('connection', me.server['@']);
}
// not online anymore
delete me.server.online;
}
});
// Compile the initial `buffer`
this.compile();
}
/**
* Start listening for requests
*
* @param {Number} port The port number it should be listening to.
* @param {Server} server A HTTP server instance, this will be used to listen for inline requests
* @param {Function} cb The callback needs to be called once server is ready
* @api public
*/
Server.prototype.listen = function listen (port, server, cb){
var me = this
, args = slice.call(arguments, 0)
, callback;
// assign the correct vars, for flexible arguments
args.forEach(function args (arg){
var type = typeof arg;
if (type === 'number') me.port = arg;
if (type === 'function') callback = arg;
if (type === 'object') me.server = arg;
});
if (this.server) {
// no one in their right mind would ever create a `@` prototype, so Im just gonna store
// my function on the server, so I can remove it later again once the server(s) closes
this.server['@'] = function connection (socket) {
socket.once('data', function requestData (data) {
// if it's a Flash policy request, and we can write to the
if (
data
&& data[0] === 60
&& data.toString() === '\0'
&& socket
&& (socket.readyState === 'open' || socket.readyState === 'writeOnly')
){
// send the buffer
try { socket.end(me.buffer); }
catch (e) {}
}
});
};
// attach it
this.server.on('connection', this.server['@']);
}
// We add a callback method, so we can set a flag for when the server is `enabled` or `online`.
// this flag is needed because if a error occurs and the we cannot boot up the server the
// fallback functionality should not be removed during the `close` event
this.port >= 0 && this.socket.listen(this.port, function serverListening () {
me.socket.online = true;
if (callback) {
callback.call(me);
callback = undefined;
}
});
return this;
};
/**
* Responds to socket connects and writes the compile policy file.
*
* @param {net.Socket} socket The socket that needs to receive the message
* @api private
*/
Server.prototype.responder = function responder (socket){
if (socket && socket.readyState == 'open' && socket.end) {
try { socket.end(this.buffer); }
catch (e) {}
}
};
/**
* Compiles the supplied origins to a Flash Policy File format and stores it in a Node.js Buffer
* this way it can be send over the wire without any performance loss.
*
* @api private
*/
Server.prototype.compile = function compile (){
var xml = [
''
, ''
, ''
];
// add the allow access element
this.origins.forEach(function origin (origin){
var parts = origin.split(':');
xml.push('');
});
xml.push('');
// store the result in a buffer so we don't have to re-generate it all the time
this.buffer = new Buffer(xml.join(''), 'utf8');
return this;
};
/**
* Adds a new origin to the Flash Policy File.
*
* @param {Arguments} The origins that need to be added.
* @api public
*/
Server.prototype.add = function add(){
var args = slice.call(arguments, 0)
, i = args.length;
// flag duplicates
while (i--) {
if (this.origins.indexOf(args[i]) >= 0){
args[i] = null;
}
}
// Add all the arguments to the array
// but first we want to remove all `falsy` values from the args
Array.prototype.push.apply(
this.origins
, args.filter(function filter (value) {
return !!value;
})
);
this.compile();
return this;
};
/**
* Removes a origin from the Flash Policy File.
*
* @param {String} origin The origin that needs to be removed from the server
* @api public
*/
Server.prototype.remove = function remove (origin){
var position = this.origins.indexOf(origin);
// only remove and recompile if we have a match
if (position > 0) {
this.origins.splice(position, 1);
this.compile();
}
return this;
};
/**
* Closes and cleans up the server
*
* @api public
*/
Server.prototype.close = function close () {
this.socket.removeAllListeners();
try { this.socket.close(); }
catch (e) {}
return this;
};
/**
* Proxy the event listener requests to the created Net server
*/
Object.keys(EventEmitter.prototype).forEach(function proxy (key){
Server.prototype[key] = Server.prototype[key] || function () {
if (this.socket) {
this.socket[key].apply(this.socket, arguments);
}
return this;
};
});
/**
* Creates a new server instance.
*
* @param {Object} options A options object to override the default config
* @param {Array} origins The origins that should be allowed by the server
* @api public
*/
exports.createServer = function createServer (options, origins) {
origins = Array.isArray(origins)
? origins
: (Array.isArray(options) ? options : false);
options = !Array.isArray(options) && options
? options
: {};
return new Server(options, origins);
};
/**
* Provide a hook to the original server, so it can be extended if needed.
*
* @type {Net.Server}
*/
exports.Server = Server;
/**
* Module version
*
* @type {String}
*/
exports.version = '0.0.5';
FlashPolicyFileServer-0.0.6/package.json 0000664 0000000 0000000 00000001371 13073465515 0020222 0 ustar 00root root 0000000 0000000 {
"name": "policyfile",
"version": "0.0.6",
"author": "Arnout Kazemier",
"description": "Flash Socket Policy File Server. A server to respond to Flash Socket Policy requests, both inline and through a dedicated server instance.",
"keywords": [
"flash",
"socket",
"policy",
"file",
"server",
"Flash Socket Policy File Server",
"cross domain"
],
"maintainers": [
{
"name": "Arnout Kazemier",
"email": "info@3rd-Eden.com",
"web": "http://blog.3rd-Eden.com"
}
],
"license": {
"type": "MIT",
"url": "https://github.com/3rd-Eden/FlashPolicyFileServer/blob/master/LICENSE"
},
"repository": {
"type": "git",
"url": "https://github.com/3rd-Eden/FlashPolicyFileServer.git"
}
}
FlashPolicyFileServer-0.0.6/tests/ 0000775 0000000 0000000 00000000000 13073465515 0017074 5 ustar 00root root 0000000 0000000 FlashPolicyFileServer-0.0.6/tests/ssl/ 0000775 0000000 0000000 00000000000 13073465515 0017675 5 ustar 00root root 0000000 0000000 FlashPolicyFileServer-0.0.6/tests/ssl/ssl.crt 0000664 0000000 0000000 00000002315 13073465515 0021211 0 ustar 00root root 0000000 0000000 -----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIJAMUSOvlaeyQHMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQwHhcNMTAxMTE2MDkzMjQ5WhcNMTMxMTE1MDkzMjQ5WjBF
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAz+LXZOjcQCJq3+ZKUFabj71oo/ex/XsBcFqtBThjjTw9CVEVwfPQQp4X
wtPiB204vnYXwQ1/R2NdTQqCZu47l79LssL/u2a5Y9+0NEU3nQA5qdt+1FAE0c5o
exPimXOrR3GWfKz7PmZ2O0117IeCUUXPG5U8umhDe/4mDF4ZNJiKc404WthquTqg
S7rLQZHhZ6D0EnGnOkzlmxJMYPNHSOY1/6ivdNUUcC87awNEA3lgfhy25IyBK3QJ
c+aYKNTbt70Lery3bu2wWLFGtmNiGlQTS4JsxImRsECTI727ObS7/FWAQsqW+COL
0Sa5BuMFrFIpjPrEe0ih7vRRbdmXRwIDAQABo1AwTjAdBgNVHQ4EFgQUDnV4d6mD
tOnluLoCjkUHTX/n4agwHwYDVR0jBBgwFoAUDnV4d6mDtOnluLoCjkUHTX/n4agw
DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAFwV4MQfTo+qMv9JMiyno
IEiqfOz4RgtmBqRnXUffcjS2dhc7/z+FPZnM79Kej8eLHoVfxCyWRHFlzm93vEdv
wxOCrD13EDOi08OOZfxWyIlCa6Bg8cMAKqQzd2OvQOWqlRWBTThBJIhWflU33izX
Qn5GdmYqhfpc+9ZHHGhvXNydtRQkdxVK2dZNzLBvBlLlRmtoClU7xm3A+/5dddeP
AQHEPtyFlUw49VYtZ3ru6KqPms7MKvcRhYLsy9rwSfuuniMlx4d0bDR7TOkw0QQS
A0N8MGQRQpzl4mw4jLzyM5d5QtuGBh2P6hPGa0YQxtI3RPT/p6ENzzBiAKXiSfzo
xw==
-----END CERTIFICATE-----
FlashPolicyFileServer-0.0.6/tests/ssl/ssl.private.key 0000664 0000000 0000000 00000003213 13073465515 0022660 0 ustar 00root root 0000000 0000000 -----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAz+LXZOjcQCJq3+ZKUFabj71oo/ex/XsBcFqtBThjjTw9CVEV
wfPQQp4XwtPiB204vnYXwQ1/R2NdTQqCZu47l79LssL/u2a5Y9+0NEU3nQA5qdt+
1FAE0c5oexPimXOrR3GWfKz7PmZ2O0117IeCUUXPG5U8umhDe/4mDF4ZNJiKc404
WthquTqgS7rLQZHhZ6D0EnGnOkzlmxJMYPNHSOY1/6ivdNUUcC87awNEA3lgfhy2
5IyBK3QJc+aYKNTbt70Lery3bu2wWLFGtmNiGlQTS4JsxImRsECTI727ObS7/FWA
QsqW+COL0Sa5BuMFrFIpjPrEe0ih7vRRbdmXRwIDAQABAoIBAGe4+9VqZfJN+dsq
8Osyuz01uQ8OmC0sAWTIqUlQgENIyf9rCJsUBlYmwR5BT6Z69XP6QhHdpSK+TiAR
XUz0EqG9HYzcxHIBaACP7j6iRoQ8R4kbbiWKo0z3WqQGIOqFjvD/mKEuQdE5mEYw
eOUCG6BnX1WY2Yr8WKd2AA/tp0/Y4d8z04u9eodMpSTbHTzYMJb5SbBN1vo6FY7q
8zSuO0BMzXlAxUsCwHsk1GQHFr8Oh3zIR7bQGtMBouI+6Lhh7sjFYsfxJboqMTBV
IKaA216M6ggHG7MU1/jeKcMGDmEfqQLQoyWp29rMK6TklUgipME2L3UD7vTyAVzz
xbVOpZkCgYEA8CXW4sZBBrSSrLR5SB+Ubu9qNTggLowOsC/kVKB2WJ4+xooc5HQo
mFhq1v/WxPQoWIxdYsfg2odlL+JclK5Qcy6vXmRSdAQ5lK9gBDKxZSYc3NwAw2HA
zyHCTK+I0n8PBYQ+yGcrxu0WqTGnlLW+Otk4CejO34WlgHwbH9bbY5UCgYEA3ZvT
C4+OoMHXlmICSt29zUrYiL33IWsR3/MaONxTEDuvgkOSXXQOl/8Ebd6Nu+3WbsSN
bjiPC/JyL1YCVmijdvFpl4gjtgvfJifs4G+QHvO6YfsYoVANk4u6g6rUuBIOwNK4
RwYxwDc0oysp+g7tPxoSgDHReEVKJNzGBe9NGGsCgYEA4O4QP4gCEA3B9BF2J5+s
n9uPVxmiyvZUK6Iv8zP4pThTBBMIzNIf09G9AHPQ7djikU2nioY8jXKTzC3xGTHM
GJZ5m6fLsu7iH+nDvSreDSeNkTBfZqGAvoGYQ8uGE+L+ZuRfCcXYsxIOT5s6o4c3
Dle2rVFpsuKzCY00urW796ECgYBn3go75+xEwrYGQSer6WR1nTgCV29GVYXKPooy
zmmMOT1Yw80NSkEw0pFD4cTyqVYREsTrPU0mn1sPfrOXxnGfZSVFpcR/Je9QVfQ7
eW7GYxwfom335aqHVj10SxRqteP+UoWWnHujCPz94VRKZMakBddYCIGSan+G6YdS
7sdmwwKBgBc2qj0wvGXDF2kCLwSGfWoMf8CS1+5fIiUIdT1e/+7MfDdbmLMIFVjF
QKS3zVViXCbrG5SY6wS9hxoc57f6E2A8vcaX6zy2xkZlGHQCpWRtEM5R01OWJQaH
HsHMmQZGUQVoDm1oRkDhrTFK4K3ukc3rAxzeTZ96utOQN8/KJsTv
-----END RSA PRIVATE KEY-----
FlashPolicyFileServer-0.0.6/tests/unit.test.js 0000664 0000000 0000000 00000015562 13073465515 0021400 0 ustar 00root root 0000000 0000000 var fspfs = require('../')
, fs = require('fs')
, http = require('http')
, https = require('https')
, net = require('net')
, should = require('should')
, assert = require('assert');
module.exports = {
// Library version should be Semver compatible
'Library version': function(){
fspfs.version.should.match(/^\d+\.\d+\.\d+$/);
}
// Creating a server instace should not cause any problems
// either using the new Server or createServer method.
, 'Create Server instance': function(){
var server = fspfs.createServer()
, server2 = new fspfs.Server({log:false}, ['blog.3rd-Eden.com:1337']);
// server 2 options test
server2.log.should.be.false;
server2.origins.length.should.equal(1);
server2.origins[0].should.equal('blog.3rd-Eden.com:1337');
// server defaults
(typeof server.log).should.be.equal('function');
server.origins.length.should.equal(1);
server.origins[0].should.equal('*:*');
// instance checking, sanity check
assert.ok(server instanceof fspfs.Server);
assert.ok(!!server.buffer);
// more options testing
server = fspfs.createServer(['blog.3rd-Eden.com:80']);
server.origins.length.should.equal(1);
server.origins[0].should.equal('blog.3rd-Eden.com:80');
server = fspfs.createServer({log:false},['blog.3rd-Eden.com:80']);
server.log.should.be.false;
server.origins.length.should.equal(1);
server.origins[0].should.equal('blog.3rd-Eden.com:80');
}
, 'Add origin': function(){
var server = fspfs.createServer();
server.add('google.com:80', 'blog.3rd-Eden.com:1337');
server.origins.length.should.equal(3);
server.origins.indexOf('google.com:80').should.be.above(0);
// don't allow duplicates
server.add('google.com:80', 'google.com:80');
var i = server.origins.length
, count = 0;
while(i--){
if (server.origins[i] === 'google.com:80'){
count++;
}
}
count.should.equal(1);
}
, 'Remove origin': function(){
var server = fspfs.createServer();
server.add('google.com:80', 'blog.3rd-Eden.com:1337');
server.origins.length.should.equal(3);
server.remove('google.com:80');
server.origins.length.should.equal(2);
server.origins.indexOf('google.com:80').should.equal(-1);
}
, 'Buffer': function(){
var server = fspfs.createServer();
Buffer.isBuffer(server.buffer).should.be.true;
server.buffer.toString().indexOf('to-ports="*"').should.be.above(0);
server.buffer.toString().indexOf('domain="*"').should.be.above(0);
server.buffer.toString().indexOf('domain="google.com"').should.equal(-1);
// The buffers should be rebuild when new origins are added
server.add('google.com:80');
server.buffer.toString().indexOf('to-ports="80"').should.be.above(0);
server.buffer.toString().indexOf('domain="google.com"').should.be.above(0);
server.remove('google.com:80');
server.buffer.toString().indexOf('to-ports="80"').should.equal(-1);
server.buffer.toString().indexOf('domain="google.com"').should.equal(-1);
}
, 'Responder': function(){
var server = fspfs.createServer()
, calls = 0
// dummy socket to emulate a `real` socket
, dummySocket = {
readyState: 'open'
, end: function(buffer){
calls++;
Buffer.isBuffer(buffer).should.be.true;
buffer.toString().should.equal(server.buffer.toString());
}
};
server.responder(dummySocket);
calls.should.equal(1);
}
, 'Event proxy': function(){
var server = fspfs.createServer()
, calls = 0;
Object.keys(process.EventEmitter.prototype).forEach(function proxy(key){
assert.ok(!!server[key] && typeof server[key] === 'function');
});
// test if it works by calling a none default event
server.on('pew', function(){
calls++;
});
server.emit('pew');
calls.should.equal(1);
}
, 'inline response http': function(){
var port = 1335
, httpserver = http.createServer(function(q,r){r.writeHead(200);r.end(':3')})
, server = fspfs.createServer();
httpserver.listen(port, function(){
server.listen(port + 1, httpserver, function(){
var client = net.createConnection(port);
client.write('\0');
client.on('error', function(err){
assert.ok(!err, err)
});
client.on('data', function(data){
var response = data.toString();
console.log(response);
response.indexOf('to-ports="*"').should.be.above(0);
response.indexOf('domain="*"').should.be.above(0);
response.indexOf('domain="google.com"').should.equal(-1);
// clean up
client.destroy();
server.close();
httpserver.close();
});
});
});
}
, 'server response': function(){
var port = 1340
, server = fspfs.createServer();
server.listen(port, function(){
var client = net.createConnection(port);
client.write('\0');
client.on('error', function(err){
assert.ok(!err, err)
});
client.on('data', function(data){
var response = data.toString();
response.indexOf('to-ports="*"').should.be.above(0);
response.indexOf('domain="*"').should.be.above(0);
response.indexOf('domain="google.com"').should.equal(-1);
// clean up
client.destroy();
server.close();
});
});
}
, 'inline response https': function(){
var port = 1345
, ssl = {
key: fs.readFileSync(__dirname + '/ssl/ssl.private.key').toString()
, cert: fs.readFileSync(__dirname + '/ssl/ssl.crt').toString()
}
, httpserver = https.createServer(ssl, function(q,r){r.writeHead(200);r.end(':3')})
, server = fspfs.createServer();
httpserver.listen(port, function(){
server.listen(port + 1, httpserver, function(){
var client = net.createConnection(port);
client.write('\0');
client.on('error', function(err){
assert.ok(!err, err)
});
client.on('data', function(data){
var response = data.toString();
response.indexOf('to-ports="*"').should.be.above(0);
response.indexOf('domain="*"').should.be.above(0);
response.indexOf('domain="google.com"').should.equal(-1);
// clean up
client.destroy();
server.close();
httpserver.close();
});
});
});
}
, 'connect_failed': function(){
var server = fspfs.createServer();
server.on('connect_failed', function(){
assert.ok(true);
});
server.listen(function(){
assert.ok(false, 'Run this test without root access');
server.close();
});
}
};