From 61c95602c43be41edbc9637e0b87817764f11625 Mon Sep 17 00:00:00 2001 From: Fabiano Franz Date: Wed, 27 Mar 2013 17:26:08 -0300 Subject: [PATCH] Bug 924633 - now dealing with empty certificate and private key files --- lib/rhc/commands/alias.rb | 3 +++ lib/rhc/rest/alias.rb | 2 +- spec/rhc/assets/empty.txt | 0 spec/rhc/commands/alias_spec.rb | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 spec/rhc/assets/empty.txt diff --git a/lib/rhc/commands/alias.rb b/lib/rhc/commands/alias.rb index bffe9ff11..e0500d940 100644 --- a/lib/rhc/commands/alias.rb +++ b/lib/rhc/commands/alias.rb @@ -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) diff --git a/lib/rhc/rest/alias.rb b/lib/rhc/rest/alias.rb index c69dda4b0..09af1a3a6 100644 --- a/lib/rhc/rest/alias.rb +++ b/lib/rhc/rest/alias.rb @@ -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 diff --git a/spec/rhc/assets/empty.txt b/spec/rhc/assets/empty.txt new file mode 100644 index 000000000..e69de29bb diff --git a/spec/rhc/commands/alias_spec.rb b/spec/rhc/commands/alias_spec.rb index 307ae75ad..06407cdd5 100644 --- a/spec/rhc/commands/alias_spec.rb +++ b/spec/rhc/commands/alias_spec.rb @@ -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