[Cases] Make the audit logger required (#146569)

This PR makes the audit logger required for the
`AuthorizationAuditLogger`. We can do this because the security plugin
is not optional anymore.
This commit is contained in:
Jonathan Buttner 2022-12-01 08:14:17 -05:00 committed by GitHub
parent 7e035f4189
commit 08805d0d69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 26 deletions

View file

@ -38,23 +38,6 @@ describe('audit_logger', () => {
logger = new AuthorizationAuditLogger(mockLogger);
});
it('does not throw an error when the underlying audit logger is undefined', () => {
const authLogger = new AuthorizationAuditLogger();
jest.spyOn(authLogger, 'log');
expect(() => {
authLogger.log({
operation: Operations.createCase,
entity: {
owner: 'a',
id: '1',
},
});
}).not.toThrow();
expect(authLogger.log).toHaveBeenCalledTimes(1);
});
it('logs a message with a saved object ID in the message field', () => {
logger.log({
operation: Operations.createCase,

View file

@ -21,9 +21,9 @@ interface CreateAuditMsgParams {
* Audit logger for authorization operations
*/
export class AuthorizationAuditLogger {
private readonly auditLogger?: AuditLogger;
private readonly auditLogger: AuditLogger;
constructor(logger?: AuditLogger) {
constructor(logger: AuditLogger) {
this.auditLogger = logger;
}
@ -97,6 +97,6 @@ export class AuthorizationAuditLogger {
* Logs an audit event based on the status of an operation.
*/
public log(auditMsgParams: CreateAuditMsgParams) {
this.auditLogger?.log(AuthorizationAuditLogger.createAuditMsg(auditMsgParams));
this.auditLogger.log(AuthorizationAuditLogger.createAuditMsg(auditMsgParams));
}
}

View file

@ -61,7 +61,7 @@ describe('authorization', () => {
securityAuth: securityStart.authz,
spaces: spacesStart,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(),
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});
@ -81,7 +81,7 @@ describe('authorization', () => {
securityAuth: securityStart.authz,
spaces: spacesStart,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(),
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});
@ -140,7 +140,7 @@ describe('authorization', () => {
request,
spaces: spacesStart,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(),
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});
@ -266,7 +266,7 @@ describe('authorization', () => {
securityAuth: securityStart.authz,
spaces: spacesStart,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(),
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});
@ -295,7 +295,7 @@ describe('authorization', () => {
securityAuth: securityStart.authz,
spaces: spacesStart,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(),
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});
@ -322,7 +322,7 @@ describe('authorization', () => {
securityAuth: securityStart.authz,
spaces: spacesStart,
features: featuresStart,
auditLogger: new AuthorizationAuditLogger(),
auditLogger: new AuthorizationAuditLogger(mockLogger),
logger: loggingSystemMock.createLogger(),
});