Sending correct cookie to XOS

Change-Id: I3414488ec634f05f6ff0c5b25cedc8df720e1896
diff --git a/.dockerignore b/.dockerignore
index 93f1361..5171c54 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,2 +1,2 @@
 node_modules
-npm-debug.log
+npm-debug.log
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index a4f1d03..178414b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,5 @@
-# To build use: docker build -t xosproject/xos-nb-rest .
-# To run use: docker run -p 3000:3000 -d xosproject/xos-nb-rest
+# To build use: docker build -t xosproject/xos-rest-gw .
+# To run use: docker run -p 3000:3000 -d xosproject/xos-rest-gw
 
 FROM node:argon
 
diff --git a/spec/core_proxy.spec.js b/spec/core_proxy.spec.js
index c5bb9ad..7afa118 100644
--- a/spec/core_proxy.spec.js
+++ b/spec/core_proxy.spec.js
@@ -89,11 +89,11 @@
       .get('/api/core/')
       .set('Accept', 'application/json')
       .set('x-csrftoken', 'testToken')
-      .set('cookie', 'testCookie')
+      .set('x-sessionid', 'testSession')
       .end(function(err) {
         if (err) return done(err);
         expect(myStub.set.getCall(0)).to.have.been.calledWith('x-csrftoken', 'testToken');
-        expect(myStub.set.getCall(1)).to.have.been.calledWith('cookie', 'testCookie');
+        expect(myStub.set.getCall(1)).to.have.been.calledWith('cookie', 'xossessionid=testSession');
         done();
       });
     });
diff --git a/spec/index.html b/spec/index.html
index 4f97749..c13b92f 100644
--- a/spec/index.html
+++ b/spec/index.html
@@ -2,7 +2,7 @@
 <html>
   <head>
     <title>Socket.IO chat</title>
-    <script src="http://10.1.8.44:3000/socket.io/socket.io.js"></script>
+    <script src="http://localhost:4000/socket.io/socket.io.js"></script>
     <script
       src="https://code.jquery.com/jquery-1.12.4.min.js"
       integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
@@ -14,41 +14,41 @@
         max-width: 100%;
       }
     </style>
