Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from austinmcorso/optionForSelfSignedCerts
Browse files Browse the repository at this point in the history
Added option for disabling services SSL cert checking to allow self-signed certs.
  • Loading branch information
jimmyeisenhauer authored Nov 16, 2017
2 parents c889e50 + e89431c commit 00e32d0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
The changelog for BOKOR includes information about the each release including any update notes, release notes as well as bug fixes, updates to existing features and new features.


---

## 1.2.0

### Release Notes
#### Added

- Ability to enable mocking services with self-signed certs via configuration.

---

## 1.1.1
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ port: 1234
});
```

#### Secure
By default Bokor checks a services SSL cert and will fail if the cert is self-signed / invalid CA. You can modify this behavior by adjusting the server config.
```javascript
bokor.start({
servers : serversProperties,
filters : filtersProperties,
secure: false,
});
```

## Data Fixtures

### Data Bins
Expand Down
60 changes: 31 additions & 29 deletions lib/bokor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ require('http');
function start(options) {

// -- bokor config --------------
if (options.servers != null) {
bokorOptions.servers = options.servers;
} else {
console.log('CONFIGURATION ERROR: Missing server config'.red);
return;
}

if (options.filters != null) {
bokorOptions.filters = options.filters;
} else {
console.log('CONFIGURATION ERROR: Missing filters config'.red);
return;
}

bokorOptions.port = options.port || 7777; // bokor server port
bokorOptions.staticFileLocation = options.staticFileLocation || 'static_files'; // bokor server static file location
if (options.servers != null) {
bokorOptions.servers = options.servers;
} else {
console.log('CONFIGURATION ERROR: Missing server config'.red);
return;
}

if (options.filters != null) {
bokorOptions.filters = options.filters;
} else {
console.log('CONFIGURATION ERROR: Missing filters config'.red);
return;
}

bokorOptions.port = options.port || 7777; // bokor server port
bokorOptions.staticFileLocation = options.staticFileLocation || 'static_files'; // bokor server static file location
bokorOptions.secure = options.secure === undefined ? true : false;

// -- sepia config --------------
// default bokor admin server on by default
Expand Down Expand Up @@ -102,26 +103,27 @@ function start(options) {
res.send(JSON.stringify({ status: 1 }));
});

var apiProxy = httpProxy.createProxyServer();

var apiProxy = httpProxy.createProxyServer({
secure: bokorOptions.secure,
});

var serverConfigs = Object.keys(bokorOptions.servers);
serverConfigs.forEach(serverName => {
var serverConfig = bokorOptions.servers[serverName];

server.all(serverConfig.url_filter, function(req, res) {
delete req.headers['accept-encoding'];
apiProxy.web(req, res, {
target: 'https://' + serverConfig.url,
agent: https.globalAgent,
headers: {
host: serverConfig.url
}
}, function(e) {
console.log('[ERROR] proxying to endpoint: '.red + serverConfig.url);
console.log(e);
res.send(JSON.stringify({ bokorProxyError: 1 }));
});
apiProxy.web(req, res, {
target: 'https://' + serverConfig.url,
agent: https.globalAgent,
headers: {
host: serverConfig.url
}
}, function(e) {
console.log('[ERROR] proxying to endpoint: '.red + serverConfig.url);
console.log(e);
res.send(JSON.stringify({ bokorProxyError: 1 }));
});
});

});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bokor",
"version": "1.1.1",
"version": "1.2.0",
"description": "Bokor is a simple, Record and Playback Mock Server written in Node.js, utilized for Service Virtualization.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 00e32d0

Please sign in to comment.