Skip to content

Commit 45bac4c

Browse files
author
Ben Lavender
committed
Add years to @jbarnette's life
1 parent 8c5dcd6 commit 45bac4c

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

lib/chatops/controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'chatops'
1+
require "chatops"
22

33
module ChatOps
44
module Controller
@@ -102,7 +102,7 @@ def ensure_chatops_authenticated
102102
body = request.raw_post || ""
103103
signature_string = [@chatops_url, @chatops_nonce, @chatops_timestamp, body].join("\n")
104104
# We return this just to aid client debugging.
105-
response.headers["Chatops-SignatureString"] = signature_string
105+
response.headers["Chatops-Signature-String"] = signature_string
106106
raise ConfigurationError.new("You need to add a client's public key in .pem format via #{ChatOps.public_key_env_var_name}") unless ChatOps.public_key.present?
107107
if signature_valid?(ChatOps.public_key, @chatops_signature, signature_string) ||
108108
signature_valid?(ChatOps.alt_public_key, @chatops_signature, signature_string)
@@ -117,12 +117,12 @@ def ensure_valid_chatops_url
117117
end
118118

119119
def ensure_valid_chatops_nonce
120-
@chatops_nonce = request.headers['Chatops-Nonce']
120+
@chatops_nonce = request.headers["Chatops-Nonce"]
121121
return render :status => :forbidden, :plain => "A Chatops-Nonce header is required" unless @chatops_nonce.present?
122122
end
123123

124124
def ensure_valid_chatops_signature
125-
signature_header = request.headers['Chatops-Signature']
125+
signature_header = request.headers["Chatops-Signature"]
126126

127127
begin
128128
# "Chatops-Signature: Signature keyid=foo,signature=abc123" => { "keyid"" => "foo", "signature" => "abc123" }
@@ -139,7 +139,7 @@ def ensure_valid_chatops_signature
139139
end
140140

141141
def ensure_valid_chatops_timestamp
142-
@chatops_timestamp = request.headers['Chatops-Timestamp']
142+
@chatops_timestamp = request.headers["Chatops-Timestamp"]
143143
time = Time.iso8601(@chatops_timestamp)
144144
if !(time > 1.minute.ago && time < 1.minute.from_now)
145145
return render :status => :forbidden, :plain => "Chatops timestamp not within 1 minute of server time: #{@chatops_timestamp} vs #{Time.now.utc.iso8601}"

spec/lib/chatops/controller_spec.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,42 +62,42 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
6262
end
6363

6464
it "requires authentication" do
65-
request.headers['Chatops-Timestamp'] = Time.now.utc.iso8601
65+
request.headers["Chatops-Timestamp"] = Time.now.utc.iso8601
6666
get :list
6767
expect(response.status).to eq 403
6868
end
6969

7070
it "allows public key authentication for a GET request" do
7171
nonce = SecureRandom.hex(20)
7272
timestamp = Time.now.utc.iso8601
73-
request.headers['Chatops-Nonce'] = nonce
74-
request.headers['Chatops-Timestamp'] = timestamp
73+
request.headers["Chatops-Nonce"] = nonce
74+
request.headers["Chatops-Timestamp"] = timestamp
7575
digest = OpenSSL::Digest::SHA256.new
7676
signature_string = "http://test.host/_chatops\n#{nonce}\n#{timestamp}\n"
7777
signature = Base64.encode64(@private_key.sign(digest, signature_string))
78-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
78+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
7979
get :list
80-
expect(response.headers['Chatops-SignatureString']).to eq signature_string
80+
expect(response.headers["Chatops-Signature-String"]).to eq signature_string
8181
expect(response.status).to eq 200
8282
expect(response).to be_valid_json
8383
end
8484

8585
it "allows public key authentication for a POST request" do
8686
nonce = SecureRandom.hex(20)
8787
timestamp = Time.now.utc.iso8601
88-
request.headers['Chatops-Nonce'] = nonce
89-
request.headers['Chatops-Timestamp'] = timestamp
88+
request.headers["Chatops-Nonce"] = nonce
89+
request.headers["Chatops-Timestamp"] = timestamp
9090
digest = OpenSSL::Digest::SHA256.new
9191
params = { :room_id => "123", :user => "bhuga", :params => {}}
9292

9393
body = params.to_json
94-
@request.headers["Content-Type"] = 'application/json'
94+
@request.headers["Content-Type"] = "application/json"
9595
@request.env["RAW_POST_DATA"] = body
9696
signature_string = "http://test.host/_chatops/foobar\n#{nonce}\n#{timestamp}\n#{body}"
9797
signature = Base64.encode64(@private_key.sign(digest, signature_string))
98-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
98+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
9999