-<script>
-  /* global io $ alert*/
-  function enableSocket(auth) {
+    <script>
+      /* global io $ alert*/
+      function enableSocket(auth) {
 
-    auth.user = JSON.parse(auth.user);
+        auth.user = JSON.parse(auth.user);
 
-    var socket = io.connect('http://10.1.8.44:3000', {
-      query: 'name=' + auth.user.username + '&token=' + auth.xoscsrftoken + '&sessionId=' + auth.xossessionid + '&id=' + auth.user.id
-    });
-    socket.on('event', function(data) {
-      var p = $('body').append('<p></p>');
-      p.append('<b>' + data.model + '</b><br/>');
-      p.append('<i>' + JSON.stringify(data.msg.changed_fields) + '</i>');
-      p.append('<pre>' + JSON.stringify(data.msg.object) + '</pre>');
-      console.log(data.object);
-      $.notify(data.model + ': ' + JSON.stringify(data.msg.object.name) + 'updated', 'success');
-    });
-  }
-
-  function login() {
-    var username = $('#username').val();
-    var password = $('#password').val();
-
-    $.get('http://10.1.8.44:3000/api/utility/login?username='+username+'&password='+password,
-      function(res) {
-        enableSocket(res);
-        $('#login').hide();
+        var socket = io.connect('http://localhost:4000', {
+          query: 'name=' + auth.user.username + '&token=' + auth.xoscsrftoken + '&sessionId=' + auth.xossessionid + '&id=' + auth.user.id
+        });
+        socket.on('event', function(data) {
+          var p = $('body').append('<p></p>');
+          p.append('<b>' + data.model + '</b><br/>');
+          p.append('<i>' + JSON.stringify(data.msg.changed_fields) + '</i>');
+          p.append('<pre>' + JSON.stringify(data.msg.object) + '</pre>');
+          console.log(data.object);
+          $.notify(data.model + ': ' + JSON.stringify(data.msg.object.name) + 'updated', 'success');
+        });
       }
-    )
-    .fail(function(e) {
-      alert( 'error' );
-      console.log(e);
-    });
-  }
-</script>
+
+      function login() {
+        var username = $('#username').val();
+        var password = $('#password').val();
+
+        $.get('http://localhost:4000/api/utility/login?username='+username+'&password='+password,
+          function(res) {
+            enableSocket(res);
+            $('#login').hide();
+          }
+        )
+        .fail(function(e) {
+          alert( 'error' );
+          console.log(e);
+        });
+      }
+    </script>
   </head>
   <body>
     <form onsubmit="login()" id="login">
diff --git a/spec/websocket.spec.js b/spec/websocket.spec.js
index 2822223..51b9cec 100644
--- a/spec/websocket.spec.js
+++ b/spec/websocket.spec.js
@@ -7,17 +7,17 @@
   chai.use(sinonChai);
   const io = require('socket.io-client');
   const server = require('../src/server.js');
-
-  describe('basic socket.io example', function() {
+  const port = 4000;
+  describe('Websocket', function() {
 
     var client;
 
     beforeEach(function(done) {
       // Start our server
-      server.start();
+      server.start(port);
 
       // connect a client to the server
-      client = io.connect('http://localhost:3000', {
+      client = io.connect(`http://localhost:${port}`, {
         query: 'name=test@xos.org&token=testToken&sessionId=testSession&id=1'
       });
 
@@ -44,7 +44,7 @@
     it('should not store the same user twice', (done) => {
 
       // connect a client to the server
-      const client2 = io.connect('http://localhost:3000', {
+      const client2 = io.connect(`http://localhost:${port}`, {
         query: 'name=test@xos.org&token=testToken&sessionId=testSession&id=1'
       });
 
diff --git a/src/config/logger.js b/src/config/logger.js
index df49409..dfec0dc 100644
--- a/src/config/logger.js
+++ b/src/config/logger.js
@@ -4,7 +4,7 @@
   const winston = require('winston');
   const fs = require('fs');
   const path = require('path');
-  const level = process.env.LOG_LEVEL || 'warn';
+  const level = process.env.LOG_LEVEL || 'debug';
   winston.level = level;
 
   const logFile = path.join(__dirname, '../../logs/xos-nb-rest');
diff --git a/src/controllers/redis.js b/src/controllers/redis.js
index 0277cab..0bcebe3 100644
--- a/src/controllers/redis.js
+++ b/src/controllers/redis.js
@@ -25,7 +25,7 @@
   });
 
   client.on('message', function (channel, message) {
-    logger.log('debug', 'sub channel ' + channel + ': ' + message);
+    logger.log('warn', 'sub channel ' + channel + ': ' + message);
 
     let msg;
     try {
diff --git a/src/routes/core_proxy.js b/src/routes/core_proxy.js
index 0290347..6da2eef 100644
--- a/src/routes/core_proxy.js
+++ b/src/routes/core_proxy.js
@@ -8,6 +8,14 @@
 
     const proxyRequest = (req, res) => {
 
+      // debugging helper
+      if(!req.headers['x-csrftoken']){
+        logger.log('warn', `csrftoken is missing and is required for authentication`);
+      }
+      if(!req.headers['x-sessionid']){
+        logger.log('warn', `Session id is missing and is required for authentication`);
+      }
+
       const config = require('../config/config.js').xos;
       // pick the correct method from superAgent
       const makeReq = request[req.method.toLowerCase()];
@@ -24,7 +32,7 @@
       // extend with auth info
       sentReq = sentReq
         .set('x-csrftoken', req.headers['x-csrftoken'] || null)
-        .set('cookie', req.headers.cookie || null)
+        .set('cookie', `xossessionid=${req.headers['x-sessionid']}` || null)
 
       // handle response
       sentReq
diff --git a/src/server.js b/src/server.js
index da541ce..c132cab 100644
--- a/src/server.js
+++ b/src/server.js
@@ -20,15 +20,15 @@
     res.send('Hello world');
   });
 
-  const startServer = () => {
+  const startServer = (port) => {
 
     // if is running just return it
     if(app.server) {
       return app.server;
     }
 
-    const server =  app.listen(config.port, function() {
-      logger.info(`Express is listening to http://localhost:${config.port}`);
+    const server =  app.listen(port || config.port, function() {
+      logger.info(`Express is listening to http://localhost:${port || config.port}`);
 
       // once server is ready setup WebSocket
       socketIo.create(server);