Skip to content

Commit

Permalink
Merge pull request #157 from MsysTechnologiesllc/dhfix_for_validation…
Browse files Browse the repository at this point in the history
…_key_creation_failure

Fix for validation.pem file not generating
  • Loading branch information
Nimisha Sharad authored Aug 10, 2016
2 parents 30d4b43 + b1e24a4 commit e29b840
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/chef/azure/commands/enable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get_validation_key(encrypted_text, validation_key_format)
rescue OpenSSL::PKey::RSAError => e
Chef::Log.error "Chef validation key parsing error. #{e.inspect}"
end
validation_key
validation_key.delete("\x00")
end

def get_client_key(encrypted_text)
Expand Down
36 changes: 28 additions & 8 deletions spec/unit/azure_enable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,30 +399,50 @@
end

context "get_validation_key on linux" , :unless => (RUBY_PLATFORM =~ /mswin|mingw|windows/) do
it "extracts and returns the validation_key from encrypted text." do
before do
@object = Object.new
allow(File).to receive(:read)
allow(File).to receive(:exists?).and_return(true)
allow(OpenSSL::X509::Certificate).to receive(:new)
allow(OpenSSL::PKey::RSA).to receive(:new).and_return(@object)
allow(Base64).to receive(:decode64)
allow(OpenSSL::PKCS7).to receive(:new).and_return(@object)
allow(instance).to receive(:value_from_json_file).and_return('samplevalidationkeytext')
end
it "extracts and returns the validation_key from encrypted text." do
allow(@object).to receive(:to_pem).and_return('samplevalidationkeytext')
expect(instance).to receive(:handler_settings_file)
expect(instance).to receive(:value_from_json_file).twice.and_return('')
expect(@object).to receive(:decrypt)
expect(@object).to receive(:to_pem)
instance.send(:get_validation_key, 'encrypted_text', 'format')
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
end

it "extracts and returns the validation_key from encrypted text containg null bytes" do
allow(@object).to receive(:to_pem).and_return("sample\x00validation\x00keytext\x00")
expect(instance).to receive(:handler_settings_file)
expect(@object).to receive(:decrypt)
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
end
end

context "get_validation_key on windows" , :if => (RUBY_PLATFORM =~ /mswin|mingw|windows/) do
it "extracts and returns the validation_key from encrypted text." do
before do
@object = Object.new
allow(File).to receive(:expand_path).and_return(".")
allow(File).to receive(:dirname)
allow(instance).to receive(:shell_out).and_return(OpenStruct.new(:exitstatus => 0, :stdout => ""))
allow(OpenSSL::PKey::RSA).to receive(:new).and_return(@object)
allow(instance).to receive(:value_from_json_file).and_return('samplevalidationkeytext')
end
it "extracts and returns the validation_key from encrypted text." do
allow(@object).to receive(:to_pem).and_return('samplevalidationkeytext')
expect(instance).to receive(:handler_settings_file)
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
end

it "extracts and returns the validation_key from encrypted text containg null bytes." do
allow(@object).to receive(:to_pem).and_return("sample\x00validation\x00keytext\x00")
expect(instance).to receive(:handler_settings_file)
expect(instance).to receive(:value_from_json_file).twice.and_return("")
instance.send(:get_validation_key, "encrypted_text", "format")
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
end
end

Expand Down Expand Up @@ -509,4 +529,4 @@
expect(hints['platform']).to eq 'my_platform'
end
end
end
end

0 comments on commit e29b840

Please sign in to comment.