Skip to content

Commit

Permalink
2.1.0 (#79)
Browse files Browse the repository at this point in the history
* Accept HTTP status codes between 199 and 300 as successes (#78)

* Fix: handle not JSON content in response parsing (#59)

* Coveralls Badge Fix

* Coveralls Badge Fix:Final

* Coveralls Badge Fix : istanbul package added

* Coveralls Badge Fix + snyk added

* Coveralls Badge Fix + snyk added

* Snyk removed from Makefile

* Snyk removed for timebeing

* Add more code coverage for OAuthClient (#54)

* Add better code coverage in OAuthClient

* Fix: ValidateIdToken method and unit tests (#58)

* Fix validateIdToken tests

* Pointing README Badge to Develop

* Pointing README Badge to Develop

* Update Develop Coverage Badge

* Fix: handle not JSON content in response parsing

Some intuit API as invoice download return not JSON content (PDF in this
case). `makeApiCall` wasn't working with it because of mandatory
response body parsing.

So if the response is not JSON, we don't want to parse the body.
And simply let the caller decide what to do with it.

Co-authored-by: abisalehalliprasan <anil_kumar3@intuit.com>
Co-authored-by: Oscar Rabasa <oscargrp@gmail.com>
Co-authored-by: Kevin Tang <kevin.hm.tang@gmail.com>
Co-authored-by: abisalehalliprasan <38014312+abisalehalliprasan@users.noreply.github.com>

* Release : 2.1.0

* Release : 2.1.0

* Release : 2.1.0 : Revert back dependencies

* Release : 2.1.0 : Revert back dependencies

Co-authored-by: Zina Schroeder <zina.schroeder@gmail.com>
Co-authored-by: Sébastien Boulle <sebastien@cleany.fr>
Co-authored-by: Oscar Rabasa <oscargrp@gmail.com>
Co-authored-by: Kevin Tang <kevin.hm.tang@gmail.com>
  • Loading branch information
5 people authored Apr 10, 2020
1 parent f67968e commit 714078d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 22 deletions.
26 changes: 6 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intuit-oauth",
"version": "2.0.2",
"version": "2.1.0",
"description": "Intuit Node.js client for OAuth2.0 and OpenIDConnect",
"main": "./src/OAuthClient.js",
"scripts": {
Expand Down Expand Up @@ -67,38 +67,24 @@
"dependencies": {
"atob": "2.1.2",
"csrf": "^3.0.4",
"es6-promise": "^4.2.5",
"events": "^3.0.0",
"idtoken-verifier": "^1.2.0",
"jsonwebtoken": "^8.3.0",
"oauth-signature": "^1.3.1",
"object-assign": "^4.1.1",
"popsicle": "10.0.1",
"query-string": "6.2.0",
"query-string": "^6.12.0",
"rsa-pem-from-mod-exp": "^0.8.4",
"winston": "^3.1.0"
},
"devDependencies": {
"body-parser": "^1.15.2",
"btoa": "^1.2.1",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chance": "^1.1.3",
"cors": "^2.8.1",
"coveralls": "^3.0.7",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-import": "^2.9.0",
"express": "^4.14.0",
"is-travis": "^1.0.0",
"istanbul": "^0.4.5",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.2",
"mocha": "^5.0.4",
"mocha-lcov-reporter": "^1.3.0",
"nock": "^9.2.3",
"nyc": "^11.6.0",
"phantomjs-prebuilt": "^2.1.4",
"sinon": "^7.5.0",
"standard": "^11.0.0",
"watchify": "^3.7.0"
"sinon": "^9.0.2"
}
}
4 changes: 2 additions & 2 deletions src/response/AuthResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function AuthResponse(params) {
AuthResponse.prototype.processResponse = function processResponse(response) {
this.response = response || '';
this.body = (response && response.body) || '';
this.json = this.body ? JSON.parse(this.body) : null;
this.json = this.body && this.isJson() ? JSON.parse(this.body) : null;
this.intuit_tid = (response && response.headers && response.headers.intuit_tid) || '';
};

Expand Down Expand Up @@ -86,7 +86,7 @@ AuthResponse.prototype.headers = function headers() {
* @returns {*|boolean}
*/
AuthResponse.prototype.valid = function valid() {
return (this.response && Number(this.response.status) === 200);
return (this.response && Number(this.response.status) >= 200 && Number(this.response.status) < 300);
};


Expand Down
66 changes: 66 additions & 0 deletions test/AuthResponseTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const OAuthClientTest = require('../src/OAuthClient');
const AuthResponse = require('../src/response/AuthResponse');
const expectedAccessToken = require('./mocks/bearer-token.json');
const expectedResponseMock = require('./mocks/response.json');
const expectedPdfResponseMock = require('./mocks/pdfResponse.json');


const oauthClient = new OAuthClientTest({
Expand Down Expand Up @@ -120,3 +121,68 @@ describe('Tests for AuthResponse', () => {
expect(() => authResponse.processResponse(null)).to.not.throw();
});
});

describe('Tests for AuthResponse with not json content', () => {
let authResponse;
let getStub;
let expectedResponse;

beforeEach(() => {
expectedResponse = JSON.parse(JSON.stringify(expectedPdfResponseMock));
getStub = sinon.stub().returns('application/pdf');
expectedResponse.get = getStub;

authResponse = new AuthResponse({ token: oauthClient.getToken() });
authResponse.processResponse(expectedResponse);
});

afterEach(() => {
getStub.reset();
});

it('Creates a new auth response instance', () => {
expect(authResponse).to.have.property('token');
expect(authResponse).to.have.property('response');
expect(authResponse).to.have.property('body');
expect(authResponse).to.have.property('json');
expect(authResponse).to.have.property('intuit_tid');
});

it('Process Response', () => {
authResponse.processResponse(expectedResponse);
expect(authResponse.response).to.deep.equal(expectedResponse);
});

it('Process Get Token', () => {
const token = authResponse.getToken();
expect(token).to.have.property('token_type');
expect(token).to.have.property('refresh_token');
expect(token).to.have.property('expires_in');
expect(token).to.have.property('x_refresh_token_expires_in');
});

it('Process Text() when there is body ', () => {
const text = authResponse.text();
expect(text).to.be.a('string');
expect(text).to.be.equal('%PDF-1.\ntrailer<</Root<</Pages<</Kids[<</MediaBox[0 0 3 3]>>]>>>>>>');
});

it('Process Status of AuthResponse', () => {
const status = authResponse.status();
expect(status).to.be.equal(200);
});

it('Process Headers of AuthResponse', () => {
const headers = authResponse.headers();
expect(headers).to.be.equal(expectedResponse.headers);
});

it('Process Get Json to throw an error', () => {
expect(() => authResponse.getJson()).to.throw(Error);
});

it('GetContentType should handle False', () => {
const contentType = authResponse.getContentType();
expect(contentType).to.be.equal('application/pdf');
});
});
16 changes: 16 additions & 0 deletions test/mocks/pdfResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"url":"https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer",
"headers":{
"content-type":"application/pdf",
"content-length":"1636",
"connection":"close",
"server":"nginx",
"date":"Wed, 05 Sep 2018 05:57:09 GMT",
"intuit_tid":"1234-1234-1234-123",
"cache-control":"no-cache, no-store",
"pragma":"no-cache"
},
"body":"%PDF-1.\ntrailer<</Root<</Pages<</Kids[<</MediaBox[0 0 3 3]>>]>>>>>>",
"status":200,
"statusText":"OK"
}

0 comments on commit 714078d

Please sign in to comment.