Webhooks: `HasEvent` logic not working properly
lfleischmann opened this issue · comments
Checklist
- I could not find a solution in the existing issues or docs.
- I agree to follow this project's Code of Conduct.
Describe the bug
If, for example, I plan on receiving webhooks for the user.create
and the user.update
events and I use a configuration like
webhooks:
enabled: false
hooks:
- callback: http://localhost:8002/hooks
events:
- user.create
- user.update
then I won't receive any webhooks when users get updated because the BaseWebhook.HasEvent
method returns immediately:
func (bh *BaseWebhook) HasEvent(evt events.Event) bool {
for _, event := range bh.Events {
return strings.HasPrefix(string(evt), string(event))
}
return false
}
So, user.create
does not begin with prefix user.update
and the hook is then skipped. If I change the order of events in the config it works but the HasEvent
method should probably do something like:
func (bh *BaseWebhook) HasEvent(evt events.Event) bool {
for _, event := range bh.Events {
if strings.HasPrefix(string(evt), string(event)) {
return true
}
}
return false
}
Reproducing the bug
Modify an existing test/add another test in backend/webhooks/webhook_test.go
and watch it fail:
func TestBaseWebhook_HasEvent(t *testing.T) {
baseHook := BaseWebhook{
Logger: nil,
Callback: "http://ipsum.lorem",
Events: events.Events{events.UserCreate, events.UserUpdate},
}
require.True(t, baseHook.HasEvent(events.UserUpdate))
}
Logs
No response
Configuration
No response
Hanko Version
v0.10.0
OS Hanko Backend
None
OS Version Hanko Backend
No response
OS
None
OS Version
No response
Browser Version
No response
Environment
None
Additional Context
No response