changeset 226:78c7d1c23616

Add basic auth support to mockapi Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025147.html
author Andrew Azores <aazores@redhat.com>
date Tue, 26 Sep 2017 09:49:49 -0400
parents fc747d2c2f6a
children ca1ab4a5dc73
files mock-api/401.html mock-api/mockapi.server.js package.json
diffstat 3 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mock-api/401.html	Tue Sep 26 09:49:49 2017 -0400
@@ -0,0 +1,10 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+    <title>Error 401 Unauthorized</title>
+  </head>
+  <body><h2>HTTP ERROR 401</h2>
+    <p>Problem accessing mockapi path. Reason:
+    <pre>    Unauthorized</pre></p>
+  </body>
+</html>
--- a/mock-api/mockapi.server.js	Mon Sep 25 10:31:21 2017 -0400
+++ b/mock-api/mockapi.server.js	Tue Sep 26 09:49:49 2017 -0400
@@ -1,5 +1,6 @@
 var express = require('express'),
   expressWs = require('express-ws'),
+  basicAuth = require('express-basic-auth'),
   cors = require('cors'),
   path = require('path'),
   fs = require('fs'),
@@ -11,6 +12,13 @@
 var app = express();
 expressWs(app);
 app.use(cors());
+app.use(basicAuth({
+  users: {
+    'client': 'client-pwd'
+  },
+  challenge: true,
+  unauthorizedResponse: fs.readFileSync(path.resolve(__dirname, '401.html'), 'utf8')
+}));
 
 app.set('port', port);
 app.set('host', host);
--- a/package.json	Mon Sep 25 10:31:21 2017 -0400
+++ b/package.json	Tue Sep 26 09:49:49 2017 -0400
@@ -27,7 +27,6 @@
     "es6-promise": "^4.1.0",
     "eslint": "^3.19.0",
     "eslint-plugin-mocha": "^4.9.0",
-    "express-ws": "^3.0.0",
     "extract-text-webpack-plugin": "^2.1.0",
     "file-loader": "^0.11.1",
     "font-awesome": "^4.7.0",
@@ -120,6 +119,8 @@
     "compression": "^1.6.2",
     "cors": "^2.8.3",
     "express": "^4.15.2",
+    "express-basic-auth": "^1.1.2",
+    "express-ws": "^3.0.0",
     "forever": "^0.15.3",
     "lodash": "^4.17.4"
   }