-
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
Merged
mshustov
merged 32 commits into
elastic:master
from
mshustov:issue-50658-default-route-redirection
Mar 16, 2020
Merged
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b20ecc7
add schema to ui settings params
mshustov 7e46aef
add validation for defaults and overrides
mshustov 5b55b83
validate in ui settings client
mshustov 19dae10
ui settings routes validation
mshustov 012a715
clean up tests
mshustov cc96364
use schema for defaultRoutes
mshustov 269e34e
move URL redirection to NP
mshustov f2b2dea
fix spaces test
mshustov 39e7405
Merge branch 'master' into issue-50658-default-route-redirection
mshustov b736ada
update docs
mshustov b01a668
update kbn pm
mshustov 5518bd0
fix karma test
mshustov 7a5a354
fix tests
mshustov 850d78c
address comments
mshustov a7d0100
get rid of getDEfaultRoute
mshustov 8ec9103
Merge branch 'master' into issue-50658-default-route-redirection
mshustov b21efe2
Merge branch 'master' into issue-50658-default-route-redirection
mshustov cb40a2b
regen docs
mshustov 2f8f956
fix tests
mshustov f17a82f
fix enter-spaces test
mshustov 6b5f699
validate on relative url format
mshustov 9856d0b
update i18n
mshustov 6e389a6
Merge branch 'master' into issue-50658-default-route-redirection
mshustov 84e3e5a
fix enter-spoace test
mshustov c72b5cc
Merge branch 'master' into issue-50658-default-route-redirection
mshustov ed8a9a9
move relative url validation to utils
mshustov 1036d77
add CoreApp containing application logic
mshustov 075fe07
extract public uiSettings params in a separate type
mshustov 3b8ad0c
make schema required
mshustov 57c9aef
Merge branch 'master' into issue-50658-default-route-redirection
mshustov 2ad3292
Merge branch 'master' into issue-50658-default-route-redirection
mshustov 400a167
update docs
mshustov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
docs/development/core/public/kibana-plugin-public.uisettingsparams.schema.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [schema](./kibana-plugin-public.uisettingsparams.schema.md) | ||
|
||
## UiSettingsParams.schema property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
schema?: Type<T>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
docs/development/core/server/kibana-plugin-server.uisettingsparams.schema.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) > [schema](./kibana-plugin-server.uisettingsparams.schema.md) | ||
|
||
## UiSettingsParams.schema property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
schema?: Type<T>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/core/public/ui_settings/__snapshots__/ui_settings_api.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/core/server/http/integration_tests/default_route_provider_config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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 * as kbnTestServer from '../../../../test_utils/kbn_server'; | ||
import { Root } from '../../root'; | ||
|
||
const { startES } = kbnTestServer.createTestServers({ | ||
mshustov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
adjustTimeout: (t: number) => jest.setTimeout(t), | ||
}); | ||
let esServer: kbnTestServer.TestElasticsearchUtils; | ||
|
||
describe('default route provider', () => { | ||
let root: Root; | ||
|
||
beforeAll(async () => { | ||
esServer = await startES(); | ||
root = kbnTestServer.createRootWithCorePlugins({ | ||
server: { | ||
basePath: '/hello', | ||
}, | ||
}); | ||
|
||
await root.setup(); | ||
await root.start(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await esServer.stop(); | ||
await root.shutdown(); | ||
}); | ||
|
||
it('redirects to the configured default route respecting basePath', async function() { | ||
const { status, header } = await kbnTestServer.request.get(root, '/'); | ||
|
||
expect(status).toEqual(302); | ||
expect(header).toMatchObject({ | ||
location: '/hello/app/kibana', | ||
}); | ||
}); | ||
|
||
it('ignores invalid values', async function() { | ||
const invalidRoutes = ['http://not-your-kibana.com', 'example.com', ' //example.com']; | ||
|
||
for (const url of invalidRoutes) { | ||
await kbnTestServer.request | ||
.post(root, '/api/kibana/settings/defaultRoute') | ||
.send({ value: url }) | ||
.expect(400); | ||
} | ||
|
||
const { status, header } = await kbnTestServer.request.get(root, '/'); | ||
expect(status).toEqual(302); | ||
expect(header).toMatchObject({ | ||
location: '/hello/app/kibana', | ||
}); | ||
}); | ||
|
||
it('consumes valid values', async function() { | ||
await kbnTestServer.request | ||
.post(root, '/api/kibana/settings/defaultRoute') | ||
.send({ value: '/valid' }) | ||
.expect(200); | ||
|
||
const { status, header } = await kbnTestServer.request.get(root, '/'); | ||
expect(status).toEqual(302); | ||
expect(header).toMatchObject({ | ||
location: '/hello/valid', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 😢