Skip to content

Commit

Permalink
Esri#295: Test cases added for when ssl property/parameter is not ret…
Browse files Browse the repository at this point in the history
…urned or present.
  • Loading branch information
skitterm committed Sep 20, 2018
1 parent eb96e2b commit 584b0e5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/arcgis-rest-auth/src/fetch-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IFetchTokenRawResponse {
access_token: string;
expires_in: number;
username: string;
ssl: boolean;
ssl?: boolean;
refresh_token?: string;
}

Expand Down
25 changes: 23 additions & 2 deletions packages/arcgis-rest-auth/test/UserSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,27 @@ describe("UserSession", () => {
expect(session.ssl).toBe(true);
});

it("should return a new user session with ssl as false when callback hash does not have ssl parameter", () => {
const MockWindow = {
location: {
href:
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=c%40sey&persist=true"
},
get parent() {
return this;
}
};

const session = UserSession.completeOAuth2(
{
clientId: "clientId",
redirectUri: "https://example-app.com/redirect-uri"
},
MockWindow
);
expect(session.ssl).toBe(false);
});

it("should callback to create a new user session if finds a valid opener", done => {
const MockWindow = {
opener: {
Expand All @@ -739,7 +760,7 @@ describe("UserSession", () => {
const oauthInfo = JSON.parse(oauthInfoString);
expect(oauthInfo.token).toBe("token");
expect(oauthInfo.username).toBe("c@sey");
expect(oauthInfo.ssl).toBe(false);
expect(oauthInfo.ssl).toBe(true);
expect(new Date(oauthInfo.expires).getTime()).toBeGreaterThan(
Date.now()
);
Expand All @@ -751,7 +772,7 @@ describe("UserSession", () => {
},
location: {
href:
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=c%40sey"
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=c%40sey&ssl=true"
}
};

Expand Down
29 changes: 27 additions & 2 deletions packages/arcgis-rest-auth/test/fetchToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("fetchToken()", () => {
fetchMock.postOnce(TOKEN_URL, {
access_token: "token",
expires_in: 1800,
ssl: false
ssl: true
});

fetchToken(TOKEN_URL, {
Expand All @@ -34,7 +34,7 @@ describe("fetchToken()", () => {
expect(options.body).toContain("grant_type=client_credentials");
expect(response.token).toEqual("token");
expect(response.expires).toBeGreaterThan(Date.now());
expect(response.ssl).toEqual(false);
expect(response.ssl).toEqual(true);
done();
})
.catch(e => {
Expand Down Expand Up @@ -84,4 +84,29 @@ describe("fetchToken()", () => {
fail(e);
});
});

it("should return ssl: false when there is no ssl property returned from endpoint response", done => {
fetchMock.postOnce(TOKEN_URL, {
access_token: "token",
expires_in: 1800,
refresh_token: "refreshToken",
username: "Casey"
});

fetchToken(TOKEN_URL, {
params: {
client_id: "clientId",
redirect_uri: "https://example-app.com/redirect-uri",
code: "authorizationCode",
grant_type: "authorization_code"
}
})
.then(response => {
expect(response.ssl).toEqual(false);
done();
})
.catch(e => {
fail(e);
});
});
});

0 comments on commit 584b0e5

Please sign in to comment.