From 803682713bf5eb861b1d009cd1e1d922b3e7ab84 Mon Sep 17 00:00:00 2001 From: Austin Kelleher Date: Mon, 3 Aug 2020 10:09:23 -0400 Subject: [PATCH] Fixes #6 - Update to have example 'toMatchGraphObjectSchema' usage --- package.json | 10 ++-- src/steps/__snapshots__/index.test.ts.snap | 12 ++++ src/steps/access.ts | 9 +++ src/steps/account.ts | 4 ++ src/steps/index.test.ts | 64 ++++++++++++++++++++++ yarn.lock | 51 ++++++++--------- 6 files changed, 120 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 35bd1c7..a40e6d0 100644 --- a/package.json +++ b/package.json @@ -17,18 +17,18 @@ "lint": "eslint . --cache --fix --ext .ts,.tsx", "format": "prettier --write '**/*.{ts,js,json,css,md,yml}'", "type-check": "tsc", - "test": "jest --passWithNoTests", + "test": "jest", "test:ci": "yarn lint && yarn type-check && yarn test", "build": "tsc -p tsconfig.dist.json --declaration", "prepush": "yarn lint && yarn type-check && jest --changedSince master", "prepack": "yarn build" }, "peerDependencies": { - "@jupiterone/integration-sdk-core": "^2.6.0" + "@jupiterone/integration-sdk-core": "^2.8.0" }, "devDependencies": { - "@jupiterone/integration-sdk-core": "^2.6.0", - "@jupiterone/integration-sdk-dev-tools": "^2.6.0", - "@jupiterone/integration-sdk-testing": "^2.6.0" + "@jupiterone/integration-sdk-core": "^2.8.0", + "@jupiterone/integration-sdk-dev-tools": "^2.8.0", + "@jupiterone/integration-sdk-testing": "^2.8.0" } } diff --git a/src/steps/__snapshots__/index.test.ts.snap b/src/steps/__snapshots__/index.test.ts.snap index d1b114d..d022daa 100644 --- a/src/steps/__snapshots__/index.test.ts.snap +++ b/src/steps/__snapshots__/index.test.ts.snap @@ -21,6 +21,8 @@ Object { "createdOn": undefined, "displayName": "Example Co. Acme Account", "id": "acme-unique-account-id", + "manager": "Manager Name", + "mfaEnabled": true, "name": "Example Co. Acme Account", }, Object { @@ -40,8 +42,11 @@ Object { "_type": "acme_user", "createdOn": undefined, "displayName": "User One", + "email": "test@test.com", + "firstName": "John", "id": "acme-user-1", "name": "User One", + "username": "testusername", }, Object { "_class": Array [ @@ -60,8 +65,11 @@ Object { "_type": "acme_user", "createdOn": undefined, "displayName": "User Two", + "email": "test@test.com", + "firstName": "John", "id": "acme-user-2", "name": "User Two", + "username": "testusername", }, Object { "_class": Array [ @@ -85,7 +93,9 @@ Object { "_type": "acme_group", "createdOn": undefined, "displayName": "Group One", + "email": "testgroup@test.com", "id": "acme-group-1", + "logoLink": "https://test.com/logo.png", "name": "Group One", }, ], @@ -131,5 +141,7 @@ Object { "acme_account_has_group", "acme_group_has_user", ], + "numCollectedEntities": 4, + "numCollectedRelationships": 4, } `; diff --git a/src/steps/access.ts b/src/steps/access.ts index 31d904e..d47b35f 100644 --- a/src/steps/access.ts +++ b/src/steps/access.ts @@ -26,6 +26,11 @@ export async function fetchUsers({ assign: { _type: 'acme_user', _class: 'User', + username: 'testusername', + email: 'test@test.com', + // This is a custom property that is not a part of the data model class + // hierarchy. See: https://github.com/JupiterOne/data-model/blob/master/src/schemas/User.json + firstName: 'John', }, }, }); @@ -58,6 +63,10 @@ export async function fetchGroups({ assign: { _type: 'acme_group', _class: 'UserGroup', + email: 'testgroup@test.com', + // This is a custom property that is not a part of the data model class + // hierarchy. See: https://github.com/JupiterOne/data-model/blob/master/src/schemas/UserGroup.json + logoLink: 'https://test.com/logo.png', }, }, }); diff --git a/src/steps/account.ts b/src/steps/account.ts index 9964228..4bee44b 100644 --- a/src/steps/account.ts +++ b/src/steps/account.ts @@ -21,6 +21,10 @@ export async function fetchAccountDetails({ _key: 'acme-unique-account-id', _type: 'acme_account', _class: 'Account', + mfaEnabled: true, + // This is a custom property that is not a part of the data model class + // hierarchy. See: https://github.com/JupiterOne/data-model/blob/master/src/schemas/Account.json + manager: 'Manager Name', }, }, }); diff --git a/src/steps/index.test.ts b/src/steps/index.test.ts index 5d5340e..d77cd24 100644 --- a/src/steps/index.test.ts +++ b/src/steps/index.test.ts @@ -25,8 +25,72 @@ test('should collect data', async () => { // Review snapshot, failure is a regression expect({ + numCollectedEntities: context.jobState.collectedEntities.length, + numCollectedRelationships: context.jobState.collectedRelationships.length, collectedEntities: context.jobState.collectedEntities, collectedRelationships: context.jobState.collectedRelationships, encounteredTypes: context.jobState.encounteredTypes, }).toMatchSnapshot(); + + expect( + context.jobState.collectedEntities.filter((e) => + e._class.includes('Account'), + ), + ).toMatchGraphObjectSchema({ + _class: ['Account'], + schema: { + additionalProperties: false, + properties: { + _type: { const: 'acme_account' }, + manager: { type: 'string' }, + _rawData: { + type: 'array', + items: { type: 'object' }, + }, + }, + required: ['manager'], + }, + }); + + expect( + context.jobState.collectedEntities.filter((e) => e._class.includes('User')), + ).toMatchGraphObjectSchema({ + _class: ['User'], + schema: { + additionalProperties: false, + properties: { + _type: { const: 'acme_user' }, + firstName: { type: 'string' }, + _rawData: { + type: 'array', + items: { type: 'object' }, + }, + }, + required: ['firstName'], + }, + }); + + expect( + context.jobState.collectedEntities.filter((e) => + e._class.includes('UserGroup'), + ), + ).toMatchGraphObjectSchema({ + _class: ['UserGroup'], + schema: { + additionalProperties: false, + properties: { + _type: { const: 'acme_group' }, + logoLink: { + type: 'string', + // Validate that the `logoLink` property has a URL format + format: 'url', + }, + _rawData: { + type: 'array', + items: { type: 'object' }, + }, + }, + required: ['logoLink'], + }, + }); }); diff --git a/yarn.lock b/yarn.lock index d6a16fc..5474c7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -464,33 +464,34 @@ dependencies: ajv "^6.12.0" -"@jupiterone/integration-sdk-cli@^2.6.0": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-cli/-/integration-sdk-cli-2.6.0.tgz#89d003e63340aaa9dad70408272412978b024b43" - integrity sha512-nao7qAnwNMPl4frU1FgT4PrA4wLvnrvoEiMLNELeO7eF9dlcts1wJ76xjvM0CEr5e3Cz9zA1Q7bagtpR+4sYLg== +"@jupiterone/integration-sdk-cli@^2.8.0": + version "2.8.0" + resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-cli/-/integration-sdk-cli-2.8.0.tgz#f26f632a2f23bd10747cb9f6bf10c340053d95a8" + integrity sha512-1/u0GlqMAdaLRtHG/XPvKGCNqhVFu2h2bBsm+bhtmYbEjCD3y6eu6n7lpmxR8X/3Pttf1XkKkyQTI//c02LyBQ== dependencies: - "@jupiterone/integration-sdk-runtime" "^2.6.0" + "@jupiterone/integration-sdk-runtime" "^2.8.0" commander "^5.0.0" globby "^11.0.0" lodash "^4.17.19" upath "^1.2.0" vis "^4.21.0-EOL" -"@jupiterone/integration-sdk-core@^2.6.0": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-core/-/integration-sdk-core-2.6.0.tgz#74b59cb95b2b7c0c925a770a8b2541a6cd00a909" - integrity sha512-x1nq9KNwWAK8m4SOiE6WCgStEd1E+MgaQwUnTRRHra1xQ7LP4rcdXc8XPBnmPH5sr1nS+Zy1g8LMCaf+7bV9gw== +"@jupiterone/integration-sdk-core@^2.8.0": + version "2.8.0" + resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-core/-/integration-sdk-core-2.8.0.tgz#961b308dc92a2c87597617fe0f976593d3397f56" + integrity sha512-fuM075d/km/g4ZKMSV7ozo/zucR0/BMKAg2RYoKHx5uLwJ2Lo9tjIcvH7cKhTY7ZcfbQZEyXz1qAxfC4eC9srw== dependencies: "@jupiterone/data-model" "^0.7.1" lodash "^4.17.15" uuid "^7.0.3" -"@jupiterone/integration-sdk-dev-tools@^2.6.0": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-dev-tools/-/integration-sdk-dev-tools-2.6.0.tgz#2b85f6e46f2fbc891007e9df881cc7576292cead" - integrity sha512-boN0TW2zi2WcveZYo/8bcbBnNpkeBLo+po5EblLrbxBm7THXZ8jpdKzmfQAt4FPo7GJY8d1xFTLLuZgWHsrJZw== +"@jupiterone/integration-sdk-dev-tools@^2.8.0": + version "2.8.0" + resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-dev-tools/-/integration-sdk-dev-tools-2.8.0.tgz#ca8111848d7865746b1b091247b6963d4d831ffd" + integrity sha512-NksPnlN4XsMHOvgDYW9qhWPth8/Dzorl1tyvwl/c6BCgoNj7ER2imBGqrj1Qyi29MFaZOt1Ni3kanX4dw5tX2Q== dependencies: - "@jupiterone/integration-sdk-cli" "^2.6.0" + "@jupiterone/integration-sdk-cli" "^2.8.0" + "@jupiterone/integration-sdk-testing" "^2.8.0" "@types/jest" "^25.2.3" "@types/node" "^14.0.5" "@typescript-eslint/eslint-plugin" "^3.0.2" @@ -506,12 +507,12 @@ ts-node "^8.10.2" typescript "^3.9.3" -"@jupiterone/integration-sdk-runtime@^2.6.0": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-runtime/-/integration-sdk-runtime-2.6.0.tgz#d235b357eee5435123ffd4ade43f71c4efdbb2f1" - integrity sha512-mhF7hnkNISfCXiXgfCII30FnXEeG4yQL+UZG3xblhTlDBRAkNGTbwOkTfXBNIhewmA7BRPyou+cICXEpftInRg== +"@jupiterone/integration-sdk-runtime@^2.8.0": + version "2.8.0" + resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-runtime/-/integration-sdk-runtime-2.8.0.tgz#b00e2e74e0dc7282325ddf17274325d9b0e59318" + integrity sha512-EgXqVuTst0sOqDH5bfOAFRQgviv3MY3+XJA9WVI+zf9q5lBvJajs3k5CSLkJNHerxjxwzcvwLuYrPMZqVJ64YQ== dependencies: - "@jupiterone/integration-sdk-core" "^2.6.0" + "@jupiterone/integration-sdk-core" "^2.8.0" "@lifeomic/alpha" "^1.1.3" async-sema "^3.1.0" axios "^0.19.2" @@ -529,13 +530,13 @@ rimraf "^3.0.2" uuid "^7.0.3" -"@jupiterone/integration-sdk-testing@^2.6.0": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-testing/-/integration-sdk-testing-2.6.0.tgz#4ee243d7bd5ca1b65dbaf98f83d3e07c609c9585" - integrity sha512-zwkoiO8HW1X+rCo7mgknhIex6X6ReWODoUIE3P9/DBOc3X/oHzEUrS08IfUITZsy+JgRLpDB3sJJFk1gt1+p5Q== +"@jupiterone/integration-sdk-testing@^2.8.0": + version "2.8.0" + resolved "https://registry.yarnpkg.com/@jupiterone/integration-sdk-testing/-/integration-sdk-testing-2.8.0.tgz#6c1c84d57bc2a9628e093cd617a616c434098146" + integrity sha512-v0vRVJVB3crCxqkLnuxTjry08rM9C/eCUJ4OvcFKN3hTeNnUbBoLYztFbee5ip+KJEFGazH67H4FUmbNjLIJqw== dependencies: - "@jupiterone/integration-sdk-core" "^2.6.0" - "@jupiterone/integration-sdk-runtime" "^2.6.0" + "@jupiterone/integration-sdk-core" "^2.8.0" + "@jupiterone/integration-sdk-runtime" "^2.8.0" "@pollyjs/adapter-node-http" "^4.0.4" "@pollyjs/core" "^4.0.4" "@pollyjs/persister-fs" "^4.0.4"