├── .travis.yml ├── .bowerrc ├── tests ├── resources │ ├── Recorder │ │ ├── recorder_test_rec-rsp.json │ │ ├── recorder_test_rec-req.json │ │ ├── recorder.1.json │ │ ├── recorder.json │ │ └── Record_Test_Base_Service.json │ ├── bulk │ │ ├── bulk.zip │ │ └── bulk_post.json │ ├── random │ │ ├── random_test_rec-req.json │ │ └── Random_Test_Base_Service.json │ ├── Draft │ │ ├── draft_test-req.json │ │ └── Draft_Test_Service.json │ ├── Invoke │ │ ├── invoke_test-reqs.json │ │ ├── Invoke_Test_Service.json │ │ └── Invoke_Test_Base_Service.json │ ├── Match_Template │ │ ├── requests.json │ │ └── Matching_Test_Service.json │ └── Search │ │ └── Search_Test_Service.json ├── test-report.js ├── test-random.js ├── test-template.js └── test-bulk.js ├── .dockerignore ├── public ├── images │ └── mockiato_live_invo_flow.png ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 ├── partials │ ├── addapiform.html │ ├── restClient.html │ ├── login.html │ ├── viewRecorder.html │ ├── updateForm.html │ ├── templateForm.html │ ├── modals │ │ ├── recorderHelpModal.html │ │ └── liveInvocationHelpModal.html │ ├── selectService.html │ ├── bulkUpload.html │ ├── reportui.html │ ├── draftServices.html │ ├── spec.html │ ├── recorderList.html │ ├── includes │ │ └── restClientServiceHeader.html │ ├── admin.html │ ├── deletedServices.html │ ├── datagen.html │ ├── servicehistory.html │ └── searchService.html ├── css │ ├── angucomplete-alt.css │ └── style.css ├── js │ ├── app │ │ └── controllers │ │ │ └── serviceHeader.js │ └── lib │ │ └── angular-bootstrap-file-field.js └── data │ └── statuses.json ├── models ├── mq │ ├── MQInfo.js │ ├── MQPair.js │ └── MQService.js ├── common │ ├── Archive.js │ ├── DraftService.js │ ├── System.js │ └── User.js ├── db │ └── index.js └── http │ ├── Recording.js │ └── RRPair.js ├── routes ├── mqInfo.js ├── rrpairs.js ├── report.js ├── users.js ├── restClient.js ├── systems.js ├── recording.js └── services.js ├── .gitignore ├── examples ├── mq-example.json ├── rest-xml-example.json ├── rest-json-example.json ├── soap-example.json └── hello-service.wsdl ├── docker-compose.yml ├── bower.json ├── controllers ├── restClientController.js ├── userController.js ├── rrpairController.js ├── mqInfoController.js ├── mqController.js ├── randomController.js └── systemController.js ├── Dockerfile ├── lib ├── remove-route │ ├── .gitignore │ ├── package.json │ ├── LICENSE │ ├── index.js │ └── README.md ├── auth │ ├── ldap.js │ └── local.js ├── pm2 │ └── manager.js ├── restCLI │ └── restClient.js ├── util │ ├── fuse.js │ ├── index.js │ └── constants.js └── wsdl │ └── parser.js ├── winston.js ├── docs ├── Mockiato Notice.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── INDIVIDUAL_CONTRIBUTOR_LICENSE.md ├── package.json ├── bin └── www ├── assets └── register.html └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8" 4 | -------------------------------------------------------------------------------- /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "public/js/bower_components" 3 | } 4 | -------------------------------------------------------------------------------- /tests/resources/Recorder/recorder_test_rec-rsp.json: -------------------------------------------------------------------------------- 1 | { 2 | response:"This is a good response" 3 | } -------------------------------------------------------------------------------- /tests/resources/bulk/bulk.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Optum/mockiato/HEAD/tests/resources/bulk/bulk.zip -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | uploads 4 | mocks 5 | config 6 | specs 7 | *.log 8 | *.bak 9 | .nyc_output 10 | -------------------------------------------------------------------------------- /public/images/mockiato_live_invo_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Optum/mockiato/HEAD/public/images/mockiato_live_invo_flow.png -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Optum/mockiato/HEAD/public/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Optum/mockiato/HEAD/public/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Optum/mockiato/HEAD/public/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Optum/mockiato/HEAD/public/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /tests/resources/random/random_test_rec-req.json: -------------------------------------------------------------------------------- 1 | { 2 | "test": "one", 3 | "test2:": true, 4 | "test3:": 12345, 5 | "testObj:": { 6 | "innerTest:": "testo", 7 | "innterTest2:": "testooo" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/resources/Recorder/recorder_test_rec-req.json: -------------------------------------------------------------------------------- 1 | { 2 | "test": "one", 3 | "test2:": true, 4 | "test3:": 12345, 5 | "testObj:": { 6 | "innerTest:": "testo", 7 | "innterTest2:": "testooo" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/resources/Draft/draft_test-req.json: -------------------------------------------------------------------------------- 1 | { 2 | "test": "one", 3 | "test2:": true, 4 | "test3:": 12345, 5 | "testObj:": { 6 | "innerTest:": "testo", 7 | "innterTest2:": "testooo" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /models/mq/MQInfo.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const infoSchema = new mongoose.Schema({ 4 | manager: String, 5 | reqQueue: String 6 | }); 7 | 8 | module.exports = mongoose.model('MQInfo', infoSchema); -------------------------------------------------------------------------------- /routes/mqInfo.js: -------------------------------------------------------------------------------- 1 | const mqCtrl = require('../controllers/mqInfoController'); 2 | const express = require('express'); 3 | const router = express.Router(); 4 | 5 | router.get('/', mqCtrl.getMQInfo); 6 | 7 | module.exports = router; -------------------------------------------------------------------------------- /routes/rrpairs.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | const rrCtrl = require('../controllers/rrpairController'); 5 | 6 | router.get('/:serviceId/rrpairs', rrCtrl.getPairsByServiceId); 7 | 8 | module.exports = router; -------------------------------------------------------------------------------- /routes/report.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | const reportingController = require('../controllers/reportingController'); 4 | 5 | router.get("/",reportingController.fullReport); 6 | 7 | module.exports = { 8 | router : router 9 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | uploads 3 | data/db 4 | coverage 5 | node_modules 6 | mocks 7 | config 8 | specs 9 | *.log 10 | *.bak 11 | .nyc_output 12 | *.DS_store 13 | public/js/bower_components 14 | public/fusepartials 15 | .vscode/settings.json 16 | .vscode 17 | 18 | package-lock.json 19 | -------------------------------------------------------------------------------- /examples/mq-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "sut": { 3 | "name": "test" 4 | }, 5 | "name": "mq-test", 6 | "type": "MQ", 7 | "rrpairs": [{ 8 | "payloadType": "XML", 9 | "reqData": "hi", 10 | "resData": "hello, again" 11 | }] 12 | } -------------------------------------------------------------------------------- /tests/resources/bulk/bulk_post.json: -------------------------------------------------------------------------------- 1 | 2 | 3 | { 4 | "andParams": { 5 | "firstName" : "Emmett", 6 | "lastName" : "Smith", 7 | "socialSecurityNumber" : "158-69-5844", 8 | "birthDate" : "1984-12-01", 9 | "identifier" : "8744287", 10 | "active": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /routes/users.js: -------------------------------------------------------------------------------- 1 | const userCtrl = require('../controllers/userController'); 2 | const express = require('express'); 3 | const router = express.Router(); 4 | 5 | router.get('/', userCtrl.getUsers); 6 | router.delete('/:name', tokenMiddleware, userCtrl.delUser); 7 | router.get('/admin', userCtrl.getAdminUser); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /tests/resources/Recorder/recorder.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "REST", 3 | "sut": "RecordTest", 4 | "name": "Test Recorder", 5 | "remoteHost": "localhost", 6 | "remotePort": "3000", 7 | "basePath": "/", 8 | "headerMask": [], 9 | "creator": "jlegeyt", 10 | "filters": { 11 | "bodyStrings": [], 12 | "headers": [], 13 | "statuses": [] 14 | } 15 | } -------------------------------------------------------------------------------- /tests/resources/Recorder/recorder.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "REST", 3 | "sut": "RecordTest", 4 | "name": "Test Recorder", 5 | "remoteHost": "google.com", 6 | "remotePort": "80", 7 | "basePath": "/a", 8 | "headerMask": [], 9 | "creator": "jlegeyt", 10 | "filters": { 11 | "bodyStrings": [], 12 | "headers": [], 13 | "statuses": [] 14 | } 15 | } -------------------------------------------------------------------------------- /models/common/Archive.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const Service = require('../http/Service'); 4 | const MQService = require('../mq/MQService'); 5 | 6 | const archiveSchema = new mongoose.Schema({ 7 | service: Service.schema, 8 | mqservice: MQService.schema, 9 | createdAt: { type: Date, default: Date.now } 10 | }); 11 | 12 | archiveSchema.set('usePushEach', true); 13 | module.exports = mongoose.model('Archive', archiveSchema); -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | mockiato-app: 4 | container_name: mockiato-app 5 | restart: always 6 | build: . 7 | environment: 8 | - MONGODB_HOST=mongo 9 | - MOCKIATO_NODES=4 10 | ports: 11 | - "8080:8080" 12 | depends_on: 13 | - mongo 14 | 15 | mongo: 16 | container_name: mongo 17 | image: mongo 18 | volumes: 19 | - ./data/db:/data/db 20 | ports: 21 | - "27017:27017" -------------------------------------------------------------------------------- /models/common/DraftService.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const Service = require('../http/Service'); 4 | const MQService = require('../mq/MQService'); 5 | 6 | const draftServiceSchema = new mongoose.Schema({ 7 | service: Service.schema, 8 | mqservice: MQService.schema, 9 | createdAt: { type: Date, default: Date.now } 10 | }); 11 | 12 | draftServiceSchema.set('usePushEach', true); 13 | module.exports = mongoose.model('DraftService', draftServiceSchema); -------------------------------------------------------------------------------- /routes/restClient.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | const restClientController = require('../controllers/restClientController'); 4 | 5 | // middleware for token auth. Commenting below as Rest Client Tool can be used by any user. login not required. 6 | //router.use(tokenMiddleware); 7 | 8 | //call to restClient backend 9 | router.post('/request', restClientController.processREST); 10 | 11 | 12 | 13 | 14 | 15 | module.exports = router; -------------------------------------------------------------------------------- /models/common/System.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const constants = require('../../lib/util/constants'); 3 | const MQInfo = require('../mq/MQInfo'); 4 | 5 | const sutSchema = new mongoose.Schema({ 6 | name: { 7 | type : String, 8 | required: [true, constants.REQURIED_SUT_NAME_ERR] 9 | }, 10 | members: { 11 | type : Array, 12 | default : [] 13 | }, 14 | mqInfo: MQInfo.schema 15 | }); 16 | 17 | module.exports = mongoose.model('SUT', sutSchema); 18 | -------------------------------------------------------------------------------- /routes/systems.js: -------------------------------------------------------------------------------- 1 | const sysCtrl = require('../controllers/systemController'); 2 | const express = require('express'); 3 | const router = express.Router(); 4 | 5 | // middleware for token auth 6 | router.use(tokenMiddleware); 7 | 8 | router.get('/', sysCtrl.getSystems); 9 | router.post('/', sysCtrl.addSystem); 10 | router.delete('/:name', sysCtrl.delSystem); 11 | router.get('/:name', sysCtrl.getOneSystem); 12 | router.put('/:name', sysCtrl.updateGroup); 13 | 14 | module.exports = router; 15 | -------------------------------------------------------------------------------- /models/common/User.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const passportLocalMongoose = require('passport-local-mongoose'); 3 | const authType = process.env.MOCKIATO_AUTH || 'local'; 4 | 5 | const userSchema = new mongoose.Schema({ 6 | uid: { 7 | type: String, 8 | index: true 9 | }, 10 | mail: String, 11 | password: String 12 | }); 13 | 14 | if (authType === 'local') { 15 | userSchema.plugin(passportLocalMongoose, { usernameField: 'uid', usernameUnique: false }); 16 | } 17 | 18 | module.exports = mongoose.model('User', userSchema); 19 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mockiato-ui", 3 | "private": true, 4 | "ignore": [ 5 | "**/.*", 6 | "node_modules", 7 | "public/js/bower_components", 8 | "test" 9 | ], 10 | "dependencies": { 11 | "angular": "1.7.5", 12 | "angular-messages": "1.7.5", 13 | "angular-resource": "1.7.5", 14 | "angular-route": "1.7.5", 15 | "angular-sanitize": "1.7.5", 16 | "jquery": "3.1.1", 17 | "bootstrap": "3.3.7", 18 | "chance": "1.0.16", 19 | "angucomplete-alt": "3.0.0" 20 | }, 21 | "resolutions": { 22 | "angular": "1.7.5" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /controllers/restClientController.js: -------------------------------------------------------------------------------- 1 | const debug = require('debug')('default'); 2 | const restClient = require('../lib/restCLI/restClient'); 3 | 4 | function processREST(req, res) { 5 | 6 | restClient.processRequest(req.body).then(onSuccess).catch(onError); 7 | 8 | function onSuccess(resp) { 9 | res.status(resp.status); 10 | res.set(resp.resHeaders); 11 | res.send(resp.body); 12 | } 13 | function onError(err) { 14 | debug(err); 15 | handleError(err.message, res, 400); 16 | } 17 | 18 | } 19 | 20 | module.exports = { 21 | processREST: processREST 22 | }; -------------------------------------------------------------------------------- /public/partials/addapiform.html: -------------------------------------------------------------------------------- 1 |

Mock a REST, SOAP or MQ Service

2 |
3 | 4 | 5 |
6 |
7 | 8 |
9 |
10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /public/partials/restClient.html: -------------------------------------------------------------------------------- 1 |

Test Service

2 |

**This service is stopped.

3 |

You can test your mocked service here. There are individual requests below service detail section. To test a request each request section has a Send button.

4 |
5 | 6 |
7 | 8 | 9 | 10 |
11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # import base image 2 | FROM node:8-alpine 3 | 4 | # expose HTTP 5 | EXPOSE 8080 6 | 7 | # install system dependencies 8 | RUN apk update && apk add --no-cache git python py-pip make g++ 9 | 10 | # copy the app src to the container 11 | RUN mkdir -p /app 12 | COPY . /app 13 | WORKDIR /app 14 | 15 | 16 | 17 | # install app dependencies 18 | ARG REG_URL=https://registry.npmjs.org/ 19 | RUN npm config set registry $REG_URL 20 | RUN npm install 21 | RUN npm install -g bower 22 | RUN bower install --allow-root 23 | 24 | # fix for k8s permission problems 25 | RUN mkdir /.pm2 && chmod 777 /.pm2 && chmod 777 /app 26 | 27 | # start app 28 | CMD npm run serve 29 | -------------------------------------------------------------------------------- /lib/remove-route/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | *.swp 30 | -------------------------------------------------------------------------------- /lib/remove-route/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-remove-route", 3 | "version": "0.1.1", 4 | "description": "Remove a route in express at runtime.", 5 | "main": "index.js", 6 | "scripts": { 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git+https://github.com/brennancheung/express-remove-route.git" 11 | }, 12 | "keywords": [ 13 | "express", 14 | "route", 15 | "routes", 16 | "routing", 17 | "delete", 18 | "remove" 19 | ], 20 | "author": "Brennan Cheung ", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/brennancheung/express-remove-route/issues" 24 | }, 25 | "homepage": "https://github.com/brennancheung/express-remove-route#readme" 26 | } 27 | -------------------------------------------------------------------------------- /models/db/index.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const debug = require('debug')('default'); 3 | 4 | const mongoUser = process.env.MONGODB_USER; 5 | const mongoPass = process.env.MONGODB_PASSWORD; 6 | const mongoHost = process.env.MONGODB_HOST; 7 | 8 | let mongoURI; 9 | if (mongoUser && mongoPass) { 10 | mongoURI = 'mongodb://' + mongoUser + ':' + mongoPass + '@' + mongoHost; 11 | } 12 | else { 13 | mongoURI = 'mongodb://' + mongoHost; 14 | } 15 | 16 | const Service = require('../http/Service'); 17 | 18 | Service.on('index', function(err) { 19 | if (err) debug(err); // error occurred during index creation 20 | else debug('Service models indexed successfully'); 21 | }) 22 | 23 | module.exports = mongoose.connect(mongoURI, { useMongoClient: true }); -------------------------------------------------------------------------------- /tests/resources/Invoke/invoke_test-reqs.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "test": "one", 4 | "test2:": true, 5 | "test3:": 12345, 6 | "testObj:": { 7 | "innerTest:": "testo", 8 | "innterTest2:": "testooo" 9 | } 10 | }, 11 | { 12 | "test": "two", 13 | "test2:": true, 14 | "test3:": 12345, 15 | "testObj:": { 16 | "innerTest:": "testo", 17 | "innterTest2:": "testooo" 18 | } 19 | }, 20 | { 21 | "test": "three", 22 | "test2:": true, 23 | "test3:": 12345, 24 | "testObj:": { 25 | "innerTest:": "testo", 26 | "innterTest2:": "testooo" 27 | } 28 | }, 29 | { 30 | "test": "four", 31 | "test2:": true, 32 | "test3:": 12345, 33 | "testObj:": { 34 | "innerTest:": "testo", 35 | "innterTest2:": "testooo" 36 | } 37 | } 38 | ] -------------------------------------------------------------------------------- /controllers/userController.js: -------------------------------------------------------------------------------- 1 | const User = require('../models/common/User'); 2 | 3 | function getUsers(req, res) { 4 | User.find({}, function(err, users) { 5 | if (err) { 6 | handleError(err, res, 500); 7 | return; 8 | } 9 | 10 | res.json(users); 11 | }); 12 | } 13 | 14 | function delUser(req, res) { 15 | User.findOneAndRemove({ uid : req.params.name }, function(err) { 16 | if (err) { 17 | handleError(err, res, 400); 18 | return; 19 | } 20 | res.json({ 'message' : 'deleted user', 'username' : req.params.name }); 21 | }); 22 | } 23 | 24 | function getAdminUser(req, res) { 25 | res.json(process.env.MOCKIATO_ADMIN); 26 | } 27 | 28 | module.exports = { 29 | getUsers: getUsers, 30 | delUser: delUser, 31 | getAdminUser: getAdminUser 32 | } -------------------------------------------------------------------------------- /controllers/rrpairController.js: -------------------------------------------------------------------------------- 1 | const Service = require('../models/http/Service'); 2 | const MQService = require('../models/mq/MQService'); 3 | 4 | 5 | 6 | function getPairsByServiceId(req, res) { 7 | Service.findById(req.params.serviceId, function(err, service) { 8 | if (err) { 9 | handleError(err, res, 500); 10 | return; 11 | } 12 | 13 | if (service) { 14 | res.json(service.rrpairs); 15 | } 16 | else { 17 | MQService.findById(req.params.serviceId, function(error, mqService) { 18 | if (error) { 19 | handleError(error, res, 500); 20 | return; 21 | } 22 | 23 | return res.json(mqService.rrpairs); 24 | }); 25 | } 26 | }); 27 | } 28 | 29 | module.exports = { 30 | getPairsByServiceId: getPairsByServiceId 31 | }; 32 | -------------------------------------------------------------------------------- /lib/auth/ldap.js: -------------------------------------------------------------------------------- 1 | const passport = require('passport'); 2 | const LdapStrategy = require('passport-ldapauth'); 3 | 4 | // info required for LDAP bind 5 | const adUser = process.env.AD_USER; 6 | const adPass = process.env.AD_PASS; 7 | 8 | const ldapUrl = process.env.LDAP_URL; 9 | const ldapSearchBase = process.env.LDAP_SEARCH_BASE; 10 | // fix for special character issue in OpenShift 11 | const ldapSearchFilter = replaceAmp(process.env.LDAP_SEARCH_FILTER); 12 | 13 | passport.use(new LdapStrategy({ 14 | server: { 15 | url: ldapUrl, 16 | bindDN: adUser, 17 | bindCredentials: adPass, 18 | searchBase: ldapSearchBase, 19 | searchFilter: ldapSearchFilter 20 | } 21 | })); 22 | 23 | function replaceAmp(str) { 24 | const uni = '\\u0026'; 25 | if (str.includes(uni)) { 26 | return str.replace(uni, '&'); 27 | } 28 | return str; 29 | } 30 | -------------------------------------------------------------------------------- /public/partials/login.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 | 7 |
8 |
9 | 10 | 11 |
12 | 13 |
14 |
15 | Using Mockiato externally? Register an account here. 16 | 17 |
18 |
-------------------------------------------------------------------------------- /tests/test-report.js: -------------------------------------------------------------------------------- 1 | const app = require('../app'); 2 | const request = require('supertest').agent(app); 3 | const test = require('./test.js'); 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | const mockUser = { 12 | username: getRandomString(), 13 | mail: getRandomString() + '@noreply.com', 14 | password: getRandomString() 15 | } 16 | 17 | const mockGroup = { 18 | name: getRandomString() 19 | }; 20 | 21 | function getRandomString() { 22 | return Math.random().toString(36).substring(2, 15); 23 | } 24 | 25 | 26 | 27 | describe('Report Tests', function() { 28 | this.timeout(15000); 29 | describe('Report Tests',function(){ 30 | it('Gets the full report',function(done){ 31 | request 32 | .get('/api/report') 33 | .expect(200,done); 34 | }); 35 | }); 36 | 37 | 38 | 39 | 40 | 41 | }); 42 | 43 | -------------------------------------------------------------------------------- /examples/rest-xml-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "sut": { 3 | "name": "test" 4 | }, 5 | "name": "rr-test-xml", 6 | "type": "REST", 7 | "basePath": "/v2", 8 | "rrpairs": [{ 9 | "path": "/test/resource", 10 | "verb": "POST", 11 | "payloadType": "XML", 12 | "reqHeaders": {"Content-Type":"text/xml"}, 13 | "reqData": "123", 14 | "resStatus": 201, 15 | "resHeaders": { "Content-Type":"text/xml", "x-virt-app": "Mockiato"}, 16 | "resData": "hi" 17 | }, 18 | { 19 | "path": "/test/resource", 20 | "verb": "POST", 21 | "payloadType": "XML", 22 | "reqHeaders": {"Content-Type":"text/xml"}, 23 | "reqData": "1234", 24 | "resStatus": 201, 25 | "resHeaders": { "Content-Type":"text/xml" }, 26 | "resData": "hello" 27 | }] 28 | } 29 | -------------------------------------------------------------------------------- /public/partials/viewRecorder.html: -------------------------------------------------------------------------------- 1 |

