@@ -70,7 +70,7 @@ func TestVerifyRequestForMethod(t *testing.T) {
70
70
revision , _ , proceed , err := plugin .Extract (buildConfig , "secret100" , "" , req )
71
71
72
72
if err == nil || ! strings .Contains (err .Error (), "Unsupported HTTP method" ) {
73
- t .Errorf ("Excepcted unsupported HTTP method, got %v!" , err )
73
+ t .Errorf ("Expected unsupported HTTP method, got %v!" , err )
74
74
}
75
75
if proceed {
76
76
t .Error ("Expected 'proceed' return value to be 'false'" )
@@ -80,6 +80,157 @@ func TestVerifyRequestForMethod(t *testing.T) {
80
80
}
81
81
}
82
82
83
+ func TestWrongSecretMultipleGenericWebHooks (t * testing.T ) {
84
+ req := GivenRequest ("GET" )
85
+ buildConfig := & api.BuildConfig {
86
+ Spec : api.BuildConfigSpec {
87
+ Triggers : []api.BuildTriggerPolicy {
88
+ {
89
+ Type : api .GenericWebHookBuildTriggerType ,
90
+ GenericWebHook : & api.WebHookTrigger {
91
+ Secret : "secret101" ,
92
+ },
93
+ },
94
+ {
95
+ Type : api .GenericWebHookBuildTriggerType ,
96
+ GenericWebHook : & api.WebHookTrigger {
97
+ Secret : "secret100" ,
98
+ },
99
+ },
100
+ {
101
+ Type : api .GenericWebHookBuildTriggerType ,
102
+ GenericWebHook : & api.WebHookTrigger {
103
+ Secret : "secret102" ,
104
+ },
105
+ },
106
+ },
107
+ },
108
+ }
109
+
110
+ plugin := New ()
111
+ revision , _ , proceed , err := plugin .Extract (buildConfig , "wrongsecret" , "" , req )
112
+
113
+ if err != webhook .ErrSecretMismatch {
114
+ t .Errorf ("Expected %s, got %s" , webhook .ErrSecretMismatch , err )
115
+ }
116
+
117
+ if proceed {
118
+ t .Error ("Expected 'proceed' to return 'false'" )
119
+ }
120
+
121
+ if revision != nil {
122
+ t .Errorf ("Expected the 'revision' to be nil, go %v instead" , revision )
123
+ }
124
+ }
125
+
126
+ func TestMatchSecretMultipleGenericWebHooks (t * testing.T ) {
127
+ req := GivenRequestWithPayload (t , "push-generic.json" )
128
+ buildConfig := & api.BuildConfig {
129
+ Spec : api.BuildConfigSpec {
130
+ Triggers : []api.BuildTriggerPolicy {
131
+ {
132
+ Type : api .GenericWebHookBuildTriggerType ,
133
+ GenericWebHook : & api.WebHookTrigger {
134
+ Secret : "secret101" ,
135
+ },
136
+ },
137
+ {
138
+ Type : api .GenericWebHookBuildTriggerType ,
139
+ GenericWebHook : & api.WebHookTrigger {
140
+ Secret : "secret100" ,
141
+ },
142
+ },
143
+ {
144
+ Type : api .GenericWebHookBuildTriggerType ,
145
+ GenericWebHook : & api.WebHookTrigger {
146
+ Secret : "secret102" ,
147
+ },
148
+ },
149
+ },
150
+ BuildSpec : api.BuildSpec {
151
+ Source : api.BuildSource {
152
+ Git : & api.GitBuildSource {
153
+ Ref : "master" ,
154
+ },
155
+ },
156
+ Strategy : mockBuildStrategy ,
157
+ },
158
+ },
159
+ }
160
+
161
+ plugin := New ()
162
+ revision , _ , proceed , err := plugin .Extract (buildConfig , "secret102" , "" , req )
163
+
164
+ if err != nil {
165
+ t .Errorf ("Expected no error, got %s" , err )
166
+ }
167
+
168
+ if ! proceed {
169
+ t .Error ("Expected 'proceed' to return 'true', got 'false' instead" )
170
+ }
171
+
172
+ if revision == nil {
173
+ t .Errorf ("Expected the 'revision' to not be nil" )
174
+ }
175
+ }
176
+
177
+ func TestEnvVarsMultipleGenericWebHooks (t * testing.T ) {
178
+ req := GivenRequestWithPayload (t , "push-generic-envs.json" )
179
+ buildConfig := & api.BuildConfig {
180
+ Spec : api.BuildConfigSpec {
181
+ Triggers : []api.BuildTriggerPolicy {
182
+ {
183
+ Type : api .GenericWebHookBuildTriggerType ,
184
+ GenericWebHook : & api.WebHookTrigger {
185
+ Secret : "secret101" ,
186
+ AllowEnv : true ,
187
+ },
188
+ },
189
+ {
190
+ Type : api .GenericWebHookBuildTriggerType ,
191
+ GenericWebHook : & api.WebHookTrigger {
192
+ Secret : "secret100" ,
193
+ },
194
+ },
195
+ {
196
+ Type : api .GenericWebHookBuildTriggerType ,
197
+ GenericWebHook : & api.WebHookTrigger {
198
+ Secret : "secret102" ,
199
+ },
200
+ },
201
+ },
202
+ BuildSpec : api.BuildSpec {
203
+ Source : api.BuildSource {
204
+ Git : & api.GitBuildSource {
205
+ Ref : "master" ,
206
+ },
207
+ },
208
+ Strategy : mockBuildStrategy ,
209
+ },
210
+ },
211
+ }
212
+
213
+ plugin := New ()
214
+ revision , envvars , proceed , err := plugin .Extract (buildConfig , "secret101" , "" , req )
215
+
216
+ if err != nil {
217
+ t .Errorf ("Expected to be able to trigger a build without a payload error: %v" , err )
218
+ }
219
+
220
+ if ! proceed {
221
+ t .Error ("Expected 'proceed' to return 'true'" )
222
+ }
223
+
224
+ if revision == nil {
225
+ t .Errorf ("Expected the 'revision' to not be nil" )
226
+ }
227
+
228
+ if len (envvars ) == 0 {
229
+ t .Error ("Expected env vars to be set" )
230
+ }
231
+
232
+ }
233
+
83
234
func TestWrongSecret (t * testing.T ) {
84
235
req := GivenRequest ("POST" )
85
236
buildConfig := & api.BuildConfig {
@@ -98,7 +249,7 @@ func TestWrongSecret(t *testing.T) {
98
249
revision , _ , proceed , err := plugin .Extract (buildConfig , "wrongsecret" , "" , req )
99
250
100
251
if err != webhook .ErrSecretMismatch {
101
- t .Errorf ("Excepcted %v, got %v!" , webhook .ErrSecretMismatch , err )
252
+ t .Errorf ("Expected %v, got %v!" , webhook .ErrSecretMismatch , err )
102
253
}
103
254
if proceed {
104
255
t .Error ("Expected 'proceed' return value to be 'false'" )
@@ -152,7 +303,7 @@ func TestExtractWithEmptyPayload(t *testing.T) {
152
303
}
153
304
154
305
func TestExtractWithUnmatchedRefGitPayload (t * testing.T ) {
155
- req := GivenRequestWithPayload (t , "push-github .json" )
306
+ req := GivenRequestWithPayload (t , "push-generic .json" )
156
307
buildConfig := & api.BuildConfig {
157
308
Spec : api.BuildConfigSpec {
158
309
Triggers : []api.BuildTriggerPolicy {
@@ -188,7 +339,7 @@ func TestExtractWithUnmatchedRefGitPayload(t *testing.T) {
188
339
}
189
340
190
341
func TestExtractWithGitPayload (t * testing.T ) {
191
- req := GivenRequestWithPayload (t , "push-github .json" )
342
+ req := GivenRequestWithPayload (t , "push-generic .json" )
192
343
buildConfig := & api.BuildConfig {
193
344
Spec : api.BuildConfigSpec {
194
345
Triggers : []api.BuildTriggerPolicy {
@@ -224,7 +375,7 @@ func TestExtractWithGitPayload(t *testing.T) {
224
375
}
225
376
226
377
func TestExtractWithGitPayloadAndUTF8Charset (t * testing.T ) {
227
- req := GivenRequestWithPayloadAndContentType (t , "push-github .json" , "application/json; charset=utf-8" )
378
+ req := GivenRequestWithPayloadAndContentType (t , "push-generic .json" , "application/json; charset=utf-8" )
228
379
buildConfig := & api.BuildConfig {
229
380
Spec : api.BuildConfigSpec {
230
381
Triggers : []api.BuildTriggerPolicy {
@@ -332,7 +483,7 @@ func TestExtractWithUnmatchedGitRefsPayload(t *testing.T) {
332
483
}
333
484
334
485
func TestExtractWithKeyValuePairs (t * testing.T ) {
335
- req := GivenRequestWithPayload (t , "push-github -envs.json" )
486
+ req := GivenRequestWithPayload (t , "push-generic -envs.json" )
336
487
buildConfig := & api.BuildConfig {
337
488
Spec : api.BuildConfigSpec {
338
489
Triggers : []api.BuildTriggerPolicy {
@@ -373,7 +524,7 @@ func TestExtractWithKeyValuePairs(t *testing.T) {
373
524
}
374
525
375
526
func TestExtractWithKeyValuePairsDisabled (t * testing.T ) {
376
- req := GivenRequestWithPayload (t , "push-github -envs.json" )
527
+ req := GivenRequestWithPayload (t , "push-generic -envs.json" )
377
528
buildConfig := & api.BuildConfig {
378
529
Spec : api.BuildConfigSpec {
379
530
Triggers : []api.BuildTriggerPolicy {
0 commit comments