ucf 2.0.2 → 3.0.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/latest-docs.yml +29 -0
  3. data/.github/workflows/lint.yml +19 -0
  4. data/.github/workflows/tests.yml +89 -0
  5. data/.gitignore +3 -0
  6. data/.rubocop.yml +63 -0
  7. data/{test/tc_read_dir.rb → .simplecov} +19 -21
  8. data/{Changes.rdoc → CHANGES.md} +41 -14
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/CONTRIBUTING.md +67 -0
  11. data/Gemfile +4 -2
  12. data/{Licence.rdoc → LICENCE} +1 -1
  13. data/README.md +57 -0
  14. data/Rakefile +21 -18
  15. data/bin/console +15 -0
  16. data/bin/setup +6 -0
  17. data/examples/create-ucf +11 -10
  18. data/examples/ucfinfo +11 -7
  19. data/examples/verify-ucf +5 -3
  20. data/lib/ucf/dir.rb +7 -8
  21. data/lib/ucf/file.rb +7 -8
  22. data/lib/ucf/{meta-inf.rb → meta_inf.rb} +24 -23
  23. data/lib/ucf/version.rb +6 -13
  24. data/lib/ucf.rb +4 -2
  25. data/ucf.gemspec +46 -31
  26. metadata +108 -83
  27. data/.ruby-env +0 -1
  28. data/.ruby-gemset +0 -1
  29. data/.ruby-version +0 -1
  30. data/.travis.yml +0 -19
  31. data/ReadMe.rdoc +0 -90
  32. data/test/data/META-INF/container.xml +0 -13
  33. data/test/data/META-INF/manifest.xml +0 -26
  34. data/test/data/compressed_mimetype.ucf +0 -0
  35. data/test/data/dirs/empty/mimetype +0 -1
  36. data/test/data/dirs/managed/greeting.txt +0 -1
  37. data/test/data/dirs/managed/mimetype +0 -1
  38. data/test/data/dirs/null/.gitkeep +0 -1
  39. data/test/data/empty.ucf +0 -0
  40. data/test/data/empty.zip +0 -0
  41. data/test/data/example.ucf +0 -0
  42. data/test/data/null.file +0 -0
  43. data/test/tc_create_file.rb +0 -142
  44. data/test/tc_managed_entries.rb +0 -238
  45. data/test/tc_read_file.rb +0 -119
  46. data/test/tc_reserved_names.rb +0 -357
  47. data/test/ts_ucf.rb +0 -52
  48. data/version.yml +0 -4
