(t *testing.T)
| 31 | ) |
| 32 | |
| 33 | func (s) TestBuildLoggerErrors(t *testing.T) { |
| 34 | tests := []struct { |
| 35 | name string |
| 36 | loggerConfig *v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig |
| 37 | expectedLogger audit.Logger |
| 38 | expectedError string |
| 39 | }{ |
| 40 | { |
| 41 | name: "nil typed config", |
| 42 | loggerConfig: &v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig{ |
| 43 | AuditLogger: &v3corepb.TypedExtensionConfig{ |
| 44 | TypedConfig: nil, |
| 45 | }, |
| 46 | }, |
| 47 | expectedError: "missing required field: TypedConfig", |
| 48 | }, |
| 49 | { |
| 50 | name: "Unsupported Type", |
| 51 | loggerConfig: &v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig{ |
| 52 | AuditLogger: &v3corepb.TypedExtensionConfig{ |
| 53 | Name: "TestAuditLoggerBuffer", |
| 54 | TypedConfig: testutils.MarshalAny(t, &v3rbacpb.RBAC_AuditLoggingOptions{}), |
| 55 | }, |
| 56 | }, |
| 57 | expectedError: "custom config not implemented for type ", |
| 58 | }, |
| 59 | { |
| 60 | name: "Empty name", |
| 61 | loggerConfig: &v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig{ |
| 62 | AuditLogger: &v3corepb.TypedExtensionConfig{ |
| 63 | Name: "TestAuditLoggerBuffer", |
| 64 | TypedConfig: createUDPATypedStruct(t, map[string]any{}, ""), |
| 65 | }, |
| 66 | }, |
| 67 | expectedError: "field TypedConfig.TypeURL cannot be an empty string", |
| 68 | }, |
| 69 | { |
| 70 | name: "No registered logger", |
| 71 | loggerConfig: &v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig{ |
| 72 | AuditLogger: &v3corepb.TypedExtensionConfig{ |
| 73 | Name: "UnregisteredLogger", |
| 74 | TypedConfig: createUDPATypedStruct(t, map[string]any{}, "UnregisteredLogger"), |
| 75 | }, |
| 76 | IsOptional: false, |
| 77 | }, |
| 78 | expectedError: "no builder registered for UnregisteredLogger", |
| 79 | }, |
| 80 | { |
| 81 | name: "fail to parse custom config", |
| 82 | loggerConfig: &v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig{ |
| 83 | AuditLogger: &v3corepb.TypedExtensionConfig{ |
| 84 | Name: "TestAuditLoggerCustomConfig", |
| 85 | TypedConfig: createUDPATypedStruct(t, map[string]any{"abc": "BADVALUE", "xyz": "123"}, "fail to parse custom config_TestAuditLoggerCustomConfig")}, |
| 86 | IsOptional: false, |
| 87 | }, |
| 88 | expectedError: "custom config could not be parsed", |
| 89 | }, |
| 90 | { |
nothing calls this directly
no test coverage detected