Finalize Recording

2 | 3 |
4 |
5 | 6 | 7 |
8 |
9 | 10 |
11 |
12 |
13 | 14 | 15 | 21 | -------------------------------------------------------------------------------- /examples/rest-json-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "sut": { 3 | "name": "test" 4 | }, 5 | "name": "rr-test", 6 | "type": "REST", 7 | "basePath": "/v2", 8 | "rrpairs": [{ 9 | "path": "/test/resource", 10 | "verb": "POST", 11 | "payloadType": "JSON", 12 | "reqHeaders": { "Content-Type":"application/json" }, 13 | "reqData": { "key": 123 }, 14 | "resStatus": 200, 15 | "resHeaders": { "Content-Type":"application/json", "x-virt-app": "Mockiato"}, 16 | "resData": { "msg":"hi" } 17 | }, 18 | { 19 | "path": "/test/resource", 20 | "verb": "POST", 21 | "payloadType": "JSON", 22 | "reqHeaders": { "Content-Type":"application/json" }, 23 | "reqData": { "key": 1234 }, 24 | "resStatus": 202, 25 | "resHeaders": { "Content-Type":"application/json" }, 26 | "resData": { "msg":"hello" } 27 | }] 28 | } 29 | -------------------------------------------------------------------------------- /examples/soap-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "sut": { 3 | "name": "test" 4 | }, 5 | "name": "soap-test", 6 | "type": "SOAP", 7 | "rrpairs": [ 8 | { 9 | "verb": "POST", 10 | "payloadType": "XML", 11 | "reqData": "IBM", 12 | "resStatus": 200, 13 | "resHeaders": { 14 | "Content-Type": "text/xml" 15 | }, 16 | "resData": "34.5" 17 | } 18 | ], 19 | "basePath": "/soap" 20 | } 21 | -------------------------------------------------------------------------------- /winston.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const winston = require('winston'); 3 | 4 | let filename = process.env.MOCKIATO_LOG_FILE || '/dev/null'; 5 | 6 | const transports = [ new winston.transports.Stream({ 7 | stream: fs.createWriteStream(filename) 8 | })]; 9 | 10 | if (process.env.MOCKIATO_SPLUNK_ENABLED) { 11 | const SplunkStreamEvent = require('winston-splunk-httplogger'); 12 | 13 | const splunkSettings = { 14 | url: process.env.MOCKIATO_SPLUNK_URL, 15 | index: process.env.MOCKIATO_SPLUNK_INDEX, 16 | token: process.env.MOCKIATO_SPLUNK_TOKEN, 17 | host: process.env.MOCKIATO_SPLUNK_HOST, 18 | level: 'info', 19 | sourcetype: 'mockiato:app_logs', 20 | source:'mockiato', 21 | ssl: 'true' 22 | }; 23 | transports.push(new SplunkStreamEvent({ splunk: splunkSettings })); 24 | } 25 | 26 | logger = winston.createLogger({ 27 | transports: transports, 28 | format: winston.format.combine( 29 | winston.format.colorize(), 30 | winston.format.timestamp(), 31 | winston.format.json() 32 | ), 33 | }); 34 | 35 | module.exports = logger; 36 | -------------------------------------------------------------------------------- /lib/remove-route/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Brennan Cheung 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /public/partials/updateForm.html: -------------------------------------------------------------------------------- 1 |

Update Mock Service

2 |
3 | 4 |
5 |
6 |
7 | 10 |
11 |
12 | 13 |
14 |
15 | 16 | 17 | 18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 | 26 | 32 | -------------------------------------------------------------------------------- /controllers/mqInfoController.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | const debug = require('debug')('default'); 3 | const mockiatoJmsUri = process.env.MOCKIATO_JMS_URI; 4 | 5 | function getMQInfo(req, res) { 6 | if (!mockiatoJmsUri) { 7 | debug('MOCKIATO_JMS_URI not set'); 8 | handleError('Could not retrieve MQ info', res, 500); 9 | return; 10 | } 11 | 12 | request(mockiatoJmsUri + '/env', function(err, resp, body) { 13 | if (err) { 14 | debug(err); 15 | handleError('Could not retrieve MQ info', res, 500); 16 | return; 17 | } 18 | 19 | let data = parseInfo(body); 20 | 21 | res.json(data); 22 | }); 23 | } 24 | 25 | function parseInfo(body) { 26 | let obj = JSON.parse(body); 27 | let query = process.env.MOCKIATO_JMS_QUERY; 28 | let info = unflattenObject(obj[query]); 29 | 30 | if (!info || !info.mockiato) { 31 | return { msg: 'Could not retrieve MQ info' }; 32 | } 33 | let final = info.mockiato.mq; 34 | 35 | final.defaults = { 36 | manager: process.env.DEFAULT_QUEUE_MANAGER, 37 | reqQueue: process.env.DEFAULT_REQUEST_QUEUE 38 | }; 39 | 40 | return final; 41 | } 42 | 43 | module.exports = { 44 | getMQInfo: getMQInfo 45 | }; -------------------------------------------------------------------------------- /docs/Mockiato Notice.txt: -------------------------------------------------------------------------------- 1 | Mockiato 2 | Copyright 2018 Optum 3 | 4 | Project Description: 5 | ==================== 6 | 7 | Mockiato is designed for API virtualization. With Mockiato, you can virtualize REST APIs, SOAP services, and even message-based middleware such as ActiveMQ. You can generate realistic data for testing, and export it to JSON, XML, or CSV. In seconds, via an API call or using our web-based UI, you can setup virtual endpoints that simulate your production APIs. These virtual endpoints are ideal for testing, sandboxing, knowledge transfer, and driving rapid development. 8 | 9 | 10 | 11 | Mockiato Authors: 12 | JD Weeks, ©Optum 2018 13 | 14 | Additional Copyright notices 15 | 16 | Copyright (c) 2014 Hidenari Nozaki and contributors | Licensed under the MIT license */ 17 | (c) 2015 Philipp Alferov License: MIT 18 | (c) 2010-2016 Google, Inc. http://angularjs.org License: MIT 19 | (c) 2010-2014 Google, Inc. http://angularjs.org License: MIT 20 | 21 | Additional License Links 22 | 23 | https://opensource.org/licenses/BSD-3-Clause 24 | https://opensource.org/licenses/MIT 25 | 26 | 27 | 28 | Added Files: 29 | ============ 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Modified Files: 38 | =============== 39 | -------------------------------------------------------------------------------- /tests/resources/Match_Template/requests.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "desc": "Tests matching no-condition template", 4 | "status": 200, 5 | "req": { 6 | "a": true, 7 | "b": 123 8 | } 9 | }, 10 | { 11 | "desc": "Tests non-matching no-condition template", 12 | "status": 404, 13 | "req": { 14 | "a": false 15 | } 16 | }, 17 | { 18 | "desc": "Tests matching condition template", 19 | "status": 200, 20 | "req": { 21 | "c": 3, 22 | "d": "555-55-1234", 23 | "e": "words go here", 24 | "f": true 25 | } 26 | }, 27 | { 28 | "desc": "Tests non-matching condition 'regex'", 29 | "status": 404, 30 | "req": { 31 | "c": 3, 32 | "d": "555-55-123z", 33 | "e": "words go here", 34 | "f": true 35 | } 36 | }, 37 | { 38 | "desc": "Tests non-matching condition 'lt'", 39 | "status": 404, 40 | "req": { 41 | "c": 5, 42 | "d": "555-55-1234", 43 | "e": "words go here", 44 | "f": true 45 | } 46 | }, 47 | { 48 | "desc": "Tests non-matching condition 'any'", 49 | "status": 404, 50 | "req": { 51 | "c": 3, 52 | "d": "555-55-1234", 53 | "f": true 54 | } 55 | }, 56 | { 57 | "desc": "Tests non-matching on exact reqData match", 58 | "status": 404, 59 | "req": { 60 | "c": 3, 61 | "d": "555-55-1234", 62 | "f": true 63 | } 64 | } 65 | ] -------------------------------------------------------------------------------- /public/partials/templateForm.html: -------------------------------------------------------------------------------- 1 |

Import Mock Service

2 |
3 |
4 |

Please import a virtual service in JSON format. You may use the JSON document that Mockiato creates with it's export function or create one from scratch in this format.

5 |
6 |
7 |
8 |
9 | Import Template 10 |
11 |
12 | 13 |
14 |
❌  {{uploadErrMessage}}
15 |
16 |
17 |
18 |

Preview

19 |
20 | {{importTemp.name}} 21 |

