Skip to content

Commit

Permalink
fix(lock): pass through url and options for non-federated requests
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-auth
@esri/arcgis-rest-request
  • Loading branch information
jgravois committed Apr 9, 2019
1 parent 2697887 commit 802006c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
5 changes: 1 addition & 4 deletions demos/vue/src/components/App.vue
Expand Up @@ -222,9 +222,7 @@ export default {
// session.
this.$store.dispatch("updateSession", session);
})
.catch(error => {
console.error(error);
});
.catch(error);
}
},
// The signup with an inline redirect workflow. In this case the user is just redirected to
Expand Down Expand Up @@ -270,7 +268,6 @@ export default {
})
.catch(error => {
this.searching = false;
console.error(error);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion demos/webmap-checker-sapper/package.json
Expand Up @@ -5,7 +5,7 @@
"version": "1.19.1",
"scripts": {
"dev": "sapper dev",
"build": "sapper build --legacy",
"build:legacy": "sapper build --legacy",
"export": "sapper export --legacy",
"start": "node __sapper__/build",
"cy:run": "cypress run",
Expand Down
36 changes: 36 additions & 0 deletions packages/arcgis-rest-auth/test/UserSession.test.ts
Expand Up @@ -5,6 +5,7 @@ import { UserSession } from "../src/index";
import { ICredential } from "../src/UserSession";

import {
request,
ArcGISRequestError,
ArcGISAuthError,
ErrorTypes
Expand Down Expand Up @@ -477,6 +478,41 @@ describe("UserSession", () => {
});
});

it("should throw a fully hydrated ArcGISAuthError when no owning system is advertised", done => {
const session = new UserSession({
clientId: "id",
token: "token",
refreshToken: "refresh",
tokenExpires: YESTERDAY
});

fetchMock.post("https://gisservices.city.gov/public/rest/info", {
currentVersion: 10.51,
fullVersion: "10.5.1.120"
});

request(
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query",
{
authentication: session,
params: {
foo: "bar"
}
}
).catch(e => {
expect(e.name).toEqual(ErrorTypes.ArcGISAuthError);
expect(e.code).toEqual("NOT_FEDERATED");
expect(e.message).toEqual(
"NOT_FEDERATED: https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query is not federated with any portal and is not explicitly trusted."
);
expect(e.url).toEqual(
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
);
expect(e.options.params.foo).toEqual("bar");
done();
});
});

it("should throw an ArcGISAuthError when no owning system is advertised", done => {
const session = new UserSession({
clientId: "id",
Expand Down
11 changes: 8 additions & 3 deletions packages/arcgis-rest-request/src/request.ts
Expand Up @@ -151,13 +151,18 @@ export function request(

const fetchOptions: RequestInit = {
method: httpMethod,
// ensures behavior mimics XMLHttpRequest. needed to support sending IWA cookies
/* ensures behavior mimics XMLHttpRequest.
needed to support sending IWA cookies */
credentials: "same-origin"
};

return (authentication
? authentication.getToken(url, {
fetch: options.fetch
? authentication.getToken(url, { fetch: options.fetch }).catch(err => {
/* if necessary, append original request url and
requestOptions to the error thrown by getToken() */
err.url = url;
err.options = options;
throw err;
})
: Promise.resolve("")
)
Expand Down
Expand Up @@ -7,9 +7,8 @@ import {
ArcGISOnlineError,
GenerateTokenError
} from "./../mocks/errors";
import { request } from "../../src/request";
import * as fetchMock from "fetch-mock";
import { request } from "https";
import { request as esriRequest } from "../../src/request";

describe("ArcGISRequestError", () => {
afterEach(fetchMock.restore);
Expand Down Expand Up @@ -176,7 +175,7 @@ describe("ArcGISRequestError", () => {
it("should throw an authentication error for invalid credentials", done => {
fetchMock.post("*", GenerateTokenError);

esriRequest("https://www.arcgis.com/sharing/rest/generateToken", {
request("https://www.arcgis.com/sharing/rest/generateToken", {
params: {
username: "correct",
password: "incorrect",
Expand Down

0 comments on commit 802006c

Please sign in to comment.