Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPII-3333: Improve production tests to cover more functionality #718

Merged
merged 78 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
214c5fa
GPII-3333: Improve production config tests to test more functionality.
klown Nov 9, 2018
ea8d1b2
GPII-3333: Fixed "health" flowmanager test.
klown Nov 14, 2018
3b4d44a
GPII-3333: Fixed port configuration for flowmanager tests.
klown Nov 19, 2018
c227777
GPII-3333: Added '/access_token' flowmanager test.
klown Nov 19, 2018
3368e99
GPII-3333: Use 'testUser1' instead of 'carla' for /accestoken test.
klown Nov 20, 2018
e8c9eb8
GPII-3333: Improved access token test by testing the response.
klown Nov 20, 2018
e1bb67f
GPII-3333: Improved access token test to use variable for user id.
klown Nov 20, 2018
d044422
GPII-3333: Added test for /%gpiiKey/settings/%device
klown Nov 22, 2018
b2e26e3
GPII-3333: Tidied up the onComplete listener specs.
klown Nov 22, 2018
5cb24c3
GPII-3333: Merged upstream master GPII branch
klown Dec 6, 2018
5c060ef
GPII-3333: Merged changes from branch 'GPII-3551'
klown Dec 7, 2018
a6af970
GPII-3333: Updated production tests using fixes from GPII-3551
klown Dec 7, 2018
515210c
GPII-3333: Parameterized information for some tests.
klown Dec 10, 2018
8e6b35e
GPII-3333: Improved path generation for life cycle settings test
klown Dec 11, 2018
81acd12
GPII-3333: Mergeed changes from GPII-3551
klown Dec 11, 2018
2928a28
GPII-3333: Merged upstream master GPII branch
klown Dec 13, 2018
0c6ccce
GPII-3333: Early attempt at using existing development tests in prod…
klown Dec 18, 2018
54cbb66
GPII-3333: Modified to handle set settings tests
klown Dec 21, 2018
8d67a9c
GPII-3333: Modified to ensure tests still run in development mode
klown Jan 7, 2019
c50fb98
GPII-3333: Renamed test definitions file
klown Jan 7, 2019
e748824
GPII-3333: Added development configuration for "put settings" tests.
klown Jan 8, 2019
ecafb34
GPII-3333: Removed "debugger;" statements.
klown Jan 8, 2019
05e0a47
GPII-3333: Merged changes from upstream master GPII branch.
klown Jan 10, 2019
559e5f0
GPII-3333: Added set of "put settings" tests that are expected to fail.
klown Jan 11, 2019
99aa8d0
GPII-3333: Actually add the "put settings" test defintiions
klown Jan 11, 2019
d0122e9
GPII-3333: Renamed files in prep for merge with master branch
klown Jan 15, 2019
304b3f4
GPII-3333: Merged changes from upstream master GPII branch
klown Jan 15, 2019
5d1692b
GPII-3333: Add and delete 'user' preferences safes
klown Jan 22, 2019
f3e30a3
GPII-3628: Avoid using null _id values in views.
the-t-in-rtf Jan 14, 2019
5ae3962
GPII-3333: Add and delete 'user' preferences for testing
klown Jan 30, 2019
1897098
GPII-3333: Removed _purge request and its test
klown Jan 30, 2019
6f8980c
GPII-3333: Modified to use a common GPII Key.
klown Jan 31, 2019
e1bf42d
GPII-3333: Renamed test file back to its original name
klown Jan 31, 2019
af22f2a
GPII-3333: Merged modifications from upstream master branch
klown Jan 31, 2019
ebbf7eb
GPII-3333: Removed extraneous variables and data structures.
klown Feb 1, 2019
3f4ef42
GPII-3333: Addressed reviewer comments
klown Feb 6, 2019
375017c
GPII-3333: Share grades for defining requests used by dev and prod te…
cindyli Feb 6, 2019
ee14159
GPII-3333: Shared test definition for "update snapset" test
klown Feb 8, 2019
140423e
GPII-3333: Merged changes from Cindy's branch
klown Feb 8, 2019
9c9682f
GPII-3333: Re-factored to share tests in both production and develop…
klown Feb 13, 2019
b7b53fd
GPII-3333: Syncning test names with endpoint "names"
klown Feb 13, 2019
8bc1aa9
GPII-3333: Merged changes from upstream master GPII branch
klown Feb 13, 2019
f9a0308
GPII-3333: Merged changes from Tony's GPII-3619 branch
klown Feb 14, 2019
62d6f1d
GPII-3333: Changed database setup to include snapsets
klown Feb 20, 2019
a6af103
GPII-3333: Fixed one missed case of the correct disrupted gradename
klown Feb 22, 2019
f928ea2
GPII-3333: First pass running tests in a production config using GPI…
klown Feb 22, 2019
08a80ec
GPII-3333: Modified the disruption tests sequence grade and test env…
klown Feb 27, 2019
7961149
GPII-3333: Merged upstream master GPII branch
klown Feb 28, 2019
f0423e8
GPII-3333: Fixed lint errors
klown Feb 28, 2019
87bf30d
GPII-3333: Config and disruption sequence grade common file
klown Feb 28, 2019
4c400aa
GPII-3333: Merged changes from upstream master GPII branch
klown Mar 1, 2019
9c4195c
GPII-3333: Tweaks to complete the previous merge with master
klown Mar 1, 2019
087fe41
GPII-3333: Renamed one test file for consistency
klown Mar 4, 2019
6c4b787
GPII-3333: Addressing Cindy's review comments.
klown Mar 5, 2019
aad6e0e
GPII-3333: Merged changes from upstream master GPII branch
klown Mar 5, 2019
ed4bffa
GPII-3333: Removed generation of 'build/dbData/user' GPII keys and P…
klown Mar 6, 2019
249dcac
GPII-3333: Finely tuned merge with upstream GPII master branch
klown Mar 11, 2019
d72cbf6
GPII-3333: Used plural form re: deleting user settingS.
klown Mar 12, 2019
79a3f28
GPII-3333: Merged upstream GPII master branch
klown Mar 12, 2019
929b22a
GPII-3333: Refactored add/delete tests to use sequenceElements, etc.
klown Mar 12, 2019
74b17dc
GPII-3333: Merged upstream master GPII branch
klown Mar 15, 2019
61ee7b3
GPII-3333: Fixed copyright notices
klown Mar 15, 2019
bd912ab
GPII-3333: Addressed most of Cindy's review comments
klown Mar 15, 2019
d1756f2
GPII-3333: Fixed 'git mv' error
klown Mar 18, 2019
f0b3ed8
GPII-3333: Second attempt to fix the 'git mv' error
klown Mar 18, 2019
13ea89b
GPII-3333: Improved log messages
klown Mar 18, 2019
fdcf673
GPII-3333: Guarantee that the database cleanup code always runs.
klown Mar 19, 2019
5c83f10
GPII-3333: Improved GET of prefs safe associated with test user.
klown Mar 20, 2019
6fe7b0a
GPII-3333: Separate execution of adding/removing test 'user' prefs
klown Mar 22, 2019
18a062c
GPII-3333: Used a grade to supplant use of gpii.test.push()
klown Mar 25, 2019
b490985
GPII-3333: Used a grade to supplant use of gpii.test.push()
klown Mar 26, 2019
3264c1b
GPII-3333: Modified the documentation regarding running production t…
klown Mar 27, 2019
767e32e
GPII-3333: Tweaks to spelling and spacing
klown Mar 29, 2019
6c2b287
GPII-3333: Merged changes from upstream master GPII branch
klown Mar 29, 2019
6a1d3d0
GPII-3333: Remove access tokens created by the tests.
klown Apr 2, 2019
167ef58
GPII-3333: Merged changes from upstream master GPII branch
klown Apr 9, 2019
ae7226e
GPII-3333: Remove extra access tokens added by tests
klown Apr 15, 2019
074a835
GPII-3333: Deal with access tokens created by login tests.
klown Apr 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions tests/ProductionConfigTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ https://github.com/GPII/universal/blob/master/LICENSE.txt
"use strict";

