Skip to content

Commit d5f5436

Browse files
author
Chris Stockton
committed
feat: add Before & After user created hooks to internal/conf
Also included tests for a previous commit to restore test coverage to 100%.
1 parent d758acc commit d5f5436

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

internal/conf/configuration.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ type HookConfiguration struct {
640640
CustomAccessToken ExtensibilityPointConfiguration `json:"custom_access_token" split_words:"true"`
641641
SendEmail ExtensibilityPointConfiguration `json:"send_email" split_words:"true"`
642642
SendSMS ExtensibilityPointConfiguration `json:"send_sms" split_words:"true"`
643+
644+
BeforeUserCreated ExtensibilityPointConfiguration `json:"before_user_created" split_words:"true"`
645+
AfterUserCreated ExtensibilityPointConfiguration `json:"after_user_created" split_words:"true"`
643646
}
644647

645648
type HTTPHookSecrets []string
@@ -671,6 +674,8 @@ func (h *HookConfiguration) Validate() error {
671674
h.CustomAccessToken,
672675
h.SendSMS,
673676
h.SendEmail,
677+
h.BeforeUserCreated,
678+
h.AfterUserCreated,
674679
}
675680
for _, point := range points {
676681
if err := point.ValidateExtensibilityPoint(); err != nil {
@@ -888,6 +893,18 @@ func populateGlobal(config *GlobalConfiguration) error {
888893
}
889894
}
890895

896+
if config.Hook.BeforeUserCreated.Enabled {
897+
if err := config.Hook.BeforeUserCreated.PopulateExtensibilityPoint(); err != nil {
898+
return err
899+
}
900+
}
901+
902+
if config.Hook.AfterUserCreated.Enabled {
903+
if err := config.Hook.AfterUserCreated.PopulateExtensibilityPoint(); err != nil {
904+
return err
905+
}
906+
}
907+
891908
if config.SAML.Enabled {
892909
if err := config.SAML.PopulateFields(config.API.ExternalURL); err != nil {
893910
return err

internal/conf/configuration_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,36 @@ func TestGlobal(t *testing.T) {
176176
os.Setenv("API_EXTERNAL_URL", "http://localhost:9999")
177177
}
178178

179+
{
180+
os.Setenv("API_EXTERNAL_URL", "")
181+
cfg := new(GlobalConfiguration)
182+
cfg.Hook = HookConfiguration{
183+
BeforeUserCreated: ExtensibilityPointConfiguration{
184+
Enabled: true,
185+
URI: "\n",
186+
},
187+
}
188+
189+
err := populateGlobal(cfg)
190+
require.Error(t, err)
191+
os.Setenv("API_EXTERNAL_URL", "http://localhost:9999")
192+
}
193+
194+
{
195+
os.Setenv("API_EXTERNAL_URL", "")
196+
cfg := new(GlobalConfiguration)
197+
cfg.Hook = HookConfiguration{
198+
AfterUserCreated: ExtensibilityPointConfiguration{
199+
Enabled: true,
200+
URI: "\n",
201+
},
202+
}
203+
204+
err := populateGlobal(cfg)
205+
require.Error(t, err)
206+
os.Setenv("API_EXTERNAL_URL", "http://localhost:9999")
207+
}
208+
179209
{
180210
os.Setenv("API_EXTERNAL_URL", "")
181211
cfg := new(GlobalConfiguration)
@@ -490,6 +520,11 @@ func TestValidate(t *testing.T) {
490520
err: `conf: session timebox duration must` +
491521
` be positive when set, was -1`,
492522
},
523+
{
524+
val: &SessionsConfiguration{InactivityTimeout: toPtr(time.Duration(-1))},
525+
err: `conf: session inactivity timeout duration must` +
526+
` be positive when set, was -1ns`,
527+
},
493528
{
494529
val: &SessionsConfiguration{AllowLowAAL: nil},
495530
},
@@ -532,6 +567,17 @@ func TestValidate(t *testing.T) {
532567
err: `conf: mailer validation headers not a map[string][]string format:` +
533568
` invalid character 'i' looking for beginning of value`,
534569
},
570+
{
571+
val: &MailerConfiguration{EmailValidationBlockedMX: "invalid"},
572+
err: `conf: email_validation_blocked_mx`,
573+
},
574+
{
575+
val: &MailerConfiguration{EmailValidationBlockedMX: `["foo.com"]`},
576+
check: func(t *testing.T, v any) {
577+
got := (v.(*MailerConfiguration)).GetEmailValidationBlockedMXRecords()
578+
require.True(t, got["foo.com"])
579+
},
580+
},
535581

536582
{
537583
val: &CaptchaConfiguration{Enabled: false},

0 commit comments

Comments
 (0)