22 |
{{previewTemp}}
23 |
24 |
25 |
26 | -------------------------------------------------------------------------------- /lib/auth/local.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const fs = require('fs'); 3 | const express = require('express'); 4 | const passport = require('passport'); 5 | const LocalStrategy = require('passport-local'); 6 | 7 | const router = express.Router(); 8 | const User = mongoose.model('User'); 9 | 10 | passport.use(new LocalStrategy(User.authenticate())); 11 | 12 | router.post('/', function (req, res) { 13 | User.register(new User({ uid: req.body.username, mail: req.body.mail }), req.body.password, function (err, user) { 14 | if (err) { 15 | var errName = err.name; 16 | if (errName == 'UserExistsError') { 17 | res.append('redirectUrl', '/register?ErrHint=' + encodeURIComponent('DU')); 18 | res.status(302); 19 | res.send('Error : This username already exist.'); 20 | }else{ 21 | res.append('redirectUrl', '/register?ErrHint=' + encodeURIComponent('SE')); 22 | res.status(302); 23 | res.send('Something went wrong.'); 24 | } 25 | } 26 | else { 27 | res.append('redirectUrl', '/#regS'); 28 | res.status(302); 29 | res.send('User Registration Successful!'); 30 | } 31 | }); 32 | }); 33 | 34 | router.get('/', function (req, res) { 35 | const htmlForm = fs.readFileSync('./assets/register.html'); 36 | res.set('Content-Type', 'text/html'); 37 | res.send(htmlForm); 38 | }); 39 | 40 | module.exports = router; 41 | -------------------------------------------------------------------------------- /lib/pm2/manager.js: -------------------------------------------------------------------------------- 1 | var pm2 = require('pm2'); 2 | 3 | function messageAll(message) { 4 | return new Promise(function(resolve, reject) { 5 | const pm2_worker_ids = []; 6 | 7 | if (process.env.MOCKIATO_MODE === 'single') { 8 | return resolve(pm2_worker_ids); 9 | } 10 | 11 | pm2.connect(true, function(err) { 12 | if (err) { 13 | pm2.disconnect(); 14 | return reject(err); 15 | } 16 | pm2.list(function(err, data) { 17 | if (err) { 18 | pm2.disconnect(); 19 | return reject(err); 20 | } 21 | 22 | for (let i in data) { 23 | if (data.hasOwnProperty(i)) { 24 | if (process.pid !== data[i].pid) 25 | pm2_worker_ids.push(data[i].pm2_env.pm_id); 26 | } 27 | } 28 | 29 | pm2_worker_ids.forEach(function(id){ 30 | setTimeout(function() { 31 | pm2.sendDataToProcessId(id, { 32 | type: 'process:msg', 33 | data: message, // your actual data object you want to pass to the worker 34 | id: id, // ... and target pm_id here 35 | topic: 'service-register' 36 | }, function(err, result) { 37 | if (err) console.error(err); 38 | }); 39 | }, 100); 40 | }); 41 | 42 | resolve(pm2_worker_ids); 43 | pm2.disconnect(); 44 | }); 45 | }); 46 | }); 47 | } 48 | 49 | module.exports = { 50 | messageAll: messageAll 51 | }; -------------------------------------------------------------------------------- /public/css/angucomplete-alt.css: -------------------------------------------------------------------------------- 1 | .angucomplete-holder { 2 | position: relative; 3 | } 4 | 5 | .angucomplete-dropdown { 6 | border-color: #ececec; 7 | border-width: 1px; 8 | border-style: solid; 9 | border-radius: 2px; 10 | width: 250px; 11 | padding: 6px; 12 | cursor: pointer; 13 | z-index: 9999; 14 | position: absolute; 15 | /*top: 32px; 16 | left: 0px; 17 | */ 18 | margin-top: -6px; 19 | background-color: #ffffff; 20 | } 21 | 22 | .angucomplete-searching { 23 | color: #acacac; 24 | font-size: 14px; 25 | } 26 | 27 | .angucomplete-description { 28 | font-size: 14px; 29 | } 30 | 31 | .angucomplete-row { 32 | padding: 5px; 33 | color: #000000; 34 | margin-bottom: 4px; 35 | clear: both; 36 | } 37 | 38 | .angucomplete-selected-row { 39 | background-color: lightblue; 40 | color: #ffffff; 41 | } 42 | 43 | .angucomplete-image-holder { 44 | padding-top: 2px; 45 | float: left; 46 | margin-right: 10px; 47 | margin-left: 5px; 48 | } 49 | 50 | .angucomplete-image { 51 | height: 34px; 52 | width: 34px; 53 | border-radius: 50%; 54 | border-color: #ececec; 55 | border-style: solid; 56 | border-width: 1px; 57 | } 58 | 59 | .angucomplete-image-default { 60 | /* Add your own default image here 61 | background-image: url('/assets/default.png'); 62 | */ 63 | background-position: center; 64 | background-size: contain; 65 | height: 34px; 66 | width: 34px; 67 | } 68 | -------------------------------------------------------------------------------- /models/http/Recording.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const Service = require('./Service'); 3 | const System = require('../common/System'); 4 | const constants = require('../../lib/util/constants'); 5 | 6 | const recordingSchema = new mongoose.Schema({ 7 | service: { 8 | type: Service.schema, 9 | required: [true, constants.REQUIRED_SERVICE_ERR] 10 | }, 11 | sut: { 12 | type: System.schema, 13 | required: [true, constants.REQUIRED_SUT_ERR] 14 | }, 15 | path : { 16 | type: String, 17 | required: [true, constants.REQUIRED_BASEPATH_ERR] 18 | }, 19 | remoteHost : { 20 | type: String, 21 | required: [true, constants.REMOTE_HOST_NOT_ERR] 22 | }, 23 | remotePort : { 24 | type: Number, 25 | required: [true, constants.REMOTE_PORT_NOT_ERR] 26 | }, 27 | payloadType : String, 28 | protocol : String, 29 | headerMask : Array, 30 | name: { 31 | type: String, 32 | required: [true, constants.REQUIRED_RECORDER_SERVICE_NAME_ERR] 33 | }, 34 | active : Boolean, 35 | ssl : Boolean, 36 | running: { 37 | type: Boolean, 38 | default: true 39 | }, 40 | filters:{ 41 | enabled : { 42 | type: Boolean, 43 | default : false 44 | }, 45 | bodyStrings : [String], 46 | headers : [{key:String,value:String}], 47 | statuses : [Number] 48 | } 49 | }); 50 | 51 | recordingSchema.set('usePushEach', true); 52 | module.exports = mongoose.model('Recording', recordingSchema); 53 | 54 | 55 | -------------------------------------------------------------------------------- /tests/resources/Recorder/Record_Test_Base_Service.json: -------------------------------------------------------------------------------- 1 | { 2 | "updatedAt": "2019-02-14T16:39:01.206Z", 3 | "createdAt": "2019-02-14T16:39:01.206Z", 4 | "sut": { 5 | "name": "RecordTest", 6 | "__v": 0, 7 | "members": [ 8 | "jsmith" 9 | ] 10 | }, 11 | "name": "Record Test Base", 12 | "type": "REST", 13 | "basePath": "/recordme", 14 | "lastUpdateUser": { 15 | "uid": "jsmith", 16 | "mail": "john_smith@asd.com", 17 | "_id": "5c6599a5b75e2abea8145734" 18 | }, 19 | "liveInvocation": { 20 | "liveFirst": false, 21 | "recordedRRPairs": [], 22 | "record": false, 23 | "failStrings": [ 24 | "" 25 | ], 26 | "failStatusCodes": [ 27 | null 28 | ] 29 | }, 30 | "running": true, 31 | "txnCount": 0, 32 | "delayMax": 200, 33 | "delay": 100, 34 | "rrpairs": [ 35 | { 36 | "verb": "POST", 37 | "payloadType": "JSON", 38 | "reqHeaders": { 39 | "Content-Type": "application/json" 40 | }, 41 | "reqData": { 42 | "test": "one", 43 | "test2:": true, 44 | "test3:": 12345, 45 | "testObj:": { 46 | "innerTest:": "testo", 47 | "innterTest2:": "testooo" 48 | } 49 | }, 50 | "resHeaders": { 51 | "Content-Type": "application/json" 52 | }, 53 | "resData": { 54 | "response": "This is a good response" 55 | }, 56 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 57 | "resDataString": "{\"response\":\"This is a good response\"}", 58 | "resStatus": 200 59 | } 60 | ], 61 | "matchTemplates": [ 62 | "" 63 | ] 64 | } -------------------------------------------------------------------------------- /tests/resources/random/Random_Test_Base_Service.json: -------------------------------------------------------------------------------- 1 | { 2 | "updatedAt": "2019-02-14T16:39:01.206Z", 3 | "createdAt": "2019-02-14T16:39:01.206Z", 4 | "sut": { 5 | "name": "RecordTest", 6 | "__v": 0, 7 | "members": [ 8 | "jsmith" 9 | ] 10 | }, 11 | "name": "Record Test Base", 12 | "type": "REST", 13 | "basePath": "/recordme", 14 | "lastUpdateUser": { 15 | "uid": "jsmith", 16 | "mail": "john_smith@asd.com", 17 | "_id": "5c6599a5b75e2abea8145734" 18 | }, 19 | "liveInvocation": { 20 | "liveFirst": false, 21 | "recordedRRPairs": [], 22 | "record": false, 23 | "failStrings": [ 24 | "" 25 | ], 26 | "failStatusCodes": [ 27 | null 28 | ] 29 | }, 30 | "running": true, 31 | "txnCount": 0, 32 | "delayMax": 200, 33 | "delay": 100, 34 | "rrpairs": [ 35 | { 36 | "verb": "POST", 37 | "payloadType": "JSON", 38 | "reqHeaders": { 39 | "Content-Type": "application/json" 40 | }, 41 | "reqData": { 42 | "test": "one", 43 | "test2:": true, 44 | "test3:": 12345, 45 | "testObj:": { 46 | "innerTest:": "testo", 47 | "innterTest2:": "testooo" 48 | } 49 | }, 50 | "resHeaders": { 51 | "Content-Type": "application/json" 52 | }, 53 | "resData": { 54 | "response": "NAME : {{random:name:nationality,it:middle_initial,true}}" 55 | }, 56 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 57 | "resDataString": "{\"response\":\"This is a good response\"}", 58 | "resStatus": 200 59 | } 60 | ], 61 | "matchTemplates": [ 62 | "" 63 | ] 64 | } -------------------------------------------------------------------------------- /public/js/app/controllers/serviceHeader.js: -------------------------------------------------------------------------------- 1 | var ctrl = angular.module("mockapp.controllers") 2 | .controller("serviceHeaderController",['suggestionsService','$scope','modalService','domManipulationService', 3 | function(suggestionsService,$scope,modalService,domManipulationService){ 4 | $scope.addFailStatus = function () { 5 | $scope.servicevo.failStatuses.push({ val: '' }); 6 | } 7 | $scope.removeFailStatus = function (index) { 8 | $scope.servicevo.failStatuses.splice(index, 1); 9 | } 10 | $scope.addFailString = function () { 11 | $scope.servicevo.failStrings.push({ val: '' }); 12 | } 13 | $scope.removeFailString = function (index) { 14 | $scope.servicevo.failStrings.splice(index, 1); 15 | } 16 | $scope.addTemplate = function () { 17 | $scope.servicevo.matchTemplates.push({ id: 0, val: '' }); 18 | }; 19 | 20 | $scope.removeTemplate = function (index) { 21 | $scope.servicevo.matchTemplates.splice(index, 1); 22 | }; 23 | $scope.showLiveInvocationHelp = function(){ 24 | modalService.showLiveInvocationHelp(); 25 | }; 26 | $scope.expandRequest = function(servicevo){ 27 | var ele = document.getElementsByClassName("defaultResponsePayload")[0]; 28 | servicevo.reqExpanded = true; 29 | domManipulationService.expandTextarea(ele); 30 | } 31 | $scope.collapseRequest = function(servicevo){ 32 | var ele = document.getElementsByClassName("defaultResponsePayload")[0]; 33 | servicevo.reqExpanded = false; 34 | domManipulationService.collapseTextarea(ele); 35 | } 36 | 37 | 38 | }]); -------------------------------------------------------------------------------- /lib/restCLI/restClient.js: -------------------------------------------------------------------------------- 1 | var Client = require('node-rest-client').Client; 2 | const constants = require('../util/constants'); 3 | 4 | var options = { 5 | mimetypes: { 6 | xml: ["application/xml"] 7 | } 8 | }; 9 | var client = new Client(options); 10 | 11 | function processRequest(req) { 12 | return new Promise(function (resolve, reject) { 13 | fireRequest(req, function (response) { 14 | if (response.message) 15 | return reject(response); 16 | else 17 | return resolve(response); 18 | }); 19 | }); 20 | } 21 | 22 | var fireRequest = function (req, message) { 23 | const reqJson = JSON.parse(req); 24 | if (!reqJson.basePath) 25 | return message(new Error(constants.REST_CLIENT_NO_BP)); 26 | else if (!reqJson.method) 27 | return message(new Error(constants.REST_CLIENT_NO_METHOD)); 28 | 29 | var args = { 30 | data: reqJson.reqData, 31 | path: reqJson.relativePath, 32 | parameters: reqJson.queries, 33 | headers: reqJson.reqHeaders 34 | }; 35 | 36 | var basePath = reqJson.basePath; 37 | if (reqJson.relativePath && reqJson.relativePath.startsWith('/')) 38 | basePath = reqJson.basePath + reqJson.relativePath; 39 | else if (reqJson.relativePath) 40 | basePath = reqJson.basePath + '/' + reqJson.relativePath; 41 | 42 | client.registerMethod("funtionToCall", basePath, reqJson.method); 43 | 44 | client.methods.funtionToCall(args, function (data, response) { 45 | var resp = { 46 | body: data, 47 | status: response.statusCode, 48 | resHeaders: response.headers 49 | }; 50 | return message(resp); 51 | }); 52 | } 53 | 54 | module.exports = { 55 | processRequest: processRequest 56 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mockiato", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www", 7 | "serve": "pm2 start ./bin/www -i ${MOCKIATO_NODES:=1} --name app --no-daemon", 8 | "test": "nyc --reporter=text --reporter=html mocha tests --exit" 9 | }, 10 | "nyc": { 11 | "exclude": [ 12 | "tests", 13 | "lib/pm2", 14 | "lib/remove-route", 15 | "winston.js" 16 | ] 17 | }, 18 | "dependencies": { 19 | "body-parser": "^1.18.3", 20 | "chance": "^1.0.18", 21 | "compression": "^1.7.3", 22 | "cookie-parser": "~1.4.3", 23 | "debug": "^2.6.9", 24 | "dotenv": "^5.0.1", 25 | "express": "4.16.4", 26 | "express-actuator": "^1.3.0", 27 | "express-jwt": "^5.3.1", 28 | "express-session": "1.16.1", 29 | "fuse": "^0.4.0", 30 | "helmet": "^3.12.1", 31 | "http-string-parser": "0.0.6", 32 | "jsonwebtoken": "^8.4.0", 33 | "lodash": ">=4.17.13", 34 | "mongoose": "^4.13.17", 35 | "morgan": "^1.9.1", 36 | "multer": "^1.3.1", 37 | "node-dir": "^0.1.17", 38 | "node-rest-client": "^3.1.0", 39 | "node-schedule": "^1.3.1", 40 | "object-hash": "^1.3.1", 41 | "passport": "^0.4.0", 42 | "passport-ldapauth": "^2.0.0", 43 | "passport-local": "^1.0.0", 44 | "passport-local-mongoose": "^5.0.0", 45 | "pm2": "^3.2.9", 46 | "pretty-data": "^0.40.0", 47 | "request": "^2.88.0", 48 | "soap": "^0.24.0", 49 | "swagger-ui-express": "^2.0.14", 50 | "underscore": "^1.9.1", 51 | "unzip2": "^0.2.5", 52 | "winston": "^3.1.0", 53 | "winston-splunk-httplogger": "^1.2.2", 54 | "xml2js": "0.4.19", 55 | "yamljs": "^0.3.0" 56 | }, 57 | "devDependencies": { 58 | "mocha": "^5.2.0", 59 | "nyc": "^13.1.0", 60 | "supertest": "^3.3.0" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /models/mq/MQPair.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | xml2js = require("xml2js"); 3 | const constants = require('../../lib/util/constants'); 4 | 5 | const pairSchema = new mongoose.Schema({ 6 | label: String, 7 | payloadType: String, 8 | reqData: { 9 | type: mongoose.Schema.Types.Mixed, 10 | validate: { 11 | validator: function (v) { 12 | /* Making validation true in case of DraftService. 13 | In other cases, apply normal validations. */ 14 | try{ 15 | if (this.parent().parent().constructor.modelName === 'DraftService') return true; //else continue validations. 16 | } catch (e) {/* Not a draft service so continue below validations*/ } 17 | try{ 18 | xml2js.parseString(v, function (err, result) { 19 | if(err) throw err; 20 | }); 21 | return true; 22 | }catch(e){return false;} 23 | }, 24 | message: constants.MQ_VALID_XML_REQ_ERR 25 | }, 26 | required: [true, constants.REQUIRED_REQUEST_PAYLOAD_ERR] 27 | }, 28 | resData: { 29 | type: mongoose.Schema.Types.Mixed, 30 | validate: { 31 | validator: function (v) { 32 | /* Making validation true in case of DraftService. 33 | In other cases, apply normal validations. */ 34 | try{ 35 | if (this.parent().parent().constructor.modelName === 'DraftService') return true; //else continue validations. 36 | } catch (e) {/* Not a draft service so continue below validations*/ } 37 | try{ 38 | xml2js.parseString(v, function (err, result) { 39 | if(err) throw err; 40 | }); 41 | return true; 42 | }catch(e){return false;} 43 | }, 44 | message: constants.MQ_VALID_XML_RES_ERR 45 | }, 46 | required: [true, constants.REQUIRED_RESPONSE_PAYLOAD_ERR] 47 | } 48 | }); 49 | 50 | module.exports = mongoose.model('MQPair', pairSchema); 51 | -------------------------------------------------------------------------------- /bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | const app = require('../app'); 8 | const debug = require('debug')('default'); 9 | const http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | const port = normalizePort(process.env.PORT || '8080'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | const server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | const port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; 62 | 63 | // handle specific listen errors with friendly messages 64 | switch (error.code) { 65 | case 'EACCES': 66 | debug(bind + ' requires elevated privileges'); 67 | process.exit(1); 68 | break; 69 | case 'EADDRINUSE': 70 | debug(bind + ' is already in use'); 71 | process.exit(1); 72 | break; 73 | default: 74 | throw error; 75 | } 76 | } 77 | 78 | /** 79 | * Event listener for HTTP server "listening" event. 80 | */ 81 | 82 | function onListening() { 83 | const addr = server.address(); 84 | const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; 85 | debug('Listening on ' + bind); 86 | } 87 | -------------------------------------------------------------------------------- /examples/hello-service.wsdl: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | 45 | WSDL File for HelloService 46 | 47 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /lib/util/fuse.js: -------------------------------------------------------------------------------- 1 | const fuse = require('fuse'); 2 | const fs = require('fs'); 3 | const publicPath = "/public"; 4 | const partialsPath = "/partials"; 5 | const outputPath = "/fusepartials"; 6 | 7 | function fuseFile(filename,dontRecurse){ 8 | fuse.fuseFile(__basedir + publicPath + partialsPath + "/" + filename, __basedir + publicPath + outputPath + "/" + filename, function (err, results) { 9 | if(err){ 10 | console.log("ERROR: " + err); 11 | }else{ 12 | if(!dontRecurse && (!process.env.NODE_ENV || process.env.NODE_ENV.toLowerCase() != "production")){ 13 | fs.watchFile(__basedir + publicPath + partialsPath + "/" + filename,function(type,name){ 14 | fuseFile(filename,true); 15 | }); 16 | if(results.fused.length){ 17 | results.fused.forEach(function(fusedFile){ 18 | fs.watchFile(__basedir + publicPath + partialsPath + fusedFile,function(type,name){ 19 | 20 | fuseFile(filename,true); 21 | }); 22 | 23 | }); 24 | } 25 | } 26 | } 27 | 28 | }); 29 | } 30 | 31 | function fuseAllFiles(){ 32 | if (!fs.existsSync(__basedir + publicPath + outputPath)){ 33 | fs.mkdirSync(__basedir + publicPath + outputPath); 34 | } 35 | fs.readdir(__basedir + publicPath+partialsPath,function(err,results){ 36 | var fileList = []; 37 | results.forEach(function(file){ 38 | 39 | var split = file.split("."); 40 | if(split[split.length-1].toLowerCase() == "html") 41 | fileList.push(file); 42 | 43 | }); 44 | fileList.forEach(function(file){ 45 | fuseFile(file); 46 | }); 47 | }); 48 | 49 | } 50 | 51 | module.exports = { 52 | fuseAllFiles : fuseAllFiles 53 | } 54 | -------------------------------------------------------------------------------- /routes/recording.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Router for recording 3 | */ 4 | 5 | const express = require('express'); 6 | const recordingRouter = express.Router(); 7 | const apiRouter = express.Router(); 8 | const removeRoute = require('../lib/remove-route'); 9 | 10 | var activeRecorders = {}; 11 | 12 | 13 | 14 | 15 | /** 16 | * Binds a given recorder to a path for all traffic 17 | * @param {String} path 18 | * @param {Recorder} recorder 19 | */ 20 | function bindRecorderToPath(path,recorder){ 21 | recordingRouter.all("/live" + path,recordController.Recorder.prototype.incomingRequest.bind(recorder)); 22 | } 23 | 24 | 25 | /** 26 | * Unbinds a recorder from live traffic 27 | */ 28 | function unbindRecorder(recorder){ 29 | var path = "/recording/live/" + recorder.model.sut.name + recorder.model.path + "*"; 30 | removeRoute(require('../app'),path); 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | //Early exports declaration because of circular dependency from recorderController.js 40 | module.exports = { 41 | recordingRouter: recordingRouter, 42 | apiRouter : apiRouter, 43 | bindRecorderToPath : bindRecorderToPath, 44 | unbindRecorder : unbindRecorder 45 | }; 46 | 47 | 48 | const recordController = require('../controllers/recorderController'); 49 | //Get list of recordings out in db 50 | apiRouter.get("/",recordController.getRecordings); 51 | 52 | //Get recorder by ID 53 | apiRouter.get("/:id",recordController.getRecordingById); 54 | 55 | //Get recorder by SUT 56 | apiRouter.get("/sut/:name",recordController.getRecordingBySystem); 57 | 58 | 59 | //Get RR pairs by ID + index to start at 60 | apiRouter.get("/:id/:index",recordController.getRecorderRRPairsAfter); 61 | 62 | //Add a new recorder 63 | apiRouter.put("/",recordController.addRecorder); 64 | 65 | //Remove a recorder 66 | apiRouter.delete("/:id",recordController.removeRecorder); 67 | 68 | 69 | //Start and stop recorder 70 | apiRouter.patch("/:id/start",recordController.startRecorder); 71 | apiRouter.patch("/:id/stop",recordController.stopRecorder); -------------------------------------------------------------------------------- /public/partials/modals/recorderHelpModal.html: -------------------------------------------------------------------------------- 1 |
2 |

Using this feature, the user can create service virtualizations by recording live HTTP traffic. Mockiato accomplishes this by acting as a proxy recorder- the user configures Mockiato to accept incoming requests on a particular path, and Mockiato redirects those requests to a live backend system.

3 |

Once configured, Mockiato will for all HTTP requests on, or below, the path: {{mockiatoHost}}/recording/live/GROUP/base/Path where GROUP is the chosen group for the recorder and /base/Path is the configured base path for the recorder.

4 |

These requests will be forwarded to the remote host and port configured by the user, on a path equivalent to the one sent to Mockiato, WITHOUT the /recording/live/GROUP prefix. E.g, if mockiato is configured with group exampleGroup to listen on /example/Path and send to the remote host at examplehost.com on port 5000, a request coming in on:

5 |

{{mockiatoHost}}/recording/live/exampleGroup/example/Path

6 |

Would be mapped to:

7 |

http://examplehost.com:5000/example/Path

8 |

Sub paths underneath this are also included. E.g:

9 |

{{mockiatoHost}}/recording/live/exampleGroup/example/Path/sub/Path/1

10 |

Would be mapped to:

11 |

http://examplehost.com:5000/example/Path/sub/Path/1

12 |

Any requests passed into Mockiato will be mapped as such to the configured remote backend, and any responses from the remote backend will be passed back to the client application. These requests and responses will be recorded for virtualization.

13 |

Note: No virtualization will actually be created until the user finalizes the recording in the next step.

14 |
-------------------------------------------------------------------------------- /models/mq/MQService.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const User = require('../common/User'); 4 | const System = require('../common/System'); 5 | 6 | const MQPair = require('./MQPair'); 7 | //const MQInfo = require('./MQInfo'); 8 | const constants = require('../../lib/util/constants'); 9 | 10 | const mqSchema = new mongoose.Schema({ 11 | sut: { 12 | type: System.schema, 13 | required: [true, constants.REQUIRED_SUT_ERR] 14 | }, 15 | user: User.schema, 16 | name: { 17 | type: String, 18 | required: [true, constants.REQUIRED_SERVICE_NAME_ERR], 19 | index: true 20 | }, 21 | type: { 22 | type: String, 23 | required: [true, constants.REQUIRED_SERVICE_TYPE_ERR] 24 | }, 25 | //mqInfo: MQInfo.schema, 26 | matchTemplates: [mongoose.Schema.Types.Mixed], 27 | rrpairs: { 28 | type: [MQPair.schema], 29 | required: [true, constants.REQUIRED_RRPAIRS_ERR] 30 | }, 31 | running: { 32 | type: Boolean, 33 | default: true 34 | }, 35 | lastUpdateUser:{ 36 | type: User.schema 37 | }, 38 | delay: { 39 | // force integer only 40 | type: Number, 41 | default: 0, 42 | validate: { 43 | validator: function (v) { 44 | if (Number.isInteger(v) && v >= 0) 45 | return true; 46 | else return false; 47 | }, 48 | message: '{VALUE}'+constants.NOT_VALID_INTEGER+'({PATH}).' 49 | } 50 | }, 51 | delayMax: { 52 | // force integer only 53 | type: Number, 54 | default: 0, 55 | validate: { 56 | validator: function (v) { 57 | if (Number.isInteger(v) && v >= 0) 58 | return true; 59 | else return false; 60 | }, 61 | message: '{VALUE}'+constants.NOT_VALID_INTEGER+'({PATH}).' 62 | } 63 | }, 64 | txnCount: { 65 | type: Number, 66 | default: 0, 67 | get: function(v) { return Math.round(v); }, 68 | set: function(v) { return Math.round(v); } 69 | }, 70 | },{timestamps:{createdAt:'createdAt',updatedAt:'updatedAt'}}); 71 | 72 | mqSchema.set('usePushEach', true); 73 | module.exports = mongoose.model('MQService', mqSchema); -------------------------------------------------------------------------------- /lib/remove-route/index.js: -------------------------------------------------------------------------------- 1 | var util=require('util'); 2 | var _=require('underscore'); 3 | 4 | 5 | 6 | 7 | 8 | 9 | function _findRoute(path,stack) { 10 | var count=0; 11 | var routes=[]; 12 | stack.forEach(function(layer) { 13 | if (!layer) return; 14 | if (layer && !layer.match(path)) return; 15 | if (['query', 'expressInit'].indexOf(layer.name) != -1) return; 16 | if (layer.name == 'router') { 17 | routes=routes.concat(_findRoute(trimPrefix(path, layer.path),layer.handle.stack)); 18 | } else { 19 | // change made per https://github.com/brennancheung/express-remove-route/pull/9 - JDW 20 | if (layer.name == 'bound dispatch') { 21 | routes.push({route: layer || null, stack: stack}); 22 | } 23 | } 24 | }); 25 | return routes; 26 | } 27 | 28 | function findRoute(app, path) { 29 | var stack; 30 | stack = app._router.stack; 31 | return (_findRoute(path, stack)); 32 | } 33 | 34 | function trimPrefix(path, prefix) { 35 | // This assumes prefix is already at the start of path. 36 | return path.substr(prefix.length); 37 | } 38 | 39 | 40 | module.exports = function removeRoute(app, path, method) { 41 | var found, route, stack, idx; 42 | 43 | //console.log('Path to remove: ' + path); 44 | 45 | found = findRoute(app, path); 46 | 47 | found.forEach(function(layer) { 48 | route = layer.route; 49 | stack = layer.stack; 50 | 51 | if (route) { 52 | if(_.isEmpty(method)){ // if no method delete all resource with the given path 53 | idx = stack.indexOf(route); 54 | // change made to resolve https://github.com/brennancheung/express-remove-route/issues/3 - JDW 55 | if (idx>=0) stack.splice(idx, 1); 56 | }else if(JSON.stringify(route.route.methods).toUpperCase().indexOf(method.toUpperCase())>=0){ // if method defined delete only the resource with the given ath and method 57 | idx = stack.indexOf(route); 58 | // change made to resolve https://github.com/brennancheung/express-remove-route/issues/3 - JDW 59 | if (idx>=0) stack.splice(idx, 1); 60 | } 61 | } 62 | }); 63 | 64 | return true; 65 | }; 66 | 67 | module.exports.findRoute = findRoute; -------------------------------------------------------------------------------- /tests/resources/Match_Template/Matching_Test_Service.json: -------------------------------------------------------------------------------- 1 | { 2 | "updatedAt": "2019-02-20T19:02:58.837Z", 3 | "createdAt": "2019-02-20T18:11:32.098Z", 4 | "sut": { 5 | "name": "JohnTestGroup", 6 | "__v": 0, 7 | "members": [ 8 | "jsmith", 9 | "" 10 | ] 11 | }, 12 | "name": "Matching Template Test", 13 | "type": "REST", 14 | "basePath": "/match", 15 | "lastUpdateUser": { 16 | "mail": "john_smith@asd.com", 17 | "uid": "jsmith", 18 | "_id": "5c6da44d9bf6263544bd5938" 19 | }, 20 | "liveInvocation": { 21 | "liveFirst": false, 22 | "recordedRRPairs": [], 23 | "record": false, 24 | "failStrings": [ 25 | "" 26 | ], 27 | "failStatusCodes": [ 28 | null 29 | ] 30 | }, 31 | "running": true, 32 | "txnCount": 7, 33 | "delayMax": 0, 34 | "delay": 0, 35 | "rrpairs": [ 36 | { 37 | "resDataString": "{\"response\":\"This is a good response\"}", 38 | "reqDataString": "{\"a\":true,\"b\":5}", 39 | "verb": "POST", 40 | "payloadType": "JSON", 41 | "reqHeaders": { 42 | "Content-Type": "application/json" 43 | }, 44 | "reqData": { 45 | "a": true, 46 | "b": 5 47 | }, 48 | "resHeaders": { 49 | "Content-Type": "application/json" 50 | }, 51 | "resData": { 52 | "response": "This is a good response" 53 | }, 54 | "resStatus": 200 55 | }, 56 | { 57 | "resDataString": "{\"c\":5,\"d\":\"{{ssn}}\",\"e\":\"words go here\",\"f\":true}", 58 | "reqDataString": "{\"c\":\"5\",\"d\":\"555-55-5555\",\"e\":\"words go here\",\"f\":true}", 59 | "verb": "POST", 60 | "payloadType": "JSON", 61 | "reqHeaders": { 62 | "Content-Type": "application/json" 63 | }, 64 | "reqData": { 65 | "c": "5", 66 | "d": "555-55-5555", 67 | "e": "words go here", 68 | "f": true 69 | }, 70 | "resHeaders": { 71 | "Content-Type": "application/json" 72 | }, 73 | "resData": { 74 | "c": 5, 75 | "d": "{{ssn}}", 76 | "e": "words go here", 77 | "f": true 78 | }, 79 | "resStatus": 200 80 | } 81 | ], 82 | "matchTemplates": [ 83 | "{\n\t\"a\":\"\"\n}", 84 | "{\n\t\"c\":\"lt:4\",\n\t\"d\":\"regex:^[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]$;map:ssn\",\n\t\"e\":\"any\",\n\t\"f\":\"\"\n}" 85 | ] 86 | } -------------------------------------------------------------------------------- /public/js/lib/angular-bootstrap-file-field.js: -------------------------------------------------------------------------------- 1 | /* @preserve 2 | * 3 | * angular-bootstrap-file 4 | * https://github.com/itslenny/angular-bootstrap-file-field 5 | * 6 | * Version: 0.1.3 - 02/21/2015 7 | * License: MIT 8 | */ 9 | 10 | angular.module('bootstrap.fileField',[]) 11 | .directive('fileField', function() { 12 | return { 13 | require:'ngModel', 14 | restrict: 'E', 15 | link: function (scope, element, attrs, ngModel) { 16 | //set default bootstrap class 17 | if(!attrs.class && !attrs.ngClass){ 18 | element.addClass('btn'); 19 | } 20 | 21 | var fileField = element.find('input'); 22 | 23 | //If an ACCEPT attribute was provided, add it to the input. 24 | if (attrs.accept) { 25 | fileField.attr('accept', attrs.accept); 26 | } 27 | 28 | fileField.bind('change', function(event){ 29 | scope.$evalAsync(function () { 30 | ngModel.$setViewValue(event.target.files[0]); 31 | if(attrs.preview){ 32 | var reader = new FileReader(); 33 | reader.onload = function (e) { 34 | scope.$evalAsync(function(){ 35 | try { 36 | // pretty print JSON in preview-- removed to work with xml - catch at publish instead 37 | //scope[attrs.preview]=JSON.stringify(JSON.parse(e.target.result),null," "); 38 | scope[attrs.preview]=e.target.result; 39 | } 40 | catch(e) { 41 | console.log(e); 42 | $('#failure-modal').modal('toggle'); 43 | scope[attrs.preview] = null; 44 | return; 45 | } 46 | }); 47 | }; 48 | reader.readAsText(event.target.files[0]); 49 | } 50 | }); 51 | }); 52 | fileField.bind('click',function(e){ 53 | e.stopPropagation(); 54 | }); 55 | element.bind('click',function(e){ 56 | e.preventDefault(); 57 | fileField[0].click(); 58 | }); 59 | }, 60 | template:'', 61 | replace:true, 62 | transclude:true 63 | }; 64 | }); 65 | -------------------------------------------------------------------------------- /public/data/statuses.json: -------------------------------------------------------------------------------- 1 | [{"value":100,"desc":"Continue"},{"value":101,"desc":"Switching Protocols"},{"value":102,"desc":"Processing"},{"value":103,"desc":"Early Hints"},{"value":200,"desc":"OK"},{"value":201,"desc":"Created"},{"value":202,"desc":"Accepted"},{"value":203,"desc":"Non-Authoritative Information"},{"value":204,"desc":"No Content"},{"value":205,"desc":"Reset Content"},{"value":206,"desc":"Partial Content"},{"value":207,"desc":"Multi-Status"},{"value":208,"desc":"Already Reported"},{"value":226,"desc":"IM Used"},{"value":300,"desc":"Multiple Choices"},{"value":301,"desc":"Moved Permanently"},{"value":302,"desc":"Found"},{"value":303,"desc":"See Other"},{"value":304,"desc":"Not Modified"},{"value":305,"desc":"Use Proxy"},{"value":307,"desc":"Temporary Redirect"},{"value":308,"desc":"Permanent Redirect"},{"value":400,"desc":"Bad Request"},{"value":401,"desc":"Unauthorized"},{"value":402,"desc":"Payment Required"},{"value":403,"desc":"Forbidden"},{"value":404,"desc":"Not Found"},{"value":405,"desc":"Method Not Allowed"},{"value":406,"desc":"Not Acceptable"},{"value":407,"desc":"Proxy Authentication Required"},{"value":408,"desc":"Request Timeout"},{"value":409,"desc":"Conflict"},{"value":410,"desc":"Gone"},{"value":411,"desc":"Length Required"},{"value":412,"desc":"Precondition Failed"},{"value":413,"desc":"Payload Too Large"},{"value":414,"desc":"URI Too Long"},{"value":415,"desc":"Unsupported Media Type"},{"value":416,"desc":"Range Not Satisfiable"},{"value":417,"desc":"Expectation Failed"},{"value":421,"desc":"Misdirected Request"},{"value":422,"desc":"Unprocessable Entity"},{"value":423,"desc":"Locked"},{"value":424,"desc":"Failed Dependency"},{"value":425,"desc":"Unassigned"},{"value":426,"desc":"Upgrade Required"},{"value":427,"desc":"Unassigned"},{"value":428,"desc":"Precondition Required"},{"value":429,"desc":"Too Many Requests"},{"value":430,"desc":"Unassigned"},{"value":431,"desc":"Request Header Fields Too Large"},{"value":451,"desc":"Unavailable For Legal Reasons"},{"value":500,"desc":"Internal Server Error"},{"value":501,"desc":"Not Implemented"},{"value":502,"desc":"Bad Gateway"},{"value":503,"desc":"Service Unavailable"},{"value":504,"desc":"Gateway Timeout"},{"value":505,"desc":"HTTP Version Not Supported"},{"value":506,"desc":"Variant Also Negotiates"},{"value":507,"desc":"Insufficient Storage"},{"value":508,"desc":"Loop Detected"},{"value":509,"desc":"Unassigned"},{"value":510,"desc":"Not Extended"},{"value":511,"desc":"Network Authentication Required"}] 2 | -------------------------------------------------------------------------------- /public/css/style.css: -------------------------------------------------------------------------------- 1 | .vertResize { 2 | resize: vertical; 3 | height: 50px; 4 | } 5 | 6 | .dropdown:hover .dropdown-menu { 7 | display: block; 8 | margin-top: 0; /*remove the gap so it doesn't close*/ 9 | } 10 | 11 | .dataCat{ 12 | font-weight: bold; 13 | font-size:16px; 14 | } 15 | 16 | .navbar-inverse .navbar-nav > li > a { 17 | color: #fff; 18 | } 19 | 20 | .navbar-inverse .navbar-nav > li > a:focus, .navbar-inverse .navbar-nav > li > a:hover { 21 | color: #fff; 22 | background-color: #666565; 23 | } 24 | 25 | input[type="radio"] { 26 | margin-top: -.1px; 27 | vertical-align: middle; 28 | } 29 | 30 | 31 | .move-radios{ 32 | padding-right: 20px; 33 | 34 | } 35 | 36 | .radio { 37 | position: relative; 38 | display: block; 39 | margin-top: 0px; 40 | margin-bottom: 0px; 41 | } 42 | 43 | .move-plus{ 44 | margin-left: -10px; 45 | } 46 | 47 | .btn-xl { 48 | padding: 10px 20px; 49 | font-size: 20px; 50 | border-radius: 10px; 51 | width:25%; /*Specify your width here*/ 52 | } 53 | 54 | .small-input{ 55 | width: 65px; 56 | } 57 | 58 | .urlmax{ 59 | max-width: 350px; 60 | word-wrap: break-word; 61 | } 62 | 63 | .loginform{ 64 | margin: 0 auto; 65 | width:35%; 66 | border-radius: 5px; 67 | background-color: #f2f2f2; 68 | padding: 20px; 69 | 70 | } 71 | 72 | .vertical-center { 73 | min-height: 60%; 74 | min-height: 60vh; 75 | display: flex; 76 | align-items: center; 77 | } 78 | 79 | .highlight { 80 | color: #00cc7a; 81 | } 82 | 83 | .form-group.req .col-form-label:after{ 84 | content:"*"; 85 | color:red; 86 | } 87 | 88 | .pointer{ 89 | cursor: pointer; 90 | } 91 | 92 | .padding-left-60{ 93 | padding-left: 60%; 94 | } 95 | 96 | .tab{ 97 | padding-left:3em; 98 | } 99 | 100 | .tab1{ 101 | padding-left:1em; 102 | } 103 | 104 | .borderless td, .borderless th { 105 | border: none; 106 | } 107 | 108 | .conjunction{ 109 | text-align: center; 110 | padding-top: 5px; 111 | } 112 | 113 | .wordwrap{ 114 | word-wrap: break-word; 115 | } 116 | 117 | .white{ 118 | background-color: #fff; 119 | } 120 | 121 | .greenText{ 122 | color: green; 123 | } 124 | 125 | .blueText{ 126 | color:blue; 127 | } 128 | 129 | .ng-invalid.ng-touched{ 130 | border-color:#f00; 131 | } 132 | 133 | .odd { 134 | background-color: #F5FFFA; 135 | } 136 | .even { 137 | background-color: #FFFAFA; 138 | } 139 | 140 | .sameBtns { 141 | display: block; 142 | width: 100%; 143 | margin: 2px; 144 | text-align: center; 145 | } 146 | 147 | .description { 148 | color: #000; 149 | } 150 | 151 | .description em { 152 | color: green; 153 | font-style: normal; 154 | font-family: "Times New Roman", Times, serif; 155 | } -------------------------------------------------------------------------------- /lib/remove-route/README.md: -------------------------------------------------------------------------------- 1 | # express-remove-route 2 | Delete a route in express at runtime. 3 | 4 | # Overview 5 | I wanted the ability to dynamically control Express routing but 6 | was not able to delete a route at runtime. This module solves that 7 | problem. 8 | 9 | # Installation 10 | 11 | npm install express-remove-route 12 | 13 | # Usage 14 | 15 | var removeRoute = require('express-remove-route'); 16 | 17 | var app = express(); 18 | var router = express.Router(); 19 | 20 | router.get('/remove/me', function(res, res) { 21 | res.send('I should not be here'); 22 | }); 23 | 24 | app.use('/foo', router); 25 | 26 | removeRoute(app, '/foo/remove/me'); 27 | 28 | Note that the full path is supplied to `removeRoute` not just its 29 | local path from within the `router`. 30 | 31 | # Reference 32 | ## removeRoute(app, resourcePath, resourceMethod); 33 | This is the function that remove a resource route on the fly 34 | The param `app` is the express application(app) on which you want remove the resource. 35 | the param `resourcePath` is the resource path to remove on the fly 36 | the param `resourceMethod` is the resource method with a given path to remove on the fly. If null or undefined all 37 | routes with the given path are removed. 38 | 39 | # Examples 40 | 41 | ## Remove all resources with a given path 42 | 43 | var removeRoute = require('express-remove-route'); 44 | 45 | var app = express(); 46 | var router = express.Router(); 47 | 48 | router.get('/remove/me', function(res, res) { 49 | res.send('I should not be here'); // removed 50 | }); 51 | 52 | router.put('/remove/me', function(res, res) { 53 | res.send('I should not be here'); // removed 54 | }); 55 | 56 | app.use('/foo', router); 57 | 58 | removeRoute(app, '/foo/remove/me'); // all routes with a path /foo/remove/me are removed 59 | 60 | ## Remove all resources with a given path and method 61 | 62 | var removeRoute = require('express-remove-route'); 63 | 64 | var app = express(); 65 | var router = express.Router(); 66 | 67 | router.get('/remove/me', function(res, res) { 68 | res.send('I should not be here'); // removed 69 | }); 70 | 71 | router.put('/remove/me', function(res, res) { 72 | res.send('I should be here'); // not removed 73 | }); 74 | 75 | app.use('/foo', router); 76 | 77 | removeRoute(app, '/foo/remove/me','get'); // all routes with a path /foo/remove/me in method get are removed 78 | 79 | 80 | 81 | # Caveat emptor 82 | This module has been tested against Express 4.13.3. In theory, 83 | it should work with all of 4.x. 84 | 85 | However, it will definitely *NOT* work with 3.x. 86 | 87 | Also, it makes use of undocumented private Express methods and data 88 | structures that may be subject to change. 89 | 90 | Contributors 91 | ------------ 92 | Brennan Cheung ([git@brennancheung.com](mailto:git@brennancheung.com)) 93 | 94 | Alessandro Romanino ([a.romanino@gmail.com](mailto:a.romanino@gmail.com)) 95 | -------------------------------------------------------------------------------- /tests/resources/Draft/Draft_Test_Service.json: -------------------------------------------------------------------------------- 1 | { 2 | "updatedAt": "2019-02-14T16:39:01.206Z", 3 | "createdAt": "2019-02-14T16:39:01.206Z", 4 | "sut": { 5 | "name": "DraftTest", 6 | "__v": 0, 7 | "members": [ 8 | "jsmith" 9 | ] 10 | }, 11 | "name": "Draft Test", 12 | "type": "REST", 13 | "basePath": "/draftme", 14 | "lastUpdateUser": { 15 | "uid": "jsmith", 16 | "mail": "john_smith@asd.com", 17 | "_id": "5c6599a5b75e2abea8145734" 18 | }, 19 | "liveInvocation": { 20 | "enabled": false 21 | }, 22 | "running": true, 23 | "txnCount": 0, 24 | "delayMax": 0, 25 | "delay": 0, 26 | "rrpairs": [ 27 | { 28 | "verb": "POST", 29 | "payloadType": "JSON", 30 | "reqHeaders": { 31 | "Content-Type": "application/json" 32 | }, 33 | "label":"DraftRsp", 34 | "reqData": { 35 | "test": "one", 36 | "test2:": true, 37 | "test3:": 12345, 38 | "testObj:": { 39 | "innerTest:": "testo", 40 | "innterTest2:": "testooo" 41 | } 42 | }, 43 | "resData": { 44 | "response": "This is a virtual response" 45 | }, 46 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 47 | "resDataString": "{\"response\":\"This is a virtual response\"}", 48 | "resStatus": 200 49 | }, 50 | { 51 | "verb": "POST", 52 | "payloadType": "JSON", 53 | "reqHeaders": { 54 | "Content-Type": "application/json" 55 | }, 56 | "reqData": { 57 | "test": "three", 58 | "test2:": true, 59 | "test3:": 12345, 60 | "testObj:": { 61 | "innerTest:": "testo", 62 | "innterTest2:": "testooo" 63 | } 64 | }, 65 | "resHeaders": { 66 | "Content-Type": "application/json" 67 | }, 68 | "resData": { 69 | "response": "This is a virtual response" 70 | }, 71 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 72 | "resDataString": "{\"response\":\"This is a virtual response\"}", 73 | "resStatus": 200 74 | }, 75 | { 76 | "verb": "POST", 77 | "payloadType": "JSON", 78 | "reqHeaders": { 79 | "Content-Type": "application/json" 80 | }, 81 | "reqData": { 82 | "test": "four", 83 | "test2:": true, 84 | "test3:": 12345, 85 | "testObj:": { 86 | "innerTest:": "testo", 87 | "innterTest2:": "testooo" 88 | } 89 | }, 90 | "resHeaders": { 91 | "Content-Type": "application/json" 92 | }, 93 | "resData": { 94 | "response": "This is a virtual response" 95 | }, 96 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 97 | "resDataString": "{\"response\":\"This is a virtual response\"}", 98 | "resStatus": 200 99 | } 100 | ], 101 | "matchTemplates": [ 102 | "" 103 | ] 104 | } -------------------------------------------------------------------------------- /lib/wsdl/parser.js: -------------------------------------------------------------------------------- 1 | const soap = require('soap'); 2 | const xml2js = require('xml2js'); 3 | const xmlBuilder = new xml2js.Builder(); 4 | 5 | const url = require('url'); 6 | const pd = require('pretty-data').pd; 7 | 8 | const Service = require('../../models/http/Service'); 9 | const RRPair = require('../../models/http/RRPair'); 10 | 11 | function parse(wsdl) { 12 | return new Promise(function(resolve, reject) { 13 | const serv = new Service(); 14 | serv.type = 'SOAP'; 15 | serv.matchTemplates = []; 16 | 17 | soap.createClientAsync(wsdl, function(err, client) { 18 | if (err) return reject(err); 19 | 20 | const services = client.wsdl.definitions.services; 21 | const bindings = client.wsdl.definitions.bindings; 22 | const messages = client.wsdl.definitions.messages; 23 | 24 | // extract base path 25 | let urlStr = ''; 26 | for (let s in services) { 27 | for (let p in services[s].ports) { 28 | urlStr = services[s].ports[p].location; 29 | } 30 | } 31 | if (!url.parse(urlStr).protocol) urlStr = 'http://' + urlStr; 32 | serv.basePath = url.parse(urlStr).pathname; 33 | 34 | // build req / res pairs 35 | for (let i in bindings) { 36 | const binding = bindings[i]; 37 | const methods = binding.methods; 38 | 39 | for (let j in methods) { 40 | const rr = new RRPair(); 41 | rr.verb = 'POST'; 42 | rr.payloadType = 'XML'; 43 | 44 | // set req / res headers 45 | const contentType = { 'Content-Type': 'text/xml' }; 46 | rr.reqHeaders = contentType; 47 | rr.resHeaders = contentType; 48 | 49 | // extract and set req data 50 | const inName = methods[j].input.$name; 51 | const inMsg = messages[inName]; 52 | const reqXml = toXml(inMsg.parts); 53 | const fullXml = pd.xml(`<${inName}>${reqXml}`); 54 | rr.reqData = fullXml; 55 | 56 | // create a new match template 57 | serv.matchTemplates.push(fullXml); 58 | 59 | // extract and set res data 60 | const outName = methods[j].output.$name; 61 | const outMsg = messages[outName]; 62 | const resXml = toXml(outMsg.parts); 63 | rr.resData = pd.xml(`<${outName}>${resXml}`); 64 | 65 | serv.rrpairs.push(rr); 66 | } 67 | } 68 | 69 | return resolve(serv); 70 | }); 71 | }); 72 | } 73 | 74 | function toXml(obj) { 75 | if (!obj) { 76 | return; 77 | } 78 | 79 | const xml = xmlBuilder 80 | .buildObject(obj) 81 | .substring(56) 82 | .replace(/[\[\]]/gi, '') 83 | .replace(/xs:string/g, '') 84 | .replace(/xs:int/g, '') 85 | .replace(/.*<\/targetNSAlias>/g, '') 86 | .replace(/.*<\/targetNamespace>/g, ''); 87 | 88 | return xml; 89 | } 90 | 91 | module.exports = { 92 | parse: parse 93 | }; -------------------------------------------------------------------------------- /tests/resources/Invoke/Invoke_Test_Service.json: -------------------------------------------------------------------------------- 1 | { 2 | "updatedAt": "2019-02-14T16:39:01.206Z", 3 | "createdAt": "2019-02-14T16:39:01.206Z", 4 | "sut": { 5 | "name": "RecordTest", 6 | "__v": 0, 7 | "members": [ 8 | "jsmith" 9 | ] 10 | }, 11 | "name": "Invoke Test", 12 | "type": "REST", 13 | "basePath": "/invokeme", 14 | "lastUpdateUser": { 15 | "uid": "jsmith", 16 | "mail": "john_smith@asd.com", 17 | "_id": "5c6599a5b75e2abea8145734" 18 | }, 19 | "liveInvocation": { 20 | "enabled": true, 21 | "remoteHost": "localhost", 22 | "remotePort": 15001, 23 | "remoteBasePath": "/recordme", 24 | "failStatusCodes": [ 25 | 202 26 | ], 27 | "failStrings": [ 28 | "failme" 29 | ], 30 | "record": true, 31 | "liveFirst": true 32 | }, 33 | "running": true, 34 | "txnCount": 0, 35 | "delayMax": 0, 36 | "delay": 0, 37 | "rrpairs": [ 38 | { 39 | "verb": "POST", 40 | "payloadType": "JSON", 41 | "reqHeaders": { 42 | "Content-Type": "application/json" 43 | }, 44 | "reqData": { 45 | "test": "one", 46 | "test2:": true, 47 | "test3:": 12345, 48 | "testObj:": { 49 | "innerTest:": "testo", 50 | "innterTest2:": "testooo" 51 | } 52 | }, 53 | "resHeaders": { 54 | "Content-Type": "application/json" 55 | }, 56 | "resData": { 57 | "response": "This is a virtual response" 58 | }, 59 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 60 | "resDataString": "{\"response\":\"This is a virtual response\"}", 61 | "resStatus": 200 62 | }, 63 | { 64 | "verb": "POST", 65 | "payloadType": "JSON", 66 | "reqHeaders": { 67 | "Content-Type": "application/json" 68 | }, 69 | "reqData": { 70 | "test": "three", 71 | "test2:": true, 72 | "test3:": 12345, 73 | "testObj:": { 74 | "innerTest:": "testo", 75 | "innterTest2:": "testooo" 76 | } 77 | }, 78 | "resHeaders": { 79 | "Content-Type": "application/json" 80 | }, 81 | "resData": { 82 | "response": "This is a virtual response" 83 | }, 84 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 85 | "resDataString": "{\"response\":\"This is a virtual response\"}", 86 | "resStatus": 200 87 | }, 88 | { 89 | "verb": "POST", 90 | "payloadType": "JSON", 91 | "reqHeaders": { 92 | "Content-Type": "application/json" 93 | }, 94 | "reqData": { 95 | "test": "four", 96 | "test2:": true, 97 | "test3:": 12345, 98 | "testObj:": { 99 | "innerTest:": "testo", 100 | "innterTest2:": "testooo" 101 | } 102 | }, 103 | "resHeaders": { 104 | "Content-Type": "application/json" 105 | }, 106 | "resData": { 107 | "response": "This is a virtual response" 108 | }, 109 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 110 | "resDataString": "{\"response\":\"This is a virtual response\"}", 111 | "resStatus": 200 112 | } 113 | ], 114 | "matchTemplates": [ 115 | "" 116 | ] 117 | } -------------------------------------------------------------------------------- /tests/resources/Search/Search_Test_Service.json: -------------------------------------------------------------------------------- 1 | { 2 | "updatedAt": "2019-02-14T16:39:01.206Z", 3 | "createdAt": "2019-02-14T16:39:01.206Z", 4 | "sut": { 5 | "name": "RecordTest", 6 | "__v": 0, 7 | "members": [ 8 | "jsmith" 9 | ] 10 | }, 11 | "name": "Search Test", 12 | "type": "REST", 13 | "basePath": "/invokeme", 14 | "lastUpdateUser": { 15 | "uid": "jsmith", 16 | "mail": "john_smith@asd.com", 17 | "_id": "5c6599a5b75e2abea8145734" 18 | }, 19 | "liveInvocation": { 20 | "enabled": true, 21 | "remoteHost": "localhost", 22 | "remotePort": 15001, 23 | "remoteBasePath": "/searchme", 24 | "failStatusCodes": [ 25 | 202 26 | ], 27 | "failStrings": [ 28 | "failme" 29 | ], 30 | "record": true, 31 | "liveFirst": true 32 | }, 33 | "running": true, 34 | "txnCount": 0, 35 | "delayMax": 0, 36 | "delay": 0, 37 | "rrpairs": [ 38 | { 39 | "verb": "POST", 40 | "payloadType": "JSON", 41 | "reqHeaders": { 42 | "Content-Type": "application/json" 43 | }, 44 | "reqData": { 45 | "test": "one", 46 | "test2:": true, 47 | "test3:": 12345, 48 | "testObj:": { 49 | "innerTest:": "testo", 50 | "innterTest2:": "testooo" 51 | } 52 | }, 53 | "resHeaders": { 54 | "Content-Type": "application/json" 55 | }, 56 | "resData": { 57 | "response": "This is a virtual response" 58 | }, 59 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 60 | "resDataString": "{\"response\":\"This is a virtual response\"}", 61 | "resStatus": 200 62 | }, 63 | { 64 | "verb": "POST", 65 | "payloadType": "JSON", 66 | "reqHeaders": { 67 | "Content-Type": "application/json" 68 | }, 69 | "reqData": { 70 | "test": "three", 71 | "test2:": true, 72 | "test3:": 12345, 73 | "testObj:": { 74 | "innerTest:": "testo", 75 | "innterTest2:": "testooo" 76 | } 77 | }, 78 | "resHeaders": { 79 | "Content-Type": "application/json" 80 | }, 81 | "resData": { 82 | "response": "This is a virtual response" 83 | }, 84 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 85 | "resDataString": "{\"response\":\"This is a virtual response\"}", 86 | "resStatus": 200 87 | }, 88 | { 89 | "verb": "POST", 90 | "payloadType": "JSON", 91 | "reqHeaders": { 92 | "Content-Type": "application/json" 93 | }, 94 | "reqData": { 95 | "test": "four", 96 | "test2:": true, 97 | "test3:": 12345, 98 | "testObj:": { 99 | "innerTest:": "testo", 100 | "innterTest2:": "testooo" 101 | } 102 | }, 103 | "resHeaders": { 104 | "Content-Type": "application/json" 105 | }, 106 | "resData": { 107 | "response": "This is a virtual response" 108 | }, 109 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 110 | "resDataString": "{\"response\":\"This is a virtual response\"}", 111 | "resStatus": 200 112 | } 113 | ], 114 | "matchTemplates": [ 115 | "" 116 | ] 117 | } -------------------------------------------------------------------------------- /controllers/mqController.js: -------------------------------------------------------------------------------- 1 | const System = require('../models/common/System'); 2 | const MQService = require('../models/mq/MQService'); 3 | const virtual = require('../routes/virtual'); 4 | const debug = require('debug')('default'); 5 | 6 | function registerAllMQServices() { 7 | System.find({}, function(err, systems) { 8 | if (err) { 9 | debug('Error registering MQ services: ' + err); 10 | return; 11 | } 12 | 13 | systems.forEach(function(system) { 14 | registerMQServicesInSystem(system); 15 | }); 16 | }); 17 | } 18 | 19 | function registerMQServicesInSystem(sut, exclude) { 20 | MQService.find({ 'sut.name' : sut.name }, function(err, mqservices) { 21 | if (err) { 22 | debug('Error registering MQ services: ' + err); 23 | return; 24 | } 25 | 26 | mqservices.forEach(function(mqservice) { 27 | if (!deepEquals(mqservice, exclude)) 28 | registerMQService(mqservice, sut); 29 | }); 30 | }); 31 | } 32 | 33 | function registerMQService(mqserv, sut) { 34 | if (!sut) { 35 | System.findOne({ 'name' : mqserv.sut.name }, function(err, system) { 36 | if (err) { 37 | debug('Error registering MQ service: ' + err); 38 | return; 39 | } 40 | 41 | register(mqserv, system); 42 | }); 43 | } 44 | else { 45 | register(mqserv, sut); 46 | } 47 | 48 | function register(mqservice, system) { 49 | if (!mqservice.running || !system || !system.mqInfo) { 50 | return; 51 | } 52 | 53 | mqservice.basePath = `/mq/${system.mqInfo.manager}/${system.mqInfo.reqQueue}`; 54 | 55 | mqservice.rrpairs.forEach(function(rrpair){ 56 | rrpair.verb = 'POST'; 57 | if (!rrpair.payloadType) rrpair.payloadType = 'XML'; 58 | 59 | virtual.registerRRPair(mqservice, rrpair); 60 | }); 61 | } 62 | } 63 | 64 | function deregisterMQService(mqserv) { 65 | System.findOne({ name: mqserv.sut.name }, function(err, sut) { 66 | if (err) { 67 | debug('Error deregistering MQ services: ' + err); 68 | return; 69 | } 70 | 71 | if (!sut) { 72 | return; 73 | } 74 | 75 | deregisterMQServicesByInfo(sut.mqInfo, reregister); 76 | 77 | function reregister(mqinfo) { 78 | let q = { 79 | '$and': [{ 80 | 'mqInfo.manager': mqinfo.manager 81 | }, { 82 | 'mqInfo.reqQueue': mqinfo.reqQueue 83 | }] 84 | } 85 | 86 | System.find(q, function(err, systems) { 87 | if (err) { 88 | debug('Error reregistering MQ services: ' + err); 89 | return; 90 | } 91 | 92 | systems.forEach(function(system) { 93 | registerMQServicesInSystem(system, mqserv); 94 | }); 95 | }); 96 | } 97 | }); 98 | } 99 | 100 | function deregisterMQServicesByInfo(mqinfo, cb) { 101 | if (!mqinfo) { 102 | return; 103 | } 104 | 105 | let mqserv = { 106 | basePath: `/mq/${mqinfo.manager}/${mqinfo.reqQueue}`, 107 | rrpairs: [{}] 108 | }; 109 | virtual.deregisterService(mqserv); 110 | 111 | setTimeout(function() { 112 | cb(mqinfo); 113 | }, 300); 114 | } 115 | 116 | module.exports = { 117 | registerMQService: registerMQService, 118 | deregisterMQService: deregisterMQService, 119 | registerAllMQServices: registerAllMQServices 120 | }; -------------------------------------------------------------------------------- /public/partials/selectService.html: -------------------------------------------------------------------------------- 1 |

Create New Service                       2 |  Search Service

3 |

Mockiato is an open source project developed at Optum for API virtualization. With Mockiato, you can virtualize REST APIs, SOAP services, and message-oriented middleware. Get started by selecting from the supported source materials below!

4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
Req/Res PairsMock from request / response pairs. Customize paths, methods, headers, parameters, response times, etc.
Bulk UploadMock from request / response pairs by bulk upload.
OpenAPIMock a REST service from an OpenAPI spec.
WSDLMock a SOAP service from a WSDL.
RecordCreate a virtual service by recording HTTP traffic.
ImportYou may import a virtual service in JSON format. This can be used in tandem with the export feature on the Browse page.
31 |

**New User? You need to be a part of a group to create or edit a service. Visit Admin page here.

32 |
33 |

Recently Modified Services

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
NameOwnerGroupTypeBase URLLast Modified By
{{service.name}}{{service.user.uid}}{{service.sut.name}}{{service.type}}{{ service.basePath ? mockiatoHost + '/virtual' + service.basePath : '' }}{{service.lastUpdateUser.uid}}
52 | 53 |
54 |

Admin

55 | Unused Services 56 |
57 | 58 |
-------------------------------------------------------------------------------- /tests/test-random.js: -------------------------------------------------------------------------------- 1 | const app = require('../app'); 2 | const request = require('supertest').agent(app); 3 | const test = require('./test.js'); 4 | 5 | 6 | 7 | 8 | 9 | let id; 10 | 11 | let token = '?token='; 12 | 13 | const resource = '/api/'; 14 | const baseService = require('./resources/random/Random_Test_Base_Service.json'); 15 | const serviceRequest = require('./resources/random/random_test_rec-req.json'); 16 | 17 | const mockUser = { 18 | username: getRandomString(), 19 | mail: getRandomString() + '@noreply.com', 20 | password: getRandomString() 21 | } 22 | 23 | const mockGroup = { 24 | name: getRandomString() 25 | }; 26 | 27 | function getRandomString() { 28 | return Math.random().toString(36).substring(2, 15); 29 | } 30 | 31 | 32 | baseService.sut = mockGroup; 33 | 34 | describe('Random Tests', function() { 35 | this.timeout(15000); 36 | 37 | 38 | describe('Setup', function() { 39 | it('Registers User', function(done) { 40 | request 41 | .post('/register') 42 | .send(mockUser) 43 | .expect(302) 44 | .end(done); 45 | }); 46 | it('Gets the token', function(done) { 47 | request 48 | .post('/api/login') 49 | .send({ username: mockUser.username, password: mockUser.password }) 50 | .expect(200) 51 | .expect(function(res) { 52 | token = token + res.body.token; 53 | }).end(done); 54 | }); 55 | it('Creates a group', function(done) { 56 | request 57 | .post('/api/systems' + token) 58 | .send(mockGroup) 59 | .expect(200) 60 | .end(done); 61 | }); 62 | it('Creates the base service', function(done) { 63 | request 64 | .post('/api/services' + token) 65 | .send(baseService) 66 | .expect(200) 67 | .expect(function(res){ 68 | id = res.body._id; 69 | }) 70 | .end(done); 71 | }); 72 | }); 73 | 74 | 75 | 76 | 77 | 78 | describe('Request against Random',function(){ 79 | it('Returns a good response',function(done){ 80 | request 81 | .post('/virtual/' + mockGroup.name +baseService.basePath) 82 | .send(serviceRequest) 83 | .expect(200,done); 84 | }); 85 | }); 86 | 87 | 88 | 89 | 90 | describe('Cleanup', function() { 91 | 92 | it('Deletes the base service', function(done) { 93 | request 94 | .delete('/api/services/' + id + token) 95 | .expect(200) 96 | .end(done); 97 | }); 98 | it('Deletes group', function(done) { 99 | request 100 | .delete('/api/systems/' + mockGroup.name + token) 101 | .expect(200) 102 | .end(done); 103 | }); 104 | it('Deletes user', function(done) { 105 | request 106 | .delete('/api/users/' + mockUser.username + token) 107 | .expect(200) 108 | .end(done); 109 | }); 110 | 111 | }); 112 | 113 | 114 | }); 115 | 116 | -------------------------------------------------------------------------------- /docs/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project email 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [opensource@optum.com][email]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | [email]: mailto:opensource@optum.com 76 | -------------------------------------------------------------------------------- /public/partials/bulkUpload.html: -------------------------------------------------------------------------------- 1 |

Mock a REST or SOAP Service

2 |
3 |
4 | 5 |
6 |
7 | 11 | 15 | 19 |
20 |
21 |
22 | 23 |
24 | 25 |
26 | 29 |
30 |

**No group? You need to be a part of a group to create a service. Visit Admin page here.

31 |
32 | 33 |
34 | 35 |
36 | 37 |
38 |
39 | 40 |
41 | 42 |
43 |
44 |
/virtual/{{bulkUpload.sut.name}}/
45 | 46 |
47 |
48 |
49 | 50 |
51 | 52 |
53 | 54 | Upload File    55 |
56 |
✔  {{uploadSuccessMessage}}
57 |
❌  {{uploadErrMessage}}
58 |
59 | 60 |
61 |
62 |
63 | 64 |
65 |
66 |
-------------------------------------------------------------------------------- /controllers/randomController.js: -------------------------------------------------------------------------------- 1 | const objectHash = require('object-hash'); 2 | const chance = require('chance'); 3 | const allowedMethods = ["bool","character","floating","integer","letter","natural","prime","string","paragraph","sentence","syllable","word","age","birthday","cf","cpf","first","gender","last","name","prefix","ssn","suffix","animal","android_id","apple_token","bb_pin","wp7_anid","wp8_anid2","avatar","color","company","domain","email","fbid","google_analytics","hashtag","ip","ipv6","klout","profession","tld","twitter","url","address","altitude","areacode","city","coordinates","country","depth","geohash","latitude","longitude","phone","postal","postcode","province","state","street","zip","ampm","date","hammertime","hour","millisecond","minute","month","second","timestamp","timezone","weekday","year","cc","cc_type","currency","currency_pair","dollar","euro","exp","exp_month","exp_year","capitalize","mixin","pad","pick","pickone","pickset","set","shuffle","coin","dice","guid","hash","hidden","n","normal","radio","rpg","tv","unique","weighted"]; 4 | 5 | 6 | /** 7 | * Takes a tag string (in the format {{random:methodName:arg1,val1:arg2,val2}}) and returns random value appropriately 8 | * @param {*} tag tag string 9 | * @param {*} myChance instance of Chance 10 | */ 11 | function getRandomStringFromTag(tag,myChance){ 12 | 13 | //Split tag into method + argument blocks 14 | var split = tag.split(":"); 15 | 16 | //Method name is first bit 17 | var methodName = split[1]; 18 | if(methodName.slice(-2) == "}}") 19 | methodName = methodName.slice(0,-2); 20 | var args = {}; 21 | var hasArgs = false; 22 | 23 | //If the method they're calling is one of the allowed ones... 24 | if(allowedMethods.includes(methodName)){ 25 | //Go through each arg block, and if properly formatted, save an arg 26 | for(let i = 2; i < split.length; i++){ 27 | var subSplit = split[i].split(/,|}}/); 28 | if(subSplit.length >= 2){ 29 | hasArgs = true; 30 | args[subSplit[0]] = subSplit[1]; 31 | } 32 | } 33 | //Pass given method name the args we collected, return result 34 | try{ 35 | if(hasArgs) 36 | return myChance[methodName](args); 37 | else 38 | return myChance[methodName](); 39 | }catch(e){ 40 | return "Error in Random Syntax"; 41 | } 42 | }else{ 43 | return ""; 44 | } 45 | } 46 | 47 | /** 48 | * Takes in a body string + set of req params. Uses req params to generate a seed hash, and replaces template tags with random responses based on that seed. 49 | * @param {string} resBody The response body 50 | * @param {*} reqBody Request body (in any form) 51 | * @param {*} query Query array from req 52 | * @param {*} path Path from req 53 | */ 54 | function performRandomInsertion(resBody,reqBody,query,path){ 55 | 56 | //Instantiate chance with hash based on given req values 57 | var myChance = new chance(objectHash(reqBody)+objectHash(query)+objectHash(path)); 58 | 59 | //Find our tags 60 | var split = resBody.split(/({{random:[A-Za-z:,0-9]+}})/); 61 | var retBody = ""; 62 | 63 | //Go through each split part of body, parse tags, and reassemble 64 | split.forEach(function(str){ 65 | if(str.startsWith("{{random:")){ 66 | retBody += getRandomStringFromTag(str,myChance); 67 | }else{ 68 | retBody += str; 69 | } 70 | }); 71 | 72 | return retBody; 73 | } 74 | 75 | module.exports = { 76 | performRandomInsertion:performRandomInsertion 77 | } -------------------------------------------------------------------------------- /tests/test-template.js: -------------------------------------------------------------------------------- 1 | const app = require('../app'); 2 | const request = require('supertest').agent(app); 3 | const test = require('./test-recorder.js'); 4 | const www = require('../bin/www'); 5 | 6 | 7 | 8 | 9 | 10 | let id; 11 | let token = '?token='; 12 | 13 | 14 | const service = require("./resources/Match_Template/Matching_Test_Service.json"); 15 | const requests = require("./resources/Match_Template/requests.json"); 16 | 17 | 18 | 19 | const mockUser = { 20 | username: getRandomString(), 21 | mail: getRandomString() + '@noreply.com', 22 | password: getRandomString() 23 | } 24 | 25 | const mockGroup = { 26 | name: getRandomString() 27 | }; 28 | 29 | function getRandomString() { 30 | return Math.random().toString(36).substring(2, 15); 31 | } 32 | 33 | 34 | 35 | service.sut = mockGroup; 36 | 37 | describe('Match Template Tests', function() { 38 | this.timeout(15000); 39 | 40 | 41 | describe('Setup', function() { 42 | it('Registers User', function(done) { 43 | request 44 | .post('/register') 45 | .send(mockUser) 46 | .expect(302) 47 | .end(done); 48 | }); 49 | it('Gets the token', function(done) { 50 | request 51 | .post('/api/login') 52 | .send({ username: mockUser.username, password: mockUser.password }) 53 | .expect(200) 54 | .expect(function(res) { 55 | token = token + res.body.token; 56 | }).end(done); 57 | }); 58 | it('Creates a group', function(done) { 59 | request 60 | .post('/api/systems' + token) 61 | .send(mockGroup) 62 | .expect(200) 63 | .end(done); 64 | }); 65 | it('Creates the service', function(done) { 66 | request 67 | .post('/api/services' + token) 68 | .send(service) 69 | .expect(200) 70 | .expect(function(res){ 71 | id = res.body._id; 72 | }) 73 | .end(done); 74 | }); 75 | }); 76 | 77 | describe('Tests match template with and without conditions',function(){ 78 | for(let req of requests){ 79 | it(req.desc,function(done){ 80 | request 81 | .post('/virtual/' + mockGroup.name + service.basePath) 82 | .send(req.req) 83 | .expect(req.status) 84 | .expect(function(res){ 85 | if((req.req.d && res.body.d) && req.req.d != res.body.d){ 86 | throw new Error("Mapping was not performed correctly"); 87 | 88 | } 89 | }) 90 | .end(done); 91 | }); 92 | } 93 | }); 94 | 95 | 96 | 97 | describe('Cleanup', function() { 98 | it('Deletes the service', function(done) { 99 | request 100 | .delete('/api/services/' + id + token) 101 | .expect(200) 102 | .end(done); 103 | }); 104 | it('Deletes group', function(done) { 105 | request 106 | .delete('/api/systems/' + mockGroup.name + token) 107 | .expect(200) 108 | .end(done); 109 | }); 110 | it('Deletes user', function(done) { 111 | request 112 | .delete('/api/users/' + mockUser.username + token) 113 | .expect(200) 114 | .end(done); 115 | }); 116 | 117 | }); 118 | 119 | 120 | }); 121 | 122 | -------------------------------------------------------------------------------- /public/partials/reportui.html: -------------------------------------------------------------------------------- 1 |

Mockiato statistics

2 |
3 | 4 | 5 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 73 | 81 | 89 | 90 | 92 | 93 | 94 | 95 | 96 |
6 |

Types of services

7 |
10 |

Count

11 |
Services{{reportingJson.totalServices}}
Active services{{reportingJson.activeServices}}
Draft services{{reportingJson.draftServices}}
Archived services{{reportingJson.archiveServices}}
35 |

**Services are Services+MQServices including stopped 36 | services, not including archived or draft services.

37 |

**Active services are running Services+MQServices. It does not 38 | include stopped services, archived or draft services.

39 |

40 |

Users & groups

41 |
Users{{reportingJson.users}}
Groups{{reportingJson.systems}}
55 |

56 |

Transactions

57 |
Total transactions{{reportingJson.totalTransactions}}
66 |

67 |

Group names

72 |
74 |

75 |

Services count

80 |
82 |

83 |

Transactions count

88 |
{{sutAndservice.sut}}{{sutAndservice.services}}{{sutAndservice.transactions}}
-------------------------------------------------------------------------------- /tests/resources/Invoke/Invoke_Test_Base_Service.json: -------------------------------------------------------------------------------- 1 | { 2 | "updatedAt": "2019-02-14T16:39:01.206Z", 3 | "createdAt": "2019-02-14T16:39:01.206Z", 4 | "sut": { 5 | "name": "RecordTest", 6 | "__v": 0, 7 | "members": [ 8 | "jsmith" 9 | ] 10 | }, 11 | "name": "Invoke Test Base", 12 | "type": "REST", 13 | "basePath": "/recordme", 14 | "lastUpdateUser": { 15 | "uid": "jsmith", 16 | "mail": "john_smith@asd.com", 17 | "_id": "5c6599a5b75e2abea8145734" 18 | }, 19 | "liveInvocation": { 20 | "liveFirst": false, 21 | "recordedRRPairs": [ 22 | ], 23 | "record": false, 24 | "failStrings": [ 25 | "" 26 | ], 27 | "failStatusCodes": [ 28 | null 29 | ] 30 | }, 31 | "running": true, 32 | "txnCount": 0, 33 | "delayMax": 0, 34 | "delay": 0, 35 | "rrpairs": [ 36 | { 37 | "verb": "POST", 38 | "payloadType": "JSON", 39 | "reqHeaders": { 40 | "Content-Type": "application/json" 41 | }, 42 | "reqData": { 43 | "test": "one", 44 | "test2:": true, 45 | "test3:": 12345, 46 | "testObj:": { 47 | "innerTest:": "testo", 48 | "innterTest2:": "testooo" 49 | } 50 | }, 51 | "resHeaders": { 52 | "Content-Type": "application/json" 53 | }, 54 | "resData": { 55 | "response": "This is a live response" 56 | }, 57 | "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 58 | "resDataString": "{\"response\":\"This is a live response\"}", 59 | "resStatus": 201 60 | }, 61 | { 62 | "verb": "POST", 63 | "payloadType": "JSON", 64 | "reqHeaders": { 65 | "Content-Type": "application/json" 66 | }, 67 | "reqData": { 68 | "test": "two", 69 | "test2:": true, 70 | "test3:": 12345, 71 | "testObj:": { 72 | "innerTest:": "testo", 73 | "innterTest2:": "testooo" 74 | } 75 | }, 76 | "resHeaders": { 77 | "Content-Type": "application/json" 78 | }, 79 | "resData": { 80 | "response": "This is a live response" 81 | }, 82 | "reqDataString": "{\"test\":\"two\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 83 | "resDataString": "{\"response\":\"This is a live response\"}", 84 | "resStatus": 201 85 | }, 86 | { 87 | "verb": "POST", 88 | "payloadType": "JSON", 89 | "reqHeaders": { 90 | "Content-Type": "application/json" 91 | }, 92 | "reqData": { 93 | "test": "three", 94 | "test2:": true, 95 | "test3:": 12345, 96 | "testObj:": { 97 | "innerTest:": "testo", 98 | "innterTest2:": "testooo" 99 | } 100 | }, 101 | "resHeaders": { 102 | "Content-Type": "application/json" 103 | }, 104 | "resData": { 105 | "response": "This is a failme response" 106 | }, 107 | "reqDataString": "{\"test\":\"two\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 108 | "resDataString": "{\"response\":\"This is a live response\"}", 109 | "resStatus": 201 110 | }, 111 | { 112 | "verb": "POST", 113 | "payloadType": "JSON", 114 | "reqHeaders": { 115 | "Content-Type": "application/json" 116 | }, 117 | "reqData": { 118 | "test": "four", 119 | "test2:": true, 120 | "test3:": 12345, 121 | "testObj:": { 122 | "innerTest:": "testo", 123 | "innterTest2:": "testooo" 124 | } 125 | }, 126 | "resHeaders": { 127 | "Content-Type": "application/json" 128 | }, 129 | "resData": { 130 | "response": "This is a live response" 131 | }, 132 | "reqDataString": "{\"test\":\"two\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", 133 | "resDataString": "{\"response\":\"This is a live response\"}", 134 | "resStatus": 202 135 | } 136 | ], 137 | "matchTemplates": [ 138 | "" 139 | ] 140 | } -------------------------------------------------------------------------------- /public/partials/draftServices.html: -------------------------------------------------------------------------------- 1 |

Draft Services

2 |
3 |
4 |
5 |
6 |
7 | 8 | 9 | 10 |   11 | 12 | 13 |
14 | 15 | 16 | 17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | 25 | 26 | 29 | 30 | 33 | 36 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 50 | 51 |
27 | Name 28 | Owner 31 | Group 32 | 34 | Type 35 | 37 | Base URL 38 | Action
{{service.name}}{{service.user.uid}}{{service.sut.name}}{{service.type}}{{ service.basePath ? mockiatoHost + '/virtual' + service.basePath : '' }} 48 | 49 |
52 |
53 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. Please also review our [Contributor License Agreement ("CLA")](INDIVIDUAL_CONTRIBUTOR_LICENSE.md) prior to submitting changes to the project. You will need to attest to this agreement following the instructions in the [Paperwork for Pull Requests](#paperwork-for-pull-requests) section below. 4 | 5 | --- 6 | 7 | # How to Contribute 8 | 9 | Now that we have the disclaimer out of the way, let's get into how you can be a part of our project. There are many different ways to contribute. 10 | 11 | ## Issues 12 | 13 | We track our work using Issues in GitHub. Feel free to open up your own issue to point out areas for improvement or to suggest your own new experiment. If you are comfortable with signing the waiver linked above and contributing code or documentation, grab your own issue and start working. 14 | 15 | ## Coding Standards 16 | 17 | We have some general guidelines towards contributing to this project. 18 | 19 | ### Languages 20 | 21 | *Python* 22 | 23 | The source code for this project is written in Python. You are welcome to add versions of files for other languages, however the core code will remain in Python. 24 | 25 | ### Keras Backends 26 | 27 | *Tensorflow* 28 | 29 | By default we assume that this reimplementation will be run using Tensorflow backend. As Keras grows its support for other backends, we will welcome changes that will make these scripts backend independent. 30 | 31 | ## Pull Requests 32 | 33 | If you've gotten as far as reading this section, then thank you for your suggestions. 34 | 35 | ### Paperwork for Pull Requests 36 | 37 | * Please read this guide and make sure you agree with our [Contributor License Agreement ("CLA")](INDIVIDUAL_CONTRIBUTOR_LICENSE.md). 38 | * Make sure git knows your name and email address: 39 | ``` 40 | $ git config user.name "J. Random User" 41 | $ git config user.email "j.random.user@example.com" 42 | ``` 43 | >The name and email address must be valid as we cannot accept anonymous contributions. 44 | * Write good commit messages. 45 | > Concise commit messages that describe your changes help us better understand your contributions. 46 | * The first time you open a pull request in this repository, you will see a comment on your PR with a link that will allow you to sign our Contributor License Agreement (CLA) if necessary. 47 | > The link will take you to a page that allows you to view our CLA. You will need to click the `Sign in with GitHub to agree button` and authorize the cla-assistant application to access the email addresses associated with your GitHub account. Agreeing to the CLA is also considered to be an attestation that you either wrote or have the rights to contribute the code. All committers to the PR branch will be required to sign the CLA, but you will only need to sign once. This CLA applies to all repositories in the Optum org. 48 | 49 | ## General Guidelines 50 | 51 | Ensure your pull request (PR) adheres to the following guidelines: 52 | 53 | * Try to make the name concise and descriptive. 54 | * Give a good description of the change being made. Since this is very subjective, see the [Updating Your Pull Request (PR)](#updating-your-pull-request-pr) section below for further details. 55 | * Every pull request should be associated with one or more issues. If no issue exists yet, please create your own. 56 | * Make sure that all applicable issues are mentioned somewhere in the PR description. This can be done by typing # to bring up a list of issues. 57 | 58 | ### Updating Your Pull Request (PR) 59 | 60 | A lot of times, making a PR adhere to the standards above can be difficult. If the maintainers notice anything that we'd like changed, we'll ask you to edit your PR before we merge it. This applies to both the content documented in the PR and the changed contained within the branch being merged. There's no need to open a new PR. Just edit the existing one. 61 | 62 | [email]: mailto:opensource@optum.com 63 | -------------------------------------------------------------------------------- /public/partials/spec.html: -------------------------------------------------------------------------------- 1 |

Mock from {{spec.heading}}

2 | 3 |
4 | 5 | 16 | 17 |
18 | 19 |
20 | 23 |
24 |

**No group? You need to be a part of a group to create a service. Visit Admin page here.

25 |
26 | 27 |
28 | 29 |
30 | 31 |
32 |
33 | 34 |
35 | 36 |
37 | 38 | Upload File   Or 39 |
40 | 41 |
42 | 43 |
44 |
45 | 46 |
47 |
48 | 49 |
50 |
51 | 52 |
53 |
54 | 55 |
56 | 57 |
58 |
59 |
/virtual/{{spec.sut.name}}/
60 | 61 |
62 |
63 |
64 | 65 |
66 |
✔  {{uploadSuccessMessage}}
67 |
❌  {{uploadErrMessage}}
68 |
69 |
70 |
71 | 72 |
73 |
74 |

***Either upload a spec or paste a URL. If you do both then only URL will be considered.

75 |
76 |
77 |

Preview

78 |
79 | {{uploadSpec.name}} 80 |

81 |
{{previewText}}
82 |
83 |
84 | 85 |
-------------------------------------------------------------------------------- /public/partials/recorderList.html: -------------------------------------------------------------------------------- 1 |

Browse Recorders

2 |
3 |
4 |
5 |
6 |
7 | 8 | 9 | 12 | 13 |
14 | 15 | 16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | 24 | 25 | 28 | 31 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 49 | 50 |
26 | Name 27 | 29 | Group 30 | 32 | Type 33 | 35 | Base URL 36 | Action
{{recorder.name}}{{recorder.sut.name}}{{recorder.protocol}}{{ mockiatoHost + '/recording/live/' + recorder.sut.name + recorder.path }} 45 | 46 | 47 | 48 |
51 |
52 | -------------------------------------------------------------------------------- /tests/test-bulk.js: -------------------------------------------------------------------------------- 1 | const app = require('../app'); 2 | const request = require('supertest').agent(app); 3 | const fs = require('fs'); 4 | const test = require('./test-recorder.js'); 5 | 6 | 7 | 8 | 9 | let id, filename; 10 | let token = '?token='; 11 | 12 | const bulkZip = fs.readFileSync("./tests/resources/bulk/bulk.zip"); 13 | const req = require("./resources/bulk/bulk_post.json"); 14 | 15 | const mockUser = { 16 | username: getRandomString(), 17 | mail: getRandomString() + '@noreply.com', 18 | password: getRandomString() 19 | } 20 | 21 | const mockGroup = { 22 | name: getRandomString() 23 | }; 24 | 25 | function getRandomString() { 26 | return Math.random().toString(36).substring(2, 15); 27 | } 28 | 29 | 30 | 31 | describe('Bulk Upload Tests', function() { 32 | this.timeout(15000); 33 | 34 | 35 | describe('Setup', function() { 36 | it('Registers User', function(done) { 37 | request 38 | .post('/register') 39 | .send(mockUser) 40 | .expect(302) 41 | .end(done); 42 | }); 43 | it('Gets the token', function(done) { 44 | request 45 | .post('/api/login') 46 | .send({ username: mockUser.username, password: mockUser.password }) 47 | .expect(200) 48 | .expect(function(res) { 49 | token = token + res.body.token; 50 | }).end(done); 51 | }); 52 | it('Creates a group', function(done) { 53 | request 54 | .post('/api/systems' + token) 55 | .send(mockGroup) 56 | .expect(200) 57 | .end(done); 58 | }); 59 | 60 | 61 | 62 | }); 63 | 64 | describe('Bulk upload',function(){ 65 | it('Sends zip to application',function(done){ 66 | request 67 | .post('/api/services/fromPairs/upload' + token) 68 | .attach('zipFile','./tests/resources/bulk/bulk.zip') 69 | .expect(200) 70 | .expect(function(res){ 71 | filename = res.body; 72 | }) 73 | .end(done); 74 | }); 75 | it('Publishes the service',function(done){ 76 | setTimeout(function(){ 77 | request 78 | .post('/api/services/fromPairs/publish?type=REST&group=' + mockGroup.name + '&uploaded_file_name_id=' + filename + '&url=eligibility/v1&name=TestName&' + token.slice(1)) 79 | .expect(200) 80 | .expect(function(res){ 81 | id = res.body._id; 82 | }) 83 | .end(done); 84 | },1000); 85 | }); 86 | it('Tests the get request',function(done){ 87 | request 88 | .get('/virtual/' + mockGroup.name + '/eligibility/v1/details/465039173') 89 | .expect(200,done); 90 | }); 91 | it('Tests the post request',function(done){ 92 | request 93 | .post('/virtual/' + mockGroup.name + '/eligibility/v1/search') 94 | .set('content-type','application/json') 95 | .send(req) 96 | .expect(200,done); 97 | }); 98 | 99 | }); 100 | 101 | 102 | describe('Cleanup', function() { 103 | it('Deletes the service',function(done){ 104 | request 105 | .delete('/api/services/' + id + token) 106 | .expect(200) 107 | .end(done); 108 | }); 109 | it('Deletes group', function(done) { 110 | request 111 | .delete('/api/systems/' + mockGroup.name + token) 112 | .expect(200) 113 | .end(done); 114 | }); 115 | it('Deletes user', function(done) { 116 | request 117 | .delete('/api/users/' + mockUser.username + token) 118 | .expect(200) 119 | .end(done); 120 | }); 121 | 122 | }); 123 | 124 | 125 | }); 126 | 127 | -------------------------------------------------------------------------------- /public/partials/includes/restClientServiceHeader.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Service Detail

5 |
6 |
7 | 10 |
11 |
12 |
13 | 14 |
15 |
16 | 20 | 24 |
25 |
26 |
27 | 28 |
29 | 30 |
31 | 32 |
33 |
34 | 35 |
36 | 37 |
38 | 39 |
40 |
41 | 42 |
43 | 44 |
45 | 46 |
47 |
48 | 49 |
50 | 51 |
52 | 55 |
56 |
to
57 |
58 | 61 |
62 |
63 | 64 |
65 |
66 | 67 |
68 |
69 | 70 |
71 | 72 |
73 |
74 | 75 |
76 | 77 |
78 |
79 |
80 |
-------------------------------------------------------------------------------- /routes/services.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | const multer = require('multer'); 5 | const upload = multer({ dest: 'uploads/' }); 6 | 7 | const servCtrl = require('../controllers/serviceController'); 8 | 9 | // middleware for token auth 10 | router.use(tokenMiddleware); 11 | 12 | // middleware to reject invalid services 13 | function rejectInvalid(req, res, next) { 14 | const validTypes = [ 'SOAP', 'REST', 'MQ' ]; 15 | 16 | const type = req.body.type; 17 | if (type && validTypes.includes(type)) return next(); 18 | 19 | handleError(`Service type ${type} is not supported`, res, 400); 20 | } 21 | 22 | //Upload zip in upload directory and extract the zip in RRPair directory 23 | router.post('/fromPairs/upload', upload.single('zipFile'), servCtrl.zipUploadAndExtract); 24 | 25 | //create service from RR Pairs present in RRPair directory 26 | router.post('/fromPairs/publish', servCtrl.publishExtractedRRPairs); 27 | 28 | //Upload openapi or wsdl spec in upload directory. 29 | router.post('/fromSpec/upload', upload.single('specFile'), servCtrl.specUpload); 30 | 31 | //create openapi or wsdl service from open spec or wsdl present in upload directory 32 | router.post('/fromSpec/publish', servCtrl.publishUploadedSpec); 33 | 34 | // retrieve archive services 35 | router.get('/archive', servCtrl.getArchiveServices); 36 | 37 | // retrieve draft services 38 | router.get('/draft', servCtrl.getDraftServices); 39 | 40 | //delete a virtual service from Archive 41 | router.delete('/archive/:id', servCtrl.permanentDeleteService); 42 | 43 | //delete a virtual service from Draft Service 44 | router.delete('/draft/:id', servCtrl.deleteDraftService); 45 | 46 | // restore a virtual service from Archive 47 | router.post('/archive/:id/restore', servCtrl.restoreService); 48 | 49 | // get Service Info for a virtual service from Archive 50 | router.get('/archive/:id', servCtrl.getArchiveServiceInfo); 51 | 52 | // get Service Info for a virtual service from DraftService 53 | router.get('/draft/:id', servCtrl.getDraftServiceById); 54 | 55 | // add a new virtual service 56 | router.post('/', rejectInvalid, servCtrl.addService); 57 | 58 | //Search services 59 | router.get("/search/:id",servCtrl.searchServices); 60 | router.get("/search",servCtrl.searchServices); 61 | 62 | //get Old Services 63 | router.get("/getOldServs",servCtrl.getOldServices); 64 | 65 | // retrieve a virtual service by ID (in JSON) 66 | router.get('/:id', servCtrl.getServiceById); 67 | 68 | // retrieve services with query string filters 69 | router.get('/', servCtrl.getServicesByQuery); 70 | 71 | // retrieve services by SUT 72 | router.get('/sut/:name', servCtrl.getServicesBySystem); 73 | 74 | // retrieve services by SUT Archive 75 | router.get('/sut/:name/archive', servCtrl.getServicesArchiveBySystem); 76 | 77 | // retrieve services by SUT Draft 78 | router.get('/sut/:name/draft', servCtrl.getServicesDraftBySystem); 79 | 80 | // retrieve services by user 81 | router.get('/user/:uid', servCtrl.getServicesByUser); 82 | 83 | // retrieve services by user Archive 84 | router.get('/user/:uid/archive', servCtrl.getArchiveServicesByUser); 85 | 86 | // retrieve services by user Draft 87 | router.get('/user/:uid/draft', servCtrl.getDraftServicesByUser); 88 | 89 | // update a virtual service by ID 90 | router.put('/:id', servCtrl.updateService); 91 | 92 | // update a virtual service by ID 93 | router.put('/draftservice/:id', servCtrl.updateServiceAsDraft); 94 | 95 | // delete a virtual service by ID 96 | router.delete('/:id', servCtrl.deleteService); 97 | 98 | // toggle a service on / off TODO: toggle MQ services 99 | router.post('/:id/toggle', servCtrl.toggleService); 100 | 101 | // add a new draft service 102 | router.post('/draftservice', servCtrl.addServiceAsDraft); 103 | 104 | // get Service Info for a virtual service from Archive 105 | router.get('/infoFrmArchive/:id', servCtrl.getArchiveServiceInfo); 106 | 107 | 108 | // delete a recorded RR pair 109 | router.delete('/:id/recorded/:rrpairId',servCtrl.deleteRecordedRRPair); 110 | 111 | // get recorded RR pairs from service 112 | router.get('/:id/recorded',servCtrl.getServiceRecordedRRPairs); 113 | 114 | //Merge in recorded RR pair 115 | router.patch('/:id/recorded/:rrpairId',servCtrl.mergeRecordedRRPair); 116 | 117 | //Add RRPair to service 118 | router.patch('/:id/rrpairs',servCtrl.addRRPair); 119 | 120 | const rrpairs = require('./rrpairs'); 121 | router.use(rrpairs); 122 | 123 | module.exports = router; -------------------------------------------------------------------------------- /public/partials/admin.html: -------------------------------------------------------------------------------- 1 |

Admin and Security for 2 | {{myUser}} 3 |

4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 |
13 | 14 |
{{createGroupMessage}}
15 |
16 |
17 | 18 |
19 | 20 |
21 | 24 |
{{deleteGroupMessage}}
25 |
26 | 27 | 28 |
29 | 31 |
32 |
33 |
34 | 35 |
36 |
37 |
38 | 39 |
40 | 41 |
42 | 43 |
44 |
45 | 46 |
47 |
48 | 49 |
50 |
51 | 55 |
56 |
57 |
58 | 59 |
60 |
    61 |
    62 |
    63 | {{member}} 64 |
    65 | 66 |
    67 | 71 |
    72 |

    73 |
    74 |
75 |
76 |
77 | 78 | 79 |

Groups and Owner Info

80 |
81 |

Contact any user to have access to the group.


82 |
83 | 84 |
85 | 86 |
87 |
88 |
89 | 90 |
There are no users in this group.
91 |
{{user}}{{$last ? '' : ', '}}
92 |
93 |
-------------------------------------------------------------------------------- /public/partials/deletedServices.html: -------------------------------------------------------------------------------- 1 |

Deleted Services

2 |
3 |
4 |
5 |
6 |
7 | 8 | 9 | 10 |   11 | 12 | 13 |
14 | 15 | 16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | 24 | 25 | 28 | 29 | 32 | 35 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 52 | 53 |
26 | Name 27 | Owner 30 | Group 31 | 33 | Type 34 | 36 | Base URL 37 | Action
{{service.name}}{{service.user.uid}}{{service.sut.name}}{{service.type}}{{ service.basePath ? mockiatoHost + '/virtual' + service.basePath : '' }} 47 |   48 |   49 | 50 | 51 |
54 |
55 | -------------------------------------------------------------------------------- /models/http/RRPair.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const xml2js = require("xml2js"); 3 | const constants = require('../../lib/util/constants'); 4 | 5 | const rrSchema = new mongoose.Schema({ 6 | verb: { 7 | type: String, 8 | required: [ function () { 9 | return this.parent().type === 'REST'; 10 | }, 11 | constants.REQUIRED_HTTP_METHOD_ERR 12 | ], 13 | validate: { 14 | validator: function (v) { 15 | if (this.parent().type === 'REST' && !constants.ALL_REST_METHODS.includes(v)) 16 | return false; 17 | else return true; 18 | }, 19 | message: '{VALUE}'+constants.NOT_VALID_VERB+'({PATH}).' 20 | } 21 | }, 22 | 23 | path: String, 24 | payloadType: { 25 | type: String, 26 | required: [true, constants.REQUIRED_RRPAIRS_PAYLOADTYPE_ERR], 27 | enum: { 28 | values: constants.ALL_PAYLOAD_TYPE, 29 | message: '{VALUE}'+constants.NOT_VALID_PAYLOADTYPE+'({PATH}).' 30 | }, 31 | validate: { 32 | validator: function (v) { 33 | if (this.parent().type === 'SOAP' && v === 'XML') 34 | return true; 35 | else if (this.parent().type === 'REST' && (v === 'XML' || v === 'JSON' || v === 'PLAIN')) 36 | return true; 37 | else return false; 38 | }, 39 | message: constants.SERVICETYPE_PAYLAODTYPE_COMBINATION_ERR 40 | } 41 | }, 42 | // use schema-less data-types 43 | queries: mongoose.Schema.Types.Mixed, 44 | reqHeaders: mongoose.Schema.Types.Mixed, 45 | reqData: { 46 | type: mongoose.Schema.Types.Mixed, 47 | validate: { 48 | validator: function (v) { 49 | /* Making validation true in case of DraftService. 50 | In other cases, apply normal validations. */ 51 | try { 52 | if (this.parent().parent().constructor.modelName === 'DraftService') return true; //else continue validations. 53 | } catch (e) {/* Not a draft service so continue below validations*/ } 54 | if (this.payloadType === 'JSON') { 55 | try { 56 | JSON.parse(JSON.stringify(v)); 57 | return true; 58 | } catch (e) { 59 | return false; 60 | } 61 | } else if (this.payloadType === 'XML') { 62 | try{ 63 | xml2js.parseString(v, function (err, result) { 64 | if(err) throw err; 65 | }); 66 | return true; 67 | }catch(e){return false;} 68 | } else { 69 | return true; 70 | } 71 | }, 72 | message: constants.PAYLOADTYPE_REQDATA_NOMATCH_ERR 73 | }, 74 | required: [function () { 75 | return this.parent().type === 'SOAP'; 76 | }, 77 | constants.REQUIRED_REQUEST_PAYLOAD_ERR 78 | ] 79 | }, 80 | getPayloadRequired: { 81 | type: Boolean, 82 | default: false 83 | }, 84 | reqDataString: String, 85 | resStatus: { 86 | // force integer only 87 | type: Number, 88 | default: 200, 89 | get: function(v) { return Math.round(v); }, 90 | set: function(v) { return Math.round(v); } 91 | }, 92 | resHeaders: mongoose.Schema.Types.Mixed, 93 | resData: { 94 | type: mongoose.Schema.Types.Mixed, 95 | validate: { 96 | validator: function (v) { 97 | /* Making validation true in case of DraftService. 98 | In other cases, apply normal validations. */ 99 | try { 100 | if (this.parent().parent().constructor.modelName === 'DraftService') return true; //else continue validations. 101 | } catch (e) {/* Not a draft service so continue below validations*/ } 102 | if (this.payloadType === 'JSON') { 103 | try { 104 | JSON.parse(JSON.stringify(v)); 105 | return true; 106 | } catch (e) { 107 | return false; 108 | } 109 | } else if (this.payloadType === 'XML') { 110 | try{ 111 | xml2js.parseString(v, function (err, result) { 112 | if(err) throw err; 113 | }); 114 | return true; 115 | }catch(e){return false;} 116 | } else { 117 | return true; 118 | } 119 | }, 120 | message: constants.PAYLOADTYPE_RESDATA_NOMATCH_ERR 121 | }, 122 | required: [function () { 123 | return this.parent().type === 'SOAP'; 124 | }, 125 | constants.REQUIRED_RESPONSE_PAYLOAD_ERR 126 | ] 127 | }, 128 | resDataString: String, 129 | label: String, 130 | hasRandomTags : { 131 | type:Boolean, 132 | default:false 133 | } 134 | },{minimize:false}); 135 | 136 | module.exports = mongoose.model('RRPair', rrSchema); -------------------------------------------------------------------------------- /public/partials/datagen.html: -------------------------------------------------------------------------------- 1 |

Mock Data Generation

2 |
3 |
4 |
5 |

Field Names

6 |
7 |
8 |

Data Type

9 |
10 |
11 | 12 | 13 |
14 |
15 | 16 |
17 | 18 |
19 | 56 |
57 | 58 |
59 | 62 |
63 |
64 | 65 | 66 | 67 |
68 |
69 | 73 |
74 |
75 |   76 |
77 | 78 | 81 |
82 |
83 | 84 |
85 |
86 |
87 | 88 | 91 |
92 |
93 | 94 | 100 |
101 |
102 | 103 |
104 |

❌  Add Some Field To Dowload Data.

105 |
106 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 |
21 |
22 |
23 | 24 | 25 | 28 | 29 | 32 | 35 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 58 | 59 |
26 | Name 27 | Owner 30 | Group 31 | 33 | Type 34 | 36 | Base URL 37 | 39 | Transactions 40 | Action
{{service.name}}{{service.user.uid}}{{service.sut.name}}{{service.type}}{{ service.basePath ? mockiatoHost + '/virtual' + service.basePath : '' }}{{service.txnCount}} 51 | 52 | 53 | 54 | 55 | 56 | 57 |
60 |
61 | -------------------------------------------------------------------------------- /assets/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mockiato ☕ 6 | 7 | 8 | 10 | 11 | 12 | 13 |
14 | 26 |
27 |
28 |
29 |
30 |

Register

31 | Already have an account? Log in here. 32 |
33 |
34 |
35 |
36 |
37 |
38 | 39 |
40 |
41 | 42 |
43 |
44 | 45 |
46 | 47 |
48 |
49 |
50 |
51 |
52 | 53 | 54 | 55 | 134 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/Optum/mockiato.svg?branch=master)](https://travis-ci.org/Optum/mockiato) [![DeepScan grade](https://deepscan.io/api/projects/2971/branches/22804/badge/grade.svg)](https://deepscan.io/dashboard#view=project&pid=2971&bid=22804) 2 | 3 | # Mockiato: A web-based platform for API virtualization 4 | 5 | ## Quick Start 6 | 7 | 1. Clone this repo: `git clone https://github.com/Optum/mockiato.git && cd mockiato` 8 | 2. Set secret for JWT: `echo MOCKIATO_SECRET="" > .env` 9 | 3. Start Mockiato & MongoDB: `docker-compose up` 10 | 4. View the app at http://localhost:8080 or the API documentation at http://localhost:8080/api-docs 11 | 5. Use the '...Register an account here.' link to register as a mockiato user and log in. 12 | 13 | Note:- 14 | 1. To use private NPM registry you need to provide build argument REG_URL(private registry url) in docker build or docker-compose build commands. 15 | 2. If you run the project locally (npm start) without docker you can use .npmrc file to download packages from private NPM registry. If you don't create .npmrc file NPM packages will be downloaded from public NPM registry (https://registry.npmjs.org/) by default. 16 | 17 | This quick-start makes some basic assumptions on how you want to run the application. For other possible configurations, please see the next section. 18 | 19 | ## Configuration 20 | 21 | Mockiato can be configured with the following environment variables. These can be set globally or in a file called `.env` in the project root directory. 22 | 23 | | Option | Example | Description | 24 | | ------ | ------------- | ----------- | 25 | | MOCKIATO_SECRET | | Required. Used to sign and verify JSON Web Tokens | 26 | | MOCKIATO_AUTH | local | The auth strategy to use. Defaults to "local" | 27 | | MONGODB_HOST | localhost | The hostname for your Mongo instance | 28 | | MONGODB_USER | admin | The user to connect to Mongo with | 29 | | MONGODB_PASSWORD | | The password for the Mongo user | 30 | | MOCKIATO_ADMIN | | The admin user id | 31 | | MOCKIATO_ARCHIVE | 0 0 1 * * | The time interval for archive service to delete permanently. The value is Cron-style Scheduling type| 32 | 33 | 34 | ## What is it? 35 | 36 | Mockiato is a web-based platform for API virtualization. Mockiato was developed at Optum to enable test automation, and can simulate REST APIs, SOAP services, and message-oriented middleware. 37 | 38 | Mockiato can generate realistic data for testing, and export it to JSON, XML, or CSV. Mockiato creates virtual endpoints that simulate your production APIs. These virtual services are ideal for testing, sandboxing, knowledge transfer, and driving rapid development. 39 | 40 | Mockiato is built on open-source technologies like Node.js and MongoDB, and was designed API-first with cloud readiness in mind. It exposes a RESTful API to programmatically interact with your services, as well as a modern web interface and command-line client. 41 | 42 | ## Architecture 43 | 44 | Mockiato is comprised of 3 basic architectural components: a web-based user interface, a REST API for managing services, and a Mongo database. 45 | 46 | #### Web UI 47 | 48 | Mockiato provides a simple, intuitive interface for managing virtual services. Built on AngularJS, this single-page application acts as a client to a Mockiato server. 49 | 50 | #### REST API 51 | 52 | In Mockiato, virtual services are considered resources. A REST API is exposed to facilitate CRUD (create, read, update, delete) operations on these resources. 53 | 54 | For more information on the methods available in the API, please see our Swagger documentation. 55 | 56 | #### NoSQL 57 | 58 | All of the data that comprises a virtual service (base path, request data, response data, etc.) is stored in a Mongo database. 59 | 60 | Please see the next section for more information on the data models behind Mockiato. 61 | 62 | ## Data Models 63 | 64 | Mockiato structures data according to 4 basic models: a service, a request / response pair, a group, and an owner. 65 | 66 | #### Service 67 | 68 | The service model is the primary entity, and the remaining 3 are sub-components of it. The service is comprised of a base path, type (e.g. SOAP, REST), name, owner, group, and a set of request / response pairs. 69 | 70 | #### RR Pair 71 | 72 | A request / response pair holds all information necessary for request matching (headers, status codes, HTTP methods, relative paths, request bodies, response bodies, etc.) At least one RR pair should be associated with a service for matching to occur, but many can run on a single service. For example, one service running on base path /v2/pets could have 2 RR pairs: one for creating a pet (e.g. a POST with some request data), and one for retrieving the pet (e.g. a GET with the pet ID as relative path). 73 | 74 | #### Group (SUT) 75 | 76 | Formerly known as a "system under test", a group is a convenient way to organize services. Think of it like a tag; it's just a way to say "these services belong together". It has only 2 fields: a generated ID and a name. The name is prepended to the base path of your virtual service. For example, a service with basepath /v2/pets in the group "test" will run in Mockiato on the base path /virtual/test/v2/pets. 77 | 78 | #### Owner 79 | 80 | The service owner is the person who created the service. If Mockiato is running with the LDAP authentication strategy, then the non-ID fields for the owner model are simply a username and email address. These are pulled from AD automatically on your first login. 81 | 82 | ## Contributing to the Project 83 | 84 | The Mockiato team is open to contributions to our project. For more details, see our [Contribution Guide](docs/CONTRIBUTING.md). 85 | -------------------------------------------------------------------------------- /lib/util/index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const jwt = require('jsonwebtoken'); 3 | const assert = require('assert'); 4 | const debug = require('debug')('default'); 5 | const logger = require('../../winston'); 6 | 7 | // function for responding with errors 8 | global.handleError = function(e, res, stat) { 9 | res 10 | .status(stat) 11 | .json({ error: e }); 12 | 13 | debug(e); 14 | }; 15 | 16 | // function for deep object comparison 17 | global.deepEquals = function(a, b) { 18 | try { 19 | assert.deepEqual(a, b); 20 | return true; 21 | } 22 | catch (e) { 23 | logEvent('','', 'Payload does not match expected result: ' + e); 24 | return false; 25 | } 26 | }; 27 | 28 | global.flattenObject = (function (isArray, wrapped) { 29 | return function (table) { 30 | return reduce("", {}, table); 31 | }; 32 | 33 | function reduce(path, accumulator, table) { 34 | if (isArray(table)) { 35 | var length = table.length; 36 | 37 | if (length) { 38 | var index = 0; 39 | 40 | while (index < length) { 41 | var property = path + "[" + index + "]", item = table[index++]; 42 | if (wrapped(item) !== item) accumulator[property] = item; 43 | else reduce(property, accumulator, item); 44 | } 45 | } else accumulator[path] = table; 46 | } else { 47 | var empty = true; 48 | 49 | if (path) { 50 | for (var property in table) { 51 | var item = table[property], property = path + "." + property, empty = false; 52 | if (wrapped(item) !== item) accumulator[property] = item; 53 | else reduce(property, accumulator, item); 54 | } 55 | } else { 56 | for (var property in table) { 57 | var item = table[property], empty = false; 58 | if (wrapped(item) !== item) accumulator[property] = item; 59 | else reduce(property, accumulator, item); 60 | } 61 | } 62 | 63 | if (empty) accumulator[path] = table; 64 | } 65 | 66 | return accumulator; 67 | } 68 | }(Array.isArray, Object)); 69 | 70 | global.unflattenObject = function(table) { 71 | var result = {}; 72 | 73 | for (var path in table) { 74 | var cursor = result, length = path.length, property = "", index = 0; 75 | 76 | while (index < length) { 77 | var char = path.charAt(index); 78 | 79 | if (char === "[") { 80 | var start = index + 1, 81 | end = path.indexOf("]", start), 82 | cursor = cursor[property] = cursor[property] || [], 83 | property = path.slice(start, end), 84 | index = end + 1; 85 | } else { 86 | var cursor = cursor[property] = cursor[property] || {}, 87 | start = char === "." ? index + 1 : index, 88 | bracket = path.indexOf("[", start), 89 | dot = path.indexOf(".", start); 90 | 91 | if (bracket < 0 && dot < 0) var end = index = length; 92 | else if (bracket < 0) var end = index = dot; 93 | else if (dot < 0) var end = index = bracket; 94 | else var end = index = bracket < dot ? bracket : dot; 95 | 96 | var property = path.slice(start, end); 97 | } 98 | } 99 | 100 | cursor[property] = table[path]; 101 | } 102 | 103 | return result[""]; 104 | }; 105 | 106 | global.uniq = function(a) { 107 | var prims = {"boolean":{}, "number":{}, "string":{}}, objs = []; 108 | 109 | return a.filter(function(item) { 110 | var type = typeof item; 111 | if(type in prims) 112 | return prims[type].hasOwnProperty(item) ? false : (prims[type][item] = true); 113 | else 114 | return objs.indexOf(item) >= 0 ? false : objs.push(item); 115 | }); 116 | } 117 | global.tokenMiddleware = function(req, res, next) { 118 | res.set('Content-Type', 'application/json'); 119 | if (req.method === 'GET') return next(); 120 | 121 | const token = req.query.token || req.headers['x-access-token']; 122 | if (token) { 123 | // verify secret and check expiry 124 | jwt.verify(token, require('../../app').get('secret'), function(err, decoded) { 125 | if (err) { 126 | return res.status(403).json({ 127 | success: false, 128 | message: 'Failed to authenticate token' 129 | }); 130 | } else { 131 | // save to request for use in other routes 132 | req.decoded = decoded; 133 | next(); 134 | } 135 | }); 136 | } 137 | else { 138 | return res.status(401).json({ 139 | success: false, 140 | message: 'No token provided.' 141 | }); 142 | } 143 | }; 144 | 145 | // polyfill for Object.entries() 146 | if (!Object.entries) 147 | Object.entries = function(obj) { 148 | let ownProps = Object.keys(obj), 149 | i = ownProps.length, 150 | resArray = new Array(i); // preallocate the Array 151 | while (i--) 152 | resArray[i] = [ownProps[i], obj[ownProps[i]]]; 153 | return resArray; 154 | }; 155 | 156 | 157 | global.logEvent = function(path, label, msg) { 158 | debug(path, label, msg); 159 | 160 | let event = {}; 161 | event.path = path; 162 | event.label = label; 163 | event.msg = msg; 164 | 165 | logger.info(event); 166 | }; 167 | 168 | global.escapeRegExp = function(string) { 169 | return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string 170 | } 171 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 172 | -------------------------------------------------------------------------------- /public/partials/searchService.html: -------------------------------------------------------------------------------- 1 |

Search Services

2 |
3 |
4 | 5 |
6 | 7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 | 15 |
16 |
17 |
18 | 19 |
20 | 21 |
22 |
23 |
24 | 25 | 26 |    27 | 28 |     Please enter any search filter. 29 | 30 | 31 |
32 |
33 |
34 |
35 |
36 | 37 | 38 | 41 | 42 | 45 | 48 | 51 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 71 | 72 |
39 | Name 40 | Owner 43 | Group 44 | 46 | Type 47 | 49 | Base URL 50 | 52 | Transactions 53 | Action
{{service.name}}{{service.user.uid}}{{service.sut.name}}{{service.type}}{{ service.basePath ? mockiatoHost + '/virtual' + service.basePath : '' }}{{service.txnCount}} 64 | 65 | 66 | 67 | 68 | 69 | 70 |
73 |
74 |



75 |

No match found

76 | -------------------------------------------------------------------------------- /docs/INDIVIDUAL_CONTRIBUTOR_LICENSE.md: -------------------------------------------------------------------------------- 1 | # Individual Contributor License Agreement ("Agreement") V2.0 2 | 3 | Thank you for your interest in this Optum project (the "PROJECT"). In order to clarify the intellectual property license granted with Contributions from any person or entity, the PROJECT must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of the PROJECT and its users; it does not change your rights to use your own Contributions for any other purpose. 4 | 5 | You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the PROJECT. In return, the PROJECT shall not use Your Contributions in a way that is inconsistent with stated project goals in effect at the time of the Contribution. Except for the license granted herein to the PROJECT and recipients of software distributed by the PROJECT, You reserve all right, title, and interest in and to Your Contributions. 6 | 1. Definitions. 7 | 8 | "You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with the PROJECT. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 9 | 10 | "Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to the PROJECT for inclusion in, or documentation of, any of the products owned or managed by the PROJECT (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the PROJECT or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the PROJECT for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution." 11 | 12 | 2. Grant of Copyright License. 13 | 14 | Subject to the terms and conditions of this Agreement, You hereby grant to the PROJECT and to recipients of software distributed by the PROJECT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works. 15 | 16 | 3. Grant of Patent License. 17 | 18 | Subject to the terms and conditions of this Agreement, You hereby grant to the PROJECT and to recipients of software distributed by the PROJECT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed. 19 | 20 | 4. Representations. 21 | 22 | (a) You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to the PROJECT, or that your employer has executed a separate Corporate CLA with the PROJECT. 23 | 24 | (b) You represent that each of Your Contributions is Your original creation (see section 6 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions. 25 | 26 | 5. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. 27 | 28 | 6. Should You wish to submit work that is not Your original creation, You may submit it to the PROJECT separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]". 29 | 30 | 7. You agree to notify the PROJECT of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect. 31 | -------------------------------------------------------------------------------- /lib/util/constants.js: -------------------------------------------------------------------------------- 1 | module.exports = Object.freeze({ 2 | SPACE: ' ', 3 | HTTP: 'HTTP', 4 | SOAP: 'SOAP', 5 | REST: 'REST', 6 | POST: 'POST', 7 | XML: 'XML', 8 | JSON: 'JSON', 9 | PLAIN: 'PLAIN', 10 | QUESTION_MARK: '?', 11 | AMPERSAND: '&', 12 | EQUAL_SIGN: '=', 13 | WRONG_FILE_ENDING_ERR_MSG: 'All files name should end with either -req or -rsp', 14 | ALL_REST_METHODS: '["GET", "POST", "UPDATE", "DELETE", "PATCH", "PUT", "HEAD", "CONNECT", "OPTIONS", "TRACE"]', 15 | NOT_EVEN_ERR_MSG: 'Number of files in your uploaded zip is not even.', 16 | REQ_RES_FILENAME_DIFF_ERR_MSG: 'Any of request/response file in uploaded zip have different names.', 17 | NOT_SOAP_TYPE_ERR_MSG: 'There is no soap Envelope xml in one of req/rsp file in uploaded zip.', 18 | SOAP_FILE_STARTSWITH1: '', 21 | REQ_FILE_END: '-req', 22 | RSP_FILE_END: '-rsp', 23 | APPLICATION_XML: 'application/xml', 24 | TEXT_XML: 'text/xml', 25 | APPLICATION_JSON: 'application/json', 26 | TEXT_PLAIN: 'text/plain', 27 | ORG_USR_REGISTER_VIEW: 'Mockiato ☕


You are using Mockiato in your organziation. Please login with your organization credentials.


', 28 | ALL_SERVICE_TYPE: '["REST", "SOAP", "MQ"]', 29 | REST_SOAP_REQUIREDFIELD_ERRMSG: 'Required fields (Group, Name, Base Path, Request/Response Pair) is not present.', 30 | MQ_REQUIREDFIELD_ERRMSG: 'Required fields (Group, Name, Request/Response Pair) is not present.', 31 | SOAP_MQ_RRPAIR_REQFIELD_ERRMSG: 'Required fields (Request Payload, Response Payload) not present in Request/Response Pairs.', 32 | REST_RRPAIR_REQFIELD_ERRMSG: 'Required fields (HTTP Method, Payload Type) not present in Request/Response Pairs.', 33 | REST_RRPAIR_REQRESDATA_FORMAT: 'Request or Response is not in correct Json format.', 34 | SOAP_MQ_RRPAIR_REQRESDATA_FORMAT: 'Request or Response is not in correct xml format.', 35 | ALL_PAYLOAD_TYPE: ['JSON', 'XML', 'PLAIN'], 36 | SUT_NOT_PRESENT_ERR_MSG: 'Error: sut not present in imported Template', 37 | MQ_VALID_XML_REQ_ERR: 'Request is not a valid xml.', 38 | MQ_VALID_XML_RES_ERR: 'Response is not a valid xml.', 39 | REQUIRED_REQUEST_PAYLOAD_ERR: 'Required field Request Payload (rrpairs.reqData) is not present in request.', 40 | REQUIRED_RESPONSE_PAYLOAD_ERR: 'Required field Response Payload (rrpairs.resData) is not present in request.', 41 | REQUIRED_SUT_ERR: 'Required field Group (sut) is not present in request.', 42 | REQUIRED_SUT_PARAMS_ERR: 'Required field Group (sut or sut/name) is not present in request.', 43 | REQURIED_SUT_NAME_ERR: 'Required field Gruop name (sut.name) is not present in request.', 44 | REQUIRED_SUT_MEMBERS_ERR: 'Required field Gruop members (sut.members) is not present in request.', 45 | REQUIRED_BASEPATH_ERR: 'Required field Base Path (basePath) is not present in request.', 46 | REQUIRED_SERVICE_NAME_ERR: 'Required field Service Name (name) is not present in request.', 47 | REQUIRED_SERVICE_TYPE_ERR: 'Required field Service Type (type) is not present in request.', 48 | REQUIRED_RRPAIRS_ERR: 'Required field Request/Response Pair (rrpairs) is not present in request.', 49 | REQUIRED_HTTP_METHOD_ERR: 'Required field HTTP Method (rrpairs.verb) is not present in request.', 50 | REQUIRED_RRPAIRS_PAYLOADTYPE_ERR: 'Required field Payload Type (rrpairs.payloadType) is not present in request.', 51 | SERVICETYPE_PAYLAODTYPE_COMBINATION_ERR: 'Service Type and Payload Type (payloadType in rrpairs) combination is incorrect.', 52 | PAYLOADTYPE_REQDATA_NOMATCH_ERR: 'Syntax of Request Payload (reqData) is invalid. It don\'t match with given Payload Type.', 53 | PAYLOADTYPE_RESDATA_NOMATCH_ERR: 'Syntax of Response Payload (resData) is invalid. It don\'t match with given Payload Type.', 54 | NOT_VALID_VERB:' is not a valid Http Method' , 55 | NOT_VALID_PAYLOADTYPE:' is not a valid PayLoad Type ', 56 | USER_NOT_AUTHORIZED_ERR: 'User not authorized to create on this group.', 57 | REQUST_NO_RRPAIR: 'Request don\'t contain rrpairs', 58 | DIFF_TYPE_SERV_ERR: 'There is already a different type(Rest/Soap) of service available with same name and basepath.', 59 | SERVICES_DIFFNAME_SAMEBASEPATH_ERR: 'There is another service already exist in our system with same basepath.', 60 | LIVE_OR_VIRTUAL_NOT_ERR: 'You must choose between "Live first" or "Virtual first" for a Live Invocation.', 61 | REMOTE_HOST_NOT_ERR: 'Please provide remote host', 62 | REMOTE_PORT_NOT_ERR: 'please provide remote port', 63 | REQUIRED_SERVICE_ERR : 'There is no Service in this recorder creation request.', 64 | REQUIRED_RECORDER_SERVICE_NAME_ERR: 'Record Service name is mandatory. Please provide.', 65 | DUP_RECORDER_PATH_BODY: 'This recorder\'s group and path overlap with an active recorder.', 66 | NOT_VALID_INTEGER: ' is not a valid Positive Integer Number for ', 67 | REST_CLIENT_NO_BP: 'basePath not present in request', 68 | REST_CLIENT_NO_METHOD: 'method not present in request' 69 | }); --------------------------------------------------------------------------------