File tree 2 files changed +19
-4
lines changed
lib/pact_broker/api/contracts
spec/lib/pact_broker/api/contracts
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ def valid_method?(http_method)
70
70
end
71
71
72
72
def valid_url? ( url )
73
- uri = URI ( url )
73
+ uri = parse_uri ( url )
74
74
uri . scheme && uri . host
75
75
rescue URI ::InvalidURIError
76
76
false
@@ -83,15 +83,15 @@ def allowed_webhook_method?(http_method)
83
83
end
84
84
85
85
def allowed_webhook_scheme? ( url )
86
- scheme = URI ( url ) . scheme
86
+ scheme = parse_uri ( url ) . scheme
87
87
PactBroker . configuration . webhook_scheme_whitelist . any? do | allowed_scheme |
88
88
scheme . downcase == allowed_scheme . downcase
89
89
end
90
90
end
91
91
92
92
def allowed_webhook_host? ( url )
93
93
if host_whitelist . any?
94
- PactBroker ::Webhooks ::CheckHostWhitelist . call ( URI ( url ) . host , host_whitelist ) . any?
94
+ PactBroker ::Webhooks ::CheckHostWhitelist . call ( parse_uri ( url ) . host , host_whitelist ) . any?
95
95
else
96
96
true
97
97
end
@@ -100,6 +100,10 @@ def allowed_webhook_host?(url)
100
100
def host_whitelist
101
101
PactBroker . configuration . webhook_host_whitelist
102
102
end
103
+
104
+ def parse_uri ( uri_string )
105
+ URI ( uri_string . gsub ( /\$ \{ pactbroker\. [^\} ]+\} / , 'placeholder' ) )
106
+ end
103
107
end
104
108
105
109
required ( :http_method ) . filled ( :valid_method? , :allowed_webhook_method? )
Original file line number Diff line number Diff line change @@ -179,8 +179,19 @@ def valid_webhook_with
179
179
expect ( subject . errors [ :"request.url" ] ) . to eq [ "is not a valid URL eg. http://example.org" ]
180
180
end
181
181
end
182
- end
183
182
183
+ context "with a URL that has templated parameters in it" do
184
+ let ( :json ) do
185
+ valid_webhook_with do |hash |
186
+ hash [ 'request' ] [ 'url' ] = 'https://foo/commits/${pactbroker.consumerVersionNumber}'
187
+ end
188
+ end
189
+
190
+ it "is empty" do
191
+ expect ( subject . errors ) . to be_empty
192
+ end
193
+ end
194
+ end
184
195
end
185
196
end
186
197
end
You can’t perform that action at this time.
0 commit comments