Skip to content

Commit

Permalink
Merge pull request #263 from ibm-cloud-security/development
Browse files Browse the repository at this point in the history
fix(package.json): bump GotJS from v9.6 to v11.8
  • Loading branch information
abod-akhras authored Mar 7, 2022
2 parents 5746763 + e4ab9fe commit 18ea697
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/strategies/webapp-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function handleChangeDetails(req, options, strategy) {
var generateCodeUrl = strategy.serviceConfig.getOAuthServerUrl() + GENERATE_CODE_PATH;
request({
'url': generateCodeUrl,
responseType: 'text',
'auth': {
'bearer': appIdAuthContext.accessToken + ' ' + appIdAuthContext.identityToken
}
Expand Down
29 changes: 24 additions & 5 deletions lib/utils/request-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ module.exports = (function () {

options.headers = objectKeysToLowerCase(options.headers);
options.headers["content-type"] = options.headers["content-type"] || 'application/json';
}

// GotJS doesn't allow Request Body with the GET OR DELETE Method by default.
if(options.method === 'GET' || 'DELETE') {
if(options.body === null) {
delete options.body;
}
else {
options.allowGetBody = true;
}
}

if (options.qs) {
Expand Down Expand Up @@ -85,7 +95,9 @@ module.exports = (function () {

// receive a JSON body
// This is necessary for the ServerSDK only as we are expecting JSON response in all the calls
options.responseType = 'json';
if (!options.responseType) {
options.responseType = 'json';
}

if (options.json) {
// Handle json param same as Request library used to handle, so If json is true, then body must be a JSON-serializable object.
Expand Down Expand Up @@ -122,10 +134,17 @@ module.exports = (function () {
callback(error, response, body);
} catch (err) {
error = err;
statusCode = err.statusCode;
response = {
statusCode
};
if (err.response && err.response.statusCode) {
statusCode = err.response.statusCode;
}

// If body is empty, then return the response details of the error object
if(!body && err.response) {
response = err.response;
body = err.response.body;
response.statusCode = statusCode;
}

callback(error, response, body);
}
})();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"cookie-parser": "^1.4.5",
"ejs": "^3.1.3",
"form-data": "^2.3.3",
"got": "^9.6.0",
"got": "^11.8.3",
"helmet": "^3.23.3",
"jsonwebtoken": "^8.5.1",
"log4js": "^6.4.1",
Expand All @@ -59,4 +59,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
5 changes: 3 additions & 2 deletions test/request-util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ describe('/lib/utils/request-util', function (done) {

it('should return an error if body was not sent back2', (done) => {
let sampleError = new Error("Some Error");
sampleError.statusCode = 500;
sampleError.response = {};
sampleError.response.statusCode = 500;
gotStub = sandbox.stub().rejects(sampleError);
requestUtil = proxyquire("../lib/utils/request-util", {
got: gotStub,
Expand All @@ -302,7 +303,7 @@ describe('/lib/utils/request-util', function (done) {
expect(gotStub).to.have.been.calledOnce;
expect(error).to.equal(sampleError);
expect(response).to.deep.equal({
statusCode: sampleError.statusCode
statusCode: sampleError.response.statusCode
});
done();
}
Expand Down

0 comments on commit 18ea697

Please sign in to comment.