Fix flaky test for legacy authorization (#87642)
* Unskip test * Increase attempts to 2 for retryIfConflicts * Cleanup authorization for updateApiKey
This commit is contained in:
parent
686ece9aea
commit
a0b787c39a
|
@ -817,10 +817,7 @@ export class AlertsClient {
|
||||||
attributes.consumer,
|
attributes.consumer,
|
||||||
WriteOperations.UpdateApiKey
|
WriteOperations.UpdateApiKey
|
||||||
);
|
);
|
||||||
if (
|
if (attributes.actions.length) {
|
||||||
attributes.actions.length &&
|
|
||||||
!this.authorization.shouldUseLegacyAuthorization(attributes)
|
|
||||||
) {
|
|
||||||
await this.actionsAuthorization.ensureAuthorized('execute');
|
await this.actionsAuthorization.ensureAuthorized('execute');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -14,7 +14,6 @@ const createAlertsAuthorizationMock = () => {
|
||||||
ensureAuthorized: jest.fn(),
|
ensureAuthorized: jest.fn(),
|
||||||
filterByAlertTypeAuthorization: jest.fn(),
|
filterByAlertTypeAuthorization: jest.fn(),
|
||||||
getFindAuthorizationFilter: jest.fn(),
|
getFindAuthorizationFilter: jest.fn(),
|
||||||
shouldUseLegacyAuthorization: jest.fn(),
|
|
||||||
};
|
};
|
||||||
return mocked;
|
return mocked;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,13 +8,12 @@ import Boom from '@hapi/boom';
|
||||||
import { map, mapValues, fromPairs, has } from 'lodash';
|
import { map, mapValues, fromPairs, has } from 'lodash';
|
||||||
import { KibanaRequest } from 'src/core/server';
|
import { KibanaRequest } from 'src/core/server';
|
||||||
import { ALERTS_FEATURE_ID } from '../../common';
|
import { ALERTS_FEATURE_ID } from '../../common';
|
||||||
import { AlertTypeRegistry, RawAlert } from '../types';
|
import { AlertTypeRegistry } from '../types';
|
||||||
import { SecurityPluginSetup } from '../../../security/server';
|
import { SecurityPluginSetup } from '../../../security/server';
|
||||||
import { RegistryAlertType } from '../alert_type_registry';
|
import { RegistryAlertType } from '../alert_type_registry';
|
||||||
import { PluginStartContract as FeaturesPluginStart } from '../../../features/server';
|
import { PluginStartContract as FeaturesPluginStart } from '../../../features/server';
|
||||||
import { AlertsAuthorizationAuditLogger, ScopeType } from './audit_logger';
|
import { AlertsAuthorizationAuditLogger, ScopeType } from './audit_logger';
|
||||||
import { Space } from '../../../spaces/server';
|
import { Space } from '../../../spaces/server';
|
||||||
import { LEGACY_LAST_MODIFIED_VERSION } from '../saved_objects/migrations';
|
|
||||||
import { asFiltersByAlertTypeAndConsumer } from './alerts_authorization_kuery';
|
import { asFiltersByAlertTypeAndConsumer } from './alerts_authorization_kuery';
|
||||||
import { KueryNode } from '../../../../../src/plugins/data/server';
|
import { KueryNode } from '../../../../../src/plugins/data/server';
|
||||||
|
|
||||||
|
@ -112,10 +111,6 @@ export class AlertsAuthorization {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public shouldUseLegacyAuthorization(alert: RawAlert): boolean {
|
|
||||||
return alert.meta?.versionApiKeyLastmodified === LEGACY_LAST_MODIFIED_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
private shouldCheckAuthorization(): boolean {
|
private shouldCheckAuthorization(): boolean {
|
||||||
return this.authorization?.mode?.useRbacForRequest(this.request) ?? false;
|
return this.authorization?.mode?.useRbacForRequest(this.request) ?? false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,7 @@ import { Logger, SavedObjectsErrorHelpers } from '../../../../../src/core/server
|
||||||
type RetryableForConflicts<T> = () => Promise<T>;
|
type RetryableForConflicts<T> = () => Promise<T>;
|
||||||
|
|
||||||
// number of times to retry when conflicts occur
|
// number of times to retry when conflicts occur
|
||||||
// note: it seems unlikely that we'd need more than one retry, but leaving
|
export const RetryForConflictsAttempts = 2;
|
||||||
// this statically configurable in case we DO need > 1
|
|
||||||
export const RetryForConflictsAttempts = 1;
|
|
||||||
|
|
||||||
// milliseconds to wait before retrying when conflicts occur
|
// milliseconds to wait before retrying when conflicts occur
|
||||||
// note: we considered making this random, to help avoid a stampede, but
|
// note: we considered making this random, to help avoid a stampede, but
|
||||||
|
|
|
@ -62,7 +62,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('should schedule actions on legacy alerts', async () => {
|
it('should schedule actions on legacy alerts', async () => {
|
||||||
const reference = `alert:migrated-to-7.10:${user.username}`;
|
const reference = `alert:migrated-to-7.10:${user.username}`;
|
||||||
const migratedAlertId = MIGRATED_ALERT_ID[user.username];
|
const migratedAlertId = MIGRATED_ALERT_ID[user.username];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue