Skip to content

Code breaks when algorithm=MD5 key value pair occurs in response headers #15

@himanshu219

Description

@himanshu219

Sometimes some apis give algorithm=MD5 in the response headers without quotes which breaks the code with below traceback.

// console output of parts array
realm="MMS Public API"
 domain=""
 nonce="7hziqlF0xTs4PbKVmzPlEGq0yZRNiFuY"
 algorithm=MD5
/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:107
      if (part.length > 2) {
               ^

TypeError: Cannot read property 'length' of null
    at HTTPDigest.parseChallenge [as _parseChallenge] (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:107:16)
    at HTTPDigest.handleResponse [as _handleResponse] (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:39:26)
    at ClientRequest.<anonymous> (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:29:12)
    at Object.onceWrapper (events.js:285:13)
    at ClientRequest.emit (events.js:197:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:560:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:113:17)
    at TLSSocket.socketOnData (_http_client.js:447:20)
    at TLSSocket.emit (events.js:197:13)
    at addChunk (_stream_readable.js:288:12)

at line number 106 using the following regex fixes the issue
var part = parts[i].match(/^\s*?([a-zA-Z0-0]+)="(.)"\s?$|^\s*?([a-zA-Z0-0]+)=(.)\s?$/);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions