diff options
author | TamasBakai <tamas.bakai@est.tech> | 2019-02-15 08:38:16 +0000 |
---|---|---|
committer | Tamas Bakai <tamas.bakai@est.tech> | 2019-02-15 09:47:28 +0000 |
commit | 9b780338eb8b85fc713f272a7cae865f1265f109 (patch) | |
tree | 864c1ba60eff8625f1f5c79567da0914e5e8ed65 /test/mocks/datafilecollector-testharness | |
parent | 01c69ab28550d775239697067588e3b2063188a1 (diff) |
Simulator scripts for datafile-collector
Change-Id: Idff5fb9e4406f42208367860b3d02fc2ed4a9bad
Issue-ID: DCAEGEN2-1225
Signed-off-by: TamasBakai <tamas.bakai@est.tech>
Diffstat (limited to 'test/mocks/datafilecollector-testharness')
20 files changed, 1135 insertions, 0 deletions
diff --git a/test/mocks/datafilecollector-testharness/dr-sim/.gitignore b/test/mocks/datafilecollector-testharness/dr-sim/.gitignore new file mode 100644 index 000000000..40b878db5 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/.gitignore @@ -0,0 +1 @@ +node_modules/
\ No newline at end of file diff --git a/test/mocks/datafilecollector-testharness/dr-sim/README.md b/test/mocks/datafilecollector-testharness/dr-sim/README.md new file mode 100644 index 000000000..38ad1c522 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/README.md @@ -0,0 +1,7 @@ +1. install nodejs +2. install npm +Make sure that you run these commands in the application directory "dr-sim" +3. `npm install express` +4. `npm install argparse` +5. `node dmaapDR.js` #keep it in the foreground +6. `node dmaapDR_redir.js` #keep it in the foreground diff --git a/test/mocks/datafilecollector-testharness/dr-sim/cert/certificate.crt b/test/mocks/datafilecollector-testharness/dr-sim/cert/certificate.crt new file mode 100644 index 000000000..df5a9acdb --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/cert/certificate.crt @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDijCCAnICCQDwhiz1dOajRzANBgkqhkiG9w0BAQUFADCBhjELMAkGA1UEBhMC +U0UxEjAQBgNVBAgMCXN0b2NraG9sbTESMBAGA1UEBwwJc3RvY2tob2xtMQwwCgYD +VQQKDANlc3QxCzAJBgNVBAsMAnJkMQswCQYDVQQDDAJyZDEnMCUGCSqGSIb3DQEJ +ARYYbWFydGluLnlhbi5zZXVAZ21haWwuY29tMB4XDTE4MDkyNjA5MjQyOVoXDTE4 +MTAyNjA5MjQyOVowgYYxCzAJBgNVBAYTAlNFMRIwEAYDVQQIDAlzdG9ja2hvbG0x +EjAQBgNVBAcMCXN0b2NraG9sbTEMMAoGA1UECgwDZXN0MQswCQYDVQQLDAJyZDEL +MAkGA1UEAwwCcmQxJzAlBgkqhkiG9w0BCQEWGG1hcnRpbi55YW4uc2V1QGdtYWls +LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANk/J7FGpQw/NCXx +ZTqCstNOZrpA4jvHPHFpxzsWRPVdugEaZpshmQB0Riwk0uSWCW0XnNWu1sYnMnhp +OeF2Npk/uTwndm5kMWxTul6h0bklw5k9Icbf4mFJssLouyeTWQxgFjpn6vSD4INC +c8/vJKEmoFQHbuV4Ei4dUmhITKdXg6hWqD7jQCF2tHNQK0wceCahzvdYOBq5S9LF +wLlf1FSmlTDdJjQptp18ZxBqRByePcbPk/6QW+su9tRQKXBAYxs33yUhlDDcU7hn +BqIVH/u2CEcSyhs8IJ872HrMonOHhJq9cMfr3Knc2tsESSJykBqSF4blkQq1xIkN +cjcQaDMCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAQjoyXaSmu+eWC+AhPz63Ikwn +QsOEET602iwO6zERe3O1cr2ZtxSzWO5LOmHCEQTZvDc3K+rtbqzruzdSE47l6vWb +E6h1R2+SORs9fUuRN+HYTonpxSnNLcz2p1+874BKrnBofJBK+EUFbhV589Iar0Lz +bkFDzmfWEgrr+Io7gW9bLW5q3yX7dAU7W7Dd4sYe+Afu1LlQPg3fLZO6lA09r5kc +nu+Nu4qFhgY5pOUvtO8Yu3B+MnNk8m8xbba5oADgKtGCH0wZlM9P4Gb50v+L7Je1 +zFqVtvBTHoKXjrEQynyZXJVxtkr7eX/sZRoCVSuhiouL5MGyn6RTrDbBwzulpw== +-----END CERTIFICATE----- diff --git a/test/mocks/datafilecollector-testharness/dr-sim/cert/mydomain.csr b/test/mocks/datafilecollector-testharness/dr-sim/cert/mydomain.csr new file mode 100644 index 000000000..da609a6f3 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/cert/mydomain.csr @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIIC4zCCAcsCAQAwgYYxCzAJBgNVBAYTAlNFMRIwEAYDVQQIDAlzdG9ja2hvbG0x +EjAQBgNVBAcMCXN0b2NraG9sbTEMMAoGA1UECgwDZXN0MQswCQYDVQQLDAJyZDEL +MAkGA1UEAwwCcmQxJzAlBgkqhkiG9w0BCQEWGG1hcnRpbi55YW4uc2V1QGdtYWls +LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANk/J7FGpQw/NCXx +ZTqCstNOZrpA4jvHPHFpxzsWRPVdugEaZpshmQB0Riwk0uSWCW0XnNWu1sYnMnhp +OeF2Npk/uTwndm5kMWxTul6h0bklw5k9Icbf4mFJssLouyeTWQxgFjpn6vSD4INC +c8/vJKEmoFQHbuV4Ei4dUmhITKdXg6hWqD7jQCF2tHNQK0wceCahzvdYOBq5S9LF +wLlf1FSmlTDdJjQptp18ZxBqRByePcbPk/6QW+su9tRQKXBAYxs33yUhlDDcU7hn +BqIVH/u2CEcSyhs8IJ872HrMonOHhJq9cMfr3Knc2tsESSJykBqSF4blkQq1xIkN +cjcQaDMCAwEAAaAXMBUGCSqGSIb3DQEJBzEIDAZzZWNyZXQwDQYJKoZIhvcNAQEL +BQADggEBAHFdQI+uj5nPOLVtzpedYuPMe/z6xwKTFNBGtaBO45aQvIaBvBkSAe55 +AoNjHcuNIPpTWWk7VSz3P03gVIW8RQNkuqJ+G5XyxJPtZRyjZxF5tFXM9Qnia+oI +MnPqpXLw4A5h5oR2MePAj8GaQxanD8KhoaRvPvcP4pR0uk8UpfTn8mTF2WNkErBb +yDdfC5+Dm5S6NpPZFWcIAqQ73dtYN4BkSvfSrkTRAhIU0gFHeOJfp0Y25qHWfgZc +wsU3OpbqzVHqjbsEWo4AC06U8H8kSjf4Z0e8ry6mabgEF/ukODcbZQpG77pbwgZ3 +tKkgxuGf8ylgr672GliitonkTusB2QY= +-----END CERTIFICATE REQUEST----- diff --git a/test/mocks/datafilecollector-testharness/dr-sim/cert/private.key b/test/mocks/datafilecollector-testharness/dr-sim/cert/private.key new file mode 100644 index 000000000..c9fc39e06 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/cert/private.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDZPyexRqUMPzQl +8WU6grLTTma6QOI7xzxxacc7FkT1XboBGmabIZkAdEYsJNLklgltF5zVrtbGJzJ4 +aTnhdjaZP7k8J3ZuZDFsU7peodG5JcOZPSHG3+JhSbLC6Lsnk1kMYBY6Z+r0g+CD +QnPP7yShJqBUB27leBIuHVJoSEynV4OoVqg+40AhdrRzUCtMHHgmoc73WDgauUvS +xcC5X9RUppUw3SY0KbadfGcQakQcnj3Gz5P+kFvrLvbUUClwQGMbN98lIZQw3FO4 +ZwaiFR/7tghHEsobPCCfO9h6zKJzh4SavXDH69yp3NrbBEkicpAakheG5ZEKtcSJ +DXI3EGgzAgMBAAECggEBAKmojan/XrPyxBoBrCmGmns1FjrMoyFGFikID8RQPuhU +Gwfzg0ARe/iD1a1x0JUdqxzcPOoP0cEMKXkpzD8MX9VMk6+rrezGKGbN+JUg0LVE +Db4lpLQ4cgXCVW2r7UUZ6IgmnhVcxHvSZcp8Yg94VmXX0YvuBigEnkYPNiUkmWBx +IhO3dBUOpraOcUK1ChaEseL8I7rWWBxp8g71TS4Q+KqK9bELiSltwWpuKOpWPZL3 +496mVX57a/tMdsY2rzNp+aeC2T6nBcTOdQ9yodh9HWvc79QIw47vCGYqiHgXg706 +Qe4412kmcc2joB7bncOrOvDNERm3dsZHGwWHFn0qEMECgYEA+Gl+nN2wDKdQJ/89 +SnTEiBnRpv9qs/90dfZkPzOKSqchKTHPXB2TRft+gDZNrrVhzczZlXbC5FZ3pWI1 +U3zM6DtziikQH9udNf9E7ou9A+d8+KEw7EmuBim6L6mzwpCCmGURWPj5BmeK2vVV +j+jOQGgBXnduadYXzI+dVyJPLZMCgYEA3+H08PE8GwRccIb9QFQuULKQgkl/aRKc +Qq6Fpg87/0YdW2j99mZc2CkHbv66viRwYKNVLxHE6+98z6JYbnjaztfC7XvVkfHg +6CTN/xUYCpZt7qp3TdEP3B6wieWuDP6srJVp9dX4zzS+PbANzkL0kCQq3ZcNjS9G +kyD3j5upfuECgYBhRAVUbKUrPzPuhU09Yx004U8q4WWpVwQF0FUOPiMO+gPM+njj +65yn0UKF9z1RhCnoiCZGFLtY5tZwRlT0/K/K2sRxu4RZxQb4hpw5/zMiXTicrZjX +XD4soZgKY5tEOos4GpLBULNJI6/F7jvzXkesBk1K7N6pyC+HZFBKNt/jywKBgQC2 +J5gs+XmX2cKEY7BlyJguXDqrZrVdfiDZODnRVI/SMO/t0czfz4U28przuhmiXu94 +ESxbsa9w71ezcDlXGMmehXo50wl/RzdgaaGZK0Z2RtKG3vdWvwSSaf3lFJS6SfOg +L6kYtdFMdXNbqYRyD5QAOw0NYbtK5e4cAzSpCVOswQKBgQCkVFcuk58MwtJDhlJz +xQFOqFb8uDB4ab2O+eJuW2CnKuX34uS0oSUgkIDUsX8riCptZeQLWFrz1d9j7GRy +I4JdvvTA4rWx7wPGRlOuC0W7EXolGgOEu2L0uvbO8wpTfS6lM3Bv0K0RdR3ORQjR +MtevE5IzvzTMrVcv7kPsl9mNVw== +-----END PRIVATE KEY----- diff --git a/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js new file mode 100644 index 000000000..7e57b6151 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR.js @@ -0,0 +1,80 @@ +var http = require('http'); +var https = require('https'); +var ArgumentParser = require('argparse').ArgumentParser; +var express = require('express'); +const stream = require('stream'); +var app = express(); +var fs = require("fs"); +var path = require('path'); +var privateKey = fs.readFileSync('cert/private.key', 'utf8'); +var certificate = fs.readFileSync('cert/certificate.crt', 'utf8'); +var credentials = {key: privateKey, cert: certificate}; + + +var parser = new ArgumentParser({ + version: '0.0.1', + addHelp:true, + description: 'Datarouter simulator' + }); + +parser.addArgument('--tc' , { help: 'TC $NoOfTc' } ); +parser.addArgument('--printtc' , + { + help: 'Print complete usage help', + action: 'storeTrue' + } + ); + +var args = parser.parseArgs(); + +if (args.tc=="100") { + console.log("TC: 100") +} +if (args.tc=="101") { + console.log("TC: 101") + //preparations +} +if (args.tc=="102") { + console.log("TC: 102") + //preparations +} + +if (args.printtc) { + console.log("TC 100: receive all incoming files"); + console.log("TC 101: drop/deny first 10 publishing attempt, then receive all"); + console.log("TC 102: drop/deny/every second publisging attempt"); + process.exit(0); +} + +var bodyParser = require('body-parser') +app.use(bodyParser.urlencoded({ extended: false })) + +// parse application/json +app.use(bodyParser.json()) + +// parse application/vnd.api+json as json +app.use(bodyParser.json({ type: 'application/vnd.api+json' })) + +// parse some custom thing into a Buffer +app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' })) +// parse an HTML body into a string +app.use(bodyParser.text({ type: 'text/html' })) +app.get("/",function(req, res){ + res.send("ok"); +}) +app.put('/publish/1/:filename', function (req, res) { + console.log(req.files); + console.log(req.body); + console.log(req.headers); + var filename = path.basename(req.params.filename); + res.redirect(301, 'http://127.0.0.1:3908/publish/1/'+filename) +}) +var httpServer = http.createServer(app); +var httpsServer = https.createServer(credentials, app); + +var httpPort=3906 +var httpsPort=3907 +httpServer.listen(httpPort); +console.log("DR-simulator listening (http) at "+httpPort) +httpsServer.listen(httpsPort); +console.log("DR-simulator listening (https) at "+httpsPort) diff --git a/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js new file mode 100644 index 000000000..5be1f689e --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js @@ -0,0 +1,54 @@ +var http = require('http'); +var https = require('https'); + +var express = require('express'); +const stream = require('stream'); +var app = express(); +var fs = require("fs"); +var path = require('path'); +var privateKey = fs.readFileSync('cert/private.key', 'utf8'); +var certificate = fs.readFileSync('cert/certificate.crt', 'utf8'); +var credentials = {key: privateKey, cert: certificate}; + +var bodyParser = require('body-parser') + +// parse application/x-www-form-urlencoded +app.use(bodyParser.urlencoded({ extended: false })) + +// parse application/json +app.use(bodyParser.json()) + +// parse application/vnd.api+json as json +app.use(bodyParser.json({ type: 'application/vnd.api+json' })) + +// parse some custom thing into a Buffer +app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' })) + +// parse an HTML body into a string +app.use(bodyParser.text({ type: 'text/html' })) +app.get("/",function(req, res){ + res.send("ok"); +}) + +app.put('/publish/1/:filename', function (req, res) { + console.log(req.files); + console.log(req.body) + console.log(req.headers) + var filename = path.basename(req.params.filename); + filename = path.resolve(__dirname, filename); + console.log(req.params.filename); + fs.writeFile(filename, req.body, function (error) { + if (error) { console.error(error); } + }); + res.send("ok") +}) +var httpServer = http.createServer(app); +var httpsServer = https.createServer(credentials, app); + +var httpPort=3908 +var httpsPort=3909 +httpServer.listen(httpPort); +console.log("DR-simulator listening (http) at "+httpPort) +httpsServer.listen(httpsPort); +console.log("DR-simulator listening (https) at "+httpsPort) + diff --git a/test/mocks/datafilecollector-testharness/dr-sim/package.json b/test/mocks/datafilecollector-testharness/dr-sim/package.json new file mode 100644 index 000000000..faebcc929 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/package.json @@ -0,0 +1,369 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "accepts": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", + "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", + "requires": { + "mime-types": "~2.1.18", + "negotiator": "0.6.1" + } + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "body-parser": { + "version": "1.18.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", + "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", + "requires": { + "bytes": "3.0.0", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.2", + "http-errors": "~1.6.3", + "iconv-lite": "0.4.23", + "on-finished": "~2.3.0", + "qs": "6.5.2", + "raw-body": "2.3.3", + "type-is": "~1.6.16" + } + }, + "bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" + }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha1-4TjMdeBAxyexlm/l5fjJruJW/js=" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=", + "requires": { + "ms": "2.0.0" + } + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, + "express": { + "version": "4.16.4", + "resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz", + "integrity": "sha512-j12Uuyb4FMrd/qQAm6uCHAkPtO8FDTRJZBDd5D2KOL2eLaz1yUNdUB/NOIyq0iU4q4cFarsUCrnFDPBcnksuOg==", + "requires": { + "accepts": "~1.3.5", + "array-flatten": "1.1.1", + "body-parser": "1.18.3", + "content-disposition": "0.5.2", + "content-type": "~1.0.4", + "cookie": "0.3.1", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "1.1.1", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.4", + "qs": "6.5.2", + "range-parser": "~1.2.0", + "safe-buffer": "5.1.2", + "send": "0.16.2", + "serve-static": "1.13.2", + "setprototypeof": "1.1.0", + "statuses": "~1.4.0", + "type-is": "~1.6.16", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + } + }, + "finalhandler": { + "version": "1.1.1", + "resolved": "http://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz", + "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", + "requires": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", + "statuses": "~1.4.0", + "unpipe": "~1.0.0" + } + }, + "forwarded": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, + "http-errors": { + "version": "1.6.3", + "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", + "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.3", + "setprototypeof": "1.1.0", + "statuses": ">= 1.4.0 < 2" + } + }, + "iconv-lite": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", + "integrity": "sha1-KXhx9jvlB63Pv8pxXQzQ7thOmmM=", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "ipaddr.js": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz", + "integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4=" + }, + "media-typer": { + "version": "0.3.0", + "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", + "integrity": "sha1-Eh+evEnjdm8xGnbh+hyAA8SwOqY=" + }, + "mime-db": { + "version": "1.37.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz", + "integrity": "sha1-C2oM5v2+lXbiXx8tL96IMNwK0Ng=" + }, + "mime-types": { + "version": "2.1.21", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz", + "integrity": "sha1-KJlaoey3cHQv5q5+WPkYHHRLP5Y=", + "requires": { + "mime-db": "~1.37.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, + "proxy-addr": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz", + "integrity": "sha1-7PxzO/Iv+Mb0B/onUye5q2fki5M=", + "requires": { + "forwarded": "~0.1.2", + "ipaddr.js": "1.8.0" + } + }, + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha1-yzroBuh0BERYTvFUzo7pjUA/PjY=" + }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + }, + "raw-body": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz", + "integrity": "sha1-GzJOzmtXBuFThVvBFIxlu39uoMM=", + "requires": { + "bytes": "3.0.0", + "http-errors": "1.6.3", + "iconv-lite": "0.4.23", + "unpipe": "1.0.0" + } + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha1-mR7GnSluAxN0fVm9/St0XDX4go0=" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha1-RPoWGwGHuVSd2Eu5GAL5vYOFzWo=" + }, + "send": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", + "integrity": "sha1-bsyh4PjBVtFBWXVZhI32RzCmu8E=", + "requires": { + "debug": "2.6.9", + "depd": "~1.1.2", + "destroy": "~1.0.4", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "~1.6.2", + "mime": "1.4.1", + "ms": "2.0.0", + "on-finished": "~2.3.0", + "range-parser": "~1.2.0", + "statuses": "~1.4.0" + } + }, + "serve-static": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", + "integrity": "sha1-CV6Ecv1bRiN9tQzkhqQ/S4bGzsE=", + "requires": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.2", + "send": "0.16.2" + } + }, + "setprototypeof": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", + "integrity": "sha1-0L2FU2iHtv58DYGMuWLZ2RxU5lY=" + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + }, + "statuses": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha1-u3PURtonlhBu/MG2AaJT1sRr0Ic=" + }, + "type-is": { + "version": "1.6.16", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", + "integrity": "sha1-+JzjQVQcZysl7nrjxz3uOyvlAZQ=", + "requires": { + "media-typer": "0.3.0", + "mime-types": "~2.1.18" + } + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + } + } +} diff --git a/test/mocks/datafilecollector-testharness/ftps-sftp-server/README.md b/test/mocks/datafilecollector-testharness/ftps-sftp-server/README.md new file mode 100644 index 000000000..5a1660126 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/ftps-sftp-server/README.md @@ -0,0 +1,29 @@ +###Deployment of certificates: (in case of update) + +This folder is prepared with a set of keys matching DfC for test purposes. + +Copy from datafile-app-server/config/keys to the ./tls/ the following files: + +* dfc.crt +* ftp.crt +* ftp.key + +###Docker preparations +Source: https://docs.docker.com/install/linux/linux-postinstall/ + +`sudo usermod -aG docker $USER` + +then logout-login to activate it. + +###Starting/stopping the FTPS/SFTP server(s) + +Start: `docker-compose up` + +Stop: Ctrl +C, then `docker-compose down` or `docker-compose down --remove-orphans` + +If you experience issues (or port collision), check the currently running other containers +by using 'docker ps' and stop them if necessary. + + +###Cleaning docker structure +Deep cleaning: `docker system prune`
\ No newline at end of file diff --git a/test/mocks/datafilecollector-testharness/ftps-sftp-server/configuration/vsftpd_ssl.conf b/test/mocks/datafilecollector-testharness/ftps-sftp-server/configuration/vsftpd_ssl.conf new file mode 100644 index 000000000..99d64dca0 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/ftps-sftp-server/configuration/vsftpd_ssl.conf @@ -0,0 +1,57 @@ +# Server Config +anonymous_enable=NO +local_enable=YES +write_enable=YES +local_umask=022 +dirmessage_enable=YES + +# Security and User auth +chroot_local_user=YES +pam_service_name=vsftpd_virtual +virtual_use_local_privs=YES +chmod_enable=NO +user_config_dir=/etc/vsftpd/user_conf +user_sub_token=$USER +#local_root=/srv/$USER +local_root=/srv/ +userlist_enable=NO +allow_writeable_chroot=YES + +# Logging +log_ftp_protocol=YES +xferlog_enable=YES +xferlog_std_format=YES +#xferlog_file=/dev/stdout +syslog_enable=NO +dual_log_enable=YES + +# Remap all login users to this username +guest_enable=YES +guest_username=ftp +hide_ids=YES + +# Networking +connect_from_port_20=NO +listen=YES +tcp_wrappers=YES +pasv_min_port=8001 +pasv_max_port=8010 + +# SSL +ssl_enable=Yes +require_ssl_reuse=NO +force_local_data_ssl=YES +force_local_logins_ssl=YES +ssl_ciphers=HIGH +allow_anon_ssl=NO + +ssl_tlsv1=YES +ssl_sslv2=YES +ssl_sslv3=YES +rsa_cert_file=/etc/ssl/private/ftp.crt +rsa_private_key_file=/etc/ssl/private/ftp.key + +require_cert=YES +ssl_request_cert=YES +ca_certs_file=/etc/ssl/private/dfc.crt + diff --git a/test/mocks/datafilecollector-testharness/ftps-sftp-server/docker-compose.yml b/test/mocks/datafilecollector-testharness/ftps-sftp-server/docker-compose.yml new file mode 100644 index 000000000..4d2d32984 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/ftps-sftp-server/docker-compose.yml @@ -0,0 +1,39 @@ +version: '3' + +services: + + sftp-server1: + container_name: sftp-server1 + image: atmoz/sftp:alpine + ports: + - "1022:22" + volumes: + - ./files/onap/:/home/onap/ + restart: on-failure + command: onap:pano:1001 + + ftpes-server-vsftpd: + container_name: ftpes-server-vsftpd + image: docker.io/panubo/vsftpd + ports: + - "21:21" + - "8001-8010:8001-8010" + environment: + FTP_USER: onap + FTP_PASSWORD: pano + PASV_ADDRESS: localhost + PASV_MIN_PORT: 8001 + PASV_MAX_PORT: 8010 + volumes: + - ./tls/ftp.crt:/etc/ssl/private/ftp.crt:ro + - ./tls/ftp.key:/etc/ssl/private/ftp.key:ro + - ./tls/dfc.crt:/etc/ssl/private/dfc.crt:ro + - ./configuration/vsftpd_ssl.conf:/etc/vsftpd_ssl.conf:ro + + - ./files/onap/0.5MB.tar.gz:/srv/0.5MB.tar.gz:ro + - ./files/onap/1MB.tar.gz:/srv/1MB.tar.gz:ro + - ./files/onap/5MB.tar.gz:/srv/5MB.tar.gz:ro + - ./files/onap/10MB.tar.gz:/srv/10MB.tar.gz:ro + restart: on-failure + command: vsftpd /etc/vsftpd_ssl.conf + diff --git a/test/mocks/datafilecollector-testharness/ftps-sftp-server/prepare.sh b/test/mocks/datafilecollector-testharness/ftps-sftp-server/prepare.sh new file mode 100755 index 000000000..76f333409 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/ftps-sftp-server/prepare.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +mkdir -p files/onap + +dd if=/dev/urandom of=./files/onap/0.5MB.tar.gz bs=1k count=512 +dd if=/dev/urandom of=./files/onap/1MB.tar.gz bs=1M count=1 +dd if=/dev/urandom of=./files/onap/5MB.tar.gz bs=1M count=5 +dd if=/dev/urandom of=./files/onap/10MB.tar.gz bs=1M count=10 + +sudo chown root:root ./configuration/vsftpd_ssl.conf diff --git a/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/dfc.crt b/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/dfc.crt new file mode 100644 index 000000000..0c00a5a5f --- /dev/null +++ b/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/dfc.crt @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDFjCCAf4CCQCfuDKplruMfDANBgkqhkiG9w0BAQsFADBNMQswCQYDVQQGEwJT +RTEKMAgGA1UECAwBMDEKMAgGA1UEBwwBMDEKMAgGA1UECgwBMDEMMAoGA1UECwwD +RVNUMQwwCgYDVQQDDANFU1QwHhcNMTkwMjA1MTQwMDQ5WhcNMjAwMjA1MTQwMDQ5 +WjBNMQswCQYDVQQGEwJTRTEKMAgGA1UECAwBMDEKMAgGA1UEBwwBMDEKMAgGA1UE +CgwBMDEMMAoGA1UECwwDRVNUMQwwCgYDVQQDDANFU1QwggEiMA0GCSqGSIb3DQEB +AQUAA4IBDwAwggEKAoIBAQCzUSxAWVekRZ22WaDkPDUAK+ihxdoy9iXeakS2K4xR +biT85qkyHP8kh/KgDTwcH/wJ5nSKxMh135s/EF1rJpLoDW+BR8HpAq/GX2V7N8lV +E+cDyfLxTA/emptZ+sN6JKXpgwEs7B93EsomjBnu9G8lLHXBUMRywc9rRymivAVO +DE+UsT6xO/thUgDtiKS4C37jmt0dabPblBcINY6a6dG3V+QsPXaHsKbg4O6y0jZL +nLM4PBT47rL7grmngcEnXYb3zQPV9JxY3tAHJDyiMU2VkhSB1NbJ7rOMRImesJ5o +cuLdKY12amTPQ2lwmTSL2ieGRYHo7OmZ+rPCWIksLbrbAgMBAAEwDQYJKoZIhvcN +AQELBQADggEBAE/UvlH4tfoMkEs9eTk8WgpyBVcLA2Vo9F1o2a2tvj4iXFUWGMZK +SJ+j4tnEBgpsIWNpWEOnD00ngOKTLuedFuS62if3QW34Y6Hax6qP+FMStko5jZ4F +OALZb4GZU5MR0hLSig6aB6zDa1Qe2iVK7Lr7BWG1O+8NsTUP6akIwSQufAllrpJ/ +Ng02CWK6WCaMV5Z1CnVheBw9vf/3ZVh1tm8gRrJQGlcau2/8Mg3M7yThHuDz/rPm +VbkO6aMRl3C115whBTpd1+/rwg0BzsIQjv56Ab34pWAQc20KsV8WPPDxzZhlZUHD +yc0HiF1+blZHlzc/ie/07DSklUMKJv63D1s= +-----END CERTIFICATE----- diff --git a/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/ftp.crt b/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/ftp.crt new file mode 100644 index 000000000..28932806b --- /dev/null +++ b/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/ftp.crt @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDFjCCAf4CCQC2aMod08TgbDANBgkqhkiG9w0BAQsFADBNMQswCQYDVQQGEwJT +RTEKMAgGA1UECAwBMDEKMAgGA1UEBwwBMDEKMAgGA1UECgwBMDEMMAoGA1UECwwD +RVNUMQwwCgYDVQQDDANFU1QwHhcNMTkwMjA1MTQwMDUwWhcNMjAwMjA1MTQwMDUw +WjBNMQswCQYDVQQGEwJTRTEKMAgGA1UECAwBMDEKMAgGA1UEBwwBMDEKMAgGA1UE +CgwBMDEMMAoGA1UECwwDRVNUMQwwCgYDVQQDDANFU1QwggEiMA0GCSqGSIb3DQEB +AQUAA4IBDwAwggEKAoIBAQDUOXkcBkCqWEXri3TIB1xqd/reBSigsXb+54jRn8/1 +POQGE8BGE54RJd5xurtoLpqeuqgYl9jdLW0uyfZY/ef81K2qWwwmUtzMJmREyJ3x +2QNoYfJKBbfQKHOQ1nEYBFWKo7nmWxNhJ7iBxEO1QL+jwgohF2gWgrx1KzV6Cu6S +NX71jWEa3DkYNjc08dn6rMsLfXe8Rgc1EVLxfj+JG/CDnEyKavKmcxLZlk3zD0/i +CCTaa23aeNCk4qOZ7k5T2Mlt82POlKztjjIBfpyxhoJmO2clRf6jso0BdRQ5r7yd +4Y+FAUjNbS6A41SuxF8EbSIKtS2UAMUxf1fX74WOKLQPAgMBAAEwDQYJKoZIhvcN +AQELBQADggEBAIjhg0KMyqg2EFeZOKinmeCEY3f+AfW9AnPc+MMQH7ITPJXXB4hR +3KVzn4aX19x5b6KjLKtYI+tNHpN9bECWTGPv0yloUSJttyAMmNHYX++9GYHRQoFc +9RKTzc4tZP1/vVFz0zov9iRKk1uhrEW+B7N4e/WDJpD8QbgiPGwAUsfC9lxJIdpl +2UKWhA3KazuUgH+w2udh1tDzBKmRpSMS/vFQ6cfUXBfcJYOtCIbVhZwjy1oGc+vX +PvFQCL6x+n7v12IUjzH6k284UxdqVdKBfPgkr774pFlTioa9fHu/eRBUPGOllePF +sY9S5Ba0hFWunQyyiT4d34hwDjRKojenULc= +-----END CERTIFICATE----- diff --git a/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/ftp.key b/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/ftp.key new file mode 100644 index 000000000..05144b39a --- /dev/null +++ b/test/mocks/datafilecollector-testharness/ftps-sftp-server/tls/ftp.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA1Dl5HAZAqlhF64t0yAdcanf63gUooLF2/ueI0Z/P9TzkBhPA +RhOeESXecbq7aC6anrqoGJfY3S1tLsn2WP3n/NStqlsMJlLczCZkRMid8dkDaGHy +SgW30ChzkNZxGARViqO55lsTYSe4gcRDtUC/o8IKIRdoFoK8dSs1egrukjV+9Y1h +Gtw5GDY3NPHZ+qzLC313vEYHNRFS8X4/iRvwg5xMimrypnMS2ZZN8w9P4ggk2mtt +2njQpOKjme5OU9jJbfNjzpSs7Y4yAX6csYaCZjtnJUX+o7KNAXUUOa+8neGPhQFI +zW0ugONUrsRfBG0iCrUtlADFMX9X1++Fjii0DwIDAQABAoIBAHydKsIL4dikcJn4 +jyANQnS58rJ/cPW6ftb6eVotbtzfXj07R8FeL4h+Jfm93eE0zFG75IxcTVjCHcRF +jsN+g8Pv1fGb+KxgJ4owWNwSuLuT4+5c5PoWFXLC7ej0IgAqO1hm/veGLwDzY+G+ +rss1M9IiU/ROXC4roiFit8nrtV5fvUj7UzrLLuxoHH8v727ug/Z1U+RIaiTA0b/P +4x4NTrS7QquvSk8O4IOZRVQKCN9KxOg3BBu8oM6/TOucBtRhfVoOGf9XFQPQctNu +ORFAoB6OIVY/vdkyS62kD/MGD/MQsq9c58FyjVtWxBFWanhz4syb+kaOqPRi7GA1 +tBGxd+ECgYEA8ILjwiZEKUxz7dKxRJL98327WzH+vh4v2aiiCQF/QqO06edX6OLs +UQSyhN2+XJsvmW9TxcsLdiMstKR1rEO0vU/LTyE4D8bZ0dVtK6eHJ0wPLJSf0LPL +7vReFuMHMhKn6X3uLHpws4mibXQXij8hifF2f5AUPXdkwvpi3KqpUXcCgYEA4eQ+ +HaF9G5mh5X6/oNCbHj/nDpKUJSvvoHoJoTxRD/Hn13YTz1OEhleV4QX+QQ/RsPVR +WC+RI+F9+aL82r1DJ/EA2B3tcupX/s66JQgSAA/mU09GXru7Nf5nJCRJLaeZq/zi +xDQM3dyuyuOXWE+H80K5c6E4yLAc1pj2SR+0mCkCgYBNGZiLt5qoJpMPTTh4hCqW +sNqrzGYeaizquI1hF7LFGRe41+mthXk+K6RSxYbtxu3GYRLY2FNPRs1hB0uVsoqx +GXBSaJLBM/zFsIZztRu1dEN1BhwJWmnoqzuyWIsI+UQMrMr6RTH1zAxezBVzwvMs +dlSHZhem8KxDeOLSXH801wKBgQCsO2vFCekrDyOqqM6RXhy3nr+ck9RS10IY2JPZ +FPU1tBsyY/xMuwAzsjo73Wbz0ozuYM2J8JK4ieiUW1pxqZa3sIEVRxRR5y36wUKa +k6Gt3HGgGbSs7HScgYHAw83r+nsn8GQydwFMdEPtvEQb+F/O8ZQW/tkd43HJic1X +Cc6XqQKBgQDmGijg2uO8Mxqzv2JHNqUJ0djJG7dbT2NhzdrgXUmt6M3I0iJ+CSU7 +Ls87u7WMhyYsBynInhunaNRR0bQVab7bT61p6ru2FxRuVLVx2dXjzX0+vkSrT+wu +e2oAmyPSRHtGXhnT1rqGHu7pvMTCqrhjdW6/YqZvHiAnM05iEBmjeQ== +-----END RSA PRIVATE KEY----- diff --git a/test/mocks/datafilecollector-testharness/mr-sim/.gitignore b/test/mocks/datafilecollector-testharness/mr-sim/.gitignore new file mode 100644 index 000000000..e4c889be6 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/mr-sim/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +.env/ +.pydevproject
\ No newline at end of file diff --git a/test/mocks/datafilecollector-testharness/mr-sim/README.md b/test/mocks/datafilecollector-testharness/mr-sim/README.md new file mode 100644 index 000000000..b04b9ec64 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/mr-sim/README.md @@ -0,0 +1,46 @@ +## Developer workflow + +1. ```sudo apt install python3-venv``` +2. ```source .env/bin/activate/``` +3. ```pip3 install "anypackage"``` #also include in source code +4. ```pip3 freeze | grep -v "pkg-resources" > requirements.txt``` #to create a req file +5. ```FLASK_APP=mr-sim.py flask run``` + + or + + ```python3 mr-sim.py ``` + +6. Check/lint/format the code before commit/amed by ```autopep8 --in-place --aggressive --aggressive mr-sim.py``` + + +## User workflow on *NIX + + +When cloning/fetching from the repository first time: +1. `git clone` +2. `cd "..." ` #navigate to this folder +3. `source setup.sh ` #setting up virtualenv and install requirements + + you'll get a sourced virtualenv shell here, check prompt +4. `(env) $ python3 mr-sim.py --help` + + alternatively + + `(env) $ python3 mr-sim.py --tc1` + +Every time you run the script, you'll need to step into the virtualenv by following step 3 first. + +## User workflow on Windows + +When cloning/fetching from the repository first time: + +1. 'git clone' +2. then step into the folder +3. 'pip3 install virtualenv' +4. 'pip3 install virtualenvwrapper-win' +5. 'mkvirtualenv env' +6. 'workon env' +7. 'pip3 install -r requirements.txt' #this will install in the local environment then +8. 'python3 dfc-sim.py' + +Every time you run the script, you'll need to step into the virtualenv by step 2+6.
\ No newline at end of file diff --git a/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py b/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py new file mode 100644 index 000000000..c37ae698a --- /dev/null +++ b/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py @@ -0,0 +1,289 @@ +import argparse +import os +from werkzeug import secure_filename +from flask import Flask, render_template, request +from time import sleep +import sys +import json +from flask import Flask +app = Flask(__name__) + +DEFAULT_IP = "localhost" + + +@app.route( + "/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12", + methods=['GET']) +def MR_reply(): + global mr_counter + global mr_replies + + mr_counter = mr_counter + 1 + print("MR receiver counter: " + str(mr_counter)) + + if mr_replies[mr_counter].sleepMs != 0: + sleep(mr_replies[mr_counter].sleepMs / 1000.0) + print("Sleeping: " + str(mr_replies[mr_counter].sleepMs) + " ms") + + if mr_replies[mr_counter].replytype == 0: + #print (str(mr_replies[mr_counter].jsonreply)) + print("Regular reply") + response = app.response_class( + response=mr_replies[mr_counter].jsonreply, + status=200, + mimetype='application/json') + + return response + + if mr_replies[mr_counter].replytype == 2: + + print("error: 404") + response = app.response_class( + response="", + status=404, + mimetype='application/json') + + return response + + if mr_replies[mr_counter].replytype == 1: + print("do nothing, sink request") + return + + +class Reply: + """An instance of the reply event, which can be configured to behave in a certain way + (delay, error code, reply body""" + + def to_json(self): + return self.jsonreply + + def __init__( + self, + ip=DEFAULT_IP, + file="1MB.tar.gz", + sleepMs=0, + replyType=0, + port=1022, + type="ftps"): + self.sleepMs = sleepMs + self.ip = ip + self.file = file + self.port = port + self.replytype = replyType # 0 for reply, 1 timeout, 2 deny + self.user = "onap" + self.passwd = "pano" + self.type = type + self.jsonreply = str.encode(""" + [{ + "event": { + "commonEventHeader": { + "startEpochMicrosec": 8745745764578, + "eventId": "FileReady_1797490e-10ae-4d48-9ea7-3d7d790b25e1", + "timeZoneOffset": "UTC+05.30", + "internalHeaderFields": { + "collectorTimeStamp": "Tue, 09 18 2018 10:56:52 UTC" + }, + "priority": "Normal", + "version": "4.0.1", + "reportingEntityName": "otenb5309", + "sequence": 0, + "domain": "notification", + "lastEpochMicrosec": 8745745764578, + "eventName": "Noti_RnNode-Ericsson_FileReady", + "vesEventListenerVersion": "7.0.1", + "sourceName": "oteNB5309" + }, + "notificationFields": { + "notificationFieldsVersion": "2.0", + "changeType": "FileReady", + "changeIdentifier": "PM_MEAS_FILES", + "arrayOfNamedHashMap": [ + { + "name": \"""" + + self.file + + """", + "hashMap": { + "fileFormatType": "org.3GPP.32.435#measCollec", + "location": \"""" + + self.type + + """://""" + + self.user + + """:""" + + self.passwd + + """@""" + + self.ip + + """:""" + + str(self.port) + + """/""" + + self.file + + """", + "fileFormatVersion": "V10", + "compression": "gzip" + } + } + ] + } + } + }] + """) + + +def replyFactory( + ip=DEFAULT_IP, + file="1MB.tar.gz", + factoryport=1022, + count=1, + factorytype="ftps"): + aggregatedReply = "" + # first item does not require . + aggregatedReply = Reply(ip, file, port=factoryport).to_json() + for i in range(count - 1): + aggregatedReply = aggregatedReply + b", " + \ + Reply(ip, file, port=factoryport, type=factorytype).to_json() + #print(b"aggregated reply: " + aggregatedReply) + return b"[" + aggregatedReply + b"]" + + +def prepareMrRespArrSftp(): + global mr_replies + + for i in range(400): # prepare 400 regular replies + mr_replies.append( + Reply( + port=1022, + ip="localhost", + type="sftp", + file="1MB.tar.gz")) + #mr_replies[0] is not used + + +def prepareMrRespArrFtps(): + global mr_replies + + for i in range(400): + mr_replies.append( + Reply( + port=21, + ip="localhost", + type="ftps", + file="1MB.tar.gz")) + + +def tc1(): + prepareMrRespArrSftp() + # no mutation needed in this TC + + +def tc2(): + global mr_replies + + for i in range(7): + mr_replies.append( + Reply( + port=1022, + ip="localhost", + type="sftp", + file="1MB.tar.gz")) + + # inserting and empty reply message + mr_replies[1].jsonreply = b"" + mr_replies[2].jsonreply = b"" + + # inserting a 404 error and delay + mr_replies[3].replytype = 2 + mr_replies[3].sleepMs = 2000 + + # inserting and empty reply message + mr_replies[4].jsonreply = b"" + + # sink the message + mr_replies[5].replytype = 1 + + # reply with one proper file finally + mr_replies[6] = Reply( + port=1022, + ip="localhost", + type="sftp", + file="1MB.tar.gz") + + +def tc3(): + prepareMrRespArrFtps() + + +def tc4(): + global mr_replies + + for i in range(7): + mr_replies.append( + Reply( + port=21, + ip="localhost", + type="ftps", + file="1MB.tar.gz")) + + # inserting and empty reply message + mr_replies[1].jsonreply = b"" + mr_replies[2].jsonreply = b"" + + # inserting a 404 error and delay + mr_replies[3].replytype = 2 + mr_replies[3].sleepMs = 2000 + + # inserting and empty reply message + mr_replies[4].jsonreply = b"" + + # sink the message + mr_replies[5].replytype = 1 + + # reply with one proper file finally + mr_replies[6] = Reply( + port=21, + ip="localhost", + type="fftp", + file="1MB.tar.gz") + + +if __name__ == "__main__": + mr_replies = [] + mr_counter = 0 # counting hits reaching MR instance + DR_block_single_req = 0 + + parser = argparse.ArgumentParser() + parser.add_argument( + '--tc1', + action='store_true', + help='TC1: reply all queries with 1-1 files using SFTP') + parser.add_argument( + '--tc2', + action='store_true', + help='TC2: Reply according to error scenarios, then return 1 file finally for SFTP ---NOTE: updated keys required') + parser.add_argument( + '--tc3', + action='store_true', + help='TC3: reply all queries with 1-1 files using FTPS') + parser.add_argument( + '--tc4', + action='store_true', + help='TC4: Reply according to error scenarios, then return 1 file finally for FTPS ---NOTE: updated keys required') + + args = parser.parse_args() + + if args.tc1: + print("TC: #1") + tc1() + elif args.tc2: + print("TC: #2") + tc2() + elif args.tc3: + print("TC: #3") + tc3() + elif args.tc4: + print("TC: #4") + tc4() + + else: + print("No TC was defined") + print("use --help for usage info") + sys.exit() + app.run(port=2222) diff --git a/test/mocks/datafilecollector-testharness/mr-sim/requirements.txt b/test/mocks/datafilecollector-testharness/mr-sim/requirements.txt new file mode 100644 index 000000000..6f02fb6e3 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/mr-sim/requirements.txt @@ -0,0 +1,6 @@ +Click==7.0 +Flask==1.0.2 +itsdangerous==1.1.0 +Jinja2==2.10 +MarkupSafe==1.1.0 +Werkzeug==0.14.1 diff --git a/test/mocks/datafilecollector-testharness/mr-sim/setup.sh b/test/mocks/datafilecollector-testharness/mr-sim/setup.sh new file mode 100755 index 000000000..6661d0bb8 --- /dev/null +++ b/test/mocks/datafilecollector-testharness/mr-sim/setup.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +virtualenv --version > /dev/null || { echo 'Virtualenv command is not available, exiting' ; sleep 10; exit 1; } +pip3 --version > /dev/null || { echo 'python3-pip package is not available, exiting' ; sleep 10; exit 1; } + + +if [ -d ".env" ]; then + echo ".env is prepared" +else + virtualenv --no-site-packages --distribute -p python3 .env +fi + +source .env/bin/activate && pip3 install -r requirements.txt |