cocalc/src / smc-project / node_modules / cliff / node_modules / winston / test / transports / webhook-test.js
50675 views/*1* webhook-test.js: Tests for instances of the Webhook transport2*3* (C) 2011 Marak Squires4* MIT LICENSE5*6*/78var path = require('path'),9vows = require('vows'),10fs = require('fs'),11http = require('http'),12https = require('https'),13assert = require('assert'),14winston = require('../../lib/winston'),15helpers = require('../helpers');1617var webhookTransport = new (winston.transports.Webhook)({18"host": "localhost",19"port": 8080,20"path": "/winston-test"21});2223var httpsWebhookTransport = new (winston.transports.Webhook)({24"host": "localhost",25"port": 8081,26"path": "/winston-test",27"ssl": true28});2930var authWebhookTransport = new (winston.transports.Webhook)({31"host": "localhost",32"port": 8080,33"path": "/winston-auth-test",34"auth": {35"username": "winston",36"password": "churchill"37}38});3940var requestsAuthenticated = true;4142var server = http.createServer(function (req, res) {43if (req.url == '/winston-auth-test') {44//45// Test if request has been correctly authenticated46//47// Strip 'Basic' from Authorization header48var signature = req.headers['authorization'].substr(6);49requestsAuthenticated = requestsAuthenticated &&50new Buffer(signature, 'base64').toString('utf8') == 'winston:churchill';51}52res.end();53});5455server.listen(8080);565758var httpsServer = https.createServer({59cert: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent2-cert.pem')),60key: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent2-key.pem'))61}, function (req, res) {62res.end();63});6465httpsServer.listen(8081);6667vows.describe('winston/transports/webhook').addBatch({68"An instance of the Webhook Transport": {69"when passed valid options": {70"should have the proper methods defined": function () {71helpers.assertWebhook(webhookTransport);72},73"the log() method": helpers.testNpmLevels(webhookTransport, "should respond with true", function (ign, err, logged) {74assert.isNull(err);75assert.isTrue(logged);76})77}78},79"An https instance of the Webhook Transport": {80"when passed valid options": {81"should have the proper methods defined": function () {82helpers.assertWebhook(httpsWebhookTransport);83},84"the log() method": helpers.testNpmLevels(httpsWebhookTransport, "should respond with true", function (ign, err, logged) {85assert.isNull(err);86assert.isTrue(logged);87})88}89},90"An http Basic Auth instance of the Webhook Transport": {91"when passed valid options": {92"should have the proper methods defined": function () {93helpers.assertWebhook(authWebhookTransport);94},95"the log() method": helpers.testNpmLevels(authWebhookTransport, "should respond with true", function (ign, err, logged) {96assert.isNull(err);97assert.isTrue(logged);98})99}100}101}).addBatch({102"When the tests are over": {103topic: function () {104//105// Delay destruction of the server since the106// WebHook transport responds before the request107// has actually be completed.108//109setTimeout(this.callback, 1000);110},111"the server should cleanup": function () {112server.close();113},114"requests have been correctly authenticated": function () {115assert.ok(requestsAuthenticated);116}117}118}).addBatch({119// "An instance of the Webhook Transport": transport(winston.transports.Webhook, {120// "host": "localhost",121// "port": 8080,122// "path": "/winston-test"123// })124}).export(module);125126127