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

Update schemas boolean, byteSize, and duration to coerce strings #54177

Merged

Conversation

jportner
Copy link
Contributor

@jportner jportner commented Jan 7, 2020

Summary

This PR updates the boolean, byteSize, and duration schemas in the Kibana Platform to coerce string values.

  • boolean: now accepts 'true' and 'false' (case-insensitive).
  • byteSize: now accepts number strings; assumes any string that doesn't have a unit ('b', 'kb', 'mb', etc.) must be bytes.
  • duration: now accepts number strings; assumes any string that doesn't have a time format ('ms', 'h', 'd', etc.) must be milliseconds.

Fixes: #54172

@jportner jportner added chore Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.6.0 labels Jan 7, 2020
@jportner jportner requested a review from a team as a code owner January 7, 2020 18:43
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@jportner jportner changed the title Update Duration to coerce number strings to numbers (in millis) Update schemas Boolean, ByteSizeValue, and Duration to coerce strings Jan 7, 2020
@jportner jportner changed the title Update schemas Boolean, ByteSizeValue, and Duration to coerce strings Update schemas boolean, byteSize, and duration to coerce strings Jan 7, 2020
@jportner
Copy link
Contributor Author

jportner commented Jan 7, 2020

Renamed this PR to reflect the expanded scope.

Regarding boolean:

The Joi.boolean() API allows 'true' and 'false' by default (case-insensitive).
There is nowhere in Kibana that uses boolean.falsy, boolean.sensitive, boolean.truthy, or the validation convert option -- so it doesn't make sense to add support for any of that. This PR simply changes the Kibana Platform boolean schema to act like the default Joi.boolean() does.

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 for platform changes

Some nits and comments:

packages/kbn-config-schema/src/byte_size_value/index.ts Outdated Show resolved Hide resolved
packages/kbn-config-schema/src/duration/index.ts Outdated Show resolved Hide resolved
Comment on lines 56 to +62
expect(() => schema.boolean().validate([1, 2, 3])).toThrowErrorMatchingSnapshot();

expect(() => schema.boolean().validate('abc')).toThrowErrorMatchingSnapshot();

expect(() => schema.boolean().validate(0)).toThrowErrorMatchingSnapshot();

expect(() => schema.boolean().validate('no')).toThrowErrorMatchingSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: error messages are short, should replace with inline snapshots in the whole types tests to increase tests readability. (out of the scope of the PR)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, when we wrote this library we didn't use inline snapshots in Kibana yet (or it wasn't supported by that version of Jest, can't recall already).

@azasypkin
Copy link
Member

ACK: Reviewing...

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Just a couple of test related nits and note about updating Readme file.

Comment on lines 56 to +62
expect(() => schema.boolean().validate([1, 2, 3])).toThrowErrorMatchingSnapshot();

expect(() => schema.boolean().validate('abc')).toThrowErrorMatchingSnapshot();

expect(() => schema.boolean().validate(0)).toThrowErrorMatchingSnapshot();

expect(() => schema.boolean().validate('no')).toThrowErrorMatchingSnapshot();
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, when we wrote this library we didn't use inline snapshots in Kibana yet (or it wasn't supported by that version of Jest, can't recall already).

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@jportner jportner merged commit bbe700d into elastic:master Jan 8, 2020
jportner added a commit to jportner/kibana that referenced this pull request Jan 8, 2020
…stic#54177)

* Update Duration to coerce number strings to numbers (in millis)

* Coerce in a way that's consistent with kbn-config-schema

* Update ByteSizeValue to coerce strings to numbers

* Update Boolean to coerce strings to boolean values

* Fix Jest test

* Address PR review feedback

* Whoops

* Whoops 2

* Whoops 3
jportner added a commit that referenced this pull request Jan 8, 2020
) (#54299)

* Update Duration to coerce number strings to numbers (in millis)

* Coerce in a way that's consistent with kbn-config-schema

* Update ByteSizeValue to coerce strings to numbers

* Update Boolean to coerce strings to boolean values

* Fix Jest test

* Address PR review feedback

* Whoops

* Whoops 2

* Whoops 3
@jportner jportner deleted the issue-54172-duration-string-validation branch January 8, 2020 21:08
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 9, 2020
* master: (23 commits)
  [Vis: Default editor] Reactify the timelion editor (elastic#52990)
  [Discover] fix histogram min interval (elastic#53979)
  [Telemetry] [Monitoring] Only retry fetching usage once monito… (elastic#54309)
  [docs][APM] Add runtime index config documentation (elastic#53907)
  [SIEM] Detection engine timeline (elastic#53783)
  Filter scripted fields preview field list to source fields (elastic#53826)
  Management - New platform api (elastic#52579)
  Reset region and Account when switching inventory (elastic#54287)
  [SIEM] [Case] Case workflow api schema (elastic#51535)
  Code coverage setup on CI (elastic#49003)
  [ML] DF Analytics Results: adds link to docs (elastic#54189)
  Update schemas boolean, byteSize, and duration to coerce strings (elastic#54177)
  [Metrics UI] Pass relevant shouldAllowEdit capabilities into SettingsPage (elastic#49781)
  [Canvas] Fixes bugs with autoplay and refresh (elastic#53149)
  [ML] DF Analytics Classification: ensure confusion matrix can be fetched (elastic#53629)
  Fix Vega react eslint errors (elastic#54259)
  Remove non existing codeowners (elastic#54274)
  use correct type (elastic#54244)
  [Dashboard] Removing 100% as dshDashboardViewport height (elastic#54263)
  add `examples/` to no-restricted-path config (elastic#54252)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported chore release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kibana crashing when xpack.security.sessionTimeout is set to a string
5 participants