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

Test config settings that are exposed to the browser #129438

Merged
merged 19 commits into from
Apr 9, 2022

Conversation

jportner
Copy link
Contributor

@jportner jportner commented Apr 5, 2022

Related: #123201

This PR adds integration tests that assert which config settings are exposed to the browser (both for authenticated and unauthenticated users).
It changes the Core rendering service to detect all config keys that could be exposed to the browser (via exposeToBrowser) and it returns those config keys in kbn-injected-metadata.

Note, these config keys are only injected for integration tests.

Test failures

Here are the three different types of failures you can encounter:

If you stop exposing a config setting to the browser, the test will fail.

Error: Actual config settings exposed to the browser do not match what is expected; this assertion fails if extra settings are present and/or expected settings are missing
+ expected - actual

 {
   "extra": []
-  "missing": [
-    "expected.setting.that.is.not.actually.exposed (string)"
-  ]
+  "missing": []
 }

If you expose a new config setting to the browser, the test will fail.

Error: Actual config settings exposed to the browser do not match what is expected; this
assertion fails if extra settings are present and/or expected settings are missing
+ expected - actual

 {
-  "extra": [
-    "actual.setting.that.is.unexpectedly.exposed (number)"
-  ]
+  "extra": []
   "missing": []
 }

If you do both, the test will fail.

Error: Actual config settings exposed to the browser do not match what is expected; this assertion fails if extra settings are present and/or expected settings are missing
+ expected - actual

 {
-  "extra": [
-    "actual.setting.that.is.unexpectedly.exposed (number)"
-  ]
-  "missing": [
-    "expected.setting.that.is.not.actually.exposed (string)"
-  ]
+  "extra": []
+  "missing": []
 }

@jportner jportner added release_note:skip Skip the PR/issue when compiling release notes v8.3.0 v7.17.3 labels Apr 5, 2022
WIP
Adds an integration test for all config keys that can be exposed
to the browser (even if those config settings aren't used).
@jportner jportner force-pushed the test-plugin-browser-config-exposure branch from ff0d30f to a4738c4 Compare April 5, 2022 05:47
Copy link
Contributor Author

@jportner jportner left a comment

Choose a reason for hiding this comment

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

Author's notes for reviewers.

Comment on lines +106 to +108
public getSchemaStructure() {
return recursiveGetSchemaStructure(this.internalSchema);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to expose the schema structure to the rendering service so it can traverse the schema config key paths.

Seems that the cleanest way to do this is to add a getSchemaStructure API to the root schema type like this.

Comment on lines +64 to +65
// @ts-expect-error Type 'undefined' is not assignable to type 'ExposedToBrowserDescriptor<T>'
descriptor = exposedConfig;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷‍♂️
@pgayvallet any ideas?

Comment on lines -56 to -57
// Talked to @dover, he aggreed we can skip these tests that are unexpectedly flaky
describe.skip('rendering service', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

😬
I had to unskip the suite itself, but I skipped the individual tests below because I am not sure if they are still flaky or not.

// notExposed4 is not present
},
exposedConfigKeys: {
exposed1: 'any', // 'any' is the Joi schema type for strings
Copy link
Contributor

@pgayvallet pgayvallet Apr 5, 2022

Choose a reason for hiding this comment

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

Do we really need to implement this logic trying to infer the type of each key from the schema?

If we only need the list of keys for the purpose of this PR, I'd rather just use and return that, the list of underlying keys, rather than having an half-working type detection.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The motivation behind this is:

In test/plugin_functional/test_suites/core_plugins/rendering.ts, we can clearly see what config keys are exposed and we can identify which ones are definitely harmless to expose (boolean, number, etc.):

const expectedExposedConfigKeys = [
  // NOTE: each exposed config key has its schema type at the end in "(parentheses)".
  // The schema type comes from Joi; in particular, "(any)" can mean a string or a few other data types.
  // When plugin owners make a change that exposes additional config values, the changes will be reflected in this test assertion.
  // Ensure that your change does not unintentionally expose any sensitive values!
  'console.ui.enabled (boolean)',
  'dashboard.allowByValueEmbeddables (boolean)',
  'data.autocomplete.querySuggestions.enabled (boolean)',
  'data.autocomplete.valueSuggestions.enabled (boolean)',
  'data.autocomplete.valueSuggestions.terminateAfter (duration)',

This isn't intended to be the "source of truth" for these config keys, just a bit of assistance for reviewers in the future that have to maintain that integration test.

Joe Portner added 5 commits April 7, 2022 10:06
Some Fleet config keys are no longer exposed.
The only time we need to include exposedConfigKeys in injected
metadata is for integration test assertions. This commit changes
the approach so that these are omitted in normal operation.
@jportner jportner marked this pull request as ready for review April 7, 2022 14:46
@jportner jportner requested a review from a team as a code owner April 7, 2022 14:46
@jportner jportner requested a review from pgayvallet April 7, 2022 14:46
@@ -327,6 +327,7 @@
/src/plugins/interactive_setup/ @elastic/kibana-security
/test/interactive_setup_api_integration/ @elastic/kibana-security
/test/interactive_setup_functional/ @elastic/kibana-security
/test/plugin_functional/test_suites/core_plugins/rendering.ts @elastic/kibana-security
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the integration test to my team in CODEOWNERS so we get pinged when this test is changed 👍

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

This LGTM. I also don't love the workaround of relying on Joi's internals to attempt to guess the schema type. However, since the security team will be doing CODEOWNERS reviews on these, I see how this should make your life much easier -- so I don't feel too strongly about it overall.

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM once the last failing tests have been fixed

@jportner jportner enabled auto-merge (squash) April 8, 2022 21:12
@jportner
Copy link
Contributor Author

jportner commented Apr 9, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/config-schema 123 127 +4

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 370.1KB 370.3KB +259.0B
Unknown metric groups

API count

id before after diff
@kbn/config-schema 125 129 +4

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jportner jportner merged commit 27ff7d3 into elastic:main Apr 9, 2022
jportner added a commit to jportner/kibana that referenced this pull request Apr 9, 2022
(cherry picked from commit 27ff7d3)

# Conflicts:
#	.github/CODEOWNERS
#	packages/kbn-config-schema/src/index.ts
@jportner jportner deleted the test-plugin-browser-config-exposure branch April 10, 2022 01:12
jportner added a commit that referenced this pull request Apr 11, 2022
…#129857)

* Test config settings that are exposed to the browser (#129438)

(cherry picked from commit 27ff7d3)

# Conflicts:
#	.github/CODEOWNERS
#	packages/kbn-config-schema/src/index.ts

* Enable security plugin in OSS tests

This is a partial backport of #111681, so the Kibana security
plugin is enabled but Elasticsearch security is still disabled.

* Fix exposed config key tests

The exposed config keys are slightly different in the 7.17 branch.

* Fix UI Capabilities tests

The enterpriseSearch plugin does not have a required dependency on
the security plugin in the 7.17 branch, so our bacported
assertions for these tests needed to change accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes v7.17.3 v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants