-
Notifications
You must be signed in to change notification settings - Fork 63
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
Changes from 15 commits
214c5fa
ea8d1b2
3b4d44a
c227777
3368e99
e8c9eb8
e1bb67f
d044422
b2e26e3
5cb24c3
5c060ef
a6af970
515210c
8e6b35e
81acd12
2928a28
0c6ccce
54cbb66
8d67a9c
c50fb98
e748824
ecafb34
05e0a47
559e5f0
99aa8d0
d0122e9
304b3f4
5d1692b
f3e30a3
5ae3962
1897098
6f8980c
e1bf42d
af22f2a
ebbf7eb
3f4ef42
375017c
ee14159
140423e
9c9682f
b7b53fd
8bc1aa9
f9a0308
62d6f1d
a6af103
f928ea2
08a80ec
7961149
f0423e8
87bf30d
4c400aa
9c4195c
087fe41
6c4b787
aad6e0e
ed4bffa
249dcac
d72cbf6
79a3f28
929b22a
74b17dc
61ee7b3
bd912ab
d1756f2
f0b3ed8
13ea89b
fdcf673
5c83f10
6fe7b0a
18a062c
b490985
3264c1b
767e32e
6c2b287
6a1d3d0
167ef58
ae7226e
074a835
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
/* | ||
* ======================================================================== | ||
* Testing of untrusted local config with the live cloud based flow manager | ||
|
@@ -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: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 🤞 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, [ | ||
|
@@ -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; | ||
}); | ||
|
||
|
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.