Skip to content

Commit

Permalink
Push unit tests that verify that prototype methods can't be overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
menewman committed Aug 26, 2023
1 parent 4c7927a commit 8ea6699
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/unit/request_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ describe('Request', function() {
request.custom2.should.eql(originalRequest.custom2);
});

it('should not allow overwriting methods on the Request prototype via custom properties', () => {
const request = new Request({
query: {},
method: 'GET',
headers: {
'content-type': 'application/json'
},
get() {
// malicious attempt to override the 'get' method
return 'text/html';
}
});

request.get('content-type').should.equal('application/json');
});

it('should allow getting of headers using `request.get`', function() {
const originalRequest = generateBaseRequest();

Expand Down
14 changes: 14 additions & 0 deletions test/unit/response_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ describe('Request', function() {
response.custom2.should.eql(originalResponse.custom2);
});

it('should not allow overwriting methods on the Response prototype via custom properties', () => {
const response = new Response({
headers: {
'content-type': 'application/json'
},
get() {
// malicious attempt to override the 'get' method
return 'text/html';
}
});

response.get('content-type').should.equal('application/json');
});

it('should allow getting of headers using `response.get`', function() {
const originalResponse = generateBaseResponse();

Expand Down

0 comments on commit 8ea6699

Please sign in to comment.