-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add UiSettings validation & Kibana default route redirection #59694
Changes from 7 commits
b20ecc7
7e46aef
5b55b83
19dae10
012a715
cc96364
269e34e
f2b2dea
39e7405
b736ada
b01a668
5518bd0
7a5a354
850d78c
a7d0100
8ec9103
b21efe2
cb40a2b
2f8f956
f17a82f
6b5f699
9856d0b
6e389a6
84e3e5a
c72b5cc
ed8a9a9
1036d77
075fe07
3b8ad0c
57c9aef
2ad3292
400a167
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import * as kbnTestServer from '../../../../test_utils/kbn_server'; | ||
|
||
describe('ui settings service', () => { | ||
describe('routes', () => { | ||
let root: ReturnType<typeof kbnTestServer.createRoot>; | ||
beforeAll(async () => { | ||
root = kbnTestServer.createRoot(); | ||
|
||
const { uiSettings } = await root.setup(); | ||
uiSettings.register({ | ||
custom: { | ||
value: '42', | ||
schema: schema.string(), | ||
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 was thinking about dynamic vs static declaration and it seems that dynamic is simpler. The only downside I can think of that we cannot get all the ui settings defaults without starting Kibana. That would be useful for such cases as uiSettings.overrides validation. 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. Same issue as for SO types registration, so this is consistent. |
||
}, | ||
}); | ||
|
||
await root.start(); | ||
}, 30000); | ||
afterAll(async () => await root.shutdown()); | ||
|
||
describe('set', () => { | ||
it('validates value', async () => { | ||
const response = await kbnTestServer.request | ||
.post(root, '/api/kibana/settings/custom') | ||
.send({ value: 100 }) | ||
.expect(400); | ||
|
||
expect(response.body.message).toBe( | ||
'[validation [custom]]: expected value of type [string] but got [number]' | ||
); | ||
}); | ||
}); | ||
describe('set many', () => { | ||
it('validates value', async () => { | ||
const response = await kbnTestServer.request | ||
.post(root, '/api/kibana/settings') | ||
.send({ changes: { custom: 100 } }) | ||
.expect(400); | ||
mshustov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expect(response.body.message).toBe( | ||
'[validation [custom]]: expected value of type [string] but got [number]' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
Probably related to the changes in
src/core/server/ui_settings/routes/set.ts
, but why the difference between 400 and 4xx?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.
Request failed with status code: ${err.response.status}
is not really useful. I'd rather remove them completely and provide a more descriptive message, but BWC...So I added this for BadRequest only to provide an actionable message.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.
We really need typing for our errors so that we can evolve these 😢