iostreams 0.20.3 → 1.0.0.beta
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.
- checksums.yaml +4 -4
- data/lib/io_streams/bzip2/reader.rb +9 -21
- data/lib/io_streams/bzip2/writer.rb +9 -21
- data/lib/io_streams/deprecated.rb +217 -0
- data/lib/io_streams/encode/reader.rb +12 -16
- data/lib/io_streams/encode/writer.rb +9 -13
- data/lib/io_streams/errors.rb +6 -6
- data/lib/io_streams/gzip/reader.rb +7 -14
- data/lib/io_streams/gzip/writer.rb +7 -15
- data/lib/io_streams/io_streams.rb +182 -524
- data/lib/io_streams/line/reader.rb +9 -9
- data/lib/io_streams/line/writer.rb +10 -11
- data/lib/io_streams/path.rb +190 -0
- data/lib/io_streams/paths/file.rb +176 -0
- data/lib/io_streams/paths/http.rb +92 -0
- data/lib/io_streams/paths/matcher.rb +61 -0
- data/lib/io_streams/paths/s3.rb +269 -0
- data/lib/io_streams/paths/sftp.rb +99 -0
- data/lib/io_streams/pgp.rb +47 -19
- data/lib/io_streams/pgp/reader.rb +20 -28
- data/lib/io_streams/pgp/writer.rb +24 -46
- data/lib/io_streams/reader.rb +28 -0
- data/lib/io_streams/record/reader.rb +20 -16
- data/lib/io_streams/record/writer.rb +28 -28
- data/lib/io_streams/row/reader.rb +22 -26
- data/lib/io_streams/row/writer.rb +29 -28
- data/lib/io_streams/stream.rb +400 -0
- data/lib/io_streams/streams.rb +125 -0
- data/lib/io_streams/symmetric_encryption/reader.rb +5 -13
- data/lib/io_streams/symmetric_encryption/writer.rb +16 -15
- data/lib/io_streams/tabular/header.rb +9 -3
- data/lib/io_streams/tabular/parser/array.rb +8 -3
- data/lib/io_streams/tabular/parser/csv.rb +6 -2
- data/lib/io_streams/tabular/parser/hash.rb +4 -1
- data/lib/io_streams/tabular/parser/json.rb +3 -1
- data/lib/io_streams/tabular/parser/psv.rb +3 -1
- data/lib/io_streams/tabular/utility/csv_row.rb +9 -8
- data/lib/io_streams/utils.rb +22 -0
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +28 -0
- data/lib/io_streams/xlsx/reader.rb +7 -19
- data/lib/io_streams/zip/reader.rb +7 -26
- data/lib/io_streams/zip/writer.rb +21 -38
- data/lib/iostreams.rb +15 -15
- data/test/bzip2_reader_test.rb +3 -3
- data/test/bzip2_writer_test.rb +3 -3
- data/test/deprecated_test.rb +123 -0
- data/test/encode_reader_test.rb +3 -3
- data/test/encode_writer_test.rb +6 -6
- data/test/gzip_reader_test.rb +2 -2
- data/test/gzip_writer_test.rb +3 -3
- data/test/io_streams_test.rb +43 -136
- data/test/line_reader_test.rb +20 -20
- data/test/line_writer_test.rb +3 -3
- data/test/path_test.rb +30 -28
- data/test/paths/file_test.rb +206 -0
- data/test/paths/http_test.rb +34 -0
- data/test/paths/matcher_test.rb +111 -0
- data/test/paths/s3_test.rb +207 -0
- data/test/pgp_reader_test.rb +8 -8
- data/test/pgp_writer_test.rb +13 -13
- data/test/record_reader_test.rb +5 -5
- data/test/record_writer_test.rb +4 -4
- data/test/row_reader_test.rb +5 -5
- data/test/row_writer_test.rb +6 -6
- data/test/stream_test.rb +116 -0
- data/test/streams_test.rb +255 -0
- data/test/utils_test.rb +20 -0
- data/test/xlsx_reader_test.rb +3 -3
- data/test/zip_reader_test.rb +12 -12
- data/test/zip_writer_test.rb +5 -5
- metadata +33 -45
- data/lib/io_streams/base_path.rb +0 -72
- data/lib/io_streams/file/path.rb +0 -58
- data/lib/io_streams/file/reader.rb +0 -12
- data/lib/io_streams/file/writer.rb +0 -22
- data/lib/io_streams/http/reader.rb +0 -71
- data/lib/io_streams/s3.rb +0 -26
- data/lib/io_streams/s3/path.rb +0 -40
- data/lib/io_streams/s3/reader.rb +0 -28
- data/lib/io_streams/s3/writer.rb +0 -85
- data/lib/io_streams/sftp/reader.rb +0 -67
- data/lib/io_streams/sftp/writer.rb +0 -68
- data/test/base_path_test.rb +0 -35
- data/test/file_path_test.rb +0 -97
- data/test/file_reader_test.rb +0 -33
- data/test/file_writer_test.rb +0 -50
- data/test/http_reader_test.rb +0 -38
- data/test/s3_reader_test.rb +0 -41
- data/test/s3_writer_test.rb +0 -41
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Paths
|
4
|
+
class HTTPTest < Minitest::Test
|
5
|
+
describe IOStreams::Paths::HTTP do
|
6
|
+
let :url do
|
7
|
+
"http://example.com/index.html?count=10"
|
8
|
+
end
|
9
|
+
|
10
|
+
let :ssl_url do
|
11
|
+
"https://example.com/index.html?count=10"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.open' do
|
15
|
+
it 'reads http' do
|
16
|
+
result = IOStreams::Paths::HTTP.new(url).read
|
17
|
+
assert_includes result, "<html>"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'reads https' do
|
21
|
+
result = IOStreams::Paths::HTTP.new(ssl_url).read
|
22
|
+
assert_includes result, "<html>"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'does not support streams' do
|
26
|
+
assert_raises URI::InvalidURIError do
|
27
|
+
io = StringIO.new
|
28
|
+
IOStreams::Paths::HTTP.new(io)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Paths
|
4
|
+
class MatcherTest < Minitest::Test
|
5
|
+
describe IOStreams::Paths::Matcher do
|
6
|
+
let :cases do
|
7
|
+
[
|
8
|
+
{
|
9
|
+
path: "/path/work",
|
10
|
+
pattern: "a/b/c/**/*",
|
11
|
+
expected_path: "/path/work/a/b/c",
|
12
|
+
expected_pattern: "**/*",
|
13
|
+
recursive: true,
|
14
|
+
matches: %w[/path/work/a/b/c/any/file /path/work/a/b/c/other/file /path/work/a/b/c/sub/.name],
|
15
|
+
not_matches: %w[/path/work/a/b/c/.profile]
|
16
|
+
},
|
17
|
+
{path: "/path/work", pattern: "a/b/c?/**/*", expected_path: "/path/work/a/b", expected_pattern: "c?/**/*", recursive: true},
|
18
|
+
{path: "/path/work", pattern: "**/*", expected_path: "/path/work", expected_pattern: "**/*", recursive: true},
|
19
|
+
# Case-insensitive exists that returns the actual file name.
|
20
|
+
{path: "/path/work", pattern: "a/b/file.txt", expected_path: "/path/work/a/b/file.txt", expected_pattern: nil, recursive: false},
|
21
|
+
{
|
22
|
+
path: "/path/work",
|
23
|
+
pattern: "a/b/file*{zip,gz}",
|
24
|
+
expected_path: "/path/work/a/b",
|
25
|
+
expected_pattern: "file*{zip,gz}",
|
26
|
+
recursive: false,
|
27
|
+
matches: %w[/path/work/a/b/file.GZ /path/work/a/b/FILE.ZIP /path/work/a/b/file123.zIp],
|
28
|
+
not_matches: %w[/path/work/a/b/.profile /path/work/a/b/filter.zip],
|
29
|
+
case_sensitive: false
|
30
|
+
},
|
31
|
+
{
|
32
|
+
path: "/path/work",
|
33
|
+
pattern: "a/b/file*{zip,gz}",
|
34
|
+
expected_path: "/path/work/a/b",
|
35
|
+
expected_pattern: "file*{zip,gz}",
|
36
|
+
recursive: false,
|
37
|
+
matches: %w[/path/work/a/b/file.gz /path/work/a/b/file.zip],
|
38
|
+
not_matches: %w[/path/work/a/b/file.GZ /path/work/a/b/FILE.ZIP],
|
39
|
+
case_sensitive: true
|
40
|
+
},
|
41
|
+
{path: "/path/work", pattern: "file.txt", expected_path: "/path/work/file.txt", expected_pattern: nil, recursive: false},
|
42
|
+
{path: "/path/work", pattern: "*", expected_path: "/path/work", expected_pattern: "*", recursive: false},
|
43
|
+
]
|
44
|
+
end
|
45
|
+
# , case_sensitive: false, hidden: false
|
46
|
+
|
47
|
+
describe '#recursive?' do
|
48
|
+
it 'identifies recursive paths correctly' do
|
49
|
+
cases.each do |test_case|
|
50
|
+
path = IOStreams.path(test_case[:path])
|
51
|
+
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
|
52
|
+
assert_equal test_case[:recursive], matcher.recursive?, test_case
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#path?" do
|
58
|
+
it 'optimizes path correctly' do
|
59
|
+
cases.each do |test_case|
|
60
|
+
path = IOStreams.path(test_case[:path])
|
61
|
+
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
|
62
|
+
assert_equal test_case[:expected_path], matcher.path.to_s, test_case
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#pattern" do
|
68
|
+
it 'optimizes pattern correctly' do
|
69
|
+
cases.each do |test_case|
|
70
|
+
path = IOStreams.path(test_case[:path])
|
71
|
+
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
|
72
|
+
if test_case[:expected_pattern].nil?
|
73
|
+
assert_nil matcher.pattern, test_case
|
74
|
+
else
|
75
|
+
assert_equal test_case[:expected_pattern], matcher.pattern, test_case
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#match?" do
|
82
|
+
it 'matches' do
|
83
|
+
cases.each do |test_case|
|
84
|
+
path = IOStreams.path(test_case[:path])
|
85
|
+
case_sensitive = test_case.fetch(:case_sensitive, false)
|
86
|
+
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern], case_sensitive: case_sensitive)
|
87
|
+
next unless test_case[:matches]
|
88
|
+
|
89
|
+
test_case[:matches].each do |file_name|
|
90
|
+
assert matcher.match?(file_name), test_case.merge(file_name: file_name)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should not match' do
|
96
|
+
cases.each do |test_case|
|
97
|
+
path = IOStreams.path(test_case[:path])
|
98
|
+
case_sensitive = test_case.fetch(case_sensitive, :false)
|
99
|
+
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern], case_sensitive: case_sensitive)
|
100
|
+
next unless test_case[:not_matches]
|
101
|
+
|
102
|
+
test_case[:not_matches].each do |file_name|
|
103
|
+
refute matcher.match?(file_name), test_case.merge(file_name: file_name)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Paths
|
4
|
+
class S3Test < Minitest::Test
|
5
|
+
describe IOStreams::Paths::S3 do
|
6
|
+
before do
|
7
|
+
unless ENV['S3_BUCKET_NAME']
|
8
|
+
skip "Supply 'S3_BUCKET_NAME' environment variable with S3 bucket name to test S3 paths"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let :file_name do
|
13
|
+
File.join(File.dirname(__FILE__), '..', 'files', 'text.txt')
|
14
|
+
end
|
15
|
+
|
16
|
+
let :raw do
|
17
|
+
File.read(file_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:root_path) { IOStreams::Paths::S3.new("s3://#{ENV['S3_BUCKET_NAME']}/iostreams_test") }
|
21
|
+
|
22
|
+
let :existing_path do
|
23
|
+
path = root_path.join('test.txt')
|
24
|
+
path.write(raw) unless path.exist?
|
25
|
+
path
|
26
|
+
end
|
27
|
+
|
28
|
+
let :missing_path do
|
29
|
+
root_path.join('unknown.txt')
|
30
|
+
end
|
31
|
+
|
32
|
+
let :write_path do
|
33
|
+
root_path.join('writer_test.txt').delete
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#delete' do
|
37
|
+
it 'existing file' do
|
38
|
+
assert existing_path.delete.is_a?(IOStreams::Paths::S3)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'missing file' do
|
42
|
+
assert missing_path.delete.is_a?(IOStreams::Paths::S3)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#exist?' do
|
47
|
+
it 'existing file' do
|
48
|
+
assert existing_path.exist?
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'missing file' do
|
52
|
+
refute missing_path.exist?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#mkpath' do
|
57
|
+
it 'returns self for non-existant path' do
|
58
|
+
assert existing_path.mkpath.is_a?(IOStreams::Paths::S3)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'checks for lack of existence' do
|
62
|
+
assert missing_path.mkpath.is_a?(IOStreams::Paths::S3)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#mkdir' do
|
67
|
+
it 'returns self for non-existant path' do
|
68
|
+
assert existing_path.mkdir.is_a?(IOStreams::Paths::S3)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'checks for lack of existence' do
|
72
|
+
assert missing_path.mkdir.is_a?(IOStreams::Paths::S3)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#reader' do
|
77
|
+
it 'reads' do
|
78
|
+
assert_equal raw, existing_path.reader { |io| io.read }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#size' do
|
83
|
+
it 'existing file' do
|
84
|
+
assert_equal raw.size, existing_path.size
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'missing file' do
|
88
|
+
assert_nil missing_path.size
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#writer' do
|
93
|
+
it 'writes' do
|
94
|
+
assert_equal raw.size, write_path.writer { |io| io.write(raw) }
|
95
|
+
assert write_path.exist?
|
96
|
+
assert_equal raw, write_path.read
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#each_child' do
|
101
|
+
# TODO: case_sensitive: false, directories: false, hidden: false
|
102
|
+
let(:abd_file_names) { %w[abd/test1.txt abd/test5.file abd/extra/file.csv] }
|
103
|
+
let(:files_for_test) { abd_file_names + %w[xyz/test2.csv xyz/another.csv] }
|
104
|
+
|
105
|
+
let :each_root do
|
106
|
+
root_path.join('each_child_test')
|
107
|
+
end
|
108
|
+
|
109
|
+
let :multiple_paths do
|
110
|
+
files_for_test.collect { |file_name| each_root.join(file_name) }
|
111
|
+
end
|
112
|
+
|
113
|
+
let :write_raw_data do
|
114
|
+
multiple_paths.each { |path| path.write(raw) unless path.exist? }
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'existing file returns just the file itself' do
|
118
|
+
# Glorified exists call
|
119
|
+
assert_equal [each_root.join('readme').to_s], each_root.children("readme").collect(&:to_s)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'missing file does nothing' do
|
123
|
+
# Glorified exists call
|
124
|
+
assert_equal [], missing_path.children("readme").collect(&:to_s)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'returns all the children' do
|
128
|
+
write_raw_data
|
129
|
+
assert_equal multiple_paths.collect(&:to_s).sort, each_root.children("**/*").collect(&:to_s).sort
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'returns all the children under a sub-dir' do
|
133
|
+
write_raw_data
|
134
|
+
expected = abd_file_names.collect { |file_name| each_root.join(file_name) }
|
135
|
+
assert_equal expected.collect(&:to_s).sort, each_root.children("abd/*").collect(&:to_s).sort
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'missing path' do
|
139
|
+
count = 0
|
140
|
+
missing_path.each_child { |_| count += 1 }
|
141
|
+
assert_equal 0, count
|
142
|
+
end
|
143
|
+
|
144
|
+
# Test is here since all the test artifacts have been created already in S3.
|
145
|
+
describe 'IOStreams.each_child' do
|
146
|
+
it 'returns all the children' do
|
147
|
+
write_raw_data
|
148
|
+
children = []
|
149
|
+
IOStreams.each_child(each_root.join("**/*").to_s) { |child| children << child }
|
150
|
+
assert_equal multiple_paths.collect(&:to_s).sort, children.collect(&:to_s).sort
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#move_to' do
|
156
|
+
it 'moves existing file' do
|
157
|
+
source = root_path.join("move_test_source.txt")
|
158
|
+
begin
|
159
|
+
source.write("Hello World")
|
160
|
+
target = source.directory.join("move_test_target.txt")
|
161
|
+
response = source.move_to(target)
|
162
|
+
assert_equal target, response
|
163
|
+
assert target.exist?
|
164
|
+
refute source.exist?
|
165
|
+
assert_equal "Hello World", response.read
|
166
|
+
assert_equal target.to_s, response.to_s
|
167
|
+
ensure
|
168
|
+
source&.delete
|
169
|
+
target&.delete
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'missing source file' do
|
174
|
+
source = root_path.join("move_test_source.txt")
|
175
|
+
refute source.exist?
|
176
|
+
begin
|
177
|
+
target = source.directory.join("move_test_target.txt")
|
178
|
+
assert_raises Aws::S3::Errors::NoSuchKey do
|
179
|
+
source.move_to(target)
|
180
|
+
end
|
181
|
+
refute target.exist?
|
182
|
+
ensure
|
183
|
+
source&.delete
|
184
|
+
target&.delete
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'missing target directories' do
|
189
|
+
source = root_path.join("move_test_source.txt")
|
190
|
+
begin
|
191
|
+
source.write("Hello World")
|
192
|
+
target = source.directory.join("a/b/c/move_test_target.txt")
|
193
|
+
response = source.move_to(target)
|
194
|
+
assert_equal target, response
|
195
|
+
assert target.exist?
|
196
|
+
refute source.exist?
|
197
|
+
assert_equal "Hello World", response.read
|
198
|
+
assert_equal target.to_s, response.to_s
|
199
|
+
ensure
|
200
|
+
source&.delete
|
201
|
+
target&.delete
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
data/test/pgp_reader_test.rb
CHANGED
@@ -15,30 +15,30 @@ class PgpReaderTest < Minitest::Test
|
|
15
15
|
temp_file.delete
|
16
16
|
end
|
17
17
|
|
18
|
-
describe '.
|
18
|
+
describe '.file' do
|
19
19
|
it 'reads encrypted file' do
|
20
|
-
IOStreams::Pgp::Writer.
|
20
|
+
IOStreams::Pgp::Writer.file(temp_file.path, recipient: 'receiver@example.org') do |io|
|
21
21
|
io.write(decrypted)
|
22
22
|
end
|
23
23
|
|
24
|
-
result = IOStreams::Pgp::Reader.
|
24
|
+
result = IOStreams::Pgp::Reader.file(temp_file.path, passphrase: 'receiver_passphrase') { |file| file.read }
|
25
25
|
assert_equal decrypted, result
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'fails with bad passphrase' do
|
29
29
|
assert_raises IOStreams::Pgp::Failure do
|
30
|
-
IOStreams::Pgp::Reader.
|
30
|
+
IOStreams::Pgp::Reader.file(temp_file.path, passphrase: 'BAD') { |file| file.read }
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'streams input' do
|
35
|
-
|
35
|
+
io_string = StringIO.new(''.b)
|
36
|
+
IOStreams::Pgp::Writer.stream(io_string, recipient: 'receiver@example.org', signer: 'sender@example.org', signer_passphrase: 'sender_passphrase') do |io|
|
36
37
|
io.write(decrypted)
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
result = IOStreams::Pgp::Reader.open(io, passphrase: 'receiver_passphrase', &:read)
|
40
|
+
io = StringIO.new(io_string.string)
|
41
|
+
result = IOStreams::Pgp::Reader.stream(io, passphrase: 'receiver_passphrase', &:read)
|
42
42
|
assert_equal decrypted, result
|
43
43
|
end
|
44
44
|
|
data/test/pgp_writer_test.rb
CHANGED
@@ -19,13 +19,13 @@ class PgpWriterTest < Minitest::Test
|
|
19
19
|
temp_file.delete
|
20
20
|
end
|
21
21
|
|
22
|
-
describe '.
|
22
|
+
describe '.file' do
|
23
23
|
it 'writes encrypted text file' do
|
24
|
-
IOStreams::Pgp::Writer.
|
24
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: 'receiver@example.org') do |io|
|
25
25
|
io.write(decrypted)
|
26
26
|
end
|
27
27
|
|
28
|
-
result = IOStreams::Pgp::Reader.
|
28
|
+
result = IOStreams::Pgp::Reader.file(file_name, passphrase: 'receiver_passphrase', &:read)
|
29
29
|
assert_equal decrypted, result
|
30
30
|
end
|
31
31
|
|
@@ -34,28 +34,28 @@ class PgpWriterTest < Minitest::Test
|
|
34
34
|
binary_data = File.open(binary_file_name, 'rb') { |file| file.read }
|
35
35
|
|
36
36
|
File.open(binary_file_name, 'rb') do |input|
|
37
|
-
IOStreams::Pgp::Writer.
|
38
|
-
|
37
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: 'receiver@example.org') do |output|
|
38
|
+
IO.copy_stream(input, output)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
result = IOStreams::Pgp::Reader.
|
42
|
+
result = IOStreams::Pgp::Reader.file(file_name, passphrase: 'receiver_passphrase', &:read)
|
43
43
|
assert_equal binary_data, result
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'writes and signs encrypted file' do
|
47
|
-
IOStreams::Pgp::Writer.
|
47
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: 'receiver@example.org', signer: 'sender@example.org', signer_passphrase: 'sender_passphrase') do |io|
|
48
48
|
io.write(decrypted)
|
49
49
|
end
|
50
50
|
|
51
|
-
result = IOStreams::Pgp::Reader.
|
51
|
+
result = IOStreams::Pgp::Reader.file(file_name, passphrase: 'receiver_passphrase', &:read)
|
52
52
|
assert_equal decrypted, result
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'fails with bad signer passphrase' do
|
56
56
|
skip 'GnuPG v2.1 and above passes when it should not' if IOStreams::Pgp.pgp_version.to_f >= 2.1
|
57
57
|
assert_raises IOStreams::Pgp::Failure do
|
58
|
-
IOStreams::Pgp::Writer.
|
58
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: 'receiver@example.org', signer: 'sender@example.org', signer_passphrase: 'BAD') do |io|
|
59
59
|
io.write(decrypted)
|
60
60
|
end
|
61
61
|
end
|
@@ -63,7 +63,7 @@ class PgpWriterTest < Minitest::Test
|
|
63
63
|
|
64
64
|
it 'fails with bad recipient' do
|
65
65
|
assert_raises IOStreams::Pgp::Failure do
|
66
|
-
IOStreams::Pgp::Writer.
|
66
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: 'BAD@example.org', signer: 'sender@example.org', signer_passphrase: 'sender_passphrase') do |io|
|
67
67
|
io.write(decrypted)
|
68
68
|
# Allow process to terminate
|
69
69
|
sleep 1
|
@@ -74,7 +74,7 @@ class PgpWriterTest < Minitest::Test
|
|
74
74
|
|
75
75
|
it 'fails with bad signer' do
|
76
76
|
assert_raises IOStreams::Pgp::Failure do
|
77
|
-
IOStreams::Pgp::Writer.
|
77
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: 'receiver@example.org', signer: 'BAD@example.org', signer_passphrase: 'sender_passphrase') do |io|
|
78
78
|
io.write(decrypted)
|
79
79
|
end
|
80
80
|
end
|
@@ -82,12 +82,12 @@ class PgpWriterTest < Minitest::Test
|
|
82
82
|
|
83
83
|
it 'writes to a stream' do
|
84
84
|
io_string = StringIO.new(''.b)
|
85
|
-
IOStreams::Pgp::Writer.
|
85
|
+
IOStreams::Pgp::Writer.stream(io_string, recipient: 'receiver@example.org', signer: 'sender@example.org', signer_passphrase: 'sender_passphrase') do |io|
|
86
86
|
io.write(decrypted)
|
87
87
|
end
|
88
88
|
|
89
89
|
io = StringIO.new(io_string.string)
|
90
|
-
result = IOStreams::Pgp::Reader.
|
90
|
+
result = IOStreams::Pgp::Reader.stream(io, passphrase: 'receiver_passphrase', &:read)
|
91
91
|
assert_equal decrypted, result
|
92
92
|
end
|
93
93
|
|