mini_portile2 2.1.0 → 2.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +2 -0
- data/.github/workflows/ci.yml +163 -0
- data/.github/workflows/downstream.yml +66 -0
- data/.gitignore +4 -3
- data/CHANGELOG.md +166 -0
- data/Gemfile +2 -0
- data/README.md +164 -9
- data/Rakefile +4 -6
- data/SECURITY.md +13 -0
- data/lib/mini_portile2/mini_portile.rb +384 -96
- data/lib/mini_portile2/mini_portile_cmake.rb +119 -0
- data/lib/mini_portile2/version.rb +1 -1
- data/lib/mini_portile2.rb +1 -0
- data/mini_portile2.gemspec +28 -22
- data/test/assets/gpg-fixtures/data +1 -0
- data/test/assets/gpg-fixtures/data.asc +9 -0
- data/test/assets/gpg-fixtures/data.invalid.asc +9 -0
- 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 +7 -0
- data/test/assets/test-cmake-1.0/hello.c +4 -0
- data/test/assets/test-download-archive.tar.gz +0 -0
- data/test/helper.rb +38 -3
- data/test/test_activate.rb +139 -0
- data/test/test_cmake.rb +266 -0
- data/test/test_cook.rb +134 -12
- data/test/test_digest.rb +147 -3
- data/test/test_download.rb +22 -19
- data/test/test_execute.rb +40 -0
- data/test/test_mkmf_config.rb +202 -0
- data/test/test_proxy.rb +9 -8
- data/test/test_recipe.rb +18 -0
- metadata +70 -27
- data/.travis.yml +0 -11
- data/appveyor.yml +0 -24
data/test/test_cmake.rb
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class TestCMake < TestCase
|
4
|
+
attr_accessor :assets_path, :tar_path, :recipe
|
5
|
+
|
6
|
+
def before_all
|
7
|
+
super
|
8
|
+
@assets_path = File.expand_path("../assets", __FILE__)
|
9
|
+
@tar_path = File.expand_path("../../tmp/test-cmake-1.0.tar.gz", __FILE__)
|
10
|
+
|
11
|
+
# remove any previous test files
|
12
|
+
FileUtils.rm_rf("tmp")
|
13
|
+
|
14
|
+
create_tar(@tar_path, @assets_path, "test-cmake-1.0")
|
15
|
+
start_webrick(File.dirname(@tar_path))
|
16
|
+
|
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
|
23
|
+
end
|
24
|
+
rescue => e
|
25
|
+
puts @logger.string
|
26
|
+
raise e
|
27
|
+
end
|
28
|
+
|
29
|
+
def after_all
|
30
|
+
super
|
31
|
+
stop_webrick
|
32
|
+
# leave test files for inspection
|
33
|
+
end
|
34
|
+
|
35
|
+
def exe_name
|
36
|
+
case
|
37
|
+
when MiniPortile.windows? then "hello.exe"
|
38
|
+
else "hello"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_cmake_inherits_from_base
|
43
|
+
assert(MiniPortileCMake <= MiniPortile)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_configure
|
47
|
+
cmakecache = File.join(work_dir, "CMakeCache.txt")
|
48
|
+
assert File.exist?(cmakecache), cmakecache
|
49
|
+
|
50
|
+
assert_includes(IO.read(cmakecache), "CMAKE_INSTALL_PREFIX:PATH=#{recipe.path}")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_compile
|
54
|
+
binary = File.join(work_dir, exe_name)
|
55
|
+
assert File.exist?(binary), binary
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_install
|
59
|
+
binary = File.join(recipe.path, "bin", exe_name)
|
60
|
+
assert File.exist?(binary), binary
|
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
|
70
|
+
end
|
71
|
+
|
72
|
+
class TestCMakeConfig < TestCMake
|
73
|
+
def test_make_command_configuration
|
74
|
+
MiniPortile.stub(:mswin?, false) do
|
75
|
+
without_env("MAKE") do
|
76
|
+
assert_equal("make", MiniPortileCMake.new("test", "1.0.0").make_cmd)
|
77
|
+
assert_equal("xyzzy", MiniPortileCMake.new("test", "1.0.0", make_command: "xyzzy").make_cmd)
|
78
|
+
end
|
79
|
+
with_env("MAKE"=>"asdf") do
|
80
|
+
assert_equal("asdf", MiniPortileCMake.new("test", "1.0.0").make_cmd)
|
81
|
+
assert_equal("asdf", MiniPortileCMake.new("test", "1.0.0", make_command: "xyzzy").make_cmd)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
MiniPortile.stub(:mswin?, true) do
|
86
|
+
assert_equal("nmake", MiniPortileCMake.new("test", "1.0.0").make_cmd)
|
87
|
+
end
|
88
|
+
end
|
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
|
+
|
203
|
+
def test_cmake_command_configuration
|
204
|
+
without_env("CMAKE") do
|
205
|
+
assert_equal("cmake", MiniPortileCMake.new("test", "1.0.0").cmake_cmd)
|
206
|
+
assert_equal("xyzzy", MiniPortileCMake.new("test", "1.0.0", cmake_command: "xyzzy").cmake_cmd)
|
207
|
+
end
|
208
|
+
with_env("CMAKE"=>"asdf") do
|
209
|
+
assert_equal("asdf", MiniPortileCMake.new("test", "1.0.0").cmake_cmd)
|
210
|
+
assert_equal("asdf", MiniPortileCMake.new("test", "1.0.0", cmake_command: "xyzzy").cmake_cmd)
|
211
|
+
end
|
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
|
266
|
+
end
|
data/test/test_cook.rb
CHANGED
@@ -3,26 +3,19 @@ require File.expand_path('../helper', __FILE__)
|
|
3
3
|
class TestCook < TestCase
|
4
4
|
attr_accessor :assets_path, :tar_path, :recipe
|
5
5
|
|
6
|
-
def with_custom_git_dir(dir)
|
7
|
-
old = ENV['GIT_DIR']
|
8
|
-
ENV['GIT_DIR'] = dir
|
9
|
-
yield
|
10
|
-
ensure
|
11
|
-
ENV['GIT_DIR'] = old
|
12
|
-
end
|
13
|
-
|
14
6
|
def before_all
|
15
7
|
super
|
16
8
|
@assets_path = File.expand_path("../assets", __FILE__)
|
17
9
|
@tar_path = File.expand_path("../../tmp/test mini portile-1.0.0.tar.gz", __FILE__)
|
18
10
|
|
19
|
-
# remove any previous test files
|
20
|
-
FileUtils.rm_rf("tmp")
|
11
|
+
FileUtils.rm_rf("tmp") # remove any previous test files
|
21
12
|
|
22
|
-
create_tar(@tar_path, @assets_path)
|
13
|
+
create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")
|
23
14
|
start_webrick(File.dirname(@tar_path))
|
24
15
|
|
16
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
25
17
|
@recipe = MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
|
18
|
+
recipe.logger = @logger
|
26
19
|
recipe.files << "http://localhost:#{HTTP_PORT}/#{ERB::Util.url_encode(File.basename(@tar_path))}"
|
27
20
|
recipe.patch_files << File.join(@assets_path, "patch 1.diff")
|
28
21
|
recipe.configure_options << "--option=\"path with 'space'\""
|
@@ -31,12 +24,15 @@ class TestCook < TestCase
|
|
31
24
|
recipe.cook
|
32
25
|
end
|
33
26
|
end
|
27
|
+
rescue => e
|
28
|
+
puts @logger.string
|
29
|
+
raise e
|
34
30
|
end
|
35
31
|
|
36
32
|
def after_all
|
37
33
|
super
|
38
34
|
stop_webrick
|
39
|
-
#
|
35
|
+
FileUtils.rm_rf("tmp") # remove test files
|
40
36
|
end
|
41
37
|
|
42
38
|
def test_download
|
@@ -75,3 +71,129 @@ class TestCook < TestCase
|
|
75
71
|
assert_equal( ["install"].inspect, IO.read(txt).chomp )
|
76
72
|
end
|
77
73
|
end
|
74
|
+
|
75
|
+
class TestCookConfiguration < TestCase
|
76
|
+
def test_make_command_configuration
|
77
|
+
without_env("MAKE") do
|
78
|
+
assert_equal("make", MiniPortile.new("test", "1.0.0").make_cmd)
|
79
|
+
assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", make_command: "xyzzy").make_cmd)
|
80
|
+
end
|
81
|
+
with_env("MAKE"=>"asdf") do
|
82
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0").make_cmd)
|
83
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0", make_command: "xyzzy").make_cmd)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_cc_command_configuration
|
88
|
+
without_env("CC") do
|
89
|
+
expected_compiler = RbConfig::CONFIG["CC"] || "gcc"
|
90
|
+
assert_equal(expected_compiler, MiniPortile.new("test", "1.0.0").cc_cmd)
|
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)
|
95
|
+
assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").gcc_cmd)
|
96
|
+
end
|
97
|
+
with_env("CC"=>"asdf") do
|
98
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0").cc_cmd)
|
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)
|
103
|
+
assert_equal("asdf", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").gcc_cmd)
|
104
|
+
end
|
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
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
class TestCookWithBrokenGitDir < TestCase
|
122
|
+
#
|
123
|
+
# this is a test for #69
|
124
|
+
# https://github.com/flavorjones/mini_portile/issues/69
|
125
|
+
#
|
126
|
+
attr_accessor :assets_path, :tar_path, :recipe
|
127
|
+
|
128
|
+
def before_all
|
129
|
+
super
|
130
|
+
@assets_path = File.expand_path("../assets", __FILE__)
|
131
|
+
@tar_path = File.expand_path("../../tmp/test-mini-portile-1.0.0.tar.gz", __FILE__)
|
132
|
+
|
133
|
+
@git_dir = File.join(@assets_path, "git-broken")
|
134
|
+
FileUtils.rm_rf @git_dir
|
135
|
+
FileUtils.mkdir_p @git_dir
|
136
|
+
Dir.chdir(@git_dir) do
|
137
|
+
File.open ".git", "w" do |f|
|
138
|
+
f.write "gitdir: /nonexistent"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")
|
143
|
+
|
144
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
145
|
+
@recipe = MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
|
146
|
+
recipe.logger = @logger
|
147
|
+
recipe.files << "file://#{@tar_path}"
|
148
|
+
recipe.patch_files << File.join(@assets_path, "patch 1.diff")
|
149
|
+
recipe.configure_options << "--option=\"path with 'space'\""
|
150
|
+
end
|
151
|
+
|
152
|
+
Dir.chdir(@git_dir) do
|
153
|
+
@recipe.cook
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def after_all
|
158
|
+
FileUtils.rm_rf @git_dir
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_patch
|
162
|
+
Dir.chdir(@git_dir) do
|
163
|
+
patch1 = File.join(work_dir, "patch 1.txt")
|
164
|
+
assert File.exist?(patch1), patch1
|
165
|
+
assert_match( /^\tchange 1/, IO.read(patch1) )
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class TestCookAgainstSourceDirectory < TestCase
|
171
|
+
attr_accessor :recipe
|
172
|
+
|
173
|
+
def setup
|
174
|
+
super
|
175
|
+
|
176
|
+
@logger = StringIO.new # IO to keep recipe logs in case we need to debug
|
177
|
+
@recipe ||= MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
|
178
|
+
recipe.logger = @logger
|
179
|
+
recipe.source_directory = File.expand_path("../assets/test mini portile-1.0.0", __FILE__)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_source_directory
|
184
|
+
recipe.cook
|
185
|
+
|
186
|
+
path = File.join(work_dir, "configure.txt")
|
187
|
+
assert(File.exist?(path))
|
188
|
+
assert_equal((recipe.configure_options + ["--prefix=#{recipe.path}"]).inspect,
|
189
|
+
File.read(path).chomp);
|
190
|
+
|
191
|
+
path = File.join(work_dir, "compile.txt")
|
192
|
+
assert(File.exist?(path))
|
193
|
+
assert_equal("[\"all\"]", File.read(path).chomp);
|
194
|
+
|
195
|
+
path = File.join(work_dir, "install.txt")
|
196
|
+
assert(File.exist?(path))
|
197
|
+
assert_equal("[\"install\"]", File.read(path).chomp);
|
198
|
+
end
|
199
|
+
end
|
data/test/test_digest.rb
CHANGED
@@ -11,11 +11,12 @@ class TestDigest < TestCase
|
|
11
11
|
# remove any previous test files
|
12
12
|
FileUtils.rm_rf("tmp")
|
13
13
|
|
14
|
-
create_tar(@tar_path, @assets_path)
|
14
|
+
create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")
|
15
15
|
start_webrick(File.dirname(@tar_path))
|
16
16
|
end
|
17
17
|
|
18
18
|
def after_all
|
19
|
+
super
|
19
20
|
stop_webrick
|
20
21
|
# leave test files for inspection
|
21
22
|
end
|
@@ -23,7 +24,8 @@ class TestDigest < TestCase
|
|
23
24
|
def setup
|
24
25
|
super
|
25
26
|
FileUtils.rm_rf("ports/archives")
|
26
|
-
@
|
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)
|
27
29
|
end
|
28
30
|
|
29
31
|
def download_with_digest(key, klass)
|
@@ -65,5 +67,147 @@ class TestDigest < TestCase
|
|
65
67
|
def test_wrong_md5
|
66
68
|
download_with_wrong_digest(:md5)
|
67
69
|
end
|
68
|
-
end
|
69
70
|
|
71
|
+
def public_key
|
72
|
+
<<~KEY
|
73
|
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IpfvjLKHKUZZBP
|
90
|
+
4Ko=
|
91
|
+
=SVWi
|
92
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
93
|
+
KEY
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_with_valid_gpg_signature
|
97
|
+
data_file = File.expand_path(File.join(File.dirname(__FILE__), 'assets', 'gpg-fixtures', 'data'))
|
98
|
+
|
99
|
+
@recipe.files << {
|
100
|
+
:url => "file://#{data_file}",
|
101
|
+
:gpg => {
|
102
|
+
:key => public_key,
|
103
|
+
:signature_url => "file://#{data_file}.asc"
|
104
|
+
}
|
105
|
+
}
|
106
|
+
@recipe.download
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_optional_gpg_signature_url
|
110
|
+
data_file = File.expand_path(File.join(File.dirname(__FILE__), 'assets', 'gpg-fixtures', 'data'))
|
111
|
+
|
112
|
+
@recipe.files << {
|
113
|
+
:url => "file://#{data_file}",
|
114
|
+
:gpg => {
|
115
|
+
:key => public_key
|
116
|
+
}
|
117
|
+
}
|
118
|
+
@recipe.download
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_with_invalid_gpg_signature
|
122
|
+
data_file = File.expand_path(File.join(File.dirname(__FILE__), 'assets', 'gpg-fixtures', 'data'))
|
123
|
+
|
124
|
+
@recipe.files << {
|
125
|
+
:url => "file://#{data_file}",
|
126
|
+
:gpg => {
|
127
|
+
:key => public_key,
|
128
|
+
:signature_url => "file://#{data_file}.invalid.asc"
|
129
|
+
}
|
130
|
+
}
|
131
|
+
exception = assert_raises(RuntimeError){
|
132
|
+
@recipe.download
|
133
|
+
}
|
134
|
+
assert_includes(exception.message, "signature mismatch")
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_with_invalid_key
|
138
|
+
data_file = File.expand_path(File.join(File.dirname(__FILE__), 'assets', 'gpg-fixtures', 'data'))
|
139
|
+
|
140
|
+
@recipe.files << {
|
141
|
+
:url => "file://#{data_file}",
|
142
|
+
:gpg => {
|
143
|
+
:key => "thisisaninvalidkey",
|
144
|
+
:signature_url => "file://#{data_file}.asc"
|
145
|
+
}
|
146
|
+
}
|
147
|
+
exception = assert_raises(RuntimeError){ @recipe.download }
|
148
|
+
assert_includes(exception.message, "invalid gpg key provided")
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_with_different_key_than_one_used_to_sign
|
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+MpULlfdyfvjj4heBBARCAAGBQJRCTwgAAoJEFGFCWhsfl6CzF0B
|
166
|
+
AJsQ3DJbtGcZ+0VIcM2a06RRQfBvIHqm1A/1WSYmObLGAP90lxWlNjSugvUUlqTk
|
167
|
+
YEEgRTGozg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XLCTvBmznXfaMKllsqbsy2nCJ2P2uJjOntw=
|
197
|
+
=4JAR
|
198
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
199
|
+
KEY
|
200
|
+
|
201
|
+
data_file = File.expand_path(File.join(File.dirname(__FILE__), 'assets', 'gpg-fixtures', 'data'))
|
202
|
+
|
203
|
+
@recipe.files << {
|
204
|
+
:url => "file://#{data_file}",
|
205
|
+
:gpg => {
|
206
|
+
:key => key,
|
207
|
+
:signature_url => "file://#{data_file}.asc"
|
208
|
+
}
|
209
|
+
}
|
210
|
+
exception = assert_raises(RuntimeError){ @recipe.download }
|
211
|
+
assert_includes(exception.message, "signature mismatch")
|
212
|
+
end
|
213
|
+
end
|