impeditmaiores 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.prettierignore +2 -0
- package/.travis.yml +35 -0
- package/.vscode/launch.json +24 -0
- package/.vscode/settings.json +3 -0
- package/codecov.yml +7 -0
- package/demos/ago-node-cli/README.md +29 -0
- package/demos/ago-node-cli/ago.js +33 -0
- package/demos/ago-node-cli/index.js +11 -0
- package/demos/ago-node-cli/lib/item-export-command.js +48 -0
- package/demos/ago-node-cli/lib/item-search-command.js +35 -0
- package/demos/ago-node-cli/package-lock.json +152 -0
- package/demos/ago-node-cli/package.json +30 -0
- package/demos/attachments/README.md +5 -0
- package/demos/attachments/index.html +165 -0
- package/demos/attachments/package-lock.json +182 -0
- package/demos/attachments/package.json +18 -0
- package/demos/batch-geocoder-node/NYC_Restaurant_Inspection_Results.csv +100 -0
- package/demos/batch-geocoder-node/README.md +15 -0
- package/demos/batch-geocoder-node/batch-geocode.js +115 -0
- package/demos/batch-geocoder-node/config-template.js +18 -0
- package/demos/batch-geocoder-node/package-lock.json +81 -0
- package/demos/batch-geocoder-node/package.json +37 -0
- package/demos/express/README.md +15 -0
- package/demos/express/config.json.template +3 -0
- package/demos/express/package-lock.json +413 -0
- package/demos/express/package.json +18 -0
- package/demos/express/server.js +33 -0
- package/demos/feature-service-browser/README.md +6 -0
- package/demos/feature-service-browser/index.html +122 -0
- package/demos/feature-service-browser/package-lock.json +182 -0
- package/demos/feature-service-browser/package.json +18 -0
- package/demos/geocoder-browser/README.md +10 -0
- package/demos/geocoder-browser/config.js.template +1 -0
- package/demos/geocoder-browser/index.html +131 -0
- package/demos/geocoder-browser/package-lock.json +182 -0
- package/demos/geocoder-browser/package.json +19 -0
- package/demos/geocoder-browser/post-sign-in.html +25 -0
- package/demos/jsapi-integration/README.md +25 -0
- package/demos/jsapi-integration/config.js +6 -0
- package/demos/jsapi-integration/index.html +89 -0
- package/demos/jsapi-integration/package-lock.json +184 -0
- package/demos/jsapi-integration/package.json +19 -0
- package/demos/node-cli-item-management/README.md +10 -0
- package/demos/node-cli-item-management/index.js +238 -0
- package/demos/node-cli-item-management/package-lock.json +152 -0
- package/demos/node-cli-item-management/package.json +27 -0
- package/demos/node-cli-item-management/screenshot.png +0 -0
- package/demos/oauth2-browser/README.md +14 -0
- package/demos/oauth2-browser/authenticate.html +30 -0
- package/demos/oauth2-browser/config.js.template +6 -0
- package/demos/oauth2-browser/index.html +211 -0
- package/demos/oauth2-browser/logo.svg +4 -0
- package/demos/oauth2-browser/package-lock.json +224 -0
- package/demos/oauth2-browser/package.json +18 -0
- package/demos/oauth2-browser/style.css +36 -0
- package/demos/oauth2-browser-retry/README.md +25 -0
- package/demos/oauth2-browser-retry/authenticate.html +22 -0
- package/demos/oauth2-browser-retry/index.html +116 -0
- package/demos/oauth2-browser-retry/logo.svg +4 -0
- package/demos/stream-response-to-file/README.md +7 -0
- package/demos/stream-response-to-file/index.js +36 -0
- package/demos/stream-response-to-file/output/.gitkeep +0 -0
- package/demos/stream-response-to-file/package-lock.json +60 -0
- package/demos/stream-response-to-file/package.json +33 -0
- package/demos/tree-shaking-rollup/.babelrc +3 -0
- package/demos/tree-shaking-rollup/README.md +9 -0
- package/demos/tree-shaking-rollup/index.html +11 -0
- package/demos/tree-shaking-rollup/package-lock.json +2225 -0
- package/demos/tree-shaking-rollup/package.json +25 -0
- package/demos/tree-shaking-rollup/rollup.config.js +17 -0
- package/demos/tree-shaking-rollup/src/index.js +8 -0
- package/demos/tree-shaking-webpack/README.md +8 -0
- package/demos/tree-shaking-webpack/index.html +11 -0
- package/demos/tree-shaking-webpack/package-lock.json +4614 -0
- package/demos/tree-shaking-webpack/package.json +24 -0
- package/demos/tree-shaking-webpack/src/index.js +10 -0
- package/demos/tree-shaking-webpack/webpack.config.js +27 -0
- package/demos/vue/.env.example +11 -0
- package/demos/vue/.eslintrc.js +17 -0
- package/demos/vue/.postcssrc.js +5 -0
- package/demos/vue/README.md +17 -0
- package/demos/vue/babel.config.js +3 -0
- package/demos/vue/package-lock.json +11342 -0
- package/demos/vue/package.json +33 -0
- package/demos/vue/public/favicon.ico +0 -0
- package/demos/vue/public/index.html +24 -0
- package/demos/vue/src/assets/logo.svg +29 -0
- package/demos/vue/src/components/App.vue +305 -0
- package/demos/vue/src/components/Authenticate.vue +65 -0
- package/demos/vue/src/components/Loader.vue +230 -0
- package/demos/vue/src/main.js +92 -0
- package/demos/webmap-checker-sapper/.env.example +5 -0
- package/demos/webmap-checker-sapper/README.md +123 -0
- package/demos/webmap-checker-sapper/appveyor.yml +18 -0
- package/demos/webmap-checker-sapper/cypress/fixtures/example.json +5 -0
- package/demos/webmap-checker-sapper/cypress/integration/spec.js +19 -0
- package/demos/webmap-checker-sapper/cypress/plugins/index.js +17 -0
- package/demos/webmap-checker-sapper/cypress/support/commands.js +25 -0
- package/demos/webmap-checker-sapper/cypress/support/index.js +20 -0
- package/demos/webmap-checker-sapper/cypress.json +4 -0
- package/demos/webmap-checker-sapper/package-lock.json +3870 -0
- package/demos/webmap-checker-sapper/package.json +50 -0
- package/demos/webmap-checker-sapper/rollup.config.js +87 -0
- package/demos/webmap-checker-sapper/src/client.js +20 -0
- package/demos/webmap-checker-sapper/src/components/LayerStatus.html +108 -0
- package/demos/webmap-checker-sapper/src/components/Nav.html +21 -0
- package/demos/webmap-checker-sapper/src/components/WebMap.html +62 -0
- package/demos/webmap-checker-sapper/src/routes/_error.html +41 -0
- package/demos/webmap-checker-sapper/src/routes/_layout.html +21 -0
- package/demos/webmap-checker-sapper/src/routes/auth/authorize.js +18 -0
- package/demos/webmap-checker-sapper/src/routes/auth/exchange-token.js +20 -0
- package/demos/webmap-checker-sapper/src/routes/auth/post-sign-in.js +24 -0
- package/demos/webmap-checker-sapper/src/routes/auth/sign-out.js +10 -0
- package/demos/webmap-checker-sapper/src/routes/index.html +20 -0
- package/demos/webmap-checker-sapper/src/routes/webmaps/[webmapId].html +83 -0
- package/demos/webmap-checker-sapper/src/routes/webmaps/index.html +59 -0
- package/demos/webmap-checker-sapper/src/server.js +101 -0
- package/demos/webmap-checker-sapper/src/service-worker.js +82 -0
- package/demos/webmap-checker-sapper/src/template.html +33 -0
- package/demos/webmap-checker-sapper/src/userInfoMiddleware.js +21 -0
- package/demos/webmap-checker-sapper/src/utils.js +33 -0
- package/demos/webmap-checker-sapper/static/favicon.png +0 -0
- package/demos/webmap-checker-sapper/static/global.css +36 -0
- package/demos/webmap-checker-sapper/static/manifest.json +20 -0
- package/demos/webmap-checker-sapper/static/svelte-logo-192.png +0 -0
- package/demos/webmap-checker-sapper/static/svelte-logo-512.png +0 -0
- package/docs/FAQ.md +48 -0
- package/docs/HISTORY.md +62 -0
- package/docs/acetate.config.js +262 -0
- package/docs/build-typedoc.js +434 -0
- package/docs/generate-srihashes.js +53 -0
- package/docs/src/_layout.html +86 -0
- package/docs/src/api/_declaration.html +600 -0
- package/docs/src/api/_layout.html +204 -0
- package/docs/src/api/_package.html +38 -0
- package/docs/src/api/index.html +16 -0
- package/docs/src/guides/_layout.html +24 -0
- package/docs/src/guides/amd-requirejs-dojo.md +40 -0
- package/docs/src/guides/browser-authentication.md +41 -0
- package/docs/src/guides/bundlers.md +52 -0
- package/docs/src/guides/cli-authentication.md +9 -0
- package/docs/src/guides/client-server-authentication.md +9 -0
- package/docs/src/guides/embedded-apps.md +93 -0
- package/docs/src/guides/from-a-cdn.md +38 -0
- package/docs/src/guides/index.md +59 -0
- package/docs/src/guides/node.md +87 -0
- package/docs/src/guides/package-overview.md +111 -0
- package/docs/src/guides/server-authentication.md +9 -0
- package/docs/src/guides/whats-new-v2-0.md +305 -0
- package/docs/src/img/icons.png +0 -0
- package/docs/src/img/icons@2x.png +0 -0
- package/docs/src/index.html +12 -0
- package/docs/src/js/api-search.js +112 -0
- package/docs/src/js/nav-toggle.js +41 -0
- package/docs/src/sass/_highlight.scss +96 -0
- package/docs/src/sass/_icons.scss +157 -0
- package/docs/src/sass/style.scss +242 -0
- package/docs/src/srihashes.json +12 -0
- package/jasmine.json +7 -0
- package/karma.conf.js +106 -0
- package/lerna.json +8 -0
- package/notes/README.md +68 -0
- package/package.json +87 -0
- package/packages/arcgis-rest-auth/README.md +71 -0
- package/packages/arcgis-rest-auth/package-lock.json +11 -0
- package/packages/arcgis-rest-auth/package.json +69 -0
- package/packages/arcgis-rest-auth/src/ApplicationSession.ts +122 -0
- package/packages/arcgis-rest-auth/src/UserSession.ts +1206 -0
- package/packages/arcgis-rest-auth/src/app-tokens.ts +91 -0
- package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +24 -0
- package/packages/arcgis-rest-auth/src/federation-utils.ts +85 -0
- package/packages/arcgis-rest-auth/src/fetch-token.ts +50 -0
- package/packages/arcgis-rest-auth/src/generate-token.ts +35 -0
- package/packages/arcgis-rest-auth/src/index.ts +9 -0
- package/packages/arcgis-rest-auth/src/validate-app-access.ts +68 -0
- package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +124 -0
- package/packages/arcgis-rest-auth/test/UserSession.test.ts +1807 -0
- package/packages/arcgis-rest-auth/test/app-tokens.test.ts +91 -0
- package/packages/arcgis-rest-auth/test/federation-utils.test.ts +323 -0
- package/packages/arcgis-rest-auth/test/fetchToken.test.ts +112 -0
- package/packages/arcgis-rest-auth/test/generateToken.test.ts +102 -0
- package/packages/arcgis-rest-auth/test/utils.ts +14 -0
- package/packages/arcgis-rest-auth/test/validate-app-access.test.ts +46 -0
- package/packages/arcgis-rest-auth/tsconfig.json +6 -0
- package/packages/arcgis-rest-feature-layer/README.md +77 -0
- package/packages/arcgis-rest-feature-layer/package-lock.json +11 -0
- package/packages/arcgis-rest-feature-layer/package.json +64 -0
- package/packages/arcgis-rest-feature-layer/src/add.ts +56 -0
- package/packages/arcgis-rest-feature-layer/src/addAttachment.ts +53 -0
- package/packages/arcgis-rest-feature-layer/src/applyEdits.ts +90 -0
- package/packages/arcgis-rest-feature-layer/src/decodeValues.ts +124 -0
- package/packages/arcgis-rest-feature-layer/src/delete.ts +61 -0
- package/packages/arcgis-rest-feature-layer/src/deleteAttachments.ts +52 -0
- package/packages/arcgis-rest-feature-layer/src/getAttachments.ts +55 -0
- package/packages/arcgis-rest-feature-layer/src/getLayer.ts +24 -0
- package/packages/arcgis-rest-feature-layer/src/getService.ts +26 -0
- package/packages/arcgis-rest-feature-layer/src/helpers.ts +79 -0
- package/packages/arcgis-rest-feature-layer/src/index.ts +31 -0
- package/packages/arcgis-rest-feature-layer/src/query.ts +204 -0
- package/packages/arcgis-rest-feature-layer/src/queryRelated.ts +89 -0
- package/packages/arcgis-rest-feature-layer/src/update.ts +56 -0
- package/packages/arcgis-rest-feature-layer/src/updateAttachment.ts +59 -0
- package/packages/arcgis-rest-feature-layer/test/attachments.test.ts +200 -0
- package/packages/arcgis-rest-feature-layer/test/crud.test.ts +195 -0
- package/packages/arcgis-rest-feature-layer/test/decodeValues.test.ts +67 -0
- package/packages/arcgis-rest-feature-layer/test/getLayer.test.ts +31 -0
- package/packages/arcgis-rest-feature-layer/test/getService.test.ts +31 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/cvdQueryResponse.ts +225 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/feature.ts +302 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/fields.ts +779 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/foo.txt +1 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/service.ts +398 -0
- package/packages/arcgis-rest-feature-layer/test/query.test.ts +167 -0
- package/packages/arcgis-rest-feature-layer/tsconfig.json +6 -0
- package/packages/arcgis-rest-geocoding/README.md +86 -0
- package/packages/arcgis-rest-geocoding/package-lock.json +11 -0
- package/packages/arcgis-rest-geocoding/package.json +64 -0
- package/packages/arcgis-rest-geocoding/src/bulk.ts +104 -0
- package/packages/arcgis-rest-geocoding/src/geocode.ts +133 -0
- package/packages/arcgis-rest-geocoding/src/helpers.ts +54 -0
- package/packages/arcgis-rest-geocoding/src/index.ts +15 -0
- package/packages/arcgis-rest-geocoding/src/reverse.ts +84 -0
- package/packages/arcgis-rest-geocoding/src/suggest.ts +45 -0
- package/packages/arcgis-rest-geocoding/test/bulk.test.ts +194 -0
- package/packages/arcgis-rest-geocoding/test/geocode.test.ts +249 -0
- package/packages/arcgis-rest-geocoding/test/helpers.test.ts +85 -0
- package/packages/arcgis-rest-geocoding/test/mocks/responses.ts +637 -0
- package/packages/arcgis-rest-geocoding/test/reverse.test.ts +126 -0
- package/packages/arcgis-rest-geocoding/test/suggest.test.ts +53 -0
- package/packages/arcgis-rest-geocoding/tsconfig.json +6 -0
- package/packages/arcgis-rest-portal/README.md +73 -0
- package/packages/arcgis-rest-portal/package-lock.json +11 -0
- package/packages/arcgis-rest-portal/package.json +64 -0
- package/packages/arcgis-rest-portal/src/groups/add-users.ts +140 -0
- package/packages/arcgis-rest-portal/src/groups/create.ts +43 -0
- package/packages/arcgis-rest-portal/src/groups/get.ts +184 -0
- package/packages/arcgis-rest-portal/src/groups/helpers.ts +14 -0
- package/packages/arcgis-rest-portal/src/groups/invite-users.ts +127 -0
- package/packages/arcgis-rest-portal/src/groups/join.ts +57 -0
- package/packages/arcgis-rest-portal/src/groups/notification.ts +77 -0
- package/packages/arcgis-rest-portal/src/groups/protect.ts +56 -0
- package/packages/arcgis-rest-portal/src/groups/remove-users.ts +76 -0
- package/packages/arcgis-rest-portal/src/groups/remove.ts +32 -0
- package/packages/arcgis-rest-portal/src/groups/search.ts +47 -0
- package/packages/arcgis-rest-portal/src/groups/update-user-membership.ts +63 -0
- package/packages/arcgis-rest-portal/src/groups/update.ts +39 -0
- package/packages/arcgis-rest-portal/src/index.ts +66 -0
- package/packages/arcgis-rest-portal/src/items/add.ts +138 -0
- package/packages/arcgis-rest-portal/src/items/content.ts +67 -0
- package/packages/arcgis-rest-portal/src/items/create.ts +150 -0
- package/packages/arcgis-rest-portal/src/items/export.ts +80 -0
- package/packages/arcgis-rest-portal/src/items/get.ts +437 -0
- package/packages/arcgis-rest-portal/src/items/helpers.ts +275 -0
- package/packages/arcgis-rest-portal/src/items/protect.ts +41 -0
- package/packages/arcgis-rest-portal/src/items/reassign.ts +61 -0
- package/packages/arcgis-rest-portal/src/items/remove.ts +135 -0
- package/packages/arcgis-rest-portal/src/items/search.ts +25 -0
- package/packages/arcgis-rest-portal/src/items/update.ts +184 -0
- package/packages/arcgis-rest-portal/src/items/upload.ts +125 -0
- package/packages/arcgis-rest-portal/src/orgs/notification.ts +131 -0
- package/packages/arcgis-rest-portal/src/sharing/access.ts +84 -0
- package/packages/arcgis-rest-portal/src/sharing/helpers.ts +81 -0
- package/packages/arcgis-rest-portal/src/sharing/is-item-shared-with-group.ts +42 -0
- package/packages/arcgis-rest-portal/src/sharing/share-item-with-group.ts +319 -0
- package/packages/arcgis-rest-portal/src/sharing/unshare-item-with-group.ts +105 -0
- package/packages/arcgis-rest-portal/src/users/get-user-tags.ts +52 -0
- package/packages/arcgis-rest-portal/src/users/get-user-url.ts +18 -0
- package/packages/arcgis-rest-portal/src/users/get-user.ts +58 -0
- package/packages/arcgis-rest-portal/src/users/invitation.ts +156 -0
- package/packages/arcgis-rest-portal/src/users/notification.ts +68 -0
- package/packages/arcgis-rest-portal/src/users/search-users.ts +37 -0
- package/packages/arcgis-rest-portal/src/users/update.ts +66 -0
- package/packages/arcgis-rest-portal/src/util/SearchQueryBuilder.ts +374 -0
- package/packages/arcgis-rest-portal/src/util/array.ts +16 -0
- package/packages/arcgis-rest-portal/src/util/generic-search.ts +99 -0
- package/packages/arcgis-rest-portal/src/util/get-portal-settings.ts +45 -0
- package/packages/arcgis-rest-portal/src/util/get-portal-url.ts +27 -0
- package/packages/arcgis-rest-portal/src/util/get-portal.ts +52 -0
- package/packages/arcgis-rest-portal/src/util/get-subscription-info.ts +43 -0
- package/packages/arcgis-rest-portal/src/util/scrub-control-chars.ts +12 -0
- package/packages/arcgis-rest-portal/src/util/search.ts +42 -0
- package/packages/arcgis-rest-portal/test/groups/add-users.test.ts +239 -0
- package/packages/arcgis-rest-portal/test/groups/crud.test.ts +180 -0
- package/packages/arcgis-rest-portal/test/groups/get.test.ts +176 -0
- package/packages/arcgis-rest-portal/test/groups/invite-users.test.ts +149 -0
- package/packages/arcgis-rest-portal/test/groups/join.test.ts +72 -0
- package/packages/arcgis-rest-portal/test/groups/notification.test.ts +112 -0
- package/packages/arcgis-rest-portal/test/groups/protect.test.ts +72 -0
- package/packages/arcgis-rest-portal/test/groups/remove-users.test.ts +140 -0
- package/packages/arcgis-rest-portal/test/groups/search.test.ts +151 -0
- package/packages/arcgis-rest-portal/test/groups/update-user-membership.test.ts +62 -0
- package/packages/arcgis-rest-portal/test/items/add.test.ts +323 -0
- package/packages/arcgis-rest-portal/test/items/content.test.ts +156 -0
- package/packages/arcgis-rest-portal/test/items/create.test.ts +399 -0
- package/packages/arcgis-rest-portal/test/items/export.test.ts +122 -0
- package/packages/arcgis-rest-portal/test/items/get.test.ts +583 -0
- package/packages/arcgis-rest-portal/test/items/helpers.test.ts +60 -0
- package/packages/arcgis-rest-portal/test/items/protect.test.ts +122 -0
- package/packages/arcgis-rest-portal/test/items/reassign.test.ts +131 -0
- package/packages/arcgis-rest-portal/test/items/remove.test.ts +238 -0
- package/packages/arcgis-rest-portal/test/items/search.test.ts +272 -0
- package/packages/arcgis-rest-portal/test/items/update.test.ts +554 -0
- package/packages/arcgis-rest-portal/test/items/upload.test.ts +282 -0
- package/packages/arcgis-rest-portal/test/mocks/groups/responses.ts +208 -0
- package/packages/arcgis-rest-portal/test/mocks/items/foo.zip +0 -0
- package/packages/arcgis-rest-portal/test/mocks/items/item.ts +526 -0
- package/packages/arcgis-rest-portal/test/mocks/items/resources.ts +38 -0
- package/packages/arcgis-rest-portal/test/mocks/items/search.ts +121 -0
- package/packages/arcgis-rest-portal/test/mocks/portal/response.ts +126 -0
- package/packages/arcgis-rest-portal/test/mocks/portal/settings-response.ts +56 -0
- package/packages/arcgis-rest-portal/test/mocks/sharing/sharing.ts +18 -0
- package/packages/arcgis-rest-portal/test/mocks/users/invitation.ts +70 -0
- package/packages/arcgis-rest-portal/test/mocks/users/notification.ts +34 -0
- package/packages/arcgis-rest-portal/test/mocks/users/user-search.ts +388 -0
- package/packages/arcgis-rest-portal/test/mocks/users/user-tags.ts +5 -0
- package/packages/arcgis-rest-portal/test/mocks/users/user.ts +174 -0
- package/packages/arcgis-rest-portal/test/orgs/notification.test.ts +142 -0
- package/packages/arcgis-rest-portal/test/sharing/access.test.ts +162 -0
- package/packages/arcgis-rest-portal/test/sharing/helpers.test.ts +55 -0
- package/packages/arcgis-rest-portal/test/sharing/share-item-with-group.test.ts +1325 -0
- package/packages/arcgis-rest-portal/test/sharing/unshare-item-with-group.test.ts +288 -0
- package/packages/arcgis-rest-portal/test/users/get-user-tags.test.ts +71 -0
- package/packages/arcgis-rest-portal/test/users/get-user-url.test.ts +40 -0
- package/packages/arcgis-rest-portal/test/users/get-user.test.ts +90 -0
- package/packages/arcgis-rest-portal/test/users/invitation.test.ts +127 -0
- package/packages/arcgis-rest-portal/test/users/notification.test.ts +77 -0
- package/packages/arcgis-rest-portal/test/users/search.test.ts +42 -0
- package/packages/arcgis-rest-portal/test/users/update.test.ts +151 -0
- package/packages/arcgis-rest-portal/test/util/SearchQueryBuilder.test.ts +340 -0
- package/packages/arcgis-rest-portal/test/util/array.test.ts +30 -0
- package/packages/arcgis-rest-portal/test/util/get-portal-settings.test.ts +68 -0
- package/packages/arcgis-rest-portal/test/util/get-portal-url.test.ts +37 -0
- package/packages/arcgis-rest-portal/test/util/portal.test.ts +148 -0
- package/packages/arcgis-rest-portal/test/util/scrub-control-chars.test.ts +22 -0
- package/packages/arcgis-rest-portal/tsconfig.json +6 -0
- package/packages/arcgis-rest-request/README.md +72 -0
- package/packages/arcgis-rest-request/package-lock.json +11 -0
- package/packages/arcgis-rest-request/package.json +60 -0
- package/packages/arcgis-rest-request/src/index.ts +25 -0
- package/packages/arcgis-rest-request/src/request.ts +413 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +76 -0
- package/packages/arcgis-rest-request/src/utils/ErrorTypes.ts +29 -0
- package/packages/arcgis-rest-request/src/utils/GrantTypes.ts +5 -0
- package/packages/arcgis-rest-request/src/utils/HTTPMethods.ts +6 -0
- package/packages/arcgis-rest-request/src/utils/IAuthenticationManager.ts +21 -0
- package/packages/arcgis-rest-request/src/utils/IFetchTokenParams.ts +11 -0
- package/packages/arcgis-rest-request/src/utils/IGenerateTokenParams.ts +9 -0
- package/packages/arcgis-rest-request/src/utils/IParamBuilder.ts +3 -0
- package/packages/arcgis-rest-request/src/utils/IParams.ts +6 -0
- package/packages/arcgis-rest-request/src/utils/IParamsBuilder.ts +5 -0
- package/packages/arcgis-rest-request/src/utils/IRequestOptions.ts +49 -0
- package/packages/arcgis-rest-request/src/utils/ITokenRequestOptions.ts +9 -0
- package/packages/arcgis-rest-request/src/utils/ResponseFormats.ts +10 -0
- package/packages/arcgis-rest-request/src/utils/append-custom-params.ts +49 -0
- package/packages/arcgis-rest-request/src/utils/clean-url.ts +20 -0
- package/packages/arcgis-rest-request/src/utils/decode-query-string.ts +27 -0
- package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +38 -0
- package/packages/arcgis-rest-request/src/utils/encode-query-string.ts +35 -0
- package/packages/arcgis-rest-request/src/utils/process-params.ts +108 -0
- package/packages/arcgis-rest-request/src/utils/retryAuthError.ts +10 -0
- package/packages/arcgis-rest-request/src/utils/warn.ts +11 -0
- package/packages/arcgis-rest-request/src/utils/with-options.ts +48 -0
- package/packages/arcgis-rest-request/test/mocks/errors.ts +76 -0
- package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +13 -0
- package/packages/arcgis-rest-request/test/mocks/param-builder.ts +7 -0
- package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +41 -0
- package/packages/arcgis-rest-request/test/mocks/webmap.ts +41 -0
- package/packages/arcgis-rest-request/test/request.test.ts +571 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +191 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +51 -0
- package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +111 -0
- package/packages/arcgis-rest-request/test/utils/clean-url.test.ts +50 -0
- package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +133 -0
- package/packages/arcgis-rest-request/test/utils/encode-query-string.test.ts +18 -0
- package/packages/arcgis-rest-request/test/utils/process-params.test.ts +205 -0
- package/packages/arcgis-rest-request/test/utils/with-options.test.ts +133 -0
- package/packages/arcgis-rest-request/tsconfig.json +4 -0
- package/packages/arcgis-rest-routing/README.md +75 -0
- package/packages/arcgis-rest-routing/package-lock.json +11 -0
- package/packages/arcgis-rest-routing/package.json +63 -0
- package/packages/arcgis-rest-routing/src/helpers.ts +16 -0
- package/packages/arcgis-rest-routing/src/index.ts +11 -0
- package/packages/arcgis-rest-routing/src/solveRoute.ts +124 -0
- package/packages/arcgis-rest-routing/test/mocks/responses.ts +825 -0
- package/packages/arcgis-rest-routing/test/solveRoute.test.ts +509 -0
- package/packages/arcgis-rest-routing/tsconfig.json +6 -0
- package/packages/arcgis-rest-service-admin/README.md +73 -0
- package/packages/arcgis-rest-service-admin/package-lock.json +11 -0
- package/packages/arcgis-rest-service-admin/package.json +65 -0
- package/packages/arcgis-rest-service-admin/src/addTo.ts +70 -0
- package/packages/arcgis-rest-service-admin/src/create.ts +189 -0
- package/packages/arcgis-rest-service-admin/src/index.ts +11 -0
- package/packages/arcgis-rest-service-admin/src/update.ts +50 -0
- package/packages/arcgis-rest-service-admin/test/addTo.test.ts +350 -0
- package/packages/arcgis-rest-service-admin/test/create.test.ts +294 -0
- package/packages/arcgis-rest-service-admin/test/mocks/layerDefinition.ts +79 -0
- package/packages/arcgis-rest-service-admin/test/mocks/service.ts +81 -0
- package/packages/arcgis-rest-service-admin/test/update.test.ts +115 -0
- package/packages/arcgis-rest-service-admin/tsconfig.json +6 -0
- package/packages/arcgis-rest-types/README.md +66 -0
- package/packages/arcgis-rest-types/package.json +54 -0
- package/packages/arcgis-rest-types/src/feature.ts +39 -0
- package/packages/arcgis-rest-types/src/geometry.ts +272 -0
- package/packages/arcgis-rest-types/src/group.ts +72 -0
- package/packages/arcgis-rest-types/src/index.ts +9 -0
- package/packages/arcgis-rest-types/src/item.ts +81 -0
- package/packages/arcgis-rest-types/src/service.ts +114 -0
- package/packages/arcgis-rest-types/src/statisticDefinition.ts +33 -0
- package/packages/arcgis-rest-types/src/symbol.ts +170 -0
- package/packages/arcgis-rest-types/src/user.ts +49 -0
- package/packages/arcgis-rest-types/src/webmap.ts +1367 -0
- package/packages/arcgis-rest-types/tsconfig.json +10 -0
- package/support/changelog.js +393 -0
- package/support/deploy-doc-site.js +16 -0
- package/support/dev.sh +6 -0
- package/support/publish.sh +47 -0
- package/support/test-helpers.js +9 -0
- package/tsconfig.json +63 -0
- package/tslint.json +16 -0
- package/umd-base-profile.js +81 -0
- package/umd-production-profile.js +13 -0
@@ -0,0 +1,1807 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
/* tslint:disable:no-empty */
|
5
|
+
import { UserSession } from "../src/index";
|
6
|
+
import { ICredential } from "../src/UserSession";
|
7
|
+
|
8
|
+
import {
|
9
|
+
request,
|
10
|
+
ArcGISRequestError,
|
11
|
+
ArcGISAuthError,
|
12
|
+
ErrorTypes,
|
13
|
+
} from "@esri/arcgis-rest-request";
|
14
|
+
import * as fetchMock from "fetch-mock";
|
15
|
+
import { YESTERDAY, TOMORROW } from "./utils";
|
16
|
+
|
17
|
+
describe("UserSession", () => {
|
18
|
+
afterEach(fetchMock.restore);
|
19
|
+
|
20
|
+
it("should serialize to and from JSON", () => {
|
21
|
+
const session = new UserSession({
|
22
|
+
clientId: "clientId",
|
23
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
24
|
+
token: "token",
|
25
|
+
tokenExpires: TOMORROW,
|
26
|
+
refreshToken: "refreshToken",
|
27
|
+
refreshTokenExpires: TOMORROW,
|
28
|
+
refreshTokenTTL: 1440,
|
29
|
+
username: "c@sey",
|
30
|
+
password: "123456",
|
31
|
+
});
|
32
|
+
|
33
|
+
const session2 = UserSession.deserialize(session.serialize());
|
34
|
+
|
35
|
+
expect(session2.clientId).toEqual("clientId");
|
36
|
+
expect(session2.redirectUri).toEqual(
|
37
|
+
"https://example-app.com/redirect-uri"
|
38
|
+
);
|
39
|
+
expect(session2.ssl).toBe(undefined);
|
40
|
+
expect(session2.token).toEqual("token");
|
41
|
+
expect(session2.tokenExpires).toEqual(TOMORROW);
|
42
|
+
expect(session2.refreshToken).toEqual("refreshToken");
|
43
|
+
expect(session2.refreshTokenExpires).toEqual(TOMORROW);
|
44
|
+
expect(session2.username).toEqual("c@sey");
|
45
|
+
expect(session2.password).toEqual("123456");
|
46
|
+
expect(session2.tokenDuration).toEqual(20160);
|
47
|
+
expect(session2.refreshTokenTTL).toEqual(1440);
|
48
|
+
});
|
49
|
+
|
50
|
+
describe(".getToken()", () => {
|
51
|
+
it("should return unexpired tokens for trusted arcgis.com domains", (done) => {
|
52
|
+
const session = new UserSession({
|
53
|
+
clientId: "id",
|
54
|
+
token: "token",
|
55
|
+
tokenExpires: TOMORROW,
|
56
|
+
});
|
57
|
+
|
58
|
+
Promise.all([
|
59
|
+
session.getToken("https://www.arcgis.com/sharing/rest/portals/self"),
|
60
|
+
session.getToken(
|
61
|
+
"https://services1.arcgis.com/MOCK_ORG/arcgis/rest/services/Private_Service/FeatureServer"
|
62
|
+
),
|
63
|
+
])
|
64
|
+
.then(([token1, token2]) => {
|
65
|
+
expect(token1).toBe("token");
|
66
|
+
expect(token2).toBe("token");
|
67
|
+
done();
|
68
|
+
})
|
69
|
+
.catch((e) => {
|
70
|
+
fail(e);
|
71
|
+
});
|
72
|
+
});
|
73
|
+
|
74
|
+
it("should return unexpired tokens when an org url is passed", (done) => {
|
75
|
+
const session = new UserSession({
|
76
|
+
clientId: "id",
|
77
|
+
token: "token",
|
78
|
+
tokenExpires: TOMORROW,
|
79
|
+
portal: "https://custom.maps.arcgis.com/sharing/rest",
|
80
|
+
});
|
81
|
+
|
82
|
+
session
|
83
|
+
.getToken(
|
84
|
+
"https://services1.arcgis.com/MOCK_ORG/arcgis/rest/services/Private_Service/FeatureServer"
|
85
|
+
)
|
86
|
+
.then((token) => {
|
87
|
+
expect(token).toBe("token");
|
88
|
+
done();
|
89
|
+
})
|
90
|
+
.catch((e) => {
|
91
|
+
fail(e);
|
92
|
+
});
|
93
|
+
});
|
94
|
+
|
95
|
+
it("should return unexpired tokens when an org url is passed on other ArcGIS Online environments", (done) => {
|
96
|
+
const session = new UserSession({
|
97
|
+
clientId: "id",
|
98
|
+
token: "token",
|
99
|
+
tokenExpires: TOMORROW,
|
100
|
+
portal: "https://custom.mapsdev.arcgis.com/sharing/rest",
|
101
|
+
});
|
102
|
+
|
103
|
+
session
|
104
|
+
.getToken(
|
105
|
+
"https://services1dev.arcgis.com/MOCK_ORG/arcgis/rest/services/Private_Service/FeatureServer"
|
106
|
+
)
|
107
|
+
.then((token) => {
|
108
|
+
expect(token).toBe("token");
|
109
|
+
done();
|
110
|
+
})
|
111
|
+
.catch((e) => {
|
112
|
+
fail(e);
|
113
|
+
});
|
114
|
+
});
|
115
|
+
|
116
|
+
it("should return unexpired tokens when there is an http/https mismatch", (done) => {
|
117
|
+
const session = new UserSession({
|
118
|
+
clientId: "id",
|
119
|
+
token: "token",
|
120
|
+
tokenExpires: TOMORROW,
|
121
|
+
portal: "http://custom.mapsdev.arcgis.com/sharing/rest",
|
122
|
+
});
|
123
|
+
|
124
|
+
session
|
125
|
+
.getToken(
|
126
|
+
"https://services1dev.arcgis.com/MOCK_ORG/arcgis/rest/services/Private_Service/FeatureServer"
|
127
|
+
)
|
128
|
+
.then((token) => {
|
129
|
+
expect(token).toBe("token");
|
130
|
+
done();
|
131
|
+
})
|
132
|
+
.catch((e) => {
|
133
|
+
fail(e);
|
134
|
+
});
|
135
|
+
});
|
136
|
+
|
137
|
+
it("should return unexpired tokens for the configured portal domain", (done) => {
|
138
|
+
const session = new UserSession({
|
139
|
+
clientId: "id",
|
140
|
+
token: "token",
|
141
|
+
tokenExpires: TOMORROW,
|
142
|
+
portal: "https://gis.city.gov/sharing/rest",
|
143
|
+
});
|
144
|
+
|
145
|
+
session
|
146
|
+
.getToken("https://gis.city.gov/sharing/rest/portals/self")
|
147
|
+
.then((token) => {
|
148
|
+
expect(token).toBe("token");
|
149
|
+
done();
|
150
|
+
})
|
151
|
+
.catch((e) => {
|
152
|
+
fail(e);
|
153
|
+
});
|
154
|
+
});
|
155
|
+
|
156
|
+
it("should return unexpired tokens for the configured portal domain, regardless of CASING", (done) => {
|
157
|
+
// This was a real configuration discovered on a portal instance
|
158
|
+
const session = new UserSession({
|
159
|
+
clientId: "id",
|
160
|
+
token: "token",
|
161
|
+
tokenExpires: TOMORROW,
|
162
|
+
portal: "https://pnp00035.esri.com/sharing/rest",
|
163
|
+
});
|
164
|
+
|
165
|
+
session
|
166
|
+
.getToken("https://PNP00035.esri.com/sharing/rest/portals/self")
|
167
|
+
.then((token) => {
|
168
|
+
expect(token).toBe("token");
|
169
|
+
done();
|
170
|
+
})
|
171
|
+
.catch((e) => {
|
172
|
+
fail(e);
|
173
|
+
});
|
174
|
+
});
|
175
|
+
|
176
|
+
it("should fetch token when contacting a server that is federated, even if on same domain, regardless of domain casing", (done) => {
|
177
|
+
// This was a real configuration discovered on a portal instance
|
178
|
+
// apparently when federating servers, the UI does not force the
|
179
|
+
// server url to lowercase, and this any feature service items generated
|
180
|
+
// will have the server name using the casing the admin entered.
|
181
|
+
// this is just a test to ensure that the mis-matched casing does not
|
182
|
+
// break the federation flow.
|
183
|
+
const session = new UserSession({
|
184
|
+
clientId: "id",
|
185
|
+
token: "existing-session-token",
|
186
|
+
refreshToken: "refresh",
|
187
|
+
tokenExpires: TOMORROW,
|
188
|
+
portal: "https://pnp00035.esri.com/portal/sharing/rest",
|
189
|
+
});
|
190
|
+
|
191
|
+
fetchMock.postOnce("https://pnp00035.esri.com/server/rest/info", {
|
192
|
+
currentVersion: 10.61,
|
193
|
+
fullVersion: "10.6.1",
|
194
|
+
owningSystemUrl: "https://pnp00035.esri.com/portal",
|
195
|
+
authInfo: {
|
196
|
+
isTokenBasedSecurity: true,
|
197
|
+
tokenServicesUrl:
|
198
|
+
"https://pnp00035.esri.com/portal/sharing/rest/generateToken",
|
199
|
+
},
|
200
|
+
});
|
201
|
+
|
202
|
+
fetchMock.postOnce("https://pnp00035.esri.com/portal/sharing/rest/info", {
|
203
|
+
owningSystemUrl: "https://pnp00035.esri.com/portal",
|
204
|
+
authInfo: {
|
205
|
+
tokenServicesUrl:
|
206
|
+
"https://pnp00035.esri.com/portal/sharing/rest/generateToken",
|
207
|
+
isTokenBasedSecurity: true,
|
208
|
+
},
|
209
|
+
});
|
210
|
+
|
211
|
+
fetchMock.postOnce(
|
212
|
+
"https://pnp00035.esri.com/portal/sharing/rest/generateToken",
|
213
|
+
{
|
214
|
+
token: "new-server-token",
|
215
|
+
expires: TOMORROW,
|
216
|
+
}
|
217
|
+
);
|
218
|
+
|
219
|
+
// request the token twice, for the same domain, but with different casing
|
220
|
+
// and we expect a single POST to generate a token once
|
221
|
+
session
|
222
|
+
.getToken(
|
223
|
+
"https://PNP00035.esri.com/server/rest/services/Hosted/perimeters_dd83/FeatureServer"
|
224
|
+
)
|
225
|
+
.then((token) => {
|
226
|
+
expect(token).toBe("new-server-token");
|
227
|
+
return session.getToken(
|
228
|
+
"https://pnp00035.esri.com/server/rest/services/Hosted/otherService/FeatureServer"
|
229
|
+
);
|
230
|
+
})
|
231
|
+
.then((token) => {
|
232
|
+
expect(token).toBe("new-server-token");
|
233
|
+
done();
|
234
|
+
})
|
235
|
+
.catch((e) => {
|
236
|
+
fail(e);
|
237
|
+
});
|
238
|
+
});
|
239
|
+
|
240
|
+
it("should fetch new tokens when tokens for trusted arcgis.com domains are expired", (done) => {
|
241
|
+
const session = new UserSession({
|
242
|
+
clientId: "id",
|
243
|
+
token: "token",
|
244
|
+
refreshToken: "refresh",
|
245
|
+
tokenExpires: YESTERDAY,
|
246
|
+
});
|
247
|
+
|
248
|
+
fetchMock.mock(
|
249
|
+
"https://www.arcgis.com/sharing/rest/oauth2/token",
|
250
|
+
{
|
251
|
+
access_token: "new",
|
252
|
+
expires_in: 1800,
|
253
|
+
username: "c@sey",
|
254
|
+
},
|
255
|
+
{ repeat: 2, method: "POST" }
|
256
|
+
);
|
257
|
+
|
258
|
+
Promise.all([
|
259
|
+
session.getToken("https://www.arcgis.com/sharing/rest/portals/self"),
|
260
|
+
session.getToken(
|
261
|
+
"https://services1.arcgis.com/MOCK_ORG/arcgis/rest/services/Private_Service/FeatureServer"
|
262
|
+
),
|
263
|
+
])
|
264
|
+
.then(([token1, token2]) => {
|
265
|
+
expect(token1).toBe("new");
|
266
|
+
expect(token2).toBe("new");
|
267
|
+
done();
|
268
|
+
})
|
269
|
+
.catch((e) => {
|
270
|
+
fail(e);
|
271
|
+
});
|
272
|
+
});
|
273
|
+
|
274
|
+
it("should pass through a token when no token expiration is present", (done) => {
|
275
|
+
const session = new UserSession({
|
276
|
+
token: "token",
|
277
|
+
});
|
278
|
+
|
279
|
+
session
|
280
|
+
.getToken("https://www.arcgis.com/sharing/rest/portals/self")
|
281
|
+
.then((token1) => {
|
282
|
+
expect(token1).toBe("token");
|
283
|
+
done();
|
284
|
+
})
|
285
|
+
.catch((e) => {
|
286
|
+
fail(e);
|
287
|
+
});
|
288
|
+
});
|
289
|
+
|
290
|
+
it("should generate a token for an untrusted, federated server", (done) => {
|
291
|
+
const session = new UserSession({
|
292
|
+
clientId: "id",
|
293
|
+
token: "token",
|
294
|
+
refreshToken: "refresh",
|
295
|
+
tokenExpires: TOMORROW,
|
296
|
+
portal: "https://gis.city.gov/sharing/rest",
|
297
|
+
});
|
298
|
+
|
299
|
+
fetchMock.postOnce("https://gisservices.city.gov/public/rest/info", {
|
300
|
+
currentVersion: 10.51,
|
301
|
+
fullVersion: "10.5.1.120",
|
302
|
+
owningSystemUrl: "https://gis.city.gov",
|
303
|
+
authInfo: {
|
304
|
+
isTokenBasedSecurity: true,
|
305
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
306
|
+
},
|
307
|
+
});
|
308
|
+
|
309
|
+
fetchMock.postOnce("https://gis.city.gov/sharing/rest/info", {
|
310
|
+
owningSystemUrl: "http://gis.city.gov",
|
311
|
+
authInfo: {
|
312
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
313
|
+
isTokenBasedSecurity: true,
|
314
|
+
},
|
315
|
+
});
|
316
|
+
|
317
|
+
fetchMock.postOnce("https://gis.city.gov/sharing/generateToken", {
|
318
|
+
token: "serverToken",
|
319
|
+
expires: TOMORROW,
|
320
|
+
});
|
321
|
+
|
322
|
+
session
|
323
|
+
.getToken(
|
324
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
|
325
|
+
)
|
326
|
+
.then((token) => {
|
327
|
+
expect(token).toBe("serverToken");
|
328
|
+
return session.getToken(
|
329
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
|
330
|
+
);
|
331
|
+
})
|
332
|
+
.then((token) => {
|
333
|
+
expect(token).toBe("serverToken");
|
334
|
+
done();
|
335
|
+
})
|
336
|
+
.catch((e) => {
|
337
|
+
fail(e);
|
338
|
+
});
|
339
|
+
});
|
340
|
+
|
341
|
+
it("should generate a token for an untrusted, federated server admin call", (done) => {
|
342
|
+
const session = new UserSession({
|
343
|
+
clientId: "id",
|
344
|
+
token: "token",
|
345
|
+
refreshToken: "refresh",
|
346
|
+
tokenExpires: TOMORROW,
|
347
|
+
portal: "https://gis.city.gov/sharing/rest",
|
348
|
+
});
|
349
|
+
|
350
|
+
fetchMock.postOnce("https://gisservices.city.gov/public/rest/info", {
|
351
|
+
currentVersion: 10.51,
|
352
|
+
fullVersion: "10.5.1.120",
|
353
|
+
owningSystemUrl: "https://gis.city.gov",
|
354
|
+
authInfo: {
|
355
|
+
isTokenBasedSecurity: true,
|
356
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
357
|
+
},
|
358
|
+
});
|
359
|
+
|
360
|
+
fetchMock.postOnce("https://gis.city.gov/sharing/rest/info", {
|
361
|
+
owningSystemUrl: "http://gis.city.gov",
|
362
|
+
authInfo: {
|
363
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
364
|
+
isTokenBasedSecurity: true,
|
365
|
+
},
|
366
|
+
});
|
367
|
+
|
368
|
+
fetchMock.postOnce("https://gis.city.gov/sharing/generateToken", {
|
369
|
+
token: "serverToken",
|
370
|
+
expires: TOMORROW,
|
371
|
+
});
|
372
|
+
|
373
|
+
session
|
374
|
+
.getToken(
|
375
|
+
"https://gisservices.city.gov/public/rest/admin/services/trees/FeatureServer/addToDefinition"
|
376
|
+
)
|
377
|
+
.then((token) => {
|
378
|
+
expect(token).toBe("serverToken");
|
379
|
+
return session.getToken(
|
380
|
+
"https://gisservices.city.gov/public/rest/admin/services/trees/FeatureServer/addToDefinition"
|
381
|
+
);
|
382
|
+
})
|
383
|
+
.then((token) => {
|
384
|
+
expect(token).toBe("serverToken");
|
385
|
+
done();
|
386
|
+
})
|
387
|
+
.catch((e) => {
|
388
|
+
fail(e);
|
389
|
+
});
|
390
|
+
});
|
391
|
+
|
392
|
+
it("should generate a token for an untrusted, federated server with user credentials", (done) => {
|
393
|
+
const session = new UserSession({
|
394
|
+
username: "c@sey",
|
395
|
+
password: "jones",
|
396
|
+
portal: "https://gis.city.gov/sharing/rest",
|
397
|
+
});
|
398
|
+
|
399
|
+
fetchMock.postOnce("https://gisservices.city.gov/public/rest/info", {
|
400
|
+
currentVersion: 10.51,
|
401
|
+
fullVersion: "10.5.1.120",
|
402
|
+
owningSystemUrl: "https://gis.city.gov",
|
403
|
+
authInfo: {
|
404
|
+
isTokenBasedSecurity: true,
|
405
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
406
|
+
},
|
407
|
+
});
|
408
|
+
|
409
|
+
fetchMock.postOnce("https://gis.city.gov/sharing/rest/info", {
|
410
|
+
owningSystemUrl: "http://gis.city.gov",
|
411
|
+
authInfo: {
|
412
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
413
|
+
isTokenBasedSecurity: true,
|
414
|
+
},
|
415
|
+
});
|
416
|
+
|
417
|
+
fetchMock.postOnce("https://gis.city.gov/sharing/generateToken", {
|
418
|
+
token: "serverToken",
|
419
|
+
expires: TOMORROW,
|
420
|
+
});
|
421
|
+
|
422
|
+
session
|
423
|
+
.getToken(
|
424
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
|
425
|
+
)
|
426
|
+
.then((token) => {
|
427
|
+
expect(token).toBe("serverToken");
|
428
|
+
done();
|
429
|
+
})
|
430
|
+
.catch((e) => {
|
431
|
+
fail(e);
|
432
|
+
});
|
433
|
+
});
|
434
|
+
|
435
|
+
it("should only make 1 token request to an untrusted portal for similar URLs", (done) => {
|
436
|
+
const session = new UserSession({
|
437
|
+
clientId: "id",
|
438
|
+
token: "token",
|
439
|
+
refreshToken: "refresh",
|
440
|
+
tokenExpires: TOMORROW,
|
441
|
+
portal: "https://gis.city.gov/sharing/rest",
|
442
|
+
});
|
443
|
+
|
444
|
+
fetchMock.mock(
|
445
|
+
"https://gisservices.city.gov/public/rest/info",
|
446
|
+
{
|
447
|
+
currentVersion: 10.51,
|
448
|
+
fullVersion: "10.5.1.120",
|
449
|
+
owningSystemUrl: "https://gis.city.gov",
|
450
|
+
authInfo: {
|
451
|
+
isTokenBasedSecurity: true,
|
452
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
453
|
+
},
|
454
|
+
},
|
455
|
+
{ repeat: 1, method: "POST" }
|
456
|
+
);
|
457
|
+
|
458
|
+
fetchMock.mock(
|
459
|
+
"https://gis.city.gov/sharing/rest/info",
|
460
|
+
{
|
461
|
+
owningSystemUrl: "http://gis.city.gov",
|
462
|
+
authInfo: {
|
463
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
464
|
+
isTokenBasedSecurity: true,
|
465
|
+
},
|
466
|
+
},
|
467
|
+
{ repeat: 1, method: "POST" }
|
468
|
+
);
|
469
|
+
|
470
|
+
fetchMock.mock(
|
471
|
+
"https://gis.city.gov/sharing/generateToken",
|
472
|
+
{
|
473
|
+
token: "serverToken",
|
474
|
+
expires: TOMORROW,
|
475
|
+
},
|
476
|
+
{ repeat: 1, method: "POST" }
|
477
|
+
);
|
478
|
+
|
479
|
+
Promise.all([
|
480
|
+
session.getToken(
|
481
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
|
482
|
+
),
|
483
|
+
session.getToken(
|
484
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
|
485
|
+
),
|
486
|
+
])
|
487
|
+
.then(([token1, token2]) => {
|
488
|
+
expect(token1).toBe("serverToken");
|
489
|
+
expect(token2).toBe("serverToken");
|
490
|
+
expect(
|
491
|
+
fetchMock.calls("https://gis.city.gov/sharing/generateToken").length
|
492
|
+
).toBe(1);
|
493
|
+
done();
|
494
|
+
})
|
495
|
+
.catch((e) => {
|
496
|
+
fail(e);
|
497
|
+
});
|
498
|
+
});
|
499
|
+
|
500
|
+
it("should throw an ArcGISAuthError when the owning system doesn't match", (done) => {
|
501
|
+
const session = new UserSession({
|
502
|
+
clientId: "id",
|
503
|
+
token: "token",
|
504
|
+
refreshToken: "refresh",
|
505
|
+
tokenExpires: YESTERDAY,
|
506
|
+
});
|
507
|
+
|
508
|
+
fetchMock.post("https://gisservices.city.gov/public/rest/info", {
|
509
|
+
currentVersion: 10.51,
|
510
|
+
fullVersion: "10.5.1.120",
|
511
|
+
owningSystemUrl: "https://gis.city.gov",
|
512
|
+
authInfo: {
|
513
|
+
isTokenBasedSecurity: true,
|
514
|
+
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
|
515
|
+
},
|
516
|
+
});
|
517
|
+
|
518
|
+
session
|
519
|
+
.getToken(
|
520
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
|
521
|
+
)
|
522
|
+
.catch((e) => {
|
523
|
+
expect(e.name).toEqual(ErrorTypes.ArcGISAuthError);
|
524
|
+
expect(e.code).toEqual("NOT_FEDERATED");
|
525
|
+
expect(e.message).toEqual(
|
526
|
+
"NOT_FEDERATED: https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query is not federated with https://www.arcgis.com/sharing/rest."
|
527
|
+
);
|
528
|
+
done();
|
529
|
+
});
|
530
|
+
});
|
531
|
+
|
532
|
+
it("should throw a fully hydrated ArcGISAuthError when no owning system is advertised", (done) => {
|
533
|
+
const session = new UserSession({
|
534
|
+
clientId: "id",
|
535
|
+
token: "token",
|
536
|
+
refreshToken: "refresh",
|
537
|
+
tokenExpires: YESTERDAY,
|
538
|
+
});
|
539
|
+
|
540
|
+
fetchMock.post("https://gisservices.city.gov/public/rest/info", {
|
541
|
+
currentVersion: 10.51,
|
542
|
+
fullVersion: "10.5.1.120",
|
543
|
+
});
|
544
|
+
|
545
|
+
fetchMock.post(
|
546
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query",
|
547
|
+
{
|
548
|
+
error: {
|
549
|
+
code: 499,
|
550
|
+
message: "Token Required",
|
551
|
+
details: [],
|
552
|
+
},
|
553
|
+
}
|
554
|
+
);
|
555
|
+
|
556
|
+
request(
|
557
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query",
|
558
|
+
{
|
559
|
+
authentication: session,
|
560
|
+
params: {
|
561
|
+
foo: "bar",
|
562
|
+
},
|
563
|
+
}
|
564
|
+
).catch((e) => {
|
565
|
+
expect(e.name).toEqual(ErrorTypes.ArcGISAuthError);
|
566
|
+
expect(e.code).toEqual("NOT_FEDERATED");
|
567
|
+
expect(e.message).toEqual(
|
568
|
+
"NOT_FEDERATED: https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query is not federated with any portal and is not explicitly trusted."
|
569
|
+
);
|
570
|
+
expect(e.url).toEqual(
|
571
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
|
572
|
+
);
|
573
|
+
expect(e.options.params.foo).toEqual("bar");
|
574
|
+
done();
|
575
|
+
});
|
576
|
+
});
|
577
|
+
|
578
|
+
it("should not throw an ArcGISAuthError when the unfederated service is public", (done) => {
|
579
|
+
const session = new UserSession({
|
580
|
+
clientId: "id",
|
581
|
+
token: "token",
|
582
|
+
refreshToken: "refresh",
|
583
|
+
tokenExpires: YESTERDAY,
|
584
|
+
});
|
585
|
+
|
586
|
+
fetchMock.post("https://gisservices.city.gov/public/rest/info", {
|
587
|
+
currentVersion: 10.51,
|
588
|
+
fullVersion: "10.5.1.120",
|
589
|
+
});
|
590
|
+
|
591
|
+
fetchMock.post(
|
592
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query",
|
593
|
+
{
|
594
|
+
count: 123,
|
595
|
+
}
|
596
|
+
);
|
597
|
+
|
598
|
+
request(
|
599
|
+
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query",
|
600
|
+
{
|
601
|
+
authentication: session,
|
602
|
+
params: {
|
603
|
+
returnCount: true,
|
604
|
+
},
|
605
|
+
}
|
606
|
+
)
|
607
|
+
.then((res) => {
|
608
|
+
expect(res.count).toEqual(123);
|
609
|
+
done();
|
610
|
+
})
|
611
|
+
.catch((e) => {
|
612
|
+
fail(e);
|
613
|
+
});
|
614
|
+
});
|
615
|
+
});
|
616
|
+
|
617
|
+
describe(".refreshSession()", () => {
|
618
|
+
it("should refresh with a username and password if expired", (done) => {
|
619
|
+
const session = new UserSession({
|
620
|
+
username: "c@sey",
|
621
|
+
password: "123456",
|
622
|
+
});
|
623
|
+
|
624
|
+
fetchMock.postOnce("https://www.arcgis.com/sharing/rest/generateToken", {
|
625
|
+
token: "token",
|
626
|
+
expires: TOMORROW.getTime(),
|
627
|
+
username: " c@sey",
|
628
|
+
});
|
629
|
+
|
630
|
+
session
|
631
|
+
.refreshSession()
|
632
|
+
.then((s) => {
|
633
|
+
expect(s.token).toBe("token");
|
634
|
+
expect(s.tokenExpires).toEqual(TOMORROW);
|
635
|
+
done();
|
636
|
+
})
|
637
|
+
.catch((e) => {
|
638
|
+
fail(e);
|
639
|
+
});
|
640
|
+
});
|
641
|
+
|
642
|
+
it("should refresh with an unexpired refresh token", (done) => {
|
643
|
+
const session = new UserSession({
|
644
|
+
clientId: "clientId",
|
645
|
+
token: "token",
|
646
|
+
username: "c@sey",
|
647
|
+
refreshToken: "refreshToken",
|
648
|
+
refreshTokenExpires: TOMORROW,
|
649
|
+
});
|
650
|
+
|
651
|
+
fetchMock.postOnce("https://www.arcgis.com/sharing/rest/oauth2/token", {
|
652
|
+
access_token: "newToken",
|
653
|
+
expires_in: 60,
|
654
|
+
username: " c@sey",
|
655
|
+
});
|
656
|
+
|
657
|
+
session
|
658
|
+
.refreshSession()
|
659
|
+
.then((s) => {
|
660
|
+
expect(s.token).toBe("newToken");
|
661
|
+
expect(s.tokenExpires.getTime()).toBeGreaterThan(Date.now());
|
662
|
+
done();
|
663
|
+
})
|
664
|
+
.catch((e) => {
|
665
|
+
fail(e);
|
666
|
+
});
|
667
|
+
});
|
668
|
+
|
669
|
+
it("should refresh with an expired refresh token", (done) => {
|
670
|
+
const session = new UserSession({
|
671
|
+
clientId: "clientId",
|
672
|
+
token: "token",
|
673
|
+
username: "c@sey",
|
674
|
+
refreshToken: "refreshToken",
|
675
|
+
refreshTokenExpires: YESTERDAY,
|
676
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
677
|
+
});
|
678
|
+
|
679
|
+
fetchMock.postOnce("https://www.arcgis.com/sharing/rest/oauth2/token", {
|
680
|
+
access_token: "newToken",
|
681
|
+
expires_in: 60,
|
682
|
+
username: " c@sey",
|
683
|
+
refresh_token: "newRefreshToken",
|
684
|
+
});
|
685
|
+
|
686
|
+
session
|
687
|
+
.refreshSession()
|
688
|
+
.then((s) => {
|
689
|
+
expect(s.token).toBe("newToken");
|
690
|
+
expect(s.tokenExpires.getTime()).toBeGreaterThan(Date.now());
|
691
|
+
expect(s.refreshToken).toBe("newRefreshToken");
|
692
|
+
expect(s.refreshTokenExpires.getTime()).toBeGreaterThan(Date.now());
|
693
|
+
done();
|
694
|
+
})
|
695
|
+
.catch((e) => {
|
696
|
+
fail(e);
|
697
|
+
});
|
698
|
+
});
|
699
|
+
|
700
|
+
it("should reject if we cannot refresh the token", (done) => {
|
701
|
+
const session = new UserSession({
|
702
|
+
clientId: "clientId",
|
703
|
+
token: "token",
|
704
|
+
username: "c@sey",
|
705
|
+
});
|
706
|
+
|
707
|
+
session.refreshSession().catch((e) => {
|
708
|
+
expect(e instanceof ArcGISAuthError).toBeTruthy();
|
709
|
+
expect(e.name).toBe("ArcGISAuthError");
|
710
|
+
expect(e.message).toBe("Unable to refresh token.");
|
711
|
+
done();
|
712
|
+
});
|
713
|
+
});
|
714
|
+
|
715
|
+
it("should only make 1 token request to the portal for similar URLs", (done) => {
|
716
|
+
const session = new UserSession({
|
717
|
+
clientId: "id",
|
718
|
+
token: "token",
|
719
|
+
refreshToken: "refresh",
|
720
|
+
tokenExpires: YESTERDAY,
|
721
|
+
});
|
722
|
+
|
723
|
+
fetchMock.mock(
|
724
|
+
"https://www.arcgis.com/sharing/rest/oauth2/token",
|
725
|
+
{
|
726
|
+
access_token: "new",
|
727
|
+
expires_in: 1800,
|
728
|
+
username: "c@sey",
|
729
|
+
},
|
730
|
+
{ repeat: 1, method: "POST" }
|
731
|
+
);
|
732
|
+
|
733
|
+
Promise.all([
|
734
|
+
session.getToken("https://www.arcgis.com/sharing/rest/portals/self"),
|
735
|
+
session.getToken("https://www.arcgis.com/sharing/rest/portals/self"),
|
736
|
+
])
|
737
|
+
.then(([token1, token2]) => {
|
738
|
+
expect(token1).toBe("new");
|
739
|
+
expect(token2).toBe("new");
|
740
|
+
expect(
|
741
|
+
fetchMock.calls("https://www.arcgis.com/sharing/rest/oauth2/token")
|
742
|
+
.length
|
743
|
+
).toBe(1);
|
744
|
+
done();
|
745
|
+
})
|
746
|
+
.catch((e) => {
|
747
|
+
fail(e);
|
748
|
+
});
|
749
|
+
});
|
750
|
+
});
|
751
|
+
|
752
|
+
describe(".beginOAuth2()", () => {
|
753
|
+
it("should authorize via a popup", (done) => {
|
754
|
+
const MockWindow: any = {
|
755
|
+
open: jasmine.createSpy("spy"),
|
756
|
+
};
|
757
|
+
|
758
|
+
UserSession.beginOAuth2(
|
759
|
+
{
|
760
|
+
clientId: "clientId123",
|
761
|
+
redirectUri: "http://example-app.com/redirect",
|
762
|
+
state: "abc123",
|
763
|
+
},
|
764
|
+
MockWindow
|
765
|
+
)
|
766
|
+
.then((session) => {
|
767
|
+
expect(session.token).toBe("token");
|
768
|
+
expect(session.username).toBe("c@sey");
|
769
|
+
expect(session.ssl).toBe(true);
|
770
|
+
expect(session.tokenExpires).toEqual(TOMORROW);
|
771
|
+
done();
|
772
|
+
})
|
773
|
+
.catch((e) => {
|
774
|
+
fail(e);
|
775
|
+
});
|
776
|
+
|
777
|
+
expect(MockWindow.open).toHaveBeenCalledWith(
|
778
|
+
"https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id=clientId123&response_type=token&expiration=20160&redirect_uri=http%3A%2F%2Fexample-app.com%2Fredirect&state=abc123&locale=",
|
779
|
+
"oauth-window",
|
780
|
+
"height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes"
|
781
|
+
);
|
782
|
+
|
783
|
+
MockWindow.__ESRI_REST_AUTH_HANDLER_clientId123(
|
784
|
+
JSON.stringify(undefined),
|
785
|
+
JSON.stringify({
|
786
|
+
token: "token",
|
787
|
+
expires: TOMORROW,
|
788
|
+
username: "c@sey",
|
789
|
+
ssl: true,
|
790
|
+
})
|
791
|
+
);
|
792
|
+
});
|
793
|
+
|
794
|
+
it("should reject the promise if there is an error", (done) => {
|
795
|
+
const MockWindow: any = {
|
796
|
+
open: jasmine.createSpy("spy"),
|
797
|
+
};
|
798
|
+
|
799
|
+
UserSession.beginOAuth2(
|
800
|
+
{
|
801
|
+
clientId: "clientId123",
|
802
|
+
redirectUri: "http://example-app.com/redirect",
|
803
|
+
locale: "fr",
|
804
|
+
},
|
805
|
+
MockWindow
|
806
|
+
).catch((e) => {
|
807
|
+
done();
|
808
|
+
});
|
809
|
+
|
810
|
+
expect(MockWindow.open).toHaveBeenCalledWith(
|
811
|
+
"https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id=clientId123&response_type=token&expiration=20160&redirect_uri=http%3A%2F%2Fexample-app.com%2Fredirect&state=clientId123&locale=fr",
|
812
|
+
"oauth-window",
|
813
|
+
"height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes"
|
814
|
+
);
|
815
|
+
|
816
|
+
MockWindow.__ESRI_REST_AUTH_HANDLER_clientId123(
|
817
|
+
JSON.stringify({
|
818
|
+
errorMessage: "unable to sign in",
|
819
|
+
error: "SIGN_IN_FAILED",
|
820
|
+
})
|
821
|
+
);
|
822
|
+
});
|
823
|
+
|
824
|
+
it("should authorize in the same window/tab", () => {
|
825
|
+
const MockWindow: any = {
|
826
|
+
location: {
|
827
|
+
href: "",
|
828
|
+
},
|
829
|
+
};
|
830
|
+
|
831
|
+
// https://github.com/palantir/tslint/issues/3056
|
832
|
+
void UserSession.beginOAuth2(
|
833
|
+
{
|
834
|
+
clientId: "clientId123",
|
835
|
+
redirectUri: "http://example-app.com/redirect",
|
836
|
+
popup: false,
|
837
|
+
},
|
838
|
+
MockWindow
|
839
|
+
);
|
840
|
+
|
841
|
+
expect(MockWindow.location.href).toBe(
|
842
|
+
"https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id=clientId123&response_type=token&expiration=20160&redirect_uri=http%3A%2F%2Fexample-app.com%2Fredirect&state=clientId123&locale="
|
843
|
+
);
|
844
|
+
});
|
845
|
+
|
846
|
+
it("should authorize using a social media provider", () => {
|
847
|
+
const MockWindow: any = {
|
848
|
+
location: {
|
849
|
+
href: "",
|
850
|
+
},
|
851
|
+
};
|
852
|
+
|
853
|
+
// https://github.com/palantir/tslint/issues/3056
|
854
|
+
void UserSession.beginOAuth2(
|
855
|
+
{
|
856
|
+
clientId: "clientId123",
|
857
|
+
redirectUri: "http://example-app.com/redirect",
|
858
|
+
popup: false,
|
859
|
+
provider: "facebook",
|
860
|
+
},
|
861
|
+
MockWindow
|
862
|
+
);
|
863
|
+
|
864
|
+
expect(MockWindow.location.href).toBe(
|
865
|
+
"https://www.arcgis.com/sharing/rest/oauth2/social/authorize?client_id=clientId123&socialLoginProviderName=facebook&autoAccountCreateForSocial=true&response_type=token&expiration=20160&redirect_uri=http%3A%2F%2Fexample-app.com%2Fredirect&state=clientId123&locale="
|
866
|
+
);
|
867
|
+
});
|
868
|
+
|
869
|
+
it("should authorize using the other social media provider", () => {
|
870
|
+
const MockWindow: any = {
|
871
|
+
location: {
|
872
|
+
href: "",
|
873
|
+
},
|
874
|
+
};
|
875
|
+
|
876
|
+
// https://github.com/palantir/tslint/issues/3056
|
877
|
+
void UserSession.beginOAuth2(
|
878
|
+
{
|
879
|
+
clientId: "clientId123",
|
880
|
+
redirectUri: "http://example-app.com/redirect",
|
881
|
+
popup: false,
|
882
|
+
provider: "google",
|
883
|
+
},
|
884
|
+
MockWindow
|
885
|
+
);
|
886
|
+
|
887
|
+
expect(MockWindow.location.href).toBe(
|
888
|
+
"https://www.arcgis.com/sharing/rest/oauth2/social/authorize?client_id=clientId123&socialLoginProviderName=google&autoAccountCreateForSocial=true&response_type=token&expiration=20160&redirect_uri=http%3A%2F%2Fexample-app.com%2Fredirect&state=clientId123&locale="
|
889
|
+
);
|
890
|
+
});
|
891
|
+
});
|
892
|
+
|
893
|
+
describe(".completeOAuth2()", () => {
|
894
|
+
it("should return a new user session if it cannot find a valid parent", () => {
|
895
|
+
const MockWindow = {
|
896
|
+
location: {
|
897
|
+
hash:
|
898
|
+
"#access_token=token&expires_in=1209600&username=c%40sey&ssl=true&persist=true",
|
899
|
+
},
|
900
|
+
get parent() {
|
901
|
+
return this;
|
902
|
+
},
|
903
|
+
};
|
904
|
+
|
905
|
+
const session = UserSession.completeOAuth2(
|
906
|
+
{
|
907
|
+
clientId: "clientId",
|
908
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
909
|
+
},
|
910
|
+
MockWindow
|
911
|
+
);
|
912
|
+
|
913
|
+
expect(session.token).toBe("token");
|
914
|
+
expect(session.tokenExpires.getTime()).toBeGreaterThan(Date.now());
|
915
|
+
expect(session.username).toBe("c@sey");
|
916
|
+
expect(session.ssl).toBe(true);
|
917
|
+
});
|
918
|
+
|
919
|
+
it("should return a new user session with ssl as false when callback hash does not have ssl parameter", () => {
|
920
|
+
const MockWindow = {
|
921
|
+
location: {
|
922
|
+
hash:
|
923
|
+
"#access_token=token&expires_in=1209600&username=c%40sey&persist=true",
|
924
|
+
},
|
925
|
+
get parent() {
|
926
|
+
return this;
|
927
|
+
},
|
928
|
+
};
|
929
|
+
|
930
|
+
const session = UserSession.completeOAuth2(
|
931
|
+
{
|
932
|
+
clientId: "clientId",
|
933
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
934
|
+
},
|
935
|
+
MockWindow
|
936
|
+
);
|
937
|
+
expect(session.ssl).toBe(false);
|
938
|
+
});
|
939
|
+
|
940
|
+
it("should callback to create a new user session if finds a valid opener.parent", (done) => {
|
941
|
+
const MockWindow = {
|
942
|
+
opener: {
|
943
|
+
parent: {
|
944
|
+
__ESRI_REST_AUTH_HANDLER_clientId(
|
945
|
+
errorString: string,
|
946
|
+
oauthInfoString: string
|
947
|
+
) {
|
948
|
+
const oauthInfo = JSON.parse(oauthInfoString);
|
949
|
+
expect(oauthInfo.token).toBe("token");
|
950
|
+
expect(oauthInfo.username).toBe("c@sey");
|
951
|
+
expect(oauthInfo.ssl).toBe(true);
|
952
|
+
expect(new Date(oauthInfo.expires).getTime()).toBeGreaterThan(
|
953
|
+
Date.now()
|
954
|
+
);
|
955
|
+
},
|
956
|
+
},
|
957
|
+
},
|
958
|
+
close() {
|
959
|
+
done();
|
960
|
+
},
|
961
|
+
location: {
|
962
|
+
hash:
|
963
|
+
"#access_token=token&expires_in=1209600&username=c%40sey&ssl=true",
|
964
|
+
},
|
965
|
+
};
|
966
|
+
|
967
|
+
UserSession.completeOAuth2(
|
968
|
+
{
|
969
|
+
clientId: "clientId",
|
970
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
971
|
+
},
|
972
|
+
MockWindow
|
973
|
+
);
|
974
|
+
});
|
975
|
+
|
976
|
+
it("should callback to create a new user session if finds a valid opener (Iframe support)", (done) => {
|
977
|
+
const MockWindow = {
|
978
|
+
opener: {
|
979
|
+
__ESRI_REST_AUTH_HANDLER_clientId(
|
980
|
+
errorString: string,
|
981
|
+
oauthInfoString: string
|
982
|
+
) {
|
983
|
+
const oauthInfo = JSON.parse(oauthInfoString);
|
984
|
+
expect(oauthInfo.token).toBe("token");
|
985
|
+
expect(oauthInfo.username).toBe("c@sey");
|
986
|
+
expect(oauthInfo.ssl).toBe(true);
|
987
|
+
expect(new Date(oauthInfo.expires).getTime()).toBeGreaterThan(
|
988
|
+
Date.now()
|
989
|
+
);
|
990
|
+
},
|
991
|
+
},
|
992
|
+
close() {
|
993
|
+
done();
|
994
|
+
},
|
995
|
+
location: {
|
996
|
+
hash:
|
997
|
+
"#access_token=token&expires_in=1209600&username=c%40sey&ssl=true",
|
998
|
+
},
|
999
|
+
};
|
1000
|
+
|
1001
|
+
UserSession.completeOAuth2(
|
1002
|
+
{
|
1003
|
+
clientId: "clientId",
|
1004
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1005
|
+
},
|
1006
|
+
MockWindow
|
1007
|
+
);
|
1008
|
+
});
|
1009
|
+
|
1010
|
+
it("should callback to create a new user session if finds a valid parent", (done) => {
|
1011
|
+
const MockWindow = {
|
1012
|
+
parent: {
|
1013
|
+
__ESRI_REST_AUTH_HANDLER_clientId(
|
1014
|
+
errorString: string,
|
1015
|
+
oauthInfoString: string
|
1016
|
+
) {
|
1017
|
+
const oauthInfo = JSON.parse(oauthInfoString);
|
1018
|
+
expect(oauthInfo.token).toBe("token");
|
1019
|
+
expect(oauthInfo.username).toBe("c@sey");
|
1020
|
+
expect(oauthInfo.ssl).toBe(true);
|
1021
|
+
expect(new Date(oauthInfo.expires).getTime()).toBeGreaterThan(
|
1022
|
+
Date.now()
|
1023
|
+
);
|
1024
|
+
},
|
1025
|
+
},
|
1026
|
+
close() {
|
1027
|
+
done();
|
1028
|
+
},
|
1029
|
+
location: {
|
1030
|
+
hash:
|
1031
|
+
"#access_token=token&expires_in=1209600&username=c%40sey&ssl=true",
|
1032
|
+
},
|
1033
|
+
};
|
1034
|
+
|
1035
|
+
UserSession.completeOAuth2(
|
1036
|
+
{
|
1037
|
+
clientId: "clientId",
|
1038
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1039
|
+
},
|
1040
|
+
MockWindow
|
1041
|
+
);
|
1042
|
+
});
|
1043
|
+
|
1044
|
+
it("should throw an error from the authorization window", () => {
|
1045
|
+
const MockWindow = {
|
1046
|
+
location: {
|
1047
|
+
hash: "#error=Invalid_Signin&error_description=Invalid_Signin",
|
1048
|
+
},
|
1049
|
+
get parent() {
|
1050
|
+
return this;
|
1051
|
+
},
|
1052
|
+
};
|
1053
|
+
|
1054
|
+
expect(function() {
|
1055
|
+
UserSession.completeOAuth2(
|
1056
|
+
{
|
1057
|
+
clientId: "clientId",
|
1058
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1059
|
+
},
|
1060
|
+
MockWindow
|
1061
|
+
);
|
1062
|
+
}).toThrowError(ArcGISRequestError, "Invalid_Signin: Invalid_Signin");
|
1063
|
+
});
|
1064
|
+
|
1065
|
+
it("should throw an error if the handler or parent window cannot be accessed", () => {
|
1066
|
+
const MockParent = {
|
1067
|
+
get parent() {
|
1068
|
+
throw new Error(
|
1069
|
+
"This window isn't where auth started, but was opened from somewhere else via window.open() perhaps from another domain which would cause a cross domain error when read."
|
1070
|
+
);
|
1071
|
+
},
|
1072
|
+
};
|
1073
|
+
|
1074
|
+
const MockWindow = {
|
1075
|
+
location: {
|
1076
|
+
hash: "#error=Invalid_Signin&error_description=Invalid_Signin",
|
1077
|
+
},
|
1078
|
+
get opener() {
|
1079
|
+
return MockParent;
|
1080
|
+
},
|
1081
|
+
};
|
1082
|
+
|
1083
|
+
expect(function() {
|
1084
|
+
UserSession.completeOAuth2(
|
1085
|
+
{
|
1086
|
+
clientId: "clientId",
|
1087
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1088
|
+
},
|
1089
|
+
MockWindow
|
1090
|
+
);
|
1091
|
+
}).toThrowError(ArcGISAuthError);
|
1092
|
+
});
|
1093
|
+
});
|
1094
|
+
|
1095
|
+
describe("postmessage auth :: ", () => {
|
1096
|
+
const MockWindow = {
|
1097
|
+
addEventListener: () => {},
|
1098
|
+
removeEventListener: () => {},
|
1099
|
+
parent: {
|
1100
|
+
postMessage: () => {},
|
1101
|
+
},
|
1102
|
+
};
|
1103
|
+
|
1104
|
+
const cred = {
|
1105
|
+
expires: TOMORROW.getTime(),
|
1106
|
+
server: "https://www.arcgis.com",
|
1107
|
+
ssl: false,
|
1108
|
+
token: "token",
|
1109
|
+
userId: "jsmith",
|
1110
|
+
};
|
1111
|
+
|
1112
|
+
it(".disablePostMessageAuth removes event listener", () => {
|
1113
|
+
const removeSpy = spyOn(MockWindow, "removeEventListener");
|
1114
|
+
const session = UserSession.fromCredential(cred);
|
1115
|
+
session.disablePostMessageAuth(MockWindow);
|
1116
|
+
expect(removeSpy.calls.count()).toBe(
|
1117
|
+
1,
|
1118
|
+
"should call removeEventListener"
|
1119
|
+
);
|
1120
|
+
});
|
1121
|
+
it(".enablePostMessageAuth adds event listener", () => {
|
1122
|
+
const addSpy = spyOn(MockWindow, "addEventListener");
|
1123
|
+
const session = UserSession.fromCredential(cred);
|
1124
|
+
session.enablePostMessageAuth(
|
1125
|
+
["https://storymaps.arcgis.com"],
|
1126
|
+
MockWindow
|
1127
|
+
);
|
1128
|
+
expect(addSpy.calls.count()).toBe(1, "should call addEventListener");
|
1129
|
+
});
|
1130
|
+
|
1131
|
+
it(".enablePostMessage handler returns credential to origin in list", () => {
|
1132
|
+
// ok, this gets kinda gnarly...
|
1133
|
+
|
1134
|
+
// create a mock window object
|
1135
|
+
// that will hold the passed in event handler so we can fire it manually
|
1136
|
+
const Win = {
|
1137
|
+
_fn: (evt: any) => {},
|
1138
|
+
addEventListener(evt: any, fn: any) {
|
1139
|
+
// enablePostMessageAuth passes in the handler, which is what we're actually testing
|
1140
|
+
Win._fn = fn;
|
1141
|
+
},
|
1142
|
+
removeEventListener() {},
|
1143
|
+
};
|
1144
|
+
// Create the session
|
1145
|
+
const session = UserSession.fromCredential(cred);
|
1146
|
+
// enable postMessageAuth allowing storymaps.arcgis.com to recieve creds
|
1147
|
+
session.enablePostMessageAuth(["https://storymaps.arcgis.com"], Win);
|
1148
|
+
// create an event object, with a matching origin
|
1149
|
+
// an a source.postMessage fn that we can spy on
|
1150
|
+
const event = {
|
1151
|
+
origin: "https://storymaps.arcgis.com",
|
1152
|
+
source: {
|
1153
|
+
postMessage(msg: any, origin: string) {},
|
1154
|
+
},
|
1155
|
+
};
|
1156
|
+
// create the spy
|
1157
|
+
const sourceSpy = spyOn(event.source, "postMessage");
|
1158
|
+
// Now, fire the handler, simulating what happens when a postMessage event comes
|
1159
|
+
// from an embedded iframe
|
1160
|
+
Win._fn(event);
|
1161
|
+
// Expectations...
|
1162
|
+
expect(sourceSpy.calls.count()).toBe(
|
1163
|
+
1,
|
1164
|
+
"souce.postMessage should be called in handler"
|
1165
|
+
);
|
1166
|
+
const args = sourceSpy.calls.argsFor(0);
|
1167
|
+
expect(args[0].type).toBe(
|
1168
|
+
"arcgis:auth:credential",
|
1169
|
+
"should send credential type"
|
1170
|
+
);
|
1171
|
+
expect(args[0].credential.userId).toBe(
|
1172
|
+
"jsmith",
|
1173
|
+
"should send credential"
|
1174
|
+
);
|
1175
|
+
// now the case where it's not a valid origin
|
1176
|
+
event.origin = "https://evil.com";
|
1177
|
+
Win._fn(event);
|
1178
|
+
expect(sourceSpy.calls.count()).toBe(
|
1179
|
+
2,
|
1180
|
+
"souce.postMessage should be called in handler"
|
1181
|
+
);
|
1182
|
+
const args2 = sourceSpy.calls.argsFor(1);
|
1183
|
+
expect(args2[0].type).toBe("arcgis:auth:rejected", "should send reject");
|
1184
|
+
});
|
1185
|
+
|
1186
|
+
it(".fromParent happy path", () => {
|
1187
|
+
// create a mock window that will fire the handler
|
1188
|
+
const Win = {
|
1189
|
+
_fn: (evt: any) => {},
|
1190
|
+
addEventListener(evt: any, fn: any) {
|
1191
|
+
Win._fn = fn;
|
1192
|
+
},
|
1193
|
+
removeEventListener() {},
|
1194
|
+
parent: {
|
1195
|
+
postMessage(msg: any, origin: string) {
|
1196
|
+
Win._fn({
|
1197
|
+
origin: "https://origin.com",
|
1198
|
+
data: { type: "arcgis:auth:credential", credential: cred },
|
1199
|
+
});
|
1200
|
+
},
|
1201
|
+
},
|
1202
|
+
};
|
1203
|
+
|
1204
|
+
return UserSession.fromParent("https://origin.com", Win).then(
|
1205
|
+
(session) => {
|
1206
|
+
expect(session.username).toBe(
|
1207
|
+
"jsmith",
|
1208
|
+
"should use the cred wired throu the mock window"
|
1209
|
+
);
|
1210
|
+
}
|
1211
|
+
);
|
1212
|
+
});
|
1213
|
+
|
1214
|
+
it(".fromParent ignores other messages, then intercepts the correct one", async () => {
|
1215
|
+
// create a mock window that will fire the handler
|
1216
|
+
const Win = {
|
1217
|
+
_fn: (evt: any) => {},
|
1218
|
+
addEventListener(evt: any, fn: any) {
|
1219
|
+
Win._fn = fn;
|
1220
|
+
},
|
1221
|
+
removeEventListener() {},
|
1222
|
+
parent: {
|
1223
|
+
postMessage(msg: any, origin: string) {
|
1224
|
+
// fire one we intend to ignore
|
1225
|
+
Win._fn({
|
1226
|
+
origin: "https://notorigin.com",
|
1227
|
+
data: { type: "other:random", foo: { bar: "baz" } },
|
1228
|
+
});
|
1229
|
+
// fire a second we want to intercept
|
1230
|
+
Win._fn({
|
1231
|
+
origin: "https://origin.com",
|
1232
|
+
data: { type: "arcgis:auth:credential", credential: cred },
|
1233
|
+
});
|
1234
|
+
},
|
1235
|
+
},
|
1236
|
+
};
|
1237
|
+
|
1238
|
+
return UserSession.fromParent("https://origin.com", Win).then((resp) => {
|
1239
|
+
expect(resp.username).toBe(
|
1240
|
+
"jsmith",
|
1241
|
+
"should use the cred wired throu the mock window"
|
1242
|
+
);
|
1243
|
+
});
|
1244
|
+
});
|
1245
|
+
|
1246
|
+
it(".fromParent rejects if invlid cred", () => {
|
1247
|
+
// create a mock window that will fire the handler
|
1248
|
+
const Win = {
|
1249
|
+
_fn: (evt: any) => {},
|
1250
|
+
addEventListener(evt: any, fn: any) {
|
1251
|
+
Win._fn = fn;
|
1252
|
+
},
|
1253
|
+
removeEventListener() {},
|
1254
|
+
parent: {
|
1255
|
+
postMessage(msg: any, origin: string) {
|
1256
|
+
Win._fn({
|
1257
|
+
origin: "https://origin.com",
|
1258
|
+
data: {
|
1259
|
+
type: "arcgis:auth:credential",
|
1260
|
+
credential: { foo: "bar" },
|
1261
|
+
},
|
1262
|
+
});
|
1263
|
+
},
|
1264
|
+
},
|
1265
|
+
};
|
1266
|
+
|
1267
|
+
return UserSession.fromParent("https://origin.com", Win).catch((err) => {
|
1268
|
+
expect(err).toBeDefined("Should reject");
|
1269
|
+
});
|
1270
|
+
});
|
1271
|
+
|
1272
|
+
it(".fromParent rejects if auth rejected", () => {
|
1273
|
+
// create a mock window that will fire the handler
|
1274
|
+
const Win = {
|
1275
|
+
_fn: (evt: any) => {},
|
1276
|
+
addEventListener(evt: any, fn: any) {
|
1277
|
+
Win._fn = fn;
|
1278
|
+
},
|
1279
|
+
removeEventListener() {},
|
1280
|
+
parent: {
|
1281
|
+
postMessage(msg: any, origin: string) {
|
1282
|
+
Win._fn({
|
1283
|
+
origin: "https://origin.com",
|
1284
|
+
data: {
|
1285
|
+
type: "arcgis:auth:rejected",
|
1286
|
+
message: "Rejected authentication request.",
|
1287
|
+
},
|
1288
|
+
});
|
1289
|
+
},
|
1290
|
+
},
|
1291
|
+
};
|
1292
|
+
|
1293
|
+
return UserSession.fromParent("https://origin.com", Win).catch((err) => {
|
1294
|
+
expect(err).toBeDefined("Should reject");
|
1295
|
+
});
|
1296
|
+
});
|
1297
|
+
|
1298
|
+
it(".fromParent rejects if auth unknown message", () => {
|
1299
|
+
// create a mock window that will fire the handler
|
1300
|
+
const Win = {
|
1301
|
+
_fn: (evt: any) => {},
|
1302
|
+
addEventListener(evt: any, fn: any) {
|
1303
|
+
Win._fn = fn;
|
1304
|
+
},
|
1305
|
+
removeEventListener() {},
|
1306
|
+
parent: {
|
1307
|
+
postMessage(msg: any, origin: string) {
|
1308
|
+
Win._fn({
|
1309
|
+
origin: "https://origin.com",
|
1310
|
+
data: { type: "arcgis:auth:other" },
|
1311
|
+
});
|
1312
|
+
},
|
1313
|
+
},
|
1314
|
+
};
|
1315
|
+
|
1316
|
+
return UserSession.fromParent("https://origin.com", Win).catch((err) => {
|
1317
|
+
expect(err.message).toBe("Unknown message type.", "Should reject");
|
1318
|
+
});
|
1319
|
+
});
|
1320
|
+
});
|
1321
|
+
|
1322
|
+
describe("validateAppAccess: ", () => {
|
1323
|
+
it("makes a request to /oauth2/validateAppAccess passing params", () => {
|
1324
|
+
const VERIFYAPPACCESS_URL =
|
1325
|
+
"https://www.arcgis.com/sharing/rest/oauth2/validateAppAccess";
|
1326
|
+
fetchMock.postOnce(VERIFYAPPACCESS_URL, {
|
1327
|
+
valid: true,
|
1328
|
+
viewOnlyUserTypeApp: false,
|
1329
|
+
});
|
1330
|
+
const session = new UserSession({
|
1331
|
+
clientId: "clientId",
|
1332
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1333
|
+
token: "FAKE-TOKEN",
|
1334
|
+
tokenExpires: TOMORROW,
|
1335
|
+
refreshToken: "refreshToken",
|
1336
|
+
refreshTokenExpires: TOMORROW,
|
1337
|
+
refreshTokenTTL: 1440,
|
1338
|
+
username: "jsmith",
|
1339
|
+
password: "123456",
|
1340
|
+
});
|
1341
|
+
return session
|
1342
|
+
.validateAppAccess("abc123")
|
1343
|
+
.then((response) => {
|
1344
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall(
|
1345
|
+
VERIFYAPPACCESS_URL
|
1346
|
+
);
|
1347
|
+
expect(url).toEqual(VERIFYAPPACCESS_URL);
|
1348
|
+
expect(options.body).toContain("f=json");
|
1349
|
+
expect(options.body).toContain("token=FAKE-TOKEN");
|
1350
|
+
expect(options.body).toContain("client_id=abc123");
|
1351
|
+
expect(response.valid).toEqual(true);
|
1352
|
+
expect(response.viewOnlyUserTypeApp).toBe(false);
|
1353
|
+
})
|
1354
|
+
.catch((e) => fail(e));
|
1355
|
+
});
|
1356
|
+
});
|
1357
|
+
|
1358
|
+
it("should throw an unknown error if the url has no error or access_token", () => {
|
1359
|
+
const MockWindow = {
|
1360
|
+
location: {
|
1361
|
+
hash: "",
|
1362
|
+
},
|
1363
|
+
get opener() {
|
1364
|
+
return this;
|
1365
|
+
},
|
1366
|
+
};
|
1367
|
+
|
1368
|
+
expect(function() {
|
1369
|
+
UserSession.completeOAuth2(
|
1370
|
+
{
|
1371
|
+
clientId: "clientId",
|
1372
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1373
|
+
},
|
1374
|
+
MockWindow
|
1375
|
+
);
|
1376
|
+
}).toThrowError(ArcGISRequestError, "Unknown error");
|
1377
|
+
});
|
1378
|
+
|
1379
|
+
describe(".authorize()", () => {
|
1380
|
+
it("should redirect the request to the authorization page", (done) => {
|
1381
|
+
const spy = jasmine.createSpy("spy");
|
1382
|
+
const MockResponse: any = {
|
1383
|
+
writeHead: spy,
|
1384
|
+
end() {
|
1385
|
+
expect(spy.calls.mostRecent().args[0]).toBe(301);
|
1386
|
+
expect(spy.calls.mostRecent().args[1].Location).toBe(
|
1387
|
+
"https://arcgis.com/sharing/rest/oauth2/authorize?client_id=clientId&duration=20160&response_type=code&redirect_uri=https%3A%2F%2Fexample-app.com%2Fredirect-uri"
|
1388
|
+
);
|
1389
|
+
done();
|
1390
|
+
},
|
1391
|
+
};
|
1392
|
+
|
1393
|
+
UserSession.authorize(
|
1394
|
+
{
|
1395
|
+
clientId: "clientId",
|
1396
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1397
|
+
},
|
1398
|
+
MockResponse
|
1399
|
+
);
|
1400
|
+
});
|
1401
|
+
});
|
1402
|
+
|
1403
|
+
describe(".exchangeAuthorizationCode()", () => {
|
1404
|
+
let paramsSpy: jasmine.Spy;
|
1405
|
+
|
1406
|
+
beforeEach(() => {
|
1407
|
+
paramsSpy = spyOn(FormData.prototype, "append").and.callThrough();
|
1408
|
+
});
|
1409
|
+
|
1410
|
+
afterAll(() => {
|
1411
|
+
paramsSpy.calls.reset();
|
1412
|
+
});
|
1413
|
+
|
1414
|
+
it("should exchange an authorization code for a new UserSession", (done) => {
|
1415
|
+
fetchMock.postOnce("https://www.arcgis.com/sharing/rest/oauth2/token", {
|
1416
|
+
access_token: "token",
|
1417
|
+
expires_in: 1800,
|
1418
|
+
refresh_token: "refreshToken",
|
1419
|
+
username: "Casey",
|
1420
|
+
ssl: true,
|
1421
|
+
});
|
1422
|
+
|
1423
|
+
UserSession.exchangeAuthorizationCode(
|
1424
|
+
{
|
1425
|
+
clientId: "clientId",
|
1426
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1427
|
+
},
|
1428
|
+
"code"
|
1429
|
+
)
|
1430
|
+
.then((session) => {
|
1431
|
+
expect(session.token).toBe("token");
|
1432
|
+
expect(session.tokenExpires.getTime()).toBeGreaterThan(Date.now());
|
1433
|
+
expect(session.username).toBe("Casey");
|
1434
|
+
expect(session.refreshToken).toBe("refreshToken");
|
1435
|
+
expect(session.ssl).toBe(true);
|
1436
|
+
done();
|
1437
|
+
})
|
1438
|
+
.catch((e) => {
|
1439
|
+
fail(e);
|
1440
|
+
});
|
1441
|
+
});
|
1442
|
+
});
|
1443
|
+
|
1444
|
+
describe(".getUser()", () => {
|
1445
|
+
afterEach(fetchMock.restore);
|
1446
|
+
|
1447
|
+
it("should cache metadata about the user", (done) => {
|
1448
|
+
// we intentionally only mock one response
|
1449
|
+
fetchMock.once(
|
1450
|
+
"https://www.arcgis.com/sharing/rest/community/self?f=json&token=token",
|
1451
|
+
{
|
1452
|
+
username: "jsmith",
|
1453
|
+
fullName: "John Smith",
|
1454
|
+
role: "org_publisher",
|
1455
|
+
}
|
1456
|
+
);
|
1457
|
+
|
1458
|
+
const session = new UserSession({
|
1459
|
+
clientId: "clientId",
|
1460
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1461
|
+
token: "token",
|
1462
|
+
tokenExpires: TOMORROW,
|
1463
|
+
refreshToken: "refreshToken",
|
1464
|
+
refreshTokenExpires: TOMORROW,
|
1465
|
+
refreshTokenTTL: 1440,
|
1466
|
+
username: "jsmith",
|
1467
|
+
password: "123456",
|
1468
|
+
});
|
1469
|
+
|
1470
|
+
session
|
1471
|
+
.getUser()
|
1472
|
+
.then((response) => {
|
1473
|
+
expect(response.role).toEqual("org_publisher");
|
1474
|
+
session
|
1475
|
+
.getUser()
|
1476
|
+
.then((cachedResponse) => {
|
1477
|
+
expect(cachedResponse.fullName).toEqual("John Smith");
|
1478
|
+
done();
|
1479
|
+
})
|
1480
|
+
.catch((e) => {
|
1481
|
+
fail(e);
|
1482
|
+
});
|
1483
|
+
})
|
1484
|
+
.catch((e) => {
|
1485
|
+
fail(e);
|
1486
|
+
});
|
1487
|
+
});
|
1488
|
+
|
1489
|
+
it("should never make more then 1 request", (done) => {
|
1490
|
+
// we intentionally only mock one response
|
1491
|
+
fetchMock.once(
|
1492
|
+
"https://www.arcgis.com/sharing/rest/community/self?f=json&token=token",
|
1493
|
+
{
|
1494
|
+
username: "jsmith",
|
1495
|
+
fullName: "John Smith",
|
1496
|
+
role: "org_publisher",
|
1497
|
+
}
|
1498
|
+
);
|
1499
|
+
|
1500
|
+
const session = new UserSession({
|
1501
|
+
clientId: "clientId",
|
1502
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1503
|
+
token: "token",
|
1504
|
+
tokenExpires: TOMORROW,
|
1505
|
+
refreshToken: "refreshToken",
|
1506
|
+
refreshTokenExpires: TOMORROW,
|
1507
|
+
refreshTokenTTL: 1440,
|
1508
|
+
username: "jsmith",
|
1509
|
+
password: "123456",
|
1510
|
+
});
|
1511
|
+
|
1512
|
+
Promise.all([session.getUser(), session.getUser()])
|
1513
|
+
.then(() => {
|
1514
|
+
done();
|
1515
|
+
})
|
1516
|
+
.catch((e) => {
|
1517
|
+
fail(e);
|
1518
|
+
});
|
1519
|
+
});
|
1520
|
+
});
|
1521
|
+
|
1522
|
+
describe(".getUsername()", () => {
|
1523
|
+
afterEach(fetchMock.restore);
|
1524
|
+
|
1525
|
+
it("should fetch the username via getUser()", (done) => {
|
1526
|
+
// we intentionally only mock one response
|
1527
|
+
fetchMock.once(
|
1528
|
+
"https://www.arcgis.com/sharing/rest/community/self?f=json&token=token",
|
1529
|
+
{
|
1530
|
+
username: "jsmith",
|
1531
|
+
}
|
1532
|
+
);
|
1533
|
+
|
1534
|
+
const session = new UserSession({
|
1535
|
+
token: "token",
|
1536
|
+
});
|
1537
|
+
|
1538
|
+
session
|
1539
|
+
.getUsername()
|
1540
|
+
.then((response) => {
|
1541
|
+
expect(response).toEqual("jsmith");
|
1542
|
+
|
1543
|
+
// also test getting it from the cache.
|
1544
|
+
session
|
1545
|
+
.getUsername()
|
1546
|
+
.then((username) => {
|
1547
|
+
done();
|
1548
|
+
|
1549
|
+
expect(username).toEqual("jsmith");
|
1550
|
+
})
|
1551
|
+
.catch((e) => {
|
1552
|
+
fail(e);
|
1553
|
+
});
|
1554
|
+
})
|
1555
|
+
.catch((e) => {
|
1556
|
+
fail(e);
|
1557
|
+
});
|
1558
|
+
});
|
1559
|
+
|
1560
|
+
it("should use a username if passed in the session", (done) => {
|
1561
|
+
const session = new UserSession({
|
1562
|
+
username: "jsmith",
|
1563
|
+
});
|
1564
|
+
|
1565
|
+
session
|
1566
|
+
.getUsername()
|
1567
|
+
.then((response) => {
|
1568
|
+
expect(response).toEqual("jsmith");
|
1569
|
+
done();
|
1570
|
+
})
|
1571
|
+
.catch((e) => {
|
1572
|
+
fail(e);
|
1573
|
+
});
|
1574
|
+
});
|
1575
|
+
});
|
1576
|
+
|
1577
|
+
describe("to/fromCredential()", () => {
|
1578
|
+
const MOCK_CREDENTIAL: ICredential = {
|
1579
|
+
expires: TOMORROW.getTime(),
|
1580
|
+
server: "https://www.arcgis.com",
|
1581
|
+
ssl: false,
|
1582
|
+
token: "token",
|
1583
|
+
userId: "jsmith",
|
1584
|
+
};
|
1585
|
+
|
1586
|
+
const MOCK_USER_SESSION = new UserSession({
|
1587
|
+
clientId: "clientId",
|
1588
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
1589
|
+
token: "token",
|
1590
|
+
ssl: false,
|
1591
|
+
tokenExpires: TOMORROW,
|
1592
|
+
refreshToken: "refreshToken",
|
1593
|
+
refreshTokenExpires: TOMORROW,
|
1594
|
+
refreshTokenTTL: 1440,
|
1595
|
+
username: "jsmith",
|
1596
|
+
password: "123456",
|
1597
|
+
});
|
1598
|
+
|
1599
|
+
it("should create a credential object from a session", () => {
|
1600
|
+
const creds = MOCK_USER_SESSION.toCredential();
|
1601
|
+
expect(creds.userId).toEqual("jsmith");
|
1602
|
+
expect(creds.server).toEqual("https://www.arcgis.com/sharing/rest");
|
1603
|
+
expect(creds.ssl).toEqual(false);
|
1604
|
+
expect(creds.token).toEqual("token");
|
1605
|
+
expect(creds.expires).toEqual(TOMORROW.getTime());
|
1606
|
+
});
|
1607
|
+
|
1608
|
+
it("should create a UserSession from a credential", () => {
|
1609
|
+
const session = UserSession.fromCredential(MOCK_CREDENTIAL);
|
1610
|
+
expect(session.username).toEqual("jsmith");
|
1611
|
+
expect(session.portal).toEqual("https://www.arcgis.com/sharing/rest");
|
1612
|
+
expect(session.ssl).toEqual(false);
|
1613
|
+
expect(session.token).toEqual("token");
|
1614
|
+
expect(session.tokenExpires).toEqual(new Date(TOMORROW));
|
1615
|
+
});
|
1616
|
+
|
1617
|
+
it("should create a UserSession from a credential that came from a UserSession", () => {
|
1618
|
+
const creds = MOCK_USER_SESSION.toCredential();
|
1619
|
+
const credSession = UserSession.fromCredential(creds);
|
1620
|
+
expect(credSession.username).toEqual("jsmith");
|
1621
|
+
expect(credSession.portal).toEqual("https://www.arcgis.com/sharing/rest");
|
1622
|
+
expect(credSession.ssl).toEqual(false);
|
1623
|
+
expect(credSession.token).toEqual("token");
|
1624
|
+
expect(credSession.tokenExpires).toEqual(new Date(TOMORROW));
|
1625
|
+
});
|
1626
|
+
});
|
1627
|
+
|
1628
|
+
describe("getServerRootUrl()", () => {
|
1629
|
+
it("should lowercase domain names", () => {
|
1630
|
+
const session = new UserSession({
|
1631
|
+
clientId: "id",
|
1632
|
+
token: "token",
|
1633
|
+
tokenExpires: TOMORROW,
|
1634
|
+
});
|
1635
|
+
|
1636
|
+
const root = session.getServerRootUrl(
|
1637
|
+
"https://PNP00035.esri.com/server/rest/services/Hosted/perimeters_dd83/FeatureServer"
|
1638
|
+
);
|
1639
|
+
expect(root).toEqual("https://pnp00035.esri.com/server");
|
1640
|
+
});
|
1641
|
+
|
1642
|
+
it("should not lowercase path names", () => {
|
1643
|
+
const session = new UserSession({
|
1644
|
+
clientId: "id",
|
1645
|
+
token: "token",
|
1646
|
+
tokenExpires: TOMORROW,
|
1647
|
+
});
|
1648
|
+
|
1649
|
+
const root = session.getServerRootUrl(
|
1650
|
+
"https://pnp00035.esri.com/tiles/LkFyxb9zDq7vAOAm/arcgis/rest/services/NB_Stereographic/VectorTileServer"
|
1651
|
+
);
|
1652
|
+
expect(root).toEqual(
|
1653
|
+
"https://pnp00035.esri.com/tiles/LkFyxb9zDq7vAOAm/arcgis"
|
1654
|
+
);
|
1655
|
+
});
|
1656
|
+
|
1657
|
+
it("should respect the original https/http protocol", () => {
|
1658
|
+
const session = new UserSession({
|
1659
|
+
clientId: "id",
|
1660
|
+
token: "token",
|
1661
|
+
tokenExpires: TOMORROW,
|
1662
|
+
});
|
1663
|
+
|
1664
|
+
const root = session.getServerRootUrl(
|
1665
|
+
"http://pnp00035.esri.com/tiles/LkFyxb9zDq7vAOAm/arcgis/rest/services/NB_Stereographic/VectorTileServer"
|
1666
|
+
);
|
1667
|
+
expect(root).toEqual(
|
1668
|
+
"http://pnp00035.esri.com/tiles/LkFyxb9zDq7vAOAm/arcgis"
|
1669
|
+
);
|
1670
|
+
});
|
1671
|
+
});
|
1672
|
+
|
1673
|
+
describe("non-federated server", () => {
|
1674
|
+
it("shouldnt fetch a fresh token if the current one isn't expired.", (done) => {
|
1675
|
+
const MOCK_USER_SESSION = new UserSession({
|
1676
|
+
username: "c@sey",
|
1677
|
+
password: "123456",
|
1678
|
+
token: "token",
|
1679
|
+
tokenExpires: TOMORROW,
|
1680
|
+
server: "https://fakeserver.com/arcgis",
|
1681
|
+
});
|
1682
|
+
|
1683
|
+
MOCK_USER_SESSION.getToken(
|
1684
|
+
"https://fakeserver.com/arcgis/rest/services/Fake/MapServer/"
|
1685
|
+
)
|
1686
|
+
.then((token) => {
|
1687
|
+
expect(token).toBe("token");
|
1688
|
+
done();
|
1689
|
+
})
|
1690
|
+
.catch((err) => {
|
1691
|
+
fail(err);
|
1692
|
+
});
|
1693
|
+
});
|
1694
|
+
|
1695
|
+
it("should fetch a fresh token if the current one is expired.", (done) => {
|
1696
|
+
const MOCK_USER_SESSION = new UserSession({
|
1697
|
+
username: "jsmith",
|
1698
|
+
password: "123456",
|
1699
|
+
token: "token",
|
1700
|
+
tokenExpires: YESTERDAY,
|
1701
|
+
server: "https://fakeserver.com/arcgis",
|
1702
|
+
});
|
1703
|
+
|
1704
|
+
fetchMock.postOnce("https://fakeserver.com/arcgis/rest/info", {
|
1705
|
+
currentVersion: 10.61,
|
1706
|
+
fullVersion: "10.6.1",
|
1707
|
+
authInfo: {
|
1708
|
+
isTokenBasedSecurity: true,
|
1709
|
+
tokenServicesUrl: "https://fakeserver.com/arcgis/tokens/",
|
1710
|
+
},
|
1711
|
+
});
|
1712
|
+
|
1713
|
+
fetchMock.postOnce("https://fakeserver.com/arcgis/tokens/", {
|
1714
|
+
token: "fresh-token",
|
1715
|
+
expires: TOMORROW.getTime(),
|
1716
|
+
username: " jsmith",
|
1717
|
+
});
|
1718
|
+
|
1719
|
+
MOCK_USER_SESSION.getToken(
|
1720
|
+
"https://fakeserver.com/arcgis/rest/services/Fake/MapServer/"
|
1721
|
+
)
|
1722
|
+
.then((token) => {
|
1723
|
+
expect(token).toBe("fresh-token");
|
1724
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall(
|
1725
|
+
"https://fakeserver.com/arcgis/tokens/"
|
1726
|
+
);
|
1727
|
+
expect(options.method).toBe("POST");
|
1728
|
+
expect(options.body).toContain("f=json");
|
1729
|
+
expect(options.body).toContain("username=jsmith");
|
1730
|
+
expect(options.body).toContain("password=123456");
|
1731
|
+
expect(options.body).toContain("client=referer");
|
1732
|
+
done();
|
1733
|
+
})
|
1734
|
+
.catch((err) => {
|
1735
|
+
fail(err);
|
1736
|
+
});
|
1737
|
+
});
|
1738
|
+
|
1739
|
+
it("should trim down the server url if necessary.", (done) => {
|
1740
|
+
const MOCK_USER_SESSION = new UserSession({
|
1741
|
+
username: "jsmith",
|
1742
|
+
password: "123456",
|
1743
|
+
token: "token",
|
1744
|
+
tokenExpires: YESTERDAY,
|
1745
|
+
server: "https://fakeserver.com/arcgis/rest/services/blah/",
|
1746
|
+
});
|
1747
|
+
|
1748
|
+
fetchMock.postOnce("https://fakeserver.com/arcgis/rest/info", {
|
1749
|
+
currentVersion: 10.61,
|
1750
|
+
fullVersion: "10.6.1",
|
1751
|
+
authInfo: {
|
1752
|
+
isTokenBasedSecurity: true,
|
1753
|
+
tokenServicesUrl: "https://fakeserver.com/arcgis/tokens/",
|
1754
|
+
},
|
1755
|
+
});
|
1756
|
+
|
1757
|
+
fetchMock.postOnce("https://fakeserver.com/arcgis/tokens/", {
|
1758
|
+
token: "fresh-token",
|
1759
|
+
expires: TOMORROW.getTime(),
|
1760
|
+
username: " jsmith",
|
1761
|
+
});
|
1762
|
+
|
1763
|
+
MOCK_USER_SESSION.getToken(
|
1764
|
+
"https://fakeserver.com/arcgis/rest/services/Fake/MapServer/"
|
1765
|
+
)
|
1766
|
+
.then((token) => {
|
1767
|
+
expect(token).toBe("fresh-token");
|
1768
|
+
done();
|
1769
|
+
})
|
1770
|
+
.catch((err) => {
|
1771
|
+
fail(err);
|
1772
|
+
});
|
1773
|
+
});
|
1774
|
+
|
1775
|
+
it("should throw an error if the server isnt trusted.", (done) => {
|
1776
|
+
fetchMock.postOnce("https://fakeserver2.com/arcgis/rest/info", {
|
1777
|
+
currentVersion: 10.61,
|
1778
|
+
fullVersion: "10.6.1",
|
1779
|
+
authInfo: {
|
1780
|
+
isTokenBasedSecurity: true,
|
1781
|
+
tokenServicesUrl: "https://fakeserver2.com/arcgis/tokens/",
|
1782
|
+
},
|
1783
|
+
});
|
1784
|
+
const MOCK_USER_SESSION = new UserSession({
|
1785
|
+
username: "c@sey",
|
1786
|
+
password: "123456",
|
1787
|
+
token: "token",
|
1788
|
+
tokenExpires: TOMORROW,
|
1789
|
+
server: "https://fakeserver.com/arcgis",
|
1790
|
+
});
|
1791
|
+
|
1792
|
+
MOCK_USER_SESSION.getToken(
|
1793
|
+
"https://fakeserver2.com/arcgis/rest/services/Fake/MapServer/"
|
1794
|
+
)
|
1795
|
+
.then((token) => {
|
1796
|
+
fail(token);
|
1797
|
+
})
|
1798
|
+
.catch((err) => {
|
1799
|
+
expect(err.code).toBe("NOT_FEDERATED");
|
1800
|
+
expect(err.originalMessage).toEqual(
|
1801
|
+
"https://fakeserver2.com/arcgis/rest/services/Fake/MapServer/ is not federated with any portal and is not explicitly trusted."
|
1802
|
+
);
|
1803
|
+
done();
|
1804
|
+
});
|
1805
|
+
});
|
1806
|
+
});
|
1807
|
+
});
|