symmetric-encryption 4.1.1 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/writer_test.rb DELETED
@@ -1,79 +0,0 @@
1
- require_relative 'test_helper'
2
- require 'stringio'
3
-
4
- # Unit Test for Symmetric::EncryptedStream
5
- #
6
- class WriterTest < Minitest::Test
7
- describe SymmetricEncryption::Writer do
8
- before do
9
- @data = [
10
- "Hello World\n",
11
- "Keep this secret\n",
12
- 'And keep going even further and further...'
13
- ]
14
- @data_str = @data.inject('') { |sum, str| sum << str }
15
- @data_len = @data_str.length
16
- @file_name = '._test'
17
- @source_file_name = '._source_test'
18
- end
19
-
20
- after do
21
- File.delete(@file_name) if File.exist?(@file_name)
22
- File.delete(@source_file_name) if File.exist?(@source_file_name)
23
- end
24
-
25
- [true, false, nil].each do |compress|
26
- describe "compress: #{compress.inspect}" do
27
- describe '.open' do
28
- it 'encrypt to stream' do
29
- written_len = 0
30
- stream = StringIO.new
31
- SymmetricEncryption::Writer.open(stream, compress: compress) do |file|
32
- written_len = @data.inject(0) { |sum, str| sum + file.write(str) }
33
- end
34
- size = stream.string.size
35
- if compress == false
36
- assert @data_len, size
37
- else
38
- # With small files the compressed file is larger
39
- assert size >= @data_len
40
- end
41
- assert_equal @data_len, written_len
42
- end
43
-
44
- it 'encrypt to file' do
45
- written_len = SymmetricEncryption::Writer.open(@file_name, compress: compress) do |file|
46
- @data.inject(0) { |sum, str| sum + file.write(str) }
47
- end
48
- assert_equal @data_len, written_len
49
- size = File.size(@file_name)
50
- if compress == false
51
- assert @data_len, size
52
- else
53
- # With small files the compressed file is larger
54
- assert size >= @data_len
55
- end
56
- assert_equal @data_str, SymmetricEncryption::Reader.read(@file_name)
57
- end
58
- end
59
-
60
- describe '.encrypt' do
61
- it 'stream' do
62
- target_stream = StringIO.new
63
- source_stream = StringIO.new(@data_str)
64
- source_bytes = SymmetricEncryption::Writer.encrypt(source: source_stream, target: target_stream, compress: compress)
65
- assert_equal @data_len, source_bytes
66
- assert_equal @data_str, SymmetricEncryption::Reader.read(StringIO.new(target_stream.string))
67
- end
68
-
69
- it 'file' do
70
- File.open(@source_file_name, 'wb') { |f| f.write(@data_str) }
71
- source_bytes = SymmetricEncryption::Writer.encrypt(source: @source_file_name, target: @file_name, compress: compress)
72
- assert_equal @data_len, source_bytes
73
- assert_equal @data_str, SymmetricEncryption::Reader.read(@file_name)
74
- end
75
- end
76
- end
77
- end
78
- end
79
- end