mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
don't throw if authorization mode is already initialized (#23791)
This commit is contained in:
parent
b6b6ebb5c4
commit
125e4fa6ad
5 changed files with 20 additions and 9 deletions
|
@ -1,3 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`#initialize can't be initialized twice for the same request 1`] = `"Authorization mode is already intitialized"`;
|
|
@ -18,9 +18,10 @@ export function authorizationModeFactory(
|
|||
actions,
|
||||
checkPrivilegesWithRequest,
|
||||
config,
|
||||
log,
|
||||
plugins,
|
||||
savedObjects,
|
||||
xpackInfoFeature
|
||||
xpackInfoFeature,
|
||||
) {
|
||||
const useRbacForRequestCache = new WeakMap();
|
||||
|
||||
|
@ -56,7 +57,8 @@ export function authorizationModeFactory(
|
|||
return {
|
||||
async initialize(request) {
|
||||
if (useRbacForRequestCache.has(request)) {
|
||||
throw new Error('Authorization mode is already intitialized');
|
||||
log(['security', 'debug'], `Authorization mode is already initialized`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isRbacEnabled()) {
|
||||
|
|
|
@ -18,6 +18,8 @@ const createMockConfig = (settings) => {
|
|||
return mockConfig;
|
||||
};
|
||||
|
||||
const createMockLogger = () => jest.fn();
|
||||
|
||||
const createMockXpackInfoFeature = (allowRbac) => {
|
||||
return {
|
||||
getLicenseCheckResults() {
|
||||
|
@ -31,36 +33,43 @@ const createMockXpackInfoFeature = (allowRbac) => {
|
|||
describe(`#initialize`, () => {
|
||||
test(`can't be initialized twice for the same request`, async () => {
|
||||
const mockConfig = createMockConfig();
|
||||
const mockLogger = createMockLogger();
|
||||
const mockXpackInfoFeature = createMockXpackInfoFeature();
|
||||
const mode = authorizationModeFactory({}, {}, mockConfig, {}, {}, mockXpackInfoFeature);
|
||||
const mode = authorizationModeFactory({}, {}, mockConfig, mockLogger, {}, {}, mockXpackInfoFeature);
|
||||
const request = {};
|
||||
|
||||
await mode.initialize(request);
|
||||
expect(mode.initialize(request)).rejects.toThrowErrorMatchingSnapshot();
|
||||
expect(mockLogger).not.toHaveBeenCalled();
|
||||
await mode.initialize(request);
|
||||
expect(mockLogger).toHaveBeenCalledWith(['security', 'debug'], `Authorization mode is already initialized`);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`#useRbacForRequest`, () => {
|
||||
test(`return false if not initialized for request`, async () => {
|
||||
const mockConfig = createMockConfig();
|
||||
const mockLogger = createMockLogger();
|
||||
const mockXpackInfoFeature = createMockXpackInfoFeature();
|
||||
const mode = authorizationModeFactory({}, {}, mockConfig, {}, {}, mockXpackInfoFeature);
|
||||
const mode = authorizationModeFactory({}, {}, mockConfig, mockLogger, {}, {}, mockXpackInfoFeature);
|
||||
const request = {};
|
||||
|
||||
const result = mode.useRbacForRequest(request);
|
||||
expect(result).toBe(false);
|
||||
expect(mockLogger).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test(`returns true if legacy fallback is disabled`, async () => {
|
||||
const mockConfig = createMockConfig({
|
||||
'xpack.security.authorization.legacyFallback.enabled': false,
|
||||
});
|
||||
const mockLogger = createMockLogger();
|
||||
const mockXpackInfoFeature = createMockXpackInfoFeature();
|
||||
const mode = authorizationModeFactory({}, {}, mockConfig, {}, {}, mockXpackInfoFeature);
|
||||
const mode = authorizationModeFactory({}, {}, mockConfig, mockLogger, {}, {}, mockXpackInfoFeature);
|
||||
const request = {};
|
||||
|
||||
await mode.initialize(request);
|
||||
const result = mode.useRbacForRequest(request);
|
||||
expect(result).toBe(true);
|
||||
expect(mockLogger).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,6 +20,7 @@ export function createAuthorizationService(server, xpackInfoFeature) {
|
|||
actions,
|
||||
checkPrivilegesWithRequest,
|
||||
config,
|
||||
(...args) => server.log(...args),
|
||||
server.plugins,
|
||||
server.savedObjects,
|
||||
xpackInfoFeature
|
||||
|
|
|
@ -46,6 +46,7 @@ test(`calls server.expose with exposed services`, () => {
|
|||
config: jest.fn().mockReturnValue(mockConfig),
|
||||
plugins: Symbol(),
|
||||
savedObjects: Symbol(),
|
||||
log: Symbol(),
|
||||
};
|
||||
const mockShieldClient = Symbol();
|
||||
getClient.mockReturnValue(mockShieldClient);
|
||||
|
@ -66,6 +67,7 @@ test(`calls server.expose with exposed services`, () => {
|
|||
mockActions,
|
||||
mockCheckPrivilegesWithRequest,
|
||||
mockConfig,
|
||||
expect.any(Function),
|
||||
mockServer.plugins,
|
||||
mockServer.savedObjects,
|
||||
mockXpackInfoFeature,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue