All files / src/middleware pollingBypassAuthorisation.coffee

70.59% Statements 12/17
100% Branches 0/0
0% Functions 0/3
70.59% Lines 12/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291x 1x 1x   1x 1x 1x 1x 1x   1x 1x   1x                 1x            
Q = require "q"
Channel = require("../model/channels").Channel
logger = require "winston"
 
config = require '../config/config'
statsdServer = config.get 'statsd'
application = config.get 'application'
SDC = require 'statsd-client'
os = require 'os'
 
domain = "#{os.hostname()}.#{application.name}.appMetrics"
sdc = new SDC statsdServer
 
exports.authoriseUser = (ctx, done) ->
 
  Channel.findOne { _id: ctx.request.header['channel-id'] }, (err, channel) ->
    ctx.authorisedChannel = channel
    done null, channel
 
###
# Koa middleware for bypassing authorisation for polling
###
exports.koaMiddleware = (next) ->
  startTime = new Date() if statsdServer.enabled
  authoriseUser = Q.denodeify exports.authoriseUser
  yield authoriseUser this
  sdc.timing "#{domain}.pollingBypassAuthorisationMiddleware", startTime if statsdServer.enabled
  yield next