Skip to content

Commit

Permalink
fix(portal): allow devs to pass through a bare portal url
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-auth
@esri/arcgis-rest-feature-service
@esri/arcgis-rest-geocoder
@esri/arcgis-rest-groups
@esri/arcgis-rest-items
@esri/arcgis-rest-request
@esri/arcgis-rest-sharing
@esri/arcgis-rest-users
batch-geocoder
  • Loading branch information
jgravois committed Aug 17, 2018
1 parent b93bd55 commit 99c12c0
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demos/batch-geocoder-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"homepage": "https://github.com/Esri/arcgis-rest-js#readme",
"dependencies": {
"@esri/arcgis-rest-auth": "^1.8.0",
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-geocoder": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0",
"isomorphic-fetch": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@esri/arcgis-rest-request": "^1.7.1"
},
"devDependencies": {
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-feature-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@esri/arcgis-rest-request": "^1.7.1"
},
"devDependencies": {
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-geocoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@esri/arcgis-rest-auth": "^1.8.0",
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-groups/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@esri/arcgis-rest-auth": "^1.8.0",
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-items/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@esri/arcgis-rest-auth": "^1.8.0",
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0"
},
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion packages/arcgis-rest-request/src/utils/get-portal-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { IRequestOptions } from "../request";
export function getPortalUrl(requestOptions: IRequestOptions = {}): string {
// use portal in options if specified
if (requestOptions.portal) {
return requestOptions.portal;
if (/https?:\/\//.test(requestOptions.portal)) {
return requestOptions.portal;
} else {
// if no protocol is supplied, assume secure
return `https://${requestOptions.portal}`;
}
}

// if auth was passed, use that portal
Expand Down
37 changes: 37 additions & 0 deletions packages/arcgis-rest-request/test/utils/get-portal-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe("getPortalUrl", () => {
const url = getPortalUrl();
expect(url).toEqual("https://www.arcgis.com/sharing/rest");
});

it("should use the portal from authorization if passed", () => {
const requestOptions = {
authentication: {
Expand All @@ -19,6 +20,14 @@ describe("getPortalUrl", () => {
});

it("should use the portal in the requestOptions if passed", () => {
const requestOptions = {
portal: "https://bar.com/arcgis/sharing/rest"
};
const url = getPortalUrl(requestOptions);
expect(url).toEqual("https://bar.com/arcgis/sharing/rest");
});

it("should prefer the portal in requestOptions if both are present", () => {
const requestOptions = {
authentication: {
portal: "https://foo.com/arcgis/sharing/rest",
Expand All @@ -31,4 +40,32 @@ describe("getPortalUrl", () => {
const url = getPortalUrl(requestOptions);
expect(url).toEqual("https://bar.com/arcgis/sharing/rest");
});

it("should tack on a protocol if none was supplied in requestOptions.portal", () => {
const requestOptions = {
authentication: {
portal: "https://foo.com/arcgis/sharing/rest",
getToken() {
return Promise.resolve("fake");
}
},
portal: "bar.com/arcgis/sharing/rest"
};
const url = getPortalUrl(requestOptions);
expect(url).toEqual("https://bar.com/arcgis/sharing/rest");
});

it("should not tack on a protocol if an insecure portal url was supplied in requestOptions.portal", () => {
const requestOptions = {
authentication: {
portal: "https://foo.com/arcgis/sharing/rest",
getToken() {
return Promise.resolve("fake");
}
},
portal: "http://bar.com/arcgis/sharing/rest"
};
const url = getPortalUrl(requestOptions);
expect(url).toEqual("http://bar.com/arcgis/sharing/rest");
});
});
2 changes: 1 addition & 1 deletion packages/arcgis-rest-sharing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"devDependencies": {
"@esri/arcgis-rest-auth": "^1.8.0",
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-users/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@esri/arcgis-rest-auth": "^1.8.0",
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.8.0",
"@esri/arcgis-rest-request": "^1.8.0"
},
"scripts": {
Expand Down

0 comments on commit 99c12c0

Please sign in to comment.