Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add-ssl-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
skitterm committed Sep 20, 2018
2 parents a350f76 + 30fadcb commit 65c0b82
Show file tree
Hide file tree
Showing 26 changed files with 899 additions and 698 deletions.
3 changes: 2 additions & 1 deletion packages/arcgis-rest-auth/src/UserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ export class UserSession implements IAuthenticationManager {
url: string,
requestOptions?: ITokenRequestOptions
) {
const [root] = url.split("/rest/services/");
// requests to /rest/services/ and /rest/admin/services/ are both valid
const [root] = url.split(/\/rest(\/admin)?\/services\//);
const existingToken = this.trustedServers[root];

if (existingToken && existingToken.expires.getTime() > Date.now()) {
Expand Down
51 changes: 51 additions & 0 deletions packages/arcgis-rest-auth/test/UserSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,57 @@ describe("UserSession", () => {
});
});

it("should generate a token for an untrusted, federated server admin call", done => {
const session = new UserSession({
clientId: "id",
token: "token",
refreshToken: "refresh",
tokenExpires: TOMORROW,
portal: "https://gis.city.gov/sharing/rest"
});

fetchMock.postOnce("https://gisservices.city.gov/public/rest/info", {
currentVersion: 10.51,
fullVersion: "10.5.1.120",
owningSystemUrl: "https://gis.city.gov",
authInfo: {
isTokenBasedSecurity: true,
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken"
}
});

fetchMock.postOnce("https://gis.city.gov/sharing/rest/info", {
owningSystemUrl: "http://gis.city.gov",
authInfo: {
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
isTokenBasedSecurity: true
}
});

fetchMock.postOnce("https://gis.city.gov/sharing/generateToken", {
token: "serverToken",
expires: TOMORROW
});

session
.getToken(
"https://gisservices.city.gov/public/rest/admin/services/trees/FeatureServer/addToDefinition"
)
.then(token => {
expect(token).toBe("serverToken");
return session.getToken(
"https://gisservices.city.gov/public/rest/admin/services/trees/FeatureServer/addToDefinition"
);
})
.then(token => {
expect(token).toBe("serverToken");
done();
})
.catch(e => {
fail(e);
});
});

it("should generate a token for an untrusted, federated server with user credentials", done => {
const session = new UserSession({
username: "c@sey",
Expand Down
34 changes: 34 additions & 0 deletions packages/arcgis-rest-groups/src/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
getPortalUrl
} from "@esri/arcgis-rest-request";

import { IGroupAdd } from "@esri/arcgis-rest-common-types";

import { serializeGroup } from "./helpers";

export interface IGroupAddRequestOptions extends IRequestOptions {
group: IGroupAdd;
}

/**
* Create a new Group.
* Note: The group name must be unique within the user's organization.
* @param requestOptions - Options for the request, including a group object
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function createGroup(
requestOptions: IGroupAddRequestOptions
): Promise<any> {
const url = `${getPortalUrl(requestOptions)}/community/createGroup`;
const options: IGroupAddRequestOptions = {
...requestOptions
};
// serialize the group into something Portal will accept
options.params = serializeGroup(requestOptions.group);
return request(url, options);
}
95 changes: 95 additions & 0 deletions packages/arcgis-rest-groups/src/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
getPortalUrl
} from "@esri/arcgis-rest-request";

import { IPagingParams, IGroup, IItem } from "@esri/arcgis-rest-common-types";

export interface IPagingParamsRequestOptions extends IRequestOptions {
paging: IPagingParams;
}

export interface IGroupContentResult {
total: number;
start: number;
num: number;
nextStart: number;
items: IItem[];
}

export interface IGroupUsersResult {
owner: string;
admins: string[];
users: string[];
}

/**
*
* @param id - Group Id
* @param requestOptions - Options for the request
* @returns A Promise that will resolve with the data from the response.
*/
export function getGroup(
id: string,
requestOptions?: IRequestOptions
): Promise<IGroup> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}`;
// default to a GET request
const options: IRequestOptions = {
...{ httpMethod: "GET" },
...requestOptions
};
return request(url, options);
}

/**
* Returns the content of a Group. Since the group may contain 1000s of items
* the requestParams allow for paging.
* @param id - Group Id
* @param requestOptions - Options for the request, including paging parameters.
* @returns A Promise that will resolve with the content of the group.
*/
export function getGroupContent(
id: string,
requestOptions?: IPagingParamsRequestOptions
): Promise<IGroup> {
const url = `${getPortalUrl(requestOptions)}/content/groups/${id}`;

// default to a GET request
const options: IRequestOptions = {
...{ httpMethod: "GET" },
params: { start: 1, num: 100 },
...requestOptions
} as IPagingParamsRequestOptions;

// is this the most concise way to mixin with the defaults above?
if (requestOptions && requestOptions.paging) {
options.params = { ...requestOptions.paging };
}

return request(url, options);
}

/**
* Get the usernames of the admins and members. Does not return actual 'User' objects. Those must be
* retrieved via separate calls to the User's API.
* @param id - Group Id
* @param requestOptions - Options for the request
* @returns A Promise that will resolve with arrays of the group admin usernames and the member usernames
*/
export function getGroupUsers(
id: string,
requestOptions?: IRequestOptions
): Promise<IGroupUsersResult> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}/users`;
// default to a GET request
const options: IRequestOptions = {
...{ httpMethod: "GET" },
...requestOptions
};
return request(url, options);
}
Loading

0 comments on commit 65c0b82

Please sign in to comment.