From ceb4ef2642b81423bae99d42a410d280c7b88d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Fri, 10 Mar 2017 04:33:27 -0300 Subject: [PATCH] Add test basic-auth --- package.json | 1 + tests/configs/modules/calendar/basic-auth.js | 42 ++++++++++++++++++++ tests/e2e/modules/calendar_spec.js | 16 ++++++++ tests/servers/basic-auth.js | 31 +++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 tests/configs/modules/calendar/basic-auth.js create mode 100644 tests/servers/basic-auth.js diff --git a/package.json b/package.json index 704f8394..66886cad 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "grunt-markdownlint": "^1.0.13", "grunt-stylelint": "latest", "grunt-yamllint": "latest", + "http-auth": "^3.1.3", "mocha": "^3.2.0", "spectron": "^3.4.1", "stylelint-config-standard": "latest", diff --git a/tests/configs/modules/calendar/basic-auth.js b/tests/configs/modules/calendar/basic-auth.js new file mode 100644 index 00000000..1b210102 --- /dev/null +++ b/tests/configs/modules/calendar/basic-auth.js @@ -0,0 +1,42 @@ +/* Magic Mirror Test config default calendar + * + * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com + * MIT Licensed. + */ + +var config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + + language: "en", + timeFormat: 12, + units: "metric", + electronOptions: { + webPreferences: { + nodeIntegration: true, + }, + }, + + modules: [ + { + module: "calendar", + position: "bottom_bar", + config: { + calendars: [ + { + maximumNumberOfDays: 10000, + url: "http://localhost:8010/tests/configs/data/calendar_test.ics", + auth: { + user: "MagicMirror", + pass: "CallMeADog", + method: "basic" + } + } + ] + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") {module.exports = config;} diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index f8535231..3b4ac736 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -1,4 +1,5 @@ const globalSetup = require("../global-setup"); +const serverBasicAuth = require("../../servers/basic-auth.js"); const app = globalSetup.app; const chai = require("chai"); const expect = chai.expect; @@ -26,4 +27,19 @@ describe("Calendar module", function () { }); }); + + describe("Basic auth", function() { + before(function() { + serverBasicAuth.listen(8010); + // Set config sample for use in test + process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/basic-auth.js"; + }); + + it("Should return TestEvents", function () { + return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + }); + }); + + + }); diff --git a/tests/servers/basic-auth.js b/tests/servers/basic-auth.js new file mode 100644 index 00000000..6077cf8c --- /dev/null +++ b/tests/servers/basic-auth.js @@ -0,0 +1,31 @@ +var http = require("http"); +var path = require("path"); +var auth = require("http-auth"); +var express = require("express") + +var basic = auth.basic({ + realm: "MagicMirror Area restricted." + }, (username, password, callback) => { + callback(username === "MagicMirror" && password === "CallMeADog"); + } +); + +this.server = express(); +this.server.use(auth.connect(basic)); + +// Set directories availables +var directories = ["/tests/configs"]; +var directory; +root_path = path.resolve(__dirname + "/../../"); +for (i in directories) { + directory = directories[i]; + this.server.use(directory, express.static(path.resolve(root_path + directory))); +} + +exports.listen = function () { + this.server.listen.apply(this.server, arguments); +}; + +exports.close = function (callback) { + this.server.close(callback); +};