@@ -38,7 +38,9 @@ module Webhooks
38
38
allow_any_instance_of ( PactBroker ::Webhooks ::Repository ) . to receive ( :find_by_uuid ) . and_return ( existing_webhook )
39
39
end
40
40
41
- let ( :request ) { PactBroker ::Webhooks ::WebhookRequestTemplate . new ( password : 'password' ) }
41
+ let ( :request ) { PactBroker ::Webhooks ::WebhookRequestTemplate . new ( password : existing_password , headers : headers ) }
42
+ let ( :existing_password ) { nil }
43
+ let ( :headers ) { { } }
42
44
let ( :existing_webhook ) { PactBroker ::Domain ::Webhook . new ( request : request ) }
43
45
let ( :params ) do
44
46
{
@@ -50,7 +52,19 @@ module Webhooks
50
52
51
53
subject { Service . update_by_uuid ( "1234" , params ) }
52
54
55
+ it "sends through the params to the repository" do
56
+ updated_webhook = nil
57
+ allow_any_instance_of ( PactBroker ::Webhooks ::Repository ) . to receive ( :update_by_uuid ) do | instance , uuid , webhook |
58
+ updated_webhook = webhook
59
+ true
60
+ end
61
+ subject
62
+ expect ( updated_webhook . request . url ) . to eq 'http://url'
63
+ end
64
+
53
65
context "when the webhook has a password and the incoming parameters do not contain a password" do
66
+ let ( :existing_password ) { 'password' }
67
+
54
68
it "does not overwite the password" do
55
69
updated_webhook = nil
56
70
allow_any_instance_of ( PactBroker ::Webhooks ::Repository ) . to receive ( :update_by_uuid ) do | instance , uuid , webhook |
@@ -62,6 +76,52 @@ module Webhooks
62
76
end
63
77
end
64
78
79
+ context "when the webhook has a password and the incoming parameters contain a *** password" do
80
+ let ( :existing_password ) { 'password' }
81
+ let ( :params ) do
82
+ {
83
+ 'request' => {
84
+ 'url' => 'http://url' ,
85
+ 'password' => '*******'
86
+ }
87
+ }
88
+ end
89
+
90
+ it "does not overwite the password" do
91
+ updated_webhook = nil
92
+ allow_any_instance_of ( PactBroker ::Webhooks ::Repository ) . to receive ( :update_by_uuid ) do | instance , uuid , webhook |
93
+ updated_webhook = webhook
94
+ true
95
+ end
96
+ subject
97
+ expect ( updated_webhook . request . password ) . to eq 'password'
98
+ end
99
+ end
100
+
101
+ context "when the webhook has an authorization header and the incoming parameters contain a *** authorization header" do
102
+ let ( :headers ) { { 'Authorization' => 'existing' } }
103
+ let ( :params ) do
104
+ {
105
+ 'request' => {
106
+ 'url' => "http://url" ,
107
+ 'headers' => {
108
+ 'authorization' => "***********"
109
+ }
110
+ }
111
+ }
112
+ end
113
+
114
+ it "does not overwite the authorization header" do
115
+ updated_webhook = nil
116
+ allow_any_instance_of ( PactBroker ::Webhooks ::Repository ) . to receive ( :update_by_uuid ) do | instance , uuid , webhook |
117
+ updated_webhook = webhook
118
+ true
119
+ end
120
+ subject
121
+ expect ( updated_webhook . request . headers [ 'Authorization' ] ) . to eq 'existing'
122
+ end
123
+ end
124
+
65
125
context "the incoming parameters contain a password" do
66
126
let ( :params ) do
67
127
{
0 commit comments