@@ -31,6 +31,45 @@ func TestDriverDefault_Hooks(t *testing.T) {
31
31
ctx := context .Background ()
32
32
33
33
t .Run ("type=verification" , func (t * testing.T ) {
34
+ // BEFORE hooks
35
+ for _ , tc := range []struct {
36
+ uc string
37
+ prep func (conf * config.Config )
38
+ expect func (reg * driver.RegistryDefault ) []verification.PreHookExecutor
39
+ }{
40
+ {
41
+ uc : "No hooks configured" ,
42
+ prep : func (conf * config.Config ) {},
43
+ expect : func (reg * driver.RegistryDefault ) []verification.PreHookExecutor { return nil },
44
+ },
45
+ {
46
+ uc : "Two web_hooks are configured" ,
47
+ prep : func (conf * config.Config ) {
48
+ conf .MustSet (ctx , config .ViperKeySelfServiceVerificationBeforeHooks , []map [string ]interface {}{
49
+ {"hook" : "web_hook" , "config" : map [string ]interface {}{"url" : "foo" , "method" : "POST" }},
50
+ {"hook" : "web_hook" , "config" : map [string ]interface {}{"url" : "bar" , "method" : "GET" }},
51
+ })
52
+ },
53
+ expect : func (reg * driver.RegistryDefault ) []verification.PreHookExecutor {
54
+ return []verification.PreHookExecutor {
55
+ hook .NewWebHook (reg , json .RawMessage (`{"method":"POST","url":"foo"}` )),
56
+ hook .NewWebHook (reg , json .RawMessage (`{"method":"GET","url":"bar"}` )),
57
+ }
58
+ },
59
+ },
60
+ } {
61
+ t .Run (fmt .Sprintf ("before/uc=%s" , tc .uc ), func (t * testing.T ) {
62
+ conf , reg := internal .NewFastRegistryWithMocks (t )
63
+ tc .prep (conf )
64
+
65
+ h := reg .PreVerificationHooks (ctx )
66
+
67
+ expectedExecutors := tc .expect (reg )
68
+ require .Len (t , h , len (expectedExecutors ))
69
+ assert .Equal (t , expectedExecutors , h )
70
+ })
71
+ }
72
+
34
73
// AFTER hooks
35
74
for _ , tc := range []struct {
36
75
uc string
@@ -72,6 +111,45 @@ func TestDriverDefault_Hooks(t *testing.T) {
72
111
})
73
112
74
113
t .Run ("type=recovery" , func (t * testing.T ) {
114
+ // BEFORE hooks
115
+ for _ , tc := range []struct {
116
+ uc string
117
+ prep func (conf * config.Config )
118
+ expect func (reg * driver.RegistryDefault ) []recovery.PreHookExecutor
119
+ }{
120
+ {
121
+ uc : "No hooks configured" ,
122
+ prep : func (conf * config.Config ) {},
123
+ expect : func (reg * driver.RegistryDefault ) []recovery.PreHookExecutor { return nil },
124
+ },
125
+ {
126
+ uc : "Two web_hooks are configured" ,
127
+ prep : func (conf * config.Config ) {
128
+ conf .MustSet (ctx , config .ViperKeySelfServiceRecoveryBeforeHooks , []map [string ]interface {}{
129
+ {"hook" : "web_hook" , "config" : map [string ]interface {}{"url" : "foo" , "method" : "POST" }},
130
+ {"hook" : "web_hook" , "config" : map [string ]interface {}{"url" : "bar" , "method" : "GET" }},
131
+ })
132
+ },
133
+ expect : func (reg * driver.RegistryDefault ) []recovery.PreHookExecutor {
134
+ return []recovery.PreHookExecutor {
135
+ hook .NewWebHook (reg , json .RawMessage (`{"method":"POST","url":"foo"}` )),
136
+ hook .NewWebHook (reg , json .RawMessage (`{"method":"GET","url":"bar"}` )),
137
+ }
138
+ },
139
+ },
140
+ } {
141
+ t .Run (fmt .Sprintf ("before/uc=%s" , tc .uc ), func (t * testing.T ) {
142
+ conf , reg := internal .NewFastRegistryWithMocks (t )
143
+ tc .prep (conf )
144
+
145
+ h := reg .PreRecoveryHooks (ctx )
146
+
147
+ expectedExecutors := tc .expect (reg )
148
+ require .Len (t , h , len (expectedExecutors ))
149
+ assert .Equal (t , expectedExecutors , h )
150
+ })
151
+ }
152
+
75
153
// AFTER hooks
76
154
for _ , tc := range []struct {
77
155
uc string
@@ -388,6 +466,45 @@ func TestDriverDefault_Hooks(t *testing.T) {
388
466
})
389
467
390
468
t .Run ("type=settings" , func (t * testing.T ) {
469
+ // BEFORE hooks
470
+ for _ , tc := range []struct {
471
+ uc string
472
+ prep func (conf * config.Config )
473
+ expect func (reg * driver.RegistryDefault ) []settings.PreHookExecutor
474
+ }{
475
+ {
476
+ uc : "No hooks configured" ,
477
+ prep : func (conf * config.Config ) {},
478
+ expect : func (reg * driver.RegistryDefault ) []settings.PreHookExecutor { return nil },
479
+ },
480
+ {
481
+ uc : "Two web_hooks are configured" ,
482
+ prep : func (conf * config.Config ) {
483
+ conf .MustSet (ctx , config .ViperKeySelfServiceSettingsBeforeHooks , []map [string ]interface {}{
484
+ {"hook" : "web_hook" , "config" : map [string ]interface {}{"url" : "foo" , "method" : "POST" }},
485
+ {"hook" : "web_hook" , "config" : map [string ]interface {}{"url" : "bar" , "method" : "GET" }},
486
+ })
487
+ },
488
+ expect : func (reg * driver.RegistryDefault ) []settings.PreHookExecutor {
489
+ return []settings.PreHookExecutor {
490
+ hook .NewWebHook (reg , json .RawMessage (`{"method":"POST","url":"foo"}` )),
491
+ hook .NewWebHook (reg , json .RawMessage (`{"method":"GET","url":"bar"}` )),
492
+ }
493
+ },
494
+ },
495
+ } {
496
+ t .Run (fmt .Sprintf ("before/uc=%s" , tc .uc ), func (t * testing.T ) {
497
+ conf , reg := internal .NewFastRegistryWithMocks (t )
498
+ tc .prep (conf )
499
+
500
+ h := reg .PreSettingsHooks (ctx )
501
+
502
+ expectedExecutors := tc .expect (reg )
503
+ require .Len (t , h , len (expectedExecutors ))
504
+ assert .Equal (t , expectedExecutors , h )
505
+ })
506
+ }
507
+
391
508
// AFTER hooks
392
509
for _ , tc := range []struct {
393
510
uc string
0 commit comments