-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GS: use the request's basePath when processing server-side result urls (
- Loading branch information
1 parent
28c5f27
commit f9d9538
Showing
5 changed files
with
62 additions
and
6 deletions.
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
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
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/global_search/server/services/utils.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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { httpServiceMock, httpServerMock } from '../../../../../src/core/server/mocks'; | ||
import { getRequestBasePath } from './utils'; | ||
|
||
describe('getRequestBasePath', () => { | ||
let basePath: ReturnType<typeof httpServiceMock.createBasePath>; | ||
let request: ReturnType<typeof httpServerMock.createKibanaRequest>; | ||
|
||
beforeEach(() => { | ||
basePath = httpServiceMock.createBasePath(); | ||
request = httpServerMock.createKibanaRequest(); | ||
}); | ||
|
||
it('return a IBasePath prepending the request basePath', () => { | ||
basePath.get.mockReturnValue('/base-path/s/my-space'); | ||
const requestBasePath = getRequestBasePath(request, basePath); | ||
|
||
const fullPath = requestBasePath.prepend('/app/dashboard/some-id'); | ||
|
||
expect(fullPath).toBe('/base-path/s/my-space/app/dashboard/some-id'); | ||
|
||
expect(basePath.get).toHaveBeenCalledTimes(1); | ||
expect(basePath.get).toHaveBeenCalledWith(request); | ||
|
||
expect(basePath.prepend).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
httpServiceMock.createBasePath(); |
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,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import type { IBasePath, KibanaRequest } from 'src/core/server'; | ||
import type { IBasePath as BasePathAccessor } from '../../common/utils'; | ||
|
||
export const getRequestBasePath = ( | ||
request: KibanaRequest, | ||
basePath: IBasePath | ||
): BasePathAccessor => { | ||
const requestBasePath = basePath.get(request); | ||
return { | ||
prepend: (path) => { | ||
return `${requestBasePath}/${path}`.replace(/\/{2,}/g, '/'); | ||
}, | ||
}; | ||
}; |