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\x00 validation\x00 keytext\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\x00 validation\x00 keytext\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
509529 expect ( hints [ 'platform' ] ) . to eq 'my_platform'
510530 end
511531 end
512- end
532+ end
0 commit comments