@@ -21,10 +21,14 @@ def valid_webhook_with
21
21
describe "errors" do
22
22
before do
23
23
PactBroker . configuration . webhook_http_method_whitelist = webhook_http_method_whitelist
24
+ PactBroker . configuration . webhook_host_whitelist = webhook_host_whitelist
25
+ allow ( PactBroker ::Webhooks ::CheckHostWhitelist ) . to receive ( :call ) . and_return ( whitelist_matches )
24
26
subject . validate ( hash )
25
27
end
26
28
27
29
let ( :webhook_http_method_whitelist ) { [ 'POST' ] }
30
+ let ( :whitelist_matches ) { [ 'foo' ] }
31
+ let ( :webhook_host_whitelist ) { [ ] }
28
32
29
33
context "with valid fields" do
30
34
it "is empty" do
@@ -92,7 +96,7 @@ def valid_webhook_with
92
96
end
93
97
94
98
it "contains an error for the URL" do
95
- expect ( subject . errors [ :"request.url" ] ) . to include "must be https. See /doc/webhooks#whitelist for more information."
99
+ expect ( subject . errors [ :"request.url" ] ) . to include "scheme must be https. See /doc/webhooks#whitelist for more information."
96
100
end
97
101
end
98
102
@@ -118,6 +122,28 @@ def valid_webhook_with
118
122
end
119
123
end
120
124
125
+ context "when the host whitelist is empty" do
126
+ it "does not attempt to validate the host" do
127
+ expect ( PactBroker ::Webhooks ::CheckHostWhitelist ) . to_not have_received ( :call )
128
+ end
129
+ end
130
+
131
+ context "when the host whitelist is populated" do
132
+ let ( :webhook_host_whitelist ) { [ /foo/ , "bar" ] }
133
+
134
+ it "validates the host" do
135
+ expect ( PactBroker ::Webhooks ::CheckHostWhitelist ) . to have_received ( :call ) . with ( "some.url" , webhook_host_whitelist )
136
+ end
137
+
138
+ context "when the host does not match the whitelist" do
139
+ let ( :whitelist_matches ) { [ ] }
140
+
141
+ it "contains an error" , pending : "need to work out how to do dynamic messages" do
142
+ expect ( subject . errors [ :"request.url" ] ) . to include "host must be in the whitelist /foo/, \" bar\" . See /doc/webhooks#whitelist for more information."
143
+ end
144
+ end
145
+ end
146
+
121
147
context "with no URL" do
122
148
let ( :json ) do
123
149
valid_webhook_with do |hash |
0 commit comments