Skip to content

Commit ab3e0d8

Browse files
authored
Merge pull request #3 from gunnargrosch/develop
Develop
2 parents d994a34 + 81e29fb commit ab3e0d8

File tree

5 files changed

+1092
-538
lines changed

5 files changed

+1092
-538
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

5-
`failure-azurefunctions` is a small Node module for injecting failure into Azure Functions (https://azure.microsoft.com/en-us/services/functions/). It offers a simple failure injection wrapper for your Azure Function handler where you then can choose to inject failure by setting the `failureMode` to `latency`, `exception`, `blacklist`, `diskspace` or `statuscode`. You control your failure injection using Key Vault.
5+
`failure-azurefunctions` is a small Node module for injecting failure into Azure Functions (https://azure.microsoft.com/en-us/services/functions/). It offers a simple failure injection wrapper for your Azure Function handler where you then can choose to inject failure by setting the `failureMode` to `latency`, `exception`, `denylist`, `diskspace` or `statuscode`. You control your failure injection using Key Vault.
66

77
## How to install
88

@@ -35,10 +35,10 @@ az keyvault set-policy -n <your-unique-keyvault-name> --spn <clientId-of-your-se
3535
```
3636
7. Create a secret in Key Vault.
3737
```json
38-
{"isEnabled": false, "failureMode": "latency", "rate": 1, "minLatency": 100, "maxLatency": 400, "exceptionMsg": "Exception message!", "statusCode": 404, "diskSpace": 100, "blacklist": ["*.documents.azure.com"]}
38+
{"isEnabled": false, "failureMode": "latency", "rate": 1, "minLatency": 100, "maxLatency": 400, "exceptionMsg": "Exception message!", "statusCode": 404, "diskSpace": 100, "denylist": ["*.documents.azure.com"]}
3939
```
4040
```bash
41-
az keyvault secret set --name <your-secret-name> --vault-name <your-unique-keyvault-name> --value "{\`"isEnabled\`": false, \`"failureMode\`": \`"latency\`", \`"rate\`": 1, \`"minLatency\`": 100, \`"maxLatency\`": 400, \`"exceptionMsg\`": \`"Exception message!\`", \`"statusCode\`": 404, \`"diskSpace\`": 100, \`"blacklist\`": [\`"s3.*.amazonaws.com\`", \`"dynamodb.*.amazonaws.com\`"]}"
41+
az keyvault secret set --name <your-secret-name> --vault-name <your-unique-keyvault-name> --value "{\`"isEnabled\`": false, \`"failureMode\`": \`"latency\`", \`"rate\`": 1, \`"minLatency\`": 100, \`"maxLatency\`": 400, \`"exceptionMsg\`": \`"Exception message!\`", \`"statusCode\`": 404, \`"diskSpace\`": 100, \`"denylist\`": [\`"*.documents.azure.com\`"]}"
4242
```
4343
8. Add environment variables to your Azure Function with values from above.
4444
```bash
@@ -66,7 +66,7 @@ Edit the values of your secret in Key Vault to use the failure injection module.
6666
* `exceptionMsg` is the message thrown with the exception created when `failureMode` is set to `exception`.
6767
* `statusCode` is the status code returned by your function when `failureMode` is set to `statuscode`.
6868
* `diskSpace` is size in MB of the file created in tmp when `failureMode` is set to `diskspace`.
69-
* `blacklist` is an array of regular expressions, if a connection is made to a host matching one of the regular expressions it will be blocked.
69+
* `denylist` is an array of regular expressions, if a connection is made to a host matching one of the regular expressions it will be blocked.
7070

7171
## Example
7272

@@ -78,6 +78,12 @@ Inspired by Yan Cui's articles on latency injection for AWS Lambda (https://hack
7878

7979
## Changelog
8080

81+
### 2020-08-24 v0.3.0
82+
83+
* Changed mitm mode from connect to connection for quicker enable/disable of failure injection.
84+
* Renamed block list failure injection to denylist (breaking change for that failure mode).
85+
* Updated dependencies.
86+
8187
### 2020-02-28 v0.2.0
8288

8389
* Fixed Key Vault integration.

example/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "",
3+
"version": "0.0.0",
4+
"description": "",
5+
"dependencies": {
6+
"failure-azurefunctions": ""
7+
}
8+
}

lib/failure.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ var injectFailure = function (fn) {
4949
}
5050
}
5151
createFile(process.env.TEMP + '/diskspace-failure-' + Date.now() + '.tmp', config.diskSpace)
52-
} else if (config.failureMode === 'blacklist') {
53-
console.log('Injecting dependency failure through a network blackhole for blacklisted sites: ' + config.blacklist)
52+
} else if (config.failureMode === 'denylist') {
53+
console.log('Injecting dependency failure through a network block for denylisted sites: ' + config.denylist)
5454
let mitm = Mitm()
5555
let blRegexs = []
56-
config.blacklist.forEach(function (regexStr) {
56+
config.denylist.forEach(function (regexStr) {
5757
blRegexs.push(new RegExp(regexStr))
5858
})
59-
mitm.on('connect', function (socket, opts) {
59+
mitm.on('connection', function (socket, opts) {
6060
let block = false
6161
blRegexs.forEach(function (blRegex) {
6262
if (blRegex.test(opts.host)) {

0 commit comments

Comments
 (0)