-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Search] Add routes for Role Mappings
- Loading branch information
1 parent
1124fa2
commit 6b41dd5
Showing
2 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
178 changes: 178 additions & 0 deletions
178
x-pack/plugins/enterprise_search/server/routes/app_search/role_mappings.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,178 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__'; | ||
|
||
import { | ||
registerRoleMappingsRoute, | ||
registerRoleMappingRoute, | ||
registerNewRoleMappingRoute, | ||
registerResetRoleMappingRoute, | ||
} from './role_mappings'; | ||
|
||
describe('role mappings routes', () => { | ||
describe('GET /api/app_search/role_mappings', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'get', | ||
path: '/api/app_search/role_mappings', | ||
}); | ||
|
||
registerRoleMappingsRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/role_mappings', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('POST /api/app_search/role_mappings', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'post', | ||
path: '/api/app_search/role_mappings', | ||
}); | ||
|
||
registerRoleMappingsRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/role_mappings', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GET /api/app_search/role_mappings/{id}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'get', | ||
path: '/api/app_search/role_mappings/{id}', | ||
}); | ||
|
||
registerRoleMappingRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/role_mappings/:id', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('PUT /api/app_search/role_mappings/{id}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'put', | ||
path: '/api/app_search/role_mappings/{id}', | ||
}); | ||
|
||
registerRoleMappingRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/role_mappings/:id', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('DELETE /api/app_search/role_mappings/{id}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'delete', | ||
path: '/api/app_search/role_mappings/{id}', | ||
}); | ||
|
||
registerRoleMappingRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/role_mappings/:id', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GET /api/app_search/role_mappings/new', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'get', | ||
path: '/api/app_search/role_mappings/new', | ||
}); | ||
|
||
registerNewRoleMappingRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/role_mappings/new', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GET /api/app_search/role_mappings/reset', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'post', | ||
path: '/api/app_search/role_mappings/reset', | ||
}); | ||
|
||
registerResetRoleMappingRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/role_mappings/reset', | ||
}); | ||
}); | ||
}); | ||
}); |
133 changes: 133 additions & 0 deletions
133
x-pack/plugins/enterprise_search/server/routes/app_search/role_mappings.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,133 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
import { RouteDependencies } from '../../plugin'; | ||
|
||
const roleMappingBaseSchema = { | ||
rules: schema.recordOf(schema.string(), schema.string()), | ||
roleType: schema.string(), | ||
engines: schema.arrayOf(schema.string()), | ||
accessAllEngines: schema.boolean(), | ||
authProvider: schema.arrayOf(schema.string()), | ||
}; | ||
|
||
export function registerRoleMappingsRoute({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.get( | ||
{ | ||
path: '/api/app_search/role_mappings', | ||
validate: false, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ | ||
path: '/role_mappings', | ||
}) | ||
); | ||
|
||
router.post( | ||
{ | ||
path: '/api/app_search/role_mappings', | ||
validate: { | ||
body: schema.object(roleMappingBaseSchema), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ | ||
path: '/role_mappings', | ||
}) | ||
); | ||
} | ||
|
||
export function registerRoleMappingRoute({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.get( | ||
{ | ||
path: '/api/app_search/role_mappings/{id}', | ||
validate: { | ||
params: schema.object({ | ||
id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ | ||
path: '/role_mappings/:id', | ||
}) | ||
); | ||
|
||
router.put( | ||
{ | ||
path: '/api/app_search/role_mappings/{id}', | ||
validate: { | ||
body: schema.object({ | ||
...roleMappingBaseSchema, | ||
id: schema.string(), | ||
}), | ||
params: schema.object({ | ||
id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ | ||
path: '/role_mappings/:id', | ||
}) | ||
); | ||
|
||
router.delete( | ||
{ | ||
path: '/api/app_search/role_mappings/{id}', | ||
validate: { | ||
params: schema.object({ | ||
id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ | ||
path: '/role_mappings/:id', | ||
}) | ||
); | ||
} | ||
|
||
export function registerNewRoleMappingRoute({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.get( | ||
{ | ||
path: '/api/app_search/role_mappings/new', | ||
validate: false, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ | ||
path: '/role_mappings/new', | ||
}) | ||
); | ||
} | ||
|
||
export function registerResetRoleMappingRoute({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.post( | ||
{ | ||
path: '/api/app_search/role_mappings/reset', | ||
validate: false, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ | ||
path: '/role_mappings/reset', | ||
}) | ||
); | ||
} | ||
|
||
export const registerRoleMappingsRoutes = (dependencies: RouteDependencies) => { | ||
registerRoleMappingsRoute(dependencies); | ||
registerRoleMappingRoute(dependencies); | ||
registerNewRoleMappingRoute(dependencies); | ||
registerResetRoleMappingRoute(dependencies); | ||
}; |