100-
major_version = Rails.version.split('.')[0].to_i
100+
major_version = Rails.version.split(".")[0].to_i
101101
if major_version >= 5
102102
post :execute_chatop, params: params.merge(chatop: "foobar")
103103
else
@@ -114,12 +114,12 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
114114
ENV["CHATOPS_AUTH_PUBLIC_KEY"] = other_key.public_key.to_pem
115115
nonce = SecureRandom.hex(20)
116116
timestamp = Time.now.utc.iso8601
117-
request.headers['Chatops-Nonce'] = nonce
118-
request.headers['Chatops-Timestamp'] = timestamp
117+
request.headers["Chatops-Nonce"] = nonce
118+
request.headers["Chatops-Timestamp"] = timestamp
119119
digest = OpenSSL::Digest::SHA256.new
120120
signature_string = "http://test.host/_chatops\n#{nonce}\n#{timestamp}\n"
121121
signature = Base64.encode64(@private_key.sign(digest, signature_string))
122-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
122+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
123123
get :list
124124
expect(response.status).to eq 200
125125
expect(response).to be_valid_json
@@ -128,12 +128,12 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
128128
it "raises an error trying to auth without a base url" do
129129
nonce = SecureRandom.hex(20)
130130
timestamp = Time.now.utc.iso8601
131-
request.headers['Chatops-Nonce'] = nonce
132-
request.headers['Chatops-Timestamp'] = timestamp
131+
request.headers["Chatops-Nonce"] = nonce
132+
request.headers["Chatops-Timestamp"] = timestamp
133133
digest = OpenSSL::Digest::SHA256.new
134134
signature_string = "http://test.host/_chatops\n#{nonce}\n#{timestamp}\n"
135135
signature = Base64.encode64(@private_key.sign(digest, signature_string))
136-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
136+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
137137
ENV.delete "CHATOPS_AUTH_BASE_URL"
138138
expect {
139139
get :list
@@ -143,12 +143,12 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
143143
it "raises an error trying to auth without a public key" do
144144
nonce = SecureRandom.hex(20)
145145
timestamp = Time.now.utc.iso8601
146-
request.headers['Chatops-Nonce'] = nonce
147-
request.headers['Chatops-Timestamp'] = timestamp
146+
request.headers["Chatops-Nonce"] = nonce
147+
request.headers["Chatops-Timestamp"] = timestamp
148148
digest = OpenSSL::Digest::SHA256.new
149149
signature_string = "http://test.host/_chatops\n#{nonce}\n#{timestamp}\n"
150150
signature = Base64.encode64(@private_key.sign(digest, signature_string))
151-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
151+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
152152
ENV.delete "CHATOPS_AUTH_PUBLIC_KEY"
153153
expect {
154154
get :list
@@ -160,25 +160,25 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
160160
ENV["CHATOPS_AUTH_PUBLIC_KEY"] = other_key.public_key.to_pem
161161
nonce = SecureRandom.hex(20)
162162
timestamp = Time.now.utc.iso8601
163-
request.headers['Chatops-Nonce'] = nonce
164-
request.headers['Chatops-Timestamp'] = timestamp
163+
request.headers["Chatops-Nonce"] = nonce
164+
request.headers["Chatops-Timestamp"] = timestamp
165165
digest = OpenSSL::Digest::SHA256.new
166166
signature_string = "http://test.host/_chatops\n#{nonce}\n#{timestamp}\n"
167167
signature = Base64.encode64(@private_key.sign(digest, signature_string))
168-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
168+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
169169
get :list
170170
expect(response.status).to eq 403
171171
end
172172

173173
it "doesn't allow requests more than 1 minute old" do
174174
nonce = SecureRandom.hex(20)
175175
timestamp = 2.minutes.ago.utc.iso8601
176-
request.headers['Chatops-Nonce'] = nonce
177-
request.headers['Chatops-Timestamp'] = timestamp
176+
request.headers["Chatops-Nonce"] = nonce
177+
request.headers["Chatops-Timestamp"] = timestamp
178178
digest = OpenSSL::Digest::SHA256.new
179179
signature_string = "http://test.host/_chatops\n#{nonce}\n#{timestamp}\n"
180180
signature = Base64.encode64(@private_key.sign(digest, signature_string))
181-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
181+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
182182
get :list
183183
expect(response.status).to eq 403
184184
expect(response.body).to include "Chatops timestamp not within 1 minute"
@@ -187,12 +187,12 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
187187
it "doesn't allow requests more than 1 minute in the future" do
188188
nonce = SecureRandom.hex(20)
189189
timestamp = 2.minutes.from_now.utc.iso8601
190-
request.headers['Chatops-Nonce'] = nonce
191-
request.headers['Chatops-Timestamp'] = timestamp
190+
request.headers["Chatops-Nonce"] = nonce
191+
request.headers["Chatops-Timestamp"] = timestamp
192192
digest = OpenSSL::Digest::SHA256.new
193193
signature_string = "http://test.host/_chatops\n#{nonce}\n#{timestamp}\n"
194194
signature = Base64.encode64(@private_key.sign(digest, signature_string))
195-
request.headers['Chatops-Signature'] = "Signature keyid=foo,signature=#{signature}"
195+
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
196196
get :list
197197
expect(response.status).to eq 403
198198
expect(response.body).to include "Chatops timestamp not within 1 minute"

0 commit comments

Comments
 (0)