blob: a1b2770cfb2c7c3fe128f438fc521e5a703823a2 [file] [log] [blame]
yanhuanwangdb4bd692019-03-15 07:57:38 +00001var http = require('http');
2var https = require('https');
3var ArgumentParser = require('argparse').ArgumentParser;
4var express = require('express');
5const stream = require('stream');
6var app = express();
7var fs = require("fs");
8var path = require('path');
yanhuanwang08463e52019-03-22 09:23:23 +00009var privateKey = fs.readFileSync('cert/private.key', 'utf8');
yanhuanwangdb4bd692019-03-15 07:57:38 +000010var certificate = fs.readFileSync('cert/certificate.crt', 'utf8');
yanhuanwang08463e52019-03-22 09:23:23 +000011var credentials = {
12 key: privateKey,
13 cert: certificate
14};
yanhuanwangdb4bd692019-03-15 07:57:38 +000015
16
17var parser = new ArgumentParser({
yanhuanwang08463e52019-03-22 09:23:23 +000018 version: '0.0.1',
19 addHelp: true,
20 description: 'Datarouter simulator'
21});
yanhuanwangdb4bd692019-03-15 07:57:38 +000022
yanhuanwang08463e52019-03-22 09:23:23 +000023parser.addArgument('--tc', {
24 help: 'TC $NoOfTc'
25});
26parser.addArgument('--printtc', {
27 help: 'Print complete usage help',
28 action: 'storeTrue'
29});
yanhuanwangdb4bd692019-03-15 07:57:38 +000030
31var args = parser.parseArgs();
32
yanhuanwang08463e52019-03-22 09:23:23 +000033if (args.tc == "100") {
yanhuanwangdb4bd692019-03-15 07:57:38 +000034 console.log("TC: 100")
35}
yanhuanwang08463e52019-03-22 09:23:23 +000036if (args.tc == "101") {
yanhuanwangdb4bd692019-03-15 07:57:38 +000037 console.log("TC: 101")
38 //preparations
39}
yanhuanwang08463e52019-03-22 09:23:23 +000040if (args.tc == "102") {
yanhuanwangdb4bd692019-03-15 07:57:38 +000041 console.log("TC: 102")
42 //preparations
43}
44
45if (args.printtc) {
46 console.log("TC 100: receive all incoming files");
47 console.log("TC 101: drop/deny first 10 publishing attempt, then receive all");
48 console.log("TC 102: drop/deny/every second publisging attempt");
49 process.exit(0);
50}
51
52var bodyParser = require('body-parser')
yanhuanwang08463e52019-03-22 09:23:23 +000053app.use(bodyParser.urlencoded({
54 extended: false
55}))
yanhuanwangdb4bd692019-03-15 07:57:38 +000056
57// parse application/json
58app.use(bodyParser.json())
59
60// parse application/vnd.api+json as json
yanhuanwang08463e52019-03-22 09:23:23 +000061app.use(bodyParser.json({
62 type: 'application/vnd.api+json'
63}))
yanhuanwangdb4bd692019-03-15 07:57:38 +000064
65// parse some custom thing into a Buffer
yanhuanwang08463e52019-03-22 09:23:23 +000066app.use(bodyParser.raw({
67 limit: 1024 * 1024 * 20,
68 type: 'application/octet-stream'
69}))
yanhuanwangdb4bd692019-03-15 07:57:38 +000070// parse an HTML body into a string
yanhuanwang08463e52019-03-22 09:23:23 +000071app.use(bodyParser.text({
72 type: 'text/html'
73}))
74app.get("/", function (req, res) {
yanhuanwangdb4bd692019-03-15 07:57:38 +000075 res.send("ok");
76})
77app.post('/webapi/feeds/', function (req, res) {
yanhuanwang08463e52019-03-22 09:23:23 +000078 res.setHeader('Content-Type', 'application/json');
79 var feedName = req.body.feedName;
80 console.log(feedName);
81 res.end(JSON.stringify({
82 "type": "feed",
83 "lastMod": "2019-03-21T16:00:40.489",
84 "status": "VALID",
85 "asprClassification": "unclassified",
86 "feedDescription": "generated for CSIT",
87 "feedId": "3",
88 "feedName": feedName,
89 "feedVersion": "csit",
90 "logURL": "https://dmaap-dr-prov/feedlog/3",
91 "owner": "dgl",
92 "publishURL": "https://dmaap-dr-prov/publish/3",
93 "pubs": [{
94 "lastMod": "2019-01-24T16:00:40.484",
95 "status": "VALID",
96 "dcaeLocationName": "san-francisco",
97 "feedId": "3",
98 "pubId": "3.4gh53",
99 "username": "tmp_i63w8psh6ycnoqu",
100 "userpwd": "6jkc1uwywrc8q4w"
101 }],
102 "subs": [],
103 "subscribeURL": "https://dmaap-dr-prov/subscribe/3",
104 "suspended": false
105 }));
yanhuanwangdb4bd692019-03-15 07:57:38 +0000106})
107var httpServer = http.createServer(app);
108var httpsServer = https.createServer(credentials, app);
109
yanhuanwang08463e52019-03-22 09:23:23 +0000110var httpPort = 6665
111var httpsPort = 6666
yanhuanwangdb4bd692019-03-15 07:57:38 +0000112httpServer.listen(httpPort);
yanhuanwang08463e52019-03-22 09:23:23 +0000113console.log("DR-simulator listening (http) at " + httpPort)
yanhuanwangdb4bd692019-03-15 07:57:38 +0000114httpsServer.listen(httpsPort);
yanhuanwang08463e52019-03-22 09:23:23 +0000115console.log("DR-simulator listening (https) at " + httpsPort)