test/reader_test.rb in symmetric-encryption-3.8.2 vs test/reader_test.rb in symmetric-encryption-3.8.3

- old
+ new

@@ -7,21 +7,21 @@ describe SymmetricEncryption::Reader do before do @data = [ "Hello World\n", "Keep this secret\n", - "And keep going even further and further..." + 'And keep going even further and further...' ] @data_str = @data.inject('') { |sum, str| sum << str } @data_len = @data_str.length # Use Cipher 0 since it does not always include a header @cipher = SymmetricEncryption.cipher(0) @data_encrypted_without_header = @cipher.binary_encrypt(@data_str) @data_encrypted_with_header = SymmetricEncryption::Cipher.build_header( @cipher.version, - compress = false, + false, @cipher.send(:iv), @cipher.send(:key), @cipher.cipher_name ) @data_encrypted_with_header << @cipher.binary_encrypt(@data_str) @@ -57,23 +57,22 @@ it "#each_line" do stream = StringIO.new(@data_encrypted) i = 0 # Version 0 supplied if the file/stream does not have a header - decrypted = SymmetricEncryption::Reader.open(stream, version: 0) do |file| + SymmetricEncryption::Reader.open(stream, version: 0) do |file| file.each_line do |line| assert_equal @data[i], line i += 1 end end end it "#read(size)" do stream = StringIO.new(@data_encrypted) - i = 0 # Version 0 supplied if the file/stream does not have a header - decrypted = SymmetricEncryption::Reader.open(stream, version: 0) do |file| + SymmetricEncryption::Reader.open(stream, version: 0) do |file| index = 0 [0, 10, 5, 5000].each do |size| buf = file.read(size) if size == 0 assert_equal '', buf @@ -153,11 +152,11 @@ assert_raises Errno::ENOENT do SymmetricEncryption::Reader.header_present?('missing_file') end end - it ".open return Zlib::GzipReader when compressed" do + it '.open return Zlib::GzipReader when compressed' do file = SymmetricEncryption::Reader.open(@filename) #assert_equal (@header && (options[:compress]||false)), file.is_a?(Zlib::GzipReader) file.close end @@ -182,11 +181,11 @@ assert_equal @eof, eof assert_equal (@data_size > 0 ? @data_str : nil), data end it "#each_line" do - decrypted = SymmetricEncryption::Reader.open(@filename) do |file| + SymmetricEncryption::Reader.open(@filename) do |file| i = 0 file.each_line do |line| assert_equal @data[i], line i += 1 end @@ -221,35 +220,35 @@ end end end it "#gets(delim)" do - decrypted = SymmetricEncryption::Reader.open(@filename) do |file| + SymmetricEncryption::Reader.open(@filename) do |file| i = 0 while line = file.gets("\n") assert_equal @data[i], line i += 1 end assert_equal (@data_size > 0 ? 3 : 0), i end end it "#gets(delim,size)" do - decrypted = SymmetricEncryption::Reader.open(@filename) do |file| + SymmetricEncryption::Reader.open(@filename) do |file| i = 0 - while line = file.gets("\n", 128) + while file.gets("\n", 128) i += 1 end assert_equal (@data_size > 0 ? 3 : 0), i end end end end end - describe "reading from files with previous keys" do + describe 'reading from files with previous keys' do before do @filename = '_test' # Create encrypted file with old encryption key SymmetricEncryption::Writer.open(@filename, version: 0) do |file| @data.inject(0) { |sum, str| sum + file.write(str) } @@ -258,36 +257,36 @@ after do File.delete(@filename) if File.exist?(@filename) end - it "decrypt from file in a single read" do + it 'decrypt from file in a single read' do decrypted = SymmetricEncryption::Reader.open(@filename) { |file| file.read } assert_equal @data_str, decrypted end - it "decrypt from file a line at a time" do - decrypted = SymmetricEncryption::Reader.open(@filename) do |file| + it 'decrypt from file a line at a time' do + SymmetricEncryption::Reader.open(@filename) do |file| i = 0 file.each_line do |line| assert_equal @data[i], line i += 1 end end end - it "support rewind" do + it 'support rewind' do decrypted = SymmetricEncryption::Reader.open(@filename) do |file| file.read file.rewind file.read end assert_equal @data_str, decrypted end end - describe "reading from files with previous keys without a header" do + describe 'reading from files with previous keys without a header' do before do @filename = '_test' # Create encrypted file with old encryption key SymmetricEncryption::Writer.open(@filename, version: 0, header: false, random_key: false) do |file| @data.inject(0) { |sum, str| sum + file.write(str) } @@ -300,15 +299,15 @@ rescue Errno::EACCES # Required for Windows end end - it "decrypt from file in a single read" do + it 'decrypt from file in a single read' do decrypted = SymmetricEncryption::Reader.open(@filename, version: 0) { |file| file.read } assert_equal @data_str, decrypted end - it "decrypt from file in a single read with different version" do + it 'decrypt from file in a single read with different version' do # Should fail since file was encrypted using version 0 key assert_raises OpenSSL::Cipher::CipherError do SymmetricEncryption::Reader.open(@filename, version: 2) { |file| file.read } end end