Alerting: Prohibit receivers with empty name (#113064)

This commit is contained in:
Yuri Tseretyan
2025-10-29 16:30:38 -04:00
committed by GitHub
parent f2404361bf
commit a4df6c8bb9
4 changed files with 121 additions and 64 deletions
@@ -476,6 +476,12 @@ func TestReceiverService_Create(t *testing.T) {
},
},
},
{
name: "receiver with empty name fails",
user: writer,
receiver: models.CopyReceiverWith(baseReceiver, models.ReceiverMuts.WithName("")),
expectedErr: legacy_storage.ErrReceiverInvalid,
},
} {
t.Run(tc.name, func(t *testing.T) {
sut := createReceiverServiceSut(t, &secretsService)
@@ -901,6 +907,16 @@ func TestReceiverService_UpdateReceiverName(t *testing.T) {
assert.NotNil(t, ruleStore.Calls[0].Args[4])
assert.Falsef(t, ruleStore.Calls[0].Args[5].(bool), "dryrun expected to be false")
})
t.Run("returns ErrReceiverInvalid if empty name", func(t *testing.T) {
ruleStore := &fakeAlertRuleNotificationStore{}
sut := createReceiverServiceSut(t, &secretsService)
sut.ruleNotificationsStore = ruleStore
baseReceiver.Name = ""
_, err := sut.UpdateReceiver(context.Background(), &baseReceiver, nil, writer.GetOrgID(), writer)
require.ErrorIs(t, err, legacy_storage.ErrReceiverInvalid)
})
}
func TestReceiverServiceAC_Read(t *testing.T) {