Skip to content

Commit e29b840

Browse files
author
Nimisha Sharad
authored
Merge pull request #157 from MsysTechnologiesllc/dhfix_for_validation_key_creation_failure
Fix for validation.pem file not generating
2 parents 30d4b43 + b1e24a4 commit e29b840

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

lib/chef/azure/commands/enable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def get_validation_key(encrypted_text, validation_key_format)
282282
rescue OpenSSL::PKey::RSAError => e
283283
Chef::Log.error "Chef validation key parsing error. #{e.inspect}"
284284
end
285-
validation_key
285+
validation_key.delete("\x00")
286286
end
287287

288288
def get_client_key(encrypted_text)

spec/unit/azure_enable_spec.rb

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,30 +399,50 @@
399399
end
400400

401401
context "get_validation_key on linux" , :unless => (RUBY_PLATFORM =~ /mswin|mingw|windows/) do
402-
it "extracts and returns the validation_key from encrypted text." do
402+
before do
403403
@object = Object.new
404404
allow(File).to receive(:read)
405405
allow(File).to receive(:exists?).and_return(true)
406406
allow(OpenSSL::X509::Certificate).to receive(:new)
407407
allow(OpenSSL::PKey::RSA).to receive(:new).and_return(@object)
408408
allow(Base64).to receive(:decode64)
409409
allow(OpenSSL::PKCS7).to receive(:new).and_return(@object)
410+
allow(instance).to receive(:value_from_json_file).and_return('samplevalidationkeytext')
411+
end
412+
it "extracts and returns the validation_key from encrypted text." do
413+
allow(@object).to receive(:to_pem).and_return('samplevalidationkeytext')
410414
expect(instance).to receive(:handler_settings_file)
411-
expect(instance).to receive(:value_from_json_file).twice.and_return('')
412415
expect(@object).to receive(:decrypt)
413-
expect(@object).to receive(:to_pem)
414-
instance.send(:get_validation_key, 'encrypted_text', 'format')
416+
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
417+
end
418+
419+
it "extracts and returns the validation_key from encrypted text containg null bytes" do
420+
allow(@object).to receive(:to_pem).and_return("sample\x00validation\x00keytext\x00")
421+
expect(instance).to receive(:handler_settings_file)
422+
expect(@object).to receive(:decrypt)
423+
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
415424
end
416425
end
417426

418427
context "get_validation_key on windows" , :if => (RUBY_PLATFORM =~ /mswin|mingw|windows/) do
419-
it "extracts and returns the validation_key from encrypted text." do
428+
before do
429+
@object = Object.new
420430
allow(File).to receive(:expand_path).and_return(".")
421431
allow(File).to receive(:dirname)
422432
allow(instance).to receive(:shell_out).and_return(OpenStruct.new(:exitstatus => 0, :stdout => ""))
433+
allow(OpenSSL::PKey::RSA).to receive(:new).and_return(@object)
434+
allow(instance).to receive(:value_from_json_file).and_return('samplevalidationkeytext')
435+
end
436+
it "extracts and returns the validation_key from encrypted text." do
437+
allow(@object).to receive(:to_pem).and_return('samplevalidationkeytext')
438+
expect(instance).to receive(:handler_settings_file)
439+
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
440+
end
441+
442+
it "extracts and returns the validation_key from encrypted text containg null bytes." do
443+
allow(@object).to receive(:to_pem).and_return("sample\x00validation\x00keytext\x00")
423444
expect(instance).to receive(:handler_settings_file)
424-
expect(instance).to receive(:value_from_json_file).twice.and_return("")
425-
instance.send(:get_validation_key, "encrypted_text", "format")
445+
expect(instance.send(:get_validation_key, 'encrypted_text', 'format')).to eq("samplevalidationkeytext")
426446
end
427447
end
428448

@@ -509,4 +529,4 @@
509529
expect(hints['platform']).to eq 'my_platform'
510530
end
511531
end
512-
end
532+
end

0 commit comments

Comments
 (0)