Skip to content

Commit

Permalink
Bug 924633 - now dealing with empty certificate and private key files
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianofranz committed Mar 27, 2013
1 parent c1e83d0 commit 61c9560
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/rhc/commands/alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def update_cert(app, app_alias)
raise ArgumentError, "Private key file not found: #{private_key_file_path}" if !File.exist?(private_key_file_path) || !File.file?(private_key_file_path)

certificate_content = File.read(certificate_file_path)
raise ArgumentError, "Invalid certificate file: #{certificate_file_path} is empty" if certificate_content.to_s.strip.length == 0

private_key_content = File.read(private_key_file_path)
raise ArgumentError, "Invalid private key file: #{private_key_file_path} is empty" if private_key_content.to_s.strip.length == 0

rest_app = rest_client.find_application(options.namespace, app)
rest_alias = rest_app.find_alias(app_alias)
Expand Down
2 changes: 1 addition & 1 deletion lib/rhc/rest/alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def destroy
def add_certificate(ssl_certificate_content, private_key_content, pass_phrase)
debug "Running add_certificate for alias #{@id}"
if (client.api_version_negotiated >= 1.4)
rest_method "UPDATE", {
foo = rest_method "UPDATE", {
:ssl_certificate => ssl_certificate_content,
:private_key => private_key_content,
:pass_phrase => pass_phrase
Expand Down
Empty file added spec/rhc/assets/empty.txt
Empty file.
14 changes: 14 additions & 0 deletions spec/rhc/commands/alias_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@
it { expect { run }.should exit_with_code(1) }
it { run_output.should =~ /The server does not support SSL certificates for custom aliases/m }
end
context 'invalid certificate file (empty)' do
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.foo.bar',
'--certificate', File.expand_path('../../assets/empty.txt', __FILE__),
'--private-key', File.expand_path('../../assets/cert_key_rsa', __FILE__) ] }
it { expect { run }.should exit_with_code(1) }
it { run_output.should =~ /Invalid certificate file/m }
end
context 'invalid private key file (empty)' do
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.foo.bar',
'--certificate', File.expand_path('../../assets/cert.crt', __FILE__),
'--private-key', File.expand_path('../../assets/empty.txt', __FILE__) ] }
it { expect { run }.should exit_with_code(1) }
it { run_output.should =~ /Invalid private key file/m }
end
end

describe 'alias delete-cert' do
Expand Down

0 comments on commit 61c9560

Please sign in to comment.