1212 let ( :enable_args ) { [ ] }
1313 let ( :instance ) { EnableChef . new ( extension_root , enable_args ) }
1414
15- context "for windows" do
16- before do
17- @decrypted_settings = mock_data ( 'correct_decrypted_json.txt' )
18- allow ( instance ) . to receive ( :windows? ) . and_return ( true )
19- allow ( instance ) . to receive ( :handler_settings_file ) . and_return ( mock_data ( "handler_settings.settings" ) )
20- end
15+ let ( :correct_decrypted_settings ) { mock_data ( 'correct_decrypted_json.txt' ) }
16+ let ( :incorrect_decrypted_settings ) { mock_data ( 'incorrect_decrypted_json.txt' ) }
2117
18+ describe "secret_key" do
2219 it "returns correct secret key if there is no escape character in the decrypted json" do
23- allow ( instance ) . to receive ( :shell_out ) . and_return ( OpenStruct . new ( :exitstatus => 0 , :stdout => @decrypted_settings ) )
24- secret_key_cmd = instance . send ( :secret_key , @decrypted_settings )
25- expect ( secret_key_cmd ) . to eq ( "secret_key" )
20+ allow ( OpenSSL :: PKey :: RSA ) . to receive_message_chain ( : new, :to_pem ) . and_return ( 'secret_key' )
21+ response = instance . send ( :secret_key , correct_decrypted_settings )
22+ expect ( response ) . to eq ( "secret_key" )
2623 end
2724
2825 it "returns correct secret key if there are escape characters in the decrypted json" do
29- decrypted_validation_key = mock_data ( 'incorrect_decrypted_json.txt' )
30- allow ( instance ) . to receive ( :shell_out ) . and_return ( OpenStruct . new ( :exitstatus => 0 , :stdout => decrypted_validation_key ) )
31- secret_key_cmd = instance . send ( :secret_key , @decrypted_settings )
32- expect ( secret_key_cmd ) . to eq ( "secret_key" )
33- end
34- end
35-
36-
37- context "for linux" do
38- before do
39- @decrypted_settings = mock_data ( 'correct_decrypted_json.txt' )
40- allow ( instance ) . to receive ( :windows? ) . and_return ( false )
41- allow ( instance ) . to receive ( :handler_settings_file ) . and_return ( mock_data ( "handler_settings.settings" ) )
26+ allow ( OpenSSL ::PKey ::RSA ) . to receive_message_chain ( :new , :to_pem ) . and_return ( 'secret_key' )
27+ response = instance . send ( :secret_key , incorrect_decrypted_settings )
28+ expect ( response ) . to eq ( "secret_key" )
4229 end
4330
44- it "returns correct validation key" do
45- EnableChef ::LINUX_CERT_PATH = File . expand_path ( File . dirname ( "spec/assets/*" ) )
46- secret_key_cmd = instance . send ( :secret_key , @decrypted_settings )
47- expect ( secret_key_cmd ) . to eq ( "secret_key" )
31+ context "when secret is not passed by the user" do
32+ it "returns nil" do
33+ response = instance . send ( :secret_key , "{\" validation_key\" : \" my_key\" }" )
34+ expect ( response ) . to eq ( nil )
35+ end
4836 end
4937 end
50- end
38+ end
0 commit comments