@@ -157,50 +157,53 @@ func TestIndexer_Start_ConsumeFlow(t *testing.T) {
157157 msg .AssertExpectations (t )
158158}
159159
160- func TestExtractTenantFromAuditEvent_WithUserExtra (t * testing.T ) {
160+ func TestExtractTenantFromAuditEvent_NilResponseObject (t * testing.T ) {
161+ // No ResponseObject — should fall back to platform/platform.
161162 event := & auditEvent {}
162- event .User = & struct {
163- Extra map [string ][]string `json:"extra,omitempty"`
164- }{
165- Extra : map [string ][]string {
166- "iam.miloapis.com/parent-type" : {"Project" },
167- "iam.miloapis.com/parent-name" : {"my-project" },
168- },
169- }
170163
171164 name , typ := extractTenantFromAuditEvent (event )
172165
173- if name != "my-project " {
174- t .Errorf ("tenantName: got %q, want %q" , name , "my-project " )
166+ if name != "platform " {
167+ t .Errorf ("tenantName: got %q, want %q" , name , "platform " )
175168 }
176- if typ != "Project " {
177- t .Errorf ("tenantType: got %q, want %q" , typ , "Project " )
169+ if typ != "platform " {
170+ t .Errorf ("tenantType: got %q, want %q" , typ , "platform " )
178171 }
179172}
180173
181- func TestExtractTenantFromAuditEvent_NoUserExtra (t * testing.T ) {
182- event := & auditEvent {}
183- // User.Extra is nil by default.
174+ func TestExtractTenantFromAuditEvent_WithAnnotations (t * testing.T ) {
175+ // Both scope annotations present — should be extracted and type normalized to title-case.
176+ event := & auditEvent {
177+ ResponseObject : map [string ]any {
178+ "metadata" : map [string ]any {
179+ "annotations" : map [string ]any {
180+ ScopeTypeAnnotationKey : "project" ,
181+ ScopeNameAnnotationKey : "my-project" ,
182+ },
183+ },
184+ },
185+ }
184186
185187 name , typ := extractTenantFromAuditEvent (event )
186188
187- if name != "platform " {
188- t .Errorf ("tenantName: got %q, want %q" , name , "platform " )
189+ if name != "my-project " {
190+ t .Errorf ("tenantName: got %q, want %q" , name , "my-project " )
189191 }
190- if typ != "platform " {
191- t .Errorf ("tenantType: got %q, want %q" , typ , "platform " )
192+ if typ != "Project " {
193+ t .Errorf ("tenantType: got %q, want %q" , typ , "Project " )
192194 }
193195}
194196
195- func TestExtractTenantFromAuditEvent_PartialUserExtra_TypeOnlyNoName (t * testing.T ) {
196- // Only parent-type is set; parent-name is absent.
197- // Expect: tenantType reflects the extra field, tenantName falls back to "platform".
198- event := & auditEvent {}
199- event .User = & struct {
200- Extra map [string ][]string `json:"extra,omitempty"`
201- }{
202- Extra : map [string ][]string {
203- "iam.miloapis.com/parent-type" : {"Project" },
197+ func TestExtractTenantFromAuditEvent_PartialAnnotations_TypeOnly (t * testing.T ) {
198+ // Only scope.type annotation is set; scope.name is absent.
199+ // Expect: tenantType is extracted, tenantName falls back to "platform".
200+ event := & auditEvent {
201+ ResponseObject : map [string ]any {
202+ "metadata" : map [string ]any {
203+ "annotations" : map [string ]any {
204+ ScopeTypeAnnotationKey : "Project" ,
205+ },
206+ },
204207 },
205208 }
206209
@@ -214,15 +217,13 @@ func TestExtractTenantFromAuditEvent_PartialUserExtra_TypeOnlyNoName(t *testing.
214217 }
215218}
216219
217- func TestExtractTenantFromAuditEvent_EmptySliceValues (t * testing.T ) {
218- // Keys present but with empty slices should not override the defaults.
219- event := & auditEvent {}
220- event .User = & struct {
221- Extra map [string ][]string `json:"extra,omitempty"`
222- }{
223- Extra : map [string ][]string {
224- "iam.miloapis.com/parent-type" : {},
225- "iam.miloapis.com/parent-name" : {},
220+ func TestExtractTenantFromAuditEvent_NoAnnotations (t * testing.T ) {
221+ // ResponseObject present but no scope annotations — should fall back to platform/platform.
222+ event := & auditEvent {
223+ ResponseObject : map [string ]any {
224+ "metadata" : map [string ]any {
225+ "name" : "some-resource" ,
226+ },
226227 },
227228 }
228229
0 commit comments