diff --git a/integration/mock_backend/README.md b/integration/mock_backend/README.md new file mode 100644 index 0000000..2d6bde8 --- /dev/null +++ b/integration/mock_backend/README.md @@ -0,0 +1,33 @@ +# Mock Backend + +This project will serve a simple website that returns basic HTTP parameters +as a JSON object. This is intended to be used for testing WAF behaviour. + +For example, testing that a silent redirect occurred, a header was added, +or traffic was blocked. + +## How to run + +Install dependencies with `npm i`. + +Add site keys to config.js. + +Run with `npm run start` + +## How to use + +This project is intended to fill in as a backend in a WAF workflow. This Backend +should be turned up on a server, the WAF under test should point to this server. + +Visiting the public WAF address should show pages hosted on this backend. + +The `/token/action` page hosts entry form that will asynchronously submit a +request with an 'action' token attached. + +The `/token/session` page hosts a page with session token Javascript already +installed. + +`/hello.html` is a static HTML page, intended to test JavaScript injection. + +All other pages return a synthetic JSON response. This response is intended to +be parsed by integration tests to confirm Firewall Policy behaviour. \ No newline at end of file diff --git a/integration/mock_backend/config.js b/integration/mock_backend/config.js new file mode 100644 index 0000000..003be1b --- /dev/null +++ b/integration/mock_backend/config.js @@ -0,0 +1,5 @@ +module.exports = { + port: process.env.PORT || 8080, + sessionSiteKey: 'TODO', + actionSiteKey: 'TODO', +}; \ No newline at end of file diff --git a/integration/mock_backend/index.js b/integration/mock_backend/index.js new file mode 100644 index 0000000..d19c03a --- /dev/null +++ b/integration/mock_backend/index.js @@ -0,0 +1,35 @@ +const express = require('express'); +const handlebars = require('express-handlebars'); +const path = require('path'); +const config = require('./config'); +const app = express(); + +app.engine('handlebars', handlebars.engine({defaultLayout: false})); // No default layout here +app.set('view engine', 'handlebars'); +app.set('views', path.join(__dirname, 'views')); +app.use(express.static('public')); // Serve static files from public folder + +app.get('/token/action', (req, res) => { + res.render('action', + { siteKey: config.actionSiteKey }); +}); + +app.get('/token/session', (req, res) => { + res.render('session', + { siteKey: config.sessionSiteKey }); +}); + +app.get('*', (req, res) => { + res.send({ + url: req.url, + method: req.method, + body: req.body, + headers: req.headers, + query: req.query, + params: req.params + }); +}); + +app.listen(config.port, () => { + console.log(`mock backend listening on port ${config.port}`); +}); \ No newline at end of file diff --git a/integration/mock_backend/package.json b/integration/mock_backend/package.json new file mode 100644 index 0000000..c2a3d6d --- /dev/null +++ b/integration/mock_backend/package.json @@ -0,0 +1,16 @@ +{ + "name": "mock_backend", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "run": "node index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "express": "^4.21.1", + "express-handlebars": "^8.0.1" + } +} diff --git a/integration/mock_backend/public/hello.html b/integration/mock_backend/public/hello.html new file mode 100644 index 0000000..e8af565 --- /dev/null +++ b/integration/mock_backend/public/hello.html @@ -0,0 +1,9 @@ + +
+Welcome to our website!
+ + diff --git a/integration/mock_backend/views/action.handlebars b/integration/mock_backend/views/action.handlebars new file mode 100644 index 0000000..f383ce5 --- /dev/null +++ b/integration/mock_backend/views/action.handlebars @@ -0,0 +1,36 @@ + + + + +