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.
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.
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:
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.
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!
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
6 |
Types of services
7 |
8 |
9 |
10 |
Count
11 |
12 |
13 |
14 |
Services
15 |
16 |
{{reportingJson.totalServices}}
17 |
18 |
19 |
Active services
20 |
21 |
{{reportingJson.activeServices}}
22 |
23 |
24 |
Draft services
25 |
26 |
{{reportingJson.draftServices}}
27 |
28 |
29 |
Archived services
30 |
31 |
{{reportingJson.archiveServices}}
32 |
33 |
34 |
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.
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 |
52 |
53 |
54 |
55 |
134 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/Optum/mockiato) [](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 |
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 | });
--------------------------------------------------------------------------------