Skip to content

Commit f903004

Browse files
author
Ben Lavender
authored
Merge pull request #17 from github/fix-nil-error
Fix error when no alt public key present
2 parents 5586435 + 640bb83 commit f903004

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

lib/chatops/controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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-Signature-String"] = signature_string
105+
response.headers["Chatops-Signature-String"] = Base64.strict_encode64(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)
@@ -167,6 +167,7 @@ def should_authenticate_chatops?
167167
end
168168

169169
def signature_valid?(key_string, signature, signature_string)
170+
return false unless key_string.present?
170171
digest = OpenSSL::Digest::SHA256.new
171172
decoded_signature = Base64.decode64(signature)
172173
public_key = OpenSSL::PKey::RSA.new(key_string)

lib/chatops/controller/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ChatopsController
2-
VERSION = "3.0.0"
2+
VERSION = "3.0.1"
33
end

spec/lib/chatops/controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
7777
signature = Base64.encode64(@private_key.sign(digest, signature_string))
7878
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
7979
get :list
80-
expect(response.headers["Chatops-Signature-String"]).to eq signature_string
80+
expect(response.headers["Chatops-Signature-String"]).to eq Base64.strict_encode64(signature_string)
8181
expect(response.status).to eq 200
8282
expect(response).to be_valid_json
8383
end

0 commit comments

Comments
 (0)