PageRenderTime 182ms CodeModel.GetById 124ms app.highlight 43ms RepoModel.GetById 2ms app.codeStats 0ms

/js/lib/Socket.IO-node/tests/transports.flashsocket.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 49 lines | 42 code | 6 blank | 1 comment | 2 complexity | 8d2407ebb8df4ae3ce735b46f8356ece MD5 | raw file
 1var io = require('socket.io')
 2  , net = require('net')
 3  , http = require('http')
 4  , assert = require('assert')
 5  , querystring = require('querystring')
 6  , port = 7700
 7  , encode = require('socket.io/utils').encode
 8  , decode = require('socket.io/utils').decode;
 9
10function server(callback){
11  return http.createServer(function(){});
12};
13
14function socket(server, options){
15  if (!options) options = {};
16  options.log = false;
17  if (!options.transportOptions) options.transportOptions = { 
18    'flashsocket': {
19      // disable heartbeats for tests, re-enabled in heartbeat test below
20      timeout: null 
21    }
22  };
23  return io.listen(server, options);
24};
25
26function listen(s, callback){
27  s._port = port;
28  s.listen(port, callback);
29  port++;
30  return s;
31};
32
33module.exports = {
34  
35  'test xml policy added to connection': function(){
36    var _server = server()
37      , _socket = socket(_server);
38    listen(_server, function(){
39      var conn = net.createConnection(_server._port);
40      conn.write('<policy-file-request/>\0');
41      conn.on('data', function(data){
42        assert.ok(data.toString().indexOf('<allow-access-from domain="*" to-ports="*"/>') !== -1);
43        conn.destroy();
44        _server.close();
45      });
46    });
47  }
48  
49}