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

Commit 00e32d0

Browse files
Merge pull request #11 from austinmcorso/optionForSelfSignedCerts
Added option for disabling services SSL cert checking to allow self-signed certs.
2 parents c889e50 + e89431c commit 00e32d0

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
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.
44

55

6+
---
7+
8+
## 1.2.0
9+
10+
### Release Notes
11+
#### Added
12+
13+
- Ability to enable mocking services with self-signed certs via configuration.
14+
615
---
716

817
## 1.1.1

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ port: 1234
200200
});
201201
```
202202

203+
#### Secure
204+
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.
205+
```javascript
206+
bokor.start({
207+
servers : serversProperties,
208+
filters : filtersProperties,
209+
secure: false,
210+
});
211+
```
212+
203213
## Data Fixtures
204214

205215
### Data Bins

lib/bokor.js

+31-29
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@ require('http');
2525
function start(options) {
2626

2727
// -- bokor config --------------
28-
if (options.servers != null) {
29-
bokorOptions.servers = options.servers;
30-
} else {
31-
console.log('CONFIGURATION ERROR: Missing server config'.red);
32-
return;
33-
}
34-
35-
if (options.filters != null) {
36-
bokorOptions.filters = options.filters;
37-
} else {
38-
console.log('CONFIGURATION ERROR: Missing filters config'.red);
39-
return;
40-
}
41-
42-
bokorOptions.port = options.port || 7777; // bokor server port
43-
bokorOptions.staticFileLocation = options.staticFileLocation || 'static_files'; // bokor server static file location
28+
if (options.servers != null) {
29+
bokorOptions.servers = options.servers;
30+
} else {
31+
console.log('CONFIGURATION ERROR: Missing server config'.red);
32+
return;
33+
}
34+
35+
if (options.filters != null) {
36+
bokorOptions.filters = options.filters;
37+
} else {
38+
console.log('CONFIGURATION ERROR: Missing filters config'.red);
39+
return;
40+
}
41+
42+
bokorOptions.port = options.port || 7777; // bokor server port
43+
bokorOptions.staticFileLocation = options.staticFileLocation || 'static_files'; // bokor server static file location
44+
bokorOptions.secure = options.secure === undefined ? true : false;
4445

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

105-
var apiProxy = httpProxy.createProxyServer();
106-
106+
var apiProxy = httpProxy.createProxyServer({
107+
secure: bokorOptions.secure,
108+
});
107109

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

112114
server.all(serverConfig.url_filter, function(req, res) {
113115
delete req.headers['accept-encoding'];
114-
apiProxy.web(req, res, {
115-
target: 'https://' + serverConfig.url,
116-
agent: https.globalAgent,
117-
headers: {
118-
host: serverConfig.url
119-
}
120-
}, function(e) {
121-
console.log('[ERROR] proxying to endpoint: '.red + serverConfig.url);
122-
console.log(e);
123-
res.send(JSON.stringify({ bokorProxyError: 1 }));
124-
});
116+
apiProxy.web(req, res, {
117+
target: 'https://' + serverConfig.url,
118+
agent: https.globalAgent,
119+
headers: {
120+
host: serverConfig.url
121+
}
122+
}, function(e) {
123+
console.log('[ERROR] proxying to endpoint: '.red + serverConfig.url);
124+
console.log(e);
125+
res.send(JSON.stringify({ bokorProxyError: 1 }));
126+
});
125127
});
126128

127129
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bokor",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "Bokor is a simple, Record and Playback Mock Server written in Node.js, utilized for Service Virtualization.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)