New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
applyFilter: handle empty payloads #338
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,74 @@ describe('utils', function () { | |
done(); | ||
}); | ||
}); | ||
|
||
describe('GreatResponse()', function () { | ||
|
||
var generateGreatResponse = function (requestPayload, responsePayload) { | ||
var filterRules = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New line after |
||
password: 'censor' | ||
}; | ||
|
||
var options = { | ||
'requestHeaders': true, | ||
'requestPayload': true, | ||
'responsePayload': true | ||
}; | ||
|
||
var request = { | ||
id: '1429974169154:localhost:10578:i8x5ousn:10000', | ||
raw: { | ||
req: { | ||
headers: { | ||
'user-agent': 'Paw/2.2.1 (Macintosh; OS X/10.10.3) GCDHTTPRequest' | ||
} | ||
}, | ||
res: { | ||
statusCode: 200 | ||
} | ||
}, | ||
info: { | ||
received: 1429974169154, | ||
remoteAddress: '127.0.0.1' | ||
}, | ||
method: 'POST', | ||
path: '/', | ||
query: {}, | ||
responseTime: 123, | ||
connection: { | ||
settings: { | ||
labels: [] | ||
}, | ||
info: { | ||
uri: 'http://localhost:3000' | ||
} | ||
}, | ||
payload: requestPayload, | ||
response: { | ||
source: responsePayload | ||
}, | ||
getLog: function () { | ||
return {}; | ||
} | ||
}; | ||
return new Utils.GreatResponse(request, options, filterRules); | ||
}; | ||
|
||
it('handles empty request payloads', function (done) { | ||
|
||
generateGreatResponse(null, {message: 'test'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add tests for plain strings as well. |
||
generateGreatResponse({}, {message: 'test'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style guide -> |
||
generateGreatResponse(undefined, {message: 'test'}); | ||
done(); | ||
}); | ||
|
||
it('handles empty response payloads', function (done) { | ||
|
||
generateGreatResponse({message: 'test'}, null); | ||
generateGreatResponse({message: 'test'}, {}); | ||
generateGreatResponse({message: 'test'}, undefined); | ||
done(); | ||
}); | ||
|
||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the check should be for
!(data && typeof data === 'object')
. Whilenull
orundefined
cause an issue, plain string responses or payloads cause the problem too.Also, please check the style guide. If statements must have brackets around the body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added also the condition
Object.keys(data).length > 0
, as empty objects also seem to cause this bug.