diff --git a/SampleApp_Secrets.jmx b/SampleApp_Secrets.jmx new file mode 100644 index 00000000..bfef649e --- /dev/null +++ b/SampleApp_Secrets.jmx @@ -0,0 +1,176 @@ + + + + + + false + true + false + + + + + + + + + + appToken + ${__GetSecret(appToken)} + Value for x-secret header + = + + + + + + + + 10 + 0 + 180 + 240 + 10 + + + + false + -1 + + continue + + + + + + x-secret + ${appToken} + + + + + + + + + isaacnitinwus2.azurewebsites.net + + https + + lasttimestamp + GET + true + false + true + false + + HttpClient4 + 60000 + 60000 + + + + + + + 10 + 0 + 180 + 240 + 10 + + + + false + -1 + + continue + + + + + + x-secret + ${appToken} + + + + + + true + + + + false + 2 + = + + + + isaacnitinwus2.azurewebsites.net + + https + + add + POST + true + false + true + false + + HttpClient4 + 60000 + 60000 + + + + + + + 10 + 0 + 180 + 240 + 10 + + + + false + -1 + + continue + + + + + + x-secret + ${appToken} + + + + + + + + + isaacnitinwus2.azurewebsites.net + + https + + get + GET + true + false + true + false + + HttpClient4 + 60000 + 60000 + + + + + + diff --git a/config.json b/config.json new file mode 100644 index 00000000..ef7ec377 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "enableSecretsFeature": false, + "secretHeaderValue": "1797669089" +} \ No newline at end of file diff --git a/server.js b/server.js index 51384c98..1412653b 100644 --- a/server.js +++ b/server.js @@ -6,6 +6,7 @@ var fs = require('fs'); var port = process.env.PORT || 8092; var dbOperations = require('./databaseOperations.js'); var utils = require('./utils.js'); +var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); var lastTimestamp = 0; @@ -14,6 +15,15 @@ var server = http.createServer(function (req, res) { var method = req.method.toLowerCase(); if(!reqUrl || (!!reqUrl && (reqUrl == "" || reqUrl.toLowerCase() == "index.html"))){ + if(config.enableSecretsFeature) { + console.log(req.headers['x-secret']); + console.log(config.secretHeaderValue); + if(req.headers['x-secret'] != config.secretHeaderValue) { + res.writeHead(401, "Unauthorized"); + res.end(); + return; + } + } var data = fs.readFileSync('index.html'); dbOperations.queryCount(function (visitCount){