@@ -1,357 +0,0 @@
1
- # Copyright (c) 2013-2015 The University of Manchester, UK.
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- #
11
- # * Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- #
15
- # * Neither the names of The University of Manchester nor the names of its
16
- # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
- # POSSIBILITY OF SUCH DAMAGE.
30
- #
31
- # Author: Robert Haines
32
-
33
- require 'test/unit'
34
- require 'ucf'
35
-
36
- # A class to test the overriding of reserved and managed names.
37
- class NewUCF < UCF::File
38
-
39
- private_class_method :new
40
-
41
- def initialize(filename)
42
- super(filename)
43
- register_managed_entry(ZipContainer::ManagedDirectory.new("src"))
44
- register_managed_entry(ZipContainer::ManagedDirectory.new("test"))
45
- register_managed_entry(ZipContainer::ManagedDirectory.new("lib"))
46
- register_managed_entry(ZipContainer::ManagedFile.new("index.html"))
47
-
48
- register_reserved_name("reserved_dir")
49
- end
50
-
51
- end
52
-
53
- class TestReservedNames < Test::Unit::TestCase
54
-
55
- # Check that the reserved names verify correctly.
56
- def test_verify_reserved_name
57
- assert(NewUCF.verify?($ucf_example))
58
-
59
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
60
- NewUCF.verify!($ucf_example)
61
- end
62
- end
63
-
64
- # Check the reserved names stuff all works correctly, baring in mind that
65
- # such comparisons for UCF documents should be case sensitive.
66
- def test_reserved_names
67
- UCF::File.open($ucf_example) do |ucf|
68
- assert_equal(1, ucf.reserved_names.length)
69
- assert_equal(["mimetype"], ucf.reserved_names)
70
- assert_equal(6, ucf.managed_files.length)
71
- assert_equal(["META-INF/container.xml",
72
- "META-INF/manifest.xml", "META-INF/metadata.xml",
73
- "META-INF/signatures.xml", "META-INF/encryption.xml",
74
- "META-INF/rights.xml"], ucf.managed_file_names)
75
- assert(ucf.reserved_entry?("mimetype"))
76
- assert(ucf.reserved_entry?("mimetype/"))
77
- assert(ucf.reserved_entry?("MimeType"))
78
- assert(ucf.managed_entry?("META-INF/container.xml"))
79
- assert(ucf.managed_entry?("META-INF/manifest.xml"))
80
- assert(ucf.managed_entry?("MeTa-INF/maniFest.XML"))
81
-
82
- assert_equal(1, ucf.managed_directories.length)
83
- assert_equal(["META-INF"], ucf.managed_directory_names)
84
- assert(ucf.managed_entry?("META-INF"))
85
- assert(ucf.managed_entry?("META-INF/"))
86
- assert(ucf.managed_entry?("MeTa-iNf"))
87
- assert(ucf.managed_entry?("MeTa-iNf/"))
88
- refute(ucf.reserved_entry?("META-INF"))
89
-
90
- assert_equal(7, ucf.managed_entries.length)
91
- assert_equal(["META-INF/container.xml",
92
- "META-INF/manifest.xml", "META-INF/metadata.xml",
93
- "META-INF/signatures.xml", "META-INF/encryption.xml",
94
- "META-INF/rights.xml", "META-INF"], ucf.managed_entry_names)
95
-
96
- refute(ucf.managed_entry?("This_should_fail"))
97
- refute(ucf.managed_entry?("META_INF"))
98
- refute(ucf.managed_entry?("META_INF/"))
99
- end
100
- end
101
-
102
- # Check that overriding the reserved names in a sub-class works correctly
103
- def test_subclass_reserved_names
104
- NewUCF.open($ucf_example) do |ucf|
105
- assert_equal(2, ucf.reserved_names.length)
106
- assert_equal(["mimetype", "reserved_dir"], ucf.reserved_names)
107
- assert_equal(7, ucf.managed_files.length)
108
- assert_equal(["index.html", "META-INF/container.xml",
109
- "META-INF/manifest.xml", "META-INF/metadata.xml",
110
- "META-INF/signatures.xml", "META-INF/encryption.xml",
111
- "META-INF/rights.xml"], ucf.managed_file_names)
112
- assert(ucf.reserved_entry?("mimetype"))
113
- assert(ucf.reserved_entry?("mimetype/"))
114
- assert(ucf.reserved_entry?("MimeType"))
115
- assert(ucf.managed_entry?("index.html"))
116
- assert(ucf.managed_entry?("Index.HTML"))
117
- refute(ucf.reserved_entry?("index.html"))
118
-
119
- assert_equal(4, ucf.managed_directories.length)
120
- assert_equal(["META-INF", "src", "test", "lib"],
121
- ucf.managed_directory_names)
122
- assert(ucf.managed_entry?("META-INF"))
123
- assert(ucf.managed_entry?("META-INF/"))
124
- assert(ucf.managed_entry?("MeTa-iNf"))
125
- assert(ucf.managed_entry?("src"))
126
- assert(ucf.managed_entry?("SRC"))
127
- assert(ucf.managed_entry?("test"))
128
- assert(ucf.managed_entry?("lib"))
129
- assert(ucf.managed_entry?("lIb/"))
130
- refute(ucf.reserved_entry?("META-INF"))
131
- refute(ucf.reserved_entry?("src"))
132
- refute(ucf.reserved_entry?("test"))
133
- refute(ucf.reserved_entry?("lib"))
134
-
135
- assert_equal(11, ucf.managed_entries.length)
136
- assert_equal(["index.html", "META-INF/container.xml",
137
- "META-INF/manifest.xml", "META-INF/metadata.xml",
138
- "META-INF/signatures.xml", "META-INF/encryption.xml",
139
- "META-INF/rights.xml", "META-INF", "src", "test", "lib"],
140
- ucf.managed_entry_names)
141
-
142
- refute(ucf.managed_entry?("This_should_fail"))
143
- refute(ucf.managed_entry?("META_INF"))
144
- refute(ucf.managed_entry?("META_INF/"))
145
- refute(ucf.managed_entry?("index.htm"))
146
- end
147
- end
148
-
149
- # Check that nothing happens when trying to delete the mimetype file.
150
- def test_delete_mimetype
151
- UCF::File.open($ucf_example) do |ucf|
152
- assert(ucf.file.exists?("mimetype"))
153
- assert_nil(ucf.remove("mimetype"))
154
- assert(ucf.file.exists?("mimetype"))
155
- end
156
- end
157
-
158
- # Check that nothing happens when trying to rename the mimetype file.
159
- def test_rename_mimetype
160
- UCF::File.open($ucf_example) do |ucf|
161
- assert(ucf.file.exists?("mimetype"))
162
- assert_nil(ucf.rename("mimetype", "something-else"))
163
- assert(ucf.file.exists?("mimetype"))
164
- refute(ucf.file.exists?("something-else"))
165
- end
166
- end
167
-
168
- # Check that nothing happens when trying to replace the contents of the
169
- # mimetype file.
170
- def test_replace_mimetype
171
- UCF::File.open($ucf_example) do |ucf|
172
- assert(ucf.file.exists?("mimetype"))
173
- assert_nil(ucf.replace("mimetype", $zip_empty))
174
- assert_equal("application/epub+zip", ucf.file.read("mimetype"))
175
- end
176
- end
177
-
178
- # Check that an exception is raised when trying to add file with a reserved
179
- # name.
180
- def test_add_reserved
181
- UCF::File.open($ucf_empty) do |ucf|
182
- assert_raises(ZipContainer::ReservedNameClashError) do
183
- ucf.add("META-INF", $zip_empty)
184
- end
185
- end
186
- end
187
-
188
- # Check that an exception is raised when trying to add file with a reserved
189
- # name to a subclassed container.
190
- def test_subclass_add_reserved
191
- NewUCF.open($ucf_empty) do |ucf|
192
- assert_raises(ZipContainer::ReservedNameClashError) do
193
- ucf.add("mimetype", $zip_empty)
194
- end
195
-
196
- assert_raises(ZipContainer::ReservedNameClashError) do
197
- ucf.add("reserved_dir", $zip_empty)
198
- end
199
-
200
- assert_raises(ZipContainer::ReservedNameClashError) do
201
- ucf.add("MimeType", $zip_empty)
202
- end
203
-
204
- assert_raises(ZipContainer::ReservedNameClashError) do
205
- ucf.add("Reserved_Dir", $zip_empty)
206
- end
207
- end
208
- end
209
-
210
- # Check that the META-INF directory is detected as non-existent when trying
211
- # to delete it.
212
- def test_delete_metainf
213
- UCF::File.open($ucf_example) do |ucf|
214
- assert_raises(Errno::ENOENT) do
215
- ucf.remove("META-INF")
216
- end
217
- end
218
- end
219
-
220
- # Check that the META-INF directory is detected as non-existent when trying
221
- # to rename it.
222
- def test_rename_metainf
223
- UCF::File.open($ucf_example) do |ucf|
224
- assert_raises(Errno::ENOENT) do
225
- ucf.rename("META-INF", "something-else")
226
- end
227
- end
228
- end
229
-
230
- # Check that an exception is raised when trying to create a directory with a
231
- # reserved name.
232
- def test_mkdir_reserved
233
- UCF::File.open($ucf_empty) do |ucf|
234
- assert_raises(ZipContainer::ReservedNameClashError) do
235
- ucf.mkdir("mimetype")
236
- end
237
-
238
- assert_raises(ZipContainer::ReservedNameClashError) do
239
- ucf.mkdir("META-INF/container.xml")
240
- end
241
- end
242
- end
243
-
244
- # Check that an exception is raised when trying to create a directory with a
245
- # reserved name in a subclassed container.
246
- def test_subclass_mkdir_reserved
247
- NewUCF.open($ucf_empty) do |ucf|
248
- assert_raises(ZipContainer::ReservedNameClashError) do
249
- ucf.mkdir("mimetype")
250
- end
251
-
252
- assert_raises(ZipContainer::ReservedNameClashError) do
253
- ucf.mkdir("index.html")
254
- end
255
-
256
- assert_raises(ZipContainer::ReservedNameClashError) do
257
- ucf.mkdir("reserved_dir")
258
- end
259
-
260
- assert_raises(ZipContainer::ReservedNameClashError) do
261
- ucf.mkdir("Reserved_Dir")
262
- end
263
-
264
- assert_raises(ZipContainer::ReservedNameClashError) do
265
- ucf.mkdir("META-INF/container.xml")
266
- end
267
- end
268
- end
269
-
270
- # Check that a file cannot be renamed to one of the reserved names.
271
- def test_rename_to_reserved
272
- UCF::File.open($ucf_example) do |ucf|
273
- assert_raises(ZipContainer::ReservedNameClashError) do
274
- ucf.rename("dir/code.rb", "mimetype")
275
- end
276
- end
277
- end
278
-
279
- # Check that a file cannot be renamed to one of the reserved names in a
280
- # subclassed container.
281
- def test_subclass_rename_to_reserved
282
- NewUCF.open($ucf_example) do |ucf|
283
- assert_raises(ZipContainer::ReservedNameClashError) do
284
- ucf.rename("dir/code.rb", "mimetype")
285
- end
286
-
287
- assert_raises(ZipContainer::ReservedNameClashError) do
288
- ucf.rename("dir", "reserved_dir")
289
- end
290
- end
291
- end
292
-
293
- # Check that the ruby-like File and Dir classes respect reserved and managed
294
- # names.
295
- def test_file_dir_ops_reserved
296
- UCF::File.open($ucf_empty) do |ucf|
297
- assert_raises(ZipContainer::ReservedNameClashError) do
298
- ucf.file.open("META-INF", "w") do |f|
299
- f.puts "TESTING"
300
- end
301
- end
302
-
303
- assert_nothing_raised(ZipContainer::ReservedNameClashError) do
304
- ucf.file.open("mimetype") do |f|
305
- assert_equal("application/epub+zip", f.read)
306
- end
307
- end
308
-
309
- assert_nothing_raised(ZipContainer::ReservedNameClashError) do
310
- ucf.file.delete("mimetype")
311
- assert(ucf.file.exists?("mimetype"))
312
- end
313
- end
314
- end
315
-
316
- # Check that the ruby-like File and Dir classes respect reserved names in a
317
- # subclassed container.
318
- def test_subclass_file_dir_ops_reserved
319
- NewUCF.open($ucf_empty) do |ucf|
320
- assert_raises(ZipContainer::ReservedNameClashError) do
321
- ucf.file.open("META-INF", "w") do |f|
322
- f.puts "TESTING"
323
- end
324
- end
325
-
326
- assert_raises(ZipContainer::ReservedNameClashError) do
327
- ucf.file.open("TEST", "w") do |f|
328
- f.puts "TESTING"
329
- end
330
- end
331
-
332
- assert_nothing_raised(ZipContainer::ReservedNameClashError) do
333
- ucf.file.open("mimetype") do |f|
334
- assert_equal("application/epub+zip", f.read)
335
- end
336
- end
337
-
338
- assert_nothing_raised(ZipContainer::ReservedNameClashError) do
339
- ucf.file.delete("mimetype")
340
- assert(ucf.file.exists?("mimetype"))
341
- end
342
-
343
- assert_raises(ZipContainer::ReservedNameClashError) do
344
- ucf.dir.mkdir("index.html")
345
- end
346
-
347
- assert_raises(ZipContainer::ReservedNameClashError) do
348
- ucf.dir.mkdir("reserved_dir")
349
- end
350
-
351
- assert_raises(ZipContainer::ReservedNameClashError) do
352
- ucf.dir.mkdir("Reserved_Dir")
353
- end
354
- end
355
- end
356
-
357
- end
data/test/ts_ucf.rb DELETED
@@ -1,52 +0,0 @@
1
- # Copyright (c) 2013, 2014 The University of Manchester, UK.
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- #
11
- # * Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- #
15
- # * Neither the names of The University of Manchester nor the names of its
16
- # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
- # POSSIBILITY OF SUCH DAMAGE.
30
- #
31
- # Author: Robert Haines
32
-
33
- require "coveralls"
34
- Coveralls.wear!
35
-
36
- # Example data files and directories.
37
- $dir_null = "test/data/dirs/null"
38
- $dir_empty = "test/data/dirs/empty"
39
- $dir_mngd = "test/data/dirs/managed"
40
- $file_null = "test/data/null.file"
41
- $ucf_empty = "test/data/empty.ucf"
42
- $zip_empty = "test/data/empty.zip"
43
- $ucf_compressed_mimetype = "test/data/compressed_mimetype.ucf"
44
- $ucf_example = "test/data/example.ucf"
45
- $meta_inf_dir = "test/data/META-INF"
46
-
47
- # Run test cases.
48
- require 'tc_create_file'
49
- require 'tc_read_dir'
50
- require 'tc_read_file'
51
- require 'tc_reserved_names'
52
- require 'tc_managed_entries'
data/version.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- :major: 2
3
- :minor: 0
4
- :patch: 2