mini_portile2 2.8.2 → 2.8.9
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/.github/workflows/ci.yml +101 -7
- data/.github/workflows/downstream.yml +66 -0
- data/.github/workflows/upstream.yml +39 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +66 -0
- data/Gemfile +15 -3
- data/README.md +29 -7
- data/Rakefile +3 -5
- data/lib/mini_portile2/mini_portile.rb +244 -67
- data/lib/mini_portile2/mini_portile_cmake.rb +75 -7
- data/lib/mini_portile2/version.rb +1 -1
- data/mini_portile2.gemspec +8 -12
- data/test/assets/pkgconf/libxml2/libxml-2.0.pc +13 -0
- data/test/assets/pkgconf/libxslt/libexslt.pc +13 -0
- data/test/assets/pkgconf/libxslt/libxslt.pc +13 -0
- data/test/assets/test-cmake-1.0/CMakeLists.txt +1 -1
- data/test/helper.rb +12 -1
- data/test/test_activate.rb +139 -0
- data/test/test_cmake.rb +184 -8
- data/test/test_cook.rb +30 -1
- data/test/test_digest.rb +75 -77
- data/test/test_download.rb +5 -4
- data/test/test_execute.rb +4 -3
- data/test/test_mkmf_config.rb +202 -0
- data/test/test_proxy.rb +7 -6
- data/test/test_recipe.rb +18 -0
- metadata +25 -96
@@ -0,0 +1,139 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class TestActivate < TestCase
|
4
|
+
attr_reader :recipe
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@save_env = %w[PATH CPATH LIBRARY_PATH LDFLAGS].inject({}) do |env, var|
|
10
|
+
env.update(var => ENV[var])
|
11
|
+
end
|
12
|
+
|
13
|
+
FileUtils.rm_rf(["tmp", "ports"]) # remove any previous test files
|
14
|
+
|
15
|
+
@recipe = MiniPortile.new("foo", "1.0.0").tap do |recipe|
|
16
|
+
recipe.logger = StringIO.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
FileUtils.rm_rf(["tmp", "ports"]) # remove any previous test files
|
22
|
+
|
23
|
+
@save_env.each do |var, val|
|
24
|
+
ENV[var] = val
|
25
|
+
end
|
26
|
+
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_PATH_env_var_when_bin_does_not_exist
|
31
|
+
ENV["PATH"] = "foo"
|
32
|
+
refute(Dir.exist?(bin_path))
|
33
|
+
refute_includes(path_elements('PATH'), bin_path)
|
34
|
+
|
35
|
+
recipe.activate
|
36
|
+
|
37
|
+
refute_includes(path_elements('PATH'), bin_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_PATH_env_var_when_bin_exists
|
41
|
+
ENV["PATH"] = "foo"
|
42
|
+
FileUtils.mkdir_p(bin_path)
|
43
|
+
refute_includes(path_elements('PATH'), bin_path)
|
44
|
+
|
45
|
+
recipe.activate
|
46
|
+
|
47
|
+
assert_includes(path_elements('PATH'), bin_path)
|
48
|
+
assert_equal(path_elements('PATH').first, bin_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_CPATH_env_var_when_include_does_not_exist
|
52
|
+
ENV["CPATH"] = "foo"
|
53
|
+
refute(Dir.exist?(include_path))
|
54
|
+
refute_includes(path_elements('CPATH'), include_path)
|
55
|
+
|
56
|
+
recipe.activate
|
57
|
+
|
58
|
+
refute_includes(path_elements('CPATH'), include_path)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_CPATH_env_var_when_include_exists
|
62
|
+
ENV["CPATH"] = "foo"
|
63
|
+
FileUtils.mkdir_p(include_path)
|
64
|
+
refute_includes(path_elements('CPATH'), include_path)
|
65
|
+
|
66
|
+
recipe.activate
|
67
|
+
|
68
|
+
assert_includes(path_elements('CPATH'), include_path)
|
69
|
+
assert_equal(path_elements('CPATH').first, include_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_LIBRARY_PATH_env_var_when_lib_does_not_exist
|
73
|
+
ENV["LIBRARY_PATH"] = "foo"
|
74
|
+
refute(Dir.exist?(lib_path))
|
75
|
+
refute_includes(path_elements('LIBRARY_PATH'), lib_path)
|
76
|
+
|
77
|
+
recipe.activate
|
78
|
+
|
79
|
+
refute_includes(path_elements('LIBRARY_PATH'), lib_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_LIBRARY_PATH_env_var_when_lib_exists
|
83
|
+
ENV["LIBRARY_PATH"] = "foo"
|
84
|
+
FileUtils.mkdir_p(lib_path)
|
85
|
+
refute_includes(path_elements('LIBRARY_PATH'), lib_path)
|
86
|
+
|
87
|
+
recipe.activate
|
88
|
+
|
89
|
+
assert_includes(path_elements('LIBRARY_PATH'), lib_path)
|
90
|
+
assert_equal(path_elements('LIBRARY_PATH').first, lib_path)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_LDFLAGS_env_var_when_not_cross_compiling
|
94
|
+
ENV["LDFLAGS"] = "-lfoo"
|
95
|
+
FileUtils.mkdir_p(lib_path)
|
96
|
+
assert_equal(recipe.host, recipe.original_host) # assert on setup)
|
97
|
+
|
98
|
+
refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
|
99
|
+
|
100
|
+
recipe.activate
|
101
|
+
|
102
|
+
refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_LDFLAGS_env_var_when_cross_compiling
|
106
|
+
ENV["LDFLAGS"] = "-lfoo"
|
107
|
+
recipe.host = recipe.original_host + "-x" # make them not-equal
|
108
|
+
FileUtils.mkdir_p(lib_path)
|
109
|
+
|
110
|
+
refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
|
111
|
+
|
112
|
+
recipe.activate
|
113
|
+
|
114
|
+
assert_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")
|
115
|
+
assert_equal(flag_elements('LDFLAGS').first, "-L#{lib_path}")
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def path_elements(varname)
|
121
|
+
ENV.fetch(varname, "").split(File::PATH_SEPARATOR)
|
122
|
+
end
|
123
|
+
|
124
|
+
def flag_elements(varname)
|
125
|
+
ENV.fetch(varname, "").split
|
126
|
+
end
|
127
|
+
|
128
|
+
def bin_path
|
129
|
+
MiniPortile.native_path(File.join(recipe.path, "bin"))
|
130
|
+
end
|
131
|
+
|
132
|
+
def include_path
|
133
|
+
MiniPortile.native_path(File.join(recipe.path, "include"))
|
134
|
+
end
|
135
|
+
|
136
|
+
def lib_path
|
137
|
+
MiniPortile.native_path(File.join(recipe.path, "lib"))
|
138
|
+
end
|
139
|
+
end
|
data/test/test_cmake.rb
CHANGED
@@ -14,14 +14,16 @@ class TestCMake < TestCase
|
|
14
14
|
create_tar(@tar_path, @assets_path, "test-cmake-1.0")
|
15
15
|
start_webrick(File.dirname(@tar_path))
|
16
16
|
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
17
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
18
|
+
@recipe = init_recipe
|
19
|
+
|
20
|
+
git_dir = File.join(@assets_path, "git")
|
21
|
+
with_custom_git_dir(git_dir) do
|
22
|
+
recipe.cook
|
24
23
|
end
|
24
|
+
rescue => e
|
25
|
+
puts @logger.string
|
26
|
+
raise e
|
25
27
|
end
|
26
28
|
|
27
29
|
def after_all
|
@@ -57,9 +59,17 @@ class TestCMake < TestCase
|
|
57
59
|
binary = File.join(recipe.path, "bin", exe_name)
|
58
60
|
assert File.exist?(binary), binary
|
59
61
|
end
|
62
|
+
|
63
|
+
def init_recipe
|
64
|
+
MiniPortileCMake.new("test-cmake", "1.0").tap do |recipe|
|
65
|
+
recipe.logger = @logger
|
66
|
+
recipe.files << "http://localhost:#{HTTP_PORT}/#{ERB::Util.url_encode(File.basename(@tar_path))}"
|
67
|
+
recipe.patch_files << File.join(@assets_path, "patch 1.diff")
|
68
|
+
end
|
69
|
+
end
|
60
70
|
end
|
61
71
|
|
62
|
-
class TestCMakeConfig <
|
72
|
+
class TestCMakeConfig < TestCMake
|
63
73
|
def test_make_command_configuration
|
64
74
|
MiniPortile.stub(:mswin?, false) do
|
65
75
|
without_env("MAKE") do
|
@@ -77,6 +87,119 @@ class TestCMakeConfig < TestCase
|
|
77
87
|
end
|
78
88
|
end
|
79
89
|
|
90
|
+
def test_configure_defaults_with_macos
|
91
|
+
with_env({ "CC" => nil, "CXX" => nil }) do
|
92
|
+
MiniPortile.stub(:darwin?, true) do
|
93
|
+
with_stubbed_target(os: 'darwin22', cpu: 'arm64') do
|
94
|
+
with_compilers(c_compiler: 'clang', cxx_compiler: 'clang++') do
|
95
|
+
Open3.stub(:capture2, cmake_help_mock('Unix')) do
|
96
|
+
assert_equal(
|
97
|
+
[
|
98
|
+
"-DCMAKE_SYSTEM_NAME=Darwin",
|
99
|
+
"-DCMAKE_SYSTEM_PROCESSOR=arm64",
|
100
|
+
"-DCMAKE_C_COMPILER=clang",
|
101
|
+
"-DCMAKE_CXX_COMPILER=clang++",
|
102
|
+
"-DCMAKE_BUILD_TYPE=Release"
|
103
|
+
],
|
104
|
+
@recipe.configure_defaults)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_configure_defaults_with_freebsd
|
113
|
+
with_env({ "CC" => nil, "CXX" => nil }) do
|
114
|
+
with_stubbed_target(os: 'freebsd14') do
|
115
|
+
with_compilers(c_compiler: 'cc', cxx_compiler: 'c++') do
|
116
|
+
Open3.stub(:capture2, cmake_help_mock('Unix')) do
|
117
|
+
assert_equal(
|
118
|
+
[
|
119
|
+
"-DCMAKE_SYSTEM_NAME=FreeBSD",
|
120
|
+
"-DCMAKE_SYSTEM_PROCESSOR=x86_64",
|
121
|
+
"-DCMAKE_C_COMPILER=cc",
|
122
|
+
"-DCMAKE_CXX_COMPILER=c++",
|
123
|
+
"-DCMAKE_BUILD_TYPE=Release"
|
124
|
+
],
|
125
|
+
@recipe.configure_defaults)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_configure_defaults_with_manual_system_name
|
133
|
+
MiniPortile.stub(:darwin?, false) do
|
134
|
+
with_stubbed_target do
|
135
|
+
with_compilers do
|
136
|
+
Open3.stub(:capture2, cmake_help_mock('Unix')) do
|
137
|
+
@recipe.stub(:system_name, 'Custom') do
|
138
|
+
assert_equal(
|
139
|
+
[
|
140
|
+
"-DCMAKE_SYSTEM_NAME=Custom",
|
141
|
+
"-DCMAKE_SYSTEM_PROCESSOR=x86_64",
|
142
|
+
"-DCMAKE_C_COMPILER=gcc",
|
143
|
+
"-DCMAKE_CXX_COMPILER=g++",
|
144
|
+
"-DCMAKE_BUILD_TYPE=Release"
|
145
|
+
],
|
146
|
+
@recipe.configure_defaults)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_configure_defaults_with_unix_makefiles
|
155
|
+
MiniPortile.stub(:linux?, true) do
|
156
|
+
MiniPortile.stub(:darwin?, false) do
|
157
|
+
with_stubbed_target do
|
158
|
+
with_compilers do
|
159
|
+
Open3.stub(:capture2, cmake_help_mock('Unix')) do
|
160
|
+
MiniPortile.stub(:mingw?, true) do
|
161
|
+
assert_equal(default_x86_compile_flags,
|
162
|
+
@recipe.configure_defaults)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_configure_defaults_with_msys_makefiles
|
172
|
+
MiniPortile.stub(:linux?, true) do
|
173
|
+
MiniPortile.stub(:darwin?, false) do
|
174
|
+
with_stubbed_target do
|
175
|
+
with_compilers do
|
176
|
+
Open3.stub(:capture2, cmake_help_mock('MSYS')) do
|
177
|
+
MiniPortile.stub(:mingw?, true) do
|
178
|
+
assert_equal(['-G', 'MSYS Makefiles'] + default_x86_compile_flags, @recipe.configure_defaults)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_configure_defaults_with_nmake_makefiles
|
188
|
+
MiniPortile.stub(:linux?, true) do
|
189
|
+
MiniPortile.stub(:darwin?, false) do
|
190
|
+
with_stubbed_target do
|
191
|
+
with_compilers do
|
192
|
+
Open3.stub(:capture2, cmake_help_mock('NMake')) do
|
193
|
+
MiniPortile.stub(:mswin?, true) do
|
194
|
+
assert_equal(['-G', 'NMake Makefiles'] + default_x86_compile_flags, @recipe.configure_defaults)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
80
203
|
def test_cmake_command_configuration
|
81
204
|
without_env("CMAKE") do
|
82
205
|
assert_equal("cmake", MiniPortileCMake.new("test", "1.0.0").cmake_cmd)
|
@@ -87,4 +210,57 @@ class TestCMakeConfig < TestCase
|
|
87
210
|
assert_equal("asdf", MiniPortileCMake.new("test", "1.0.0", cmake_command: "xyzzy").cmake_cmd)
|
88
211
|
end
|
89
212
|
end
|
213
|
+
|
214
|
+
def test_cmake_build_type_configuration
|
215
|
+
without_env("CMAKE_BUILD_TYPE") do
|
216
|
+
assert_equal("Release", MiniPortileCMake.new("test", "1.0.0").cmake_build_type)
|
217
|
+
assert_equal("xyzzy", MiniPortileCMake.new("test", "1.0.0", cmake_build_type: "xyzzy").cmake_build_type)
|
218
|
+
end
|
219
|
+
with_env("CMAKE_BUILD_TYPE"=>"Debug") do
|
220
|
+
assert_equal("Debug", MiniPortileCMake.new("test", "1.0.0").cmake_build_type)
|
221
|
+
assert_equal("Debug", MiniPortileCMake.new("test", "1.0.0", cmake_build_type: "xyzzy").cmake_build_type)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
private
|
226
|
+
|
227
|
+
def with_stubbed_target(os: 'linux', cpu: 'x86_64')
|
228
|
+
MiniPortile.stub(:target_os, os) do
|
229
|
+
MiniPortile.stub(:target_cpu, cpu) do
|
230
|
+
yield
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def with_compilers(c_compiler: 'gcc', cxx_compiler: 'g++')
|
236
|
+
@recipe.stub(:cc_cmd, c_compiler) do
|
237
|
+
@recipe.stub(:cxx_cmd, cxx_compiler) do
|
238
|
+
yield
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def default_x86_compile_flags
|
244
|
+
[
|
245
|
+
"-DCMAKE_SYSTEM_NAME=Linux",
|
246
|
+
"-DCMAKE_SYSTEM_PROCESSOR=x86_64",
|
247
|
+
"-DCMAKE_C_COMPILER=gcc",
|
248
|
+
"-DCMAKE_CXX_COMPILER=g++",
|
249
|
+
"-DCMAKE_BUILD_TYPE=Release"
|
250
|
+
]
|
251
|
+
end
|
252
|
+
|
253
|
+
def cmake_help_mock(generator_type)
|
254
|
+
open3_mock = MiniTest::Mock.new
|
255
|
+
cmake_script = <<~SCRIPT
|
256
|
+
echo "The following generators are available on this platform (* marks default):"
|
257
|
+
echo "* #{generator_type} Makefiles = Generates standard #{generator_type.upcase} makefiles."
|
258
|
+
SCRIPT
|
259
|
+
|
260
|
+
exit_status = MiniTest::Mock.new
|
261
|
+
exit_status.expect(:success?, true)
|
262
|
+
expected_output = [cmake_script, exit_status]
|
263
|
+
open3_mock.expect(:call, expected_output, ['cmake --help'])
|
264
|
+
open3_mock
|
265
|
+
end
|
90
266
|
end
|
data/test/test_cook.rb
CHANGED
@@ -13,7 +13,9 @@ class TestCook < TestCase
|
|
13
13
|
create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")
|
14
14
|
start_webrick(File.dirname(@tar_path))
|
15
15
|
|
16
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
16
17
|
@recipe = MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
|
18
|
+
recipe.logger = @logger
|
17
19
|
recipe.files << "http://localhost:#{HTTP_PORT}/#{ERB::Util.url_encode(File.basename(@tar_path))}"
|
18
20
|
recipe.patch_files << File.join(@assets_path, "patch 1.diff")
|
19
21
|
recipe.configure_options << "--option=\"path with 'space'\""
|
@@ -22,6 +24,9 @@ class TestCook < TestCase
|
|
22
24
|
recipe.cook
|
23
25
|
end
|
24
26
|
end
|
27
|
+
rescue => e
|
28
|
+
puts @logger.string
|
29
|
+
raise e
|
25
30
|
end
|
26
31
|
|
27
32
|
def after_all
|
@@ -79,17 +84,37 @@ class TestCookConfiguration < TestCase
|
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
82
|
-
def
|
87
|
+
def test_cc_command_configuration
|
83
88
|
without_env("CC") do
|
84
89
|
expected_compiler = RbConfig::CONFIG["CC"] || "gcc"
|
90
|
+
assert_equal(expected_compiler, MiniPortile.new("test", "1.0.0").cc_cmd)
|
85
91
|
assert_equal(expected_compiler, MiniPortile.new("test", "1.0.0").gcc_cmd)
|
92
|
+
assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").cc_cmd)
|
93
|
+
assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").cc_cmd)
|
94
|
+
assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").gcc_cmd)
|
86
95
|
assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").gcc_cmd)
|
87
96
|
end
|
88
97
|
with_env("CC"=>"asdf") do
|
98
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0").cc_cmd)
|
89
99
|
assert_equal("asdf", MiniPortile.new("test", "1.0.0").gcc_cmd)
|
100
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").cc_cmd)
|
101
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").cc_cmd)
|
102
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").gcc_cmd)
|
90
103
|
assert_equal("asdf", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").gcc_cmd)
|
91
104
|
end
|
92
105
|
end
|
106
|
+
|
107
|
+
def test_cxx_command_configuration
|
108
|
+
without_env("CXX") do
|
109
|
+
expected_compiler = RbConfig::CONFIG["CXX"] || "g++"
|
110
|
+
assert_equal(expected_compiler, MiniPortile.new("test", "1.0.0").cxx_cmd)
|
111
|
+
assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", cxx_command: "xyzzy").cxx_cmd)
|
112
|
+
end
|
113
|
+
with_env("CXX"=>"asdf") do
|
114
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0").cxx_cmd)
|
115
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0", cxx_command: "xyzzy").cxx_cmd)
|
116
|
+
end
|
117
|
+
end
|
93
118
|
end
|
94
119
|
|
95
120
|
|
@@ -116,7 +141,9 @@ class TestCookWithBrokenGitDir < TestCase
|
|
116
141
|
|
117
142
|
create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")
|
118
143
|
|
144
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
119
145
|
@recipe = MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
|
146
|
+
recipe.logger = @logger
|
120
147
|
recipe.files << "file://#{@tar_path}"
|
121
148
|
recipe.patch_files << File.join(@assets_path, "patch 1.diff")
|
122
149
|
recipe.configure_options << "--option=\"path with 'space'\""
|
@@ -146,7 +173,9 @@ class TestCookAgainstSourceDirectory < TestCase
|
|
146
173
|
def setup
|
147
174
|
super
|
148
175
|
|
176
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
149
177
|
@recipe ||= MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
|
178
|
+
recipe.logger = @logger
|
150
179
|
recipe.source_directory = File.expand_path("../assets/test mini portile-1.0.0", __FILE__)
|
151
180
|
end
|
152
181
|
end
|
data/test/test_digest.rb
CHANGED
@@ -24,7 +24,8 @@ class TestDigest < TestCase
|
|
24
24
|
def setup
|
25
25
|
super
|
26
26
|
FileUtils.rm_rf("ports/archives")
|
27
|
-
@
|
27
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
28
|
+
@recipe = MiniPortile.new("test-digest", "1.0.0", logger: @logger)
|
28
29
|
end
|
29
30
|
|
30
31
|
def download_with_digest(key, klass)
|
@@ -68,28 +69,28 @@ class TestDigest < TestCase
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def public_key
|
71
|
-
|
72
|
-
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
73
|
-
Version: GnuPG v1
|
74
|
-
|
75
|
-
mI0EVwUhJQEEAMYxFhgaAdM2Ul5r+XfpqAaI7SOxB14eRjhFjhchy4ylgVxetyLq
|
76
|
-
di3zeANXBIHsLBl7quYTlnmhJr/+GQRkCnXWiUp0tJsBVzGM3puK7c534gakEUH6
|
77
|
-
AlDtj5p3IeygzSyn8u7KORv+ainXfhwkvTO04mJmxAb2uT8ngKYFdPa1ABEBAAG0
|
78
|
-
J1Rlc3QgTWluaXBvcnRpbGUgPHRlc3RAbWluaXBvcnRpbGUub3JnPoi4BBMBAgAi
|
79
|
-
BQJXBSElAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRBl6D5JZMNwswAK
|
80
|
-
A/90Cdb+PX21weBR2Q6uR06M/alPexuXXyJL8ZcwbQMJ/pBBgcS5/h1+rQkBI/CN
|
81
|
-
qpXdDlw2Xys2k0sNwdjIw3hmYRzBrddXlCSW3Sifq/hS+kfPZ1snQmIjCgy1Xky5
|
82
|
-
QGCcPUxBUxzmra88LakkDO+euKK3hcrfeFIi611lTum1NLiNBFcFISUBBADoyY6z
|
83
|
-
2PwH3RWUbqv0VX1s3/JO3v3xMjCRKPlFwsNwLTBtZoWfR6Ao1ajeCuZKfzNKIQ2I
|
84
|
-
rn86Rcqyrq4hTj+7BTWjkIPOBthjiL1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+
2PwH3RWUbqv0VX1s3/JO3v3xMjCRKPlFwsNwLTBtZoWfR6Ao1ajeCuZKfzNKIQ2I
|
85
|
+
rn86Rcqyrq4hTj+7BTWjkIPOBthjiL1YqbEBtX7jcYRkYvdQz/IG2F4zVV6X4AAR
|
86
|
+
Twx7qaXNt67ArzbHCe5gLNRUK6e6OArkahMv7QARAQABiJ8EGAECAAkFAlcFISUC
|
87
|
+
GwwACgkQZeg+SWTDcLNFiwP/TR33ClqWOz0mpjt0xPEoZ0ORmV6fo4sjjzgQoHH/
|
88
|
+
KTdsabJbGp8oLQGW/mx3OxgbsAkyZymb5H5cjaF4HtSd4cxI5t1C9ZS/ytN8pqfR
|
89
|
+
e29SBje8DAAJn2l57s2OddXLPQ0DUwCcdNEaqgHwSk/Swxc7K+IpfvjLKHKUZZBP
|
90
|
+
4Ko=
|
91
|
+
=SVWi
|
92
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
93
|
+
KEY
|
93
94
|
end
|
94
95
|
|
95
96
|
def test_with_valid_gpg_signature
|
@@ -130,7 +131,7 @@ KEY
|
|
130
131
|
exception = assert_raises(RuntimeError){
|
131
132
|
@recipe.download
|
132
133
|
}
|
133
|
-
|
134
|
+
assert_includes(exception.message, "signature mismatch")
|
134
135
|
end
|
135
136
|
|
136
137
|
def test_with_invalid_key
|
@@ -144,60 +145,58 @@ KEY
|
|
144
145
|
}
|
145
146
|
}
|
146
147
|
exception = assert_raises(RuntimeError){ @recipe.download }
|
147
|
-
|
148
|
+
assert_includes(exception.message, "invalid gpg key provided")
|
148
149
|
end
|
149
150
|
|
150
151
|
def test_with_different_key_than_one_used_to_sign
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
/
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
+
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
-----END PGP PUBLIC KEY BLOCK-----
|
200
|
-
KEY
|
152
|
+
key = <<~KEY
|
153
|
+
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
154
|
+
Version: GnuPG v1
|
155
|
+
|
156
|
+
mQENBE7SKu8BCADQo6x4ZQfAcPlJMLmL8zBEBUS6GyKMMMDtrTh3Yaq481HB54oR
|
157
|
+
0cpKL05Ff9upjrIzLD5TJUCzYYM9GQOhguDUP8+ZU9JpSz3yO2TvH7WBbUZ8FADf
|
158
|
+
hblmmUBLNgOWgLo3W+FYhl3mz1GFS2Fvid6Tfn02L8CBAj7jxbjL1Qj/OA/WmLLc
|
159
|
+
m6BMTqI7IBlYW2vyIOIHasISGiAwZfp0ucMeXXvTtt14LGa8qXVcFnJTdwbf03AS
|
160
|
+
ljhYrQnKnpl3VpDAoQt8C68YCwjaNJW59hKqWB+XeIJ9CW98+EOAxLAFszSyGanp
|
161
|
+
rCqPd0numj9TIddjcRkTA/ZbmCWK+xjpVBGXABEBAAG0IU1heGltIERvdW5pbiA8
|
162
|
+
bWRvdW5pbkBtZG91bmluLnJ1PohGBBARAgAGBQJO01Y/AAoJEOzw6QssFyCDVyQA
|
163
|
+
n3qwTZlcZgyyzWu9Cs8gJ0CXREaSAJ92QjGLT9DijTcbB+q9OS/nl16Z/IhGBBAR
|
164
|
+
AgAGBQJO02JDAAoJEKk3YTmlJMU+P64AnjCKEXFelSVMtgefJk3+vpyt3QX1AKCH
|
165
|
+
9M3MbTWPeDUL+MpULlfdyfvjj4heBBARCAAGBQJRCTwgAAoJEFGFCWhsfl6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+
7yuff0n5+ytEt2KL51gOQE2uIxTCawHr12PsllPkbqPk/PagIttfEJqn9b0CrqPC
|
196
|
+
3HREePb2aMJ/Ctw/76COwn0mtXeIXLCTvBmznXfaMKllsqbsy2nCJ2P2uJjOntw=
|
197
|
+
=4JAR
|
198
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
199
|
+
KEY
|
201
200
|
|
202
201
|
data_file = File.expand_path(File.join(File.dirname(__FILE__), 'assets', 'gpg-fixtures', 'data'))
|
203
202
|
|
@@ -209,7 +208,6 @@ KEY
|
|
209
208
|
}
|
210
209
|
}
|
211
210
|
exception = assert_raises(RuntimeError){ @recipe.download }
|
212
|
-
|
211
|
+
assert_includes(exception.message, "signature mismatch")
|
213
212
|
end
|
214
213
|
end
|
215
|
-
|
data/test/test_download.rb
CHANGED
@@ -25,12 +25,13 @@ describe "recipe download" do
|
|
25
25
|
server.close
|
26
26
|
end
|
27
27
|
|
28
|
-
request_count
|
28
|
+
assert_operator(request_count, :>, 0)
|
29
29
|
end
|
30
30
|
|
31
31
|
before do
|
32
32
|
@request_count = 0
|
33
|
-
@
|
33
|
+
@logger = StringIO.new
|
34
|
+
@recipe = MiniPortile.new("test-download", "1.1.1", logger: @logger)
|
34
35
|
end
|
35
36
|
|
36
37
|
describe "urls" do
|
@@ -62,12 +63,12 @@ describe "recipe download" do
|
|
62
63
|
@recipe.files << "file://#{path}"
|
63
64
|
@recipe.download
|
64
65
|
assert File.exist?(dest)
|
65
|
-
Digest::MD5.file(dest).hexdigest
|
66
|
+
assert_equal("ee0e9f44e72213015ef976d5ac23931d", Digest::MD5.file(dest).hexdigest)
|
66
67
|
end
|
67
68
|
|
68
69
|
it "other" do
|
69
70
|
@recipe.files << "foo://foo"
|
70
|
-
|
71
|
+
assert_raises(ArgumentError) { @recipe.download }
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|