var fluid = require("infusion"),
jqUnit = fluid.require("node-jqunit", require, "jqUnit"),
gpii = fluid.registerNamespace("gpii"),
kettle = fluid.registerNamespace("kettle");

fluid.registerNamespace("gpii.tests.productionConfigTesting");

fluid.require("%gpii-universal");

fluid.logObjectRenderChars = 1024000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line for debugging can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that. Removed.


/*
* ========================================================================
* Testing of untrusted local config with the live cloud based flow manager
Expand All @@ -41,11 +44,111 @@ require("./shared/DevelopmentTestDefs.js");

gpii.loadTestingSupport();

gpii.tests.productionConfigTesting.accessTokenRequestPayload = {
"username": gpii.tests.development.gpiiKey,
"password": "dummy",
"client_id": "pilot-computer",
"client_secret": "pilot-computer-secret",
"grant_type": "password"
};
gpii.tests.productionConfigTesting.device = {
OS: {
id: "linux"
},
solutions: [{
"id": "org.gnome.desktop.a11y.magnifier"
}]
};
gpii.tests.productionConfigTesting.prefsUpdate = {
"contexts": {
"gpii-default": {
"name": "Default preferences",
"preferences": {
"http://registry.gpii.net/common/setting1": 12
}
}
}
};

gpii.tests.productionConfigTesting.testDefs = fluid.transform(gpii.tests.development.testDefs, function (testDefIn) {
var testDef = fluid.extend(true, {}, testDefIn, {
name: "Flow Manager production tests",
expect: 16,
config: {
configName: "gpii.tests.productionConfigTests.config",
configPath: "%gpii-universal/tests/configs"
},
components: {
healthRequest: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are test definitions that work with development configs, which start both the local flow manager and the cloud locally, for all end points provided by the cloud. It would be beneficial for reducing the work load and future reusability if these test definitions can be reused for the production configs, where the cloud is served by docker containers.

For example, the existing tests for /settings GET is at tests/platform/cloud/SettingsGetTests.js, and for /settings PUT is at tests/platform/cloud/SettingsPutTests.js. The successful and failed cases for /access_tokens can also be found there.

Copy link
Member Author

@klown klown Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cindyli These are the changes thus far for using the test definitions in SettingsGetTests.js for both development and production configurations. It's still rough, but I'm pushing it to see if it works in CI.

type: "kettle.test.request.http",
options: {
port: "9082",
hostname: "flowmanager",
path: "/health",
method: "GET",
expectedStatusCode: 200,
expectedPayload: {"isHealthy": true}
}
},
readyRequest: {
type: "kettle.test.request.http",
options: {
port: "9082",
hostname: "flowmanager",
path: "/ready",
method: "GET",
expectedStatusCode: 200,
expectedPayload: {"isReady": true}
}
},
accessTokenRequest: {
type: "kettle.test.request.http",
options: {
port: "9082",
hostname: "flowmanager",
path: "/access_token",
method: "POST",
expectedStatusCode: 200
}
},
lifeCycleRequest: {
type: "kettle.test.request.http",
options: {
port: "9082",
hostname: "flowmanager",
path: fluid.stringTemplate("/%gpiiKey/settings/%device", {
gpiiKey: gpii.tests.development.gpiiKey,
device: encodeURIComponent(JSON.stringify(
gpii.tests.productionConfigTesting.device
))}
),
headers: {
"Authorization": "Bearer token" // set at test run
},
method: "GET",
expectedStatusCode: 200
}
},
putSettingsRequestFailure: { // can't update snapset (readonly)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good test to be shared by both development and production config tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a stab at moving this "update snapset" test to a common shared test definitions file, but it failed to run in the development configuration. I'm almost certain it's because there are no snapsets in the database in that configuration.

Are the keys and prefs safes for the development tests located here: .../universal/build/tests/dbData? (Never mind the special case of the key-without-a-prefsSafe -- I know where that one is). I tried adding a snapset key/safe there, just to see if that would solve the problem, but no joy.

I don't know how the database is set up in the case of the development configuration. So, either I've put the snapset in the wrong place, or it's not being picked up by any initialization stage, or something else.

How is the database set up in the development configuration?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pouchDB set up for running dev config loads these files.

You are right that there's no snapset key in this database. The prefs files in testData/preferences directory are converted to "user" keys and loaded. See line 50, 51 in PouchTestCaseHolder.js.

It might be worthwhile to sync up the usage of testData/preferences files for running tests in the dev and production configs. Do a experiment with changing line 50, 51 to load data from %gpii-universal/build/dbData/snapset and find out if we can change to failed tests to use GPII keys loaded from %gpii-universal/build/tests/dbData/gpiiKeys.json at line 48, 49, which are user keys solely for running dev tests. If we can make this change, the generation of %gpii-universal/build/dbData/user as a part of this line can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The pouch configuration you linked to shows that carla's key and prefs safe are both loaded, but they are 'user' preferences. (Which makes me wonder why my access token request for 'carla' found nothing -- well, my problem to fix.)

More importantly, looking over that list of key/prefs json files, I wonder if all the ones that are actually 'snapsets' in production are needed as 'user' for the development tests. I'll try your suggestion to see if that's necessary. If it isn't, the problem of sharing snapsets for testing between production and development becomes simpler. 🤞

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An update, @cindyli: I made the change to lines 50 and 51 to use 'snapset' instead of 'user' prefs safes and ran the node tests, the browser tests, and the productions tests. I think I've run all of the tests. There were no test failures. That confirms we can share snapsets between production and development test configurations. \o/

I also took a peek at how/if this will change in regards to @the-t-in-rtf's GPII-3619 pull request. It looks like that is already using the 'snapset' prefs safes, and not the 'user' prefs safes.

type: "kettle.test.request.http",
options: {
port: "9082",
hostname: "flowmanager",
path: "/%gpiiKey/settings",
termMap: {
"gpiiKey": gpii.tests.development.gpiiKey
},
headers: {
"Authorization": "Bearer token" // set at test run
},
method: "PUT",
expectedStatusCode: 404,
expectedPayload: {
"isError": true,
"message": "Cannot update: GPII key \"" + gpii.tests.development.gpiiKey + "\" is a snapset while executing HTTP PUT on url http://preferences:9081/preferences/%gpiiKey?merge=%merge"
}
}
}
}
});
gpii.test.unshift(testDef.sequence, [
Expand All @@ -54,6 +157,51 @@ gpii.tests.productionConfigTesting.testDefs = fluid.transform(gpii.tests.develop
listener: "fluid.identity"
}
]);
gpii.test.push(testDef.sequence, [
{
func: "{healthRequest}.send"
}, {
event: "{healthRequest}.events.onComplete",
listener: "gpii.tests.productionConfigTesting.testResponse"
}, {
func: "{readyRequest}.send"
}, {
event: "{readyRequest}.events.onComplete",
listener: "gpii.tests.productionConfigTesting.testResponse"
}, {
func: "{accessTokenRequest}.send",
args: [gpii.tests.productionConfigTesting.accessTokenRequestPayload]
}, {
event: "{accessTokenRequest}.events.onComplete",
listener: "gpii.tests.productionConfigTesting.testAccessResponse"
}, {
func: "{lifeCycleRequest}.send",
args: [
null,
{
"headers": {
"Authorization": "{accessTokenRequest}.options.stashedAuth"
}
}
]
}, {
event: "{lifeCycleRequest}.events.onComplete",
listener: "gpii.tests.productionConfigTesting.testLifecycleResponse"
}, {
func: "{putSettingsRequestFailure}.send",
args: [
gpii.tests.productionConfigTesting.prefsUpdate,
{
"headers": {
"Authorization": "{accessTokenRequest}.options.stashedAuth"
}
}
]
}, {
event: "{putSettingsRequestFailure}.events.onComplete",
listener: "gpii.tests.productionConfigTesting.testResponse"
}
]);
return testDef;
});

Expand Down Expand Up @@ -83,4 +231,45 @@ kettle.test.testDefToServerEnvironment = function (testDef) {
};
};

gpii.tests.productionConfigTesting.testStatusCode = function (data, request) {
jqUnit.assertEquals(
"Checking status of " + request.options.path,
request.options.expectedStatusCode, request.nativeResponse.statusCode
);
};

gpii.tests.productionConfigTesting.testResponse = function (data, request) {
gpii.tests.productionConfigTesting.testStatusCode(data, request);
jqUnit.assertDeepEq(
"Checking paylod of " + request.options.path,
request.options.expectedPayload, JSON.parse(data)
);
};

gpii.tests.productionConfigTesting.testAccessResponse = function (data, request) {
var token = JSON.parse(data);
var auth = "Bearer " + token.access_token;
request.options.stashedAuth = auth;

gpii.tests.productionConfigTesting.testStatusCode(data, request);
jqUnit.assertNotNull("Checking 'access_token'", token.access_token);
jqUnit.assertNotNull("Checking 'expiresIn'", token.expiresIn);
jqUnit.assertEquals("Checking 'token_type'", "Bearer", token.token_type);
};

gpii.tests.productionConfigTesting.testLifecycleResponse = function (data, request) {
gpii.tests.productionConfigTesting.testStatusCode(data, request);

var lifeCycle = JSON.parse(data);
jqUnit.assertEquals(
"Checking lifeCycle user '" + gpii.tests.development.gpiiKey + "'",
gpii.tests.development.gpiiKey,
lifeCycle.gpiiKey
);
// These checks based on
// https://github.com/GPII/universal/blob/master/documentation/FlowManager.md#get-lifecycle-instructions-from-cloud-based-flow-manager-get-gpiikeysettingsdevice
jqUnit.assertNotNull("Checking 'solutionsRegistryEntries'", lifeCycle.solutionsRegistryEntries);
jqUnit.assertNotNull("Checking 'matchMakerOutput'", lifeCycle.matchMakerOutput);
};

kettle.test.bootstrapServer(gpii.tests.productionConfigTesting.testDefs);
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"type": "gpii.tests.productionConfigTests.config",
"options": {
"mainServerPort": 9082,
"distributeOptions": {
"flowManager.escalate": {
"record": {
Expand Down