omnibus 6.0.25 → 7.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -3
  3. data/README.md +25 -9
  4. data/Rakefile +1 -1
  5. data/lib/omnibus/build_version_dsl.rb +1 -0
  6. data/lib/omnibus/builder.rb +10 -7
  7. data/lib/omnibus/changelog_printer.rb +7 -4
  8. data/lib/omnibus/cleaner.rb +3 -0
  9. data/lib/omnibus/cli.rb +1 -1
  10. data/lib/omnibus/cli/changelog.rb +24 -24
  11. data/lib/omnibus/cli/publish.rb +5 -5
  12. data/lib/omnibus/compressor.rb +2 -2
  13. data/lib/omnibus/compressors/base.rb +1 -1
  14. data/lib/omnibus/compressors/dmg.rb +45 -7
  15. data/lib/omnibus/config.rb +12 -2
  16. data/lib/omnibus/fetchers/git_fetcher.rb +1 -0
  17. data/lib/omnibus/fetchers/net_fetcher.rb +2 -3
  18. data/lib/omnibus/file_syncer.rb +2 -2
  19. data/lib/omnibus/generator.rb +1 -0
  20. data/lib/omnibus/generator_files/Gemfile.erb +2 -2
  21. data/lib/omnibus/generator_files/README.md.erb +18 -15
  22. data/lib/omnibus/generator_files/config/projects/project.rb.erb +0 -3
  23. data/lib/omnibus/generator_files/config/software/preparation.rb.erb +30 -0
  24. data/lib/omnibus/generator_files/omnibus.rb.erb +5 -4
  25. data/lib/omnibus/health_check.rb +1 -1
  26. data/lib/omnibus/licensing.rb +3 -4
  27. data/lib/omnibus/logger.rb +2 -1
  28. data/lib/omnibus/manifest.rb +1 -1
  29. data/lib/omnibus/metadata.rb +2 -2
  30. data/lib/omnibus/packagers/appx.rb +1 -2
  31. data/lib/omnibus/packagers/base.rb +1 -0
  32. data/lib/omnibus/packagers/bff.rb +6 -8
  33. data/lib/omnibus/packagers/deb.rb +7 -10
  34. data/lib/omnibus/packagers/ips.rb +3 -6
  35. data/lib/omnibus/packagers/makeself.rb +1 -2
  36. data/lib/omnibus/packagers/msi.rb +12 -11
  37. data/lib/omnibus/packagers/pkg.rb +125 -9
  38. data/lib/omnibus/packagers/rpm.rb +13 -12
  39. data/lib/omnibus/packagers/solaris.rb +4 -4
  40. data/lib/omnibus/packagers/windows_base.rb +7 -6
  41. data/lib/omnibus/project.rb +1 -0
  42. data/lib/omnibus/publisher.rb +14 -12
  43. data/lib/omnibus/publishers/s3_publisher.rb +6 -4
  44. data/lib/omnibus/s3_cache.rb +3 -1
  45. data/lib/omnibus/s3_helpers.rb +6 -6
  46. data/lib/omnibus/software.rb +66 -30
  47. data/lib/omnibus/templating.rb +1 -1
  48. data/lib/omnibus/util.rb +3 -2
  49. data/lib/omnibus/version.rb +1 -1
  50. data/lib/omnibus/whitelist.rb +6 -1
  51. data/omnibus.gemspec +7 -6
  52. data/resources/rpm/signing.erb +7 -10
  53. data/spec/functional/builder_spec.rb +2 -1
  54. data/spec/functional/fetchers/file_fetcher_spec.rb +4 -4
  55. data/spec/functional/fetchers/git_fetcher_spec.rb +4 -4
  56. data/spec/functional/fetchers/net_fetcher_spec.rb +5 -6
  57. data/spec/functional/fetchers/path_fetcher_spec.rb +4 -4
  58. data/spec/functional/file_syncer_spec.rb +42 -0
  59. data/spec/functional/licensing_spec.rb +5 -5
  60. data/spec/spec_helper.rb +6 -0
  61. data/spec/support/examples.rb +3 -4
  62. data/spec/unit/builder_spec.rb +9 -9
  63. data/spec/unit/changelogprinter_spec.rb +8 -6
  64. data/spec/unit/compressor_spec.rb +3 -3
  65. data/spec/unit/compressors/dmg_spec.rb +43 -4
  66. data/spec/unit/fetchers/net_fetcher_spec.rb +16 -17
  67. data/spec/unit/generator_spec.rb +1 -0
  68. data/spec/unit/health_check_spec.rb +2 -6
  69. data/spec/unit/library_spec.rb +2 -1
  70. data/spec/unit/manifest_diff_spec.rb +2 -2
  71. data/spec/unit/manifest_spec.rb +1 -1
  72. data/spec/unit/metadata_spec.rb +9 -11
  73. data/spec/unit/omnibus_spec.rb +1 -1
  74. data/spec/unit/packagers/bff_spec.rb +2 -2
  75. data/spec/unit/packagers/msi_spec.rb +2 -2
  76. data/spec/unit/packagers/pkg_spec.rb +354 -0
  77. data/spec/unit/packagers/pkgsrc_spec.rb +1 -1
  78. data/spec/unit/packagers/solaris_spec.rb +7 -7
  79. data/spec/unit/project_spec.rb +2 -2
  80. data/spec/unit/publisher_spec.rb +8 -9
  81. data/spec/unit/publishers/artifactory_publisher_spec.rb +2 -4
  82. data/spec/unit/publishers/s3_publisher_spec.rb +2 -4
  83. data/spec/unit/s3_cacher_spec.rb +19 -6
  84. data/spec/unit/s3_helpers_spec.rb +22 -3
  85. data/spec/unit/software_spec.rb +72 -42
  86. data/spec/unit/util_spec.rb +1 -2
  87. metadata +32 -11
@@ -8,9 +8,7 @@ module Omnibus
8
8
  name: "chefdk",
9
9
  install_dir: "/opt/chefdk",
10
10
  library: double(Library,
11
- components: []
12
- )
13
- )
11
+ components: []))
14
12
  end
15
13
 
16
14
  def mkdump(base, size, x64 = false)
@@ -19,9 +17,7 @@ module Omnibus
19
17
  x64?: x64,
20
18
  ioh: double(x64 ? PEdump::IMAGE_OPTIONAL_HEADER64 : PEdump::IMAGE_OPTIONAL_HEADER32,
21
19
  ImageBase: base,
22
- SizeOfImage: size
23
- )
24
- )
20
+ SizeOfImage: size))
25
21
  expect(dump).to receive(:pe).and_return(pe)
26
22
  dump
27
23
  end
@@ -125,7 +125,8 @@ module Omnibus
125
125
  erchef, # project dep
126
126
  chef, # project dep
127
127
  chefdk, # project dep
128
- ])
128
+ ]
129
+ )
129
130
  end
130
131
  end
131
132
  end
@@ -12,7 +12,7 @@ module Omnibus
12
12
  end
13
13
 
14
14
  let(:manifest_one) do
15
- m = Omnibus::Manifest.new()
15
+ m = Omnibus::Manifest.new
16
16
  m.add("foo", manifest_entry_for("foo", "1.2.4", "deadbeef"))
17
17
  m.add("bar", manifest_entry_for("bar", "1.2.4", "deadbeef"))
18
18
  m.add("baz", manifest_entry_for("baz", "1.2.4", "deadbeef"))
@@ -20,7 +20,7 @@ module Omnibus
20
20
  end
21
21
 
22
22
  let(:manifest_two) do
23
- m = Omnibus::Manifest.new()
23
+ m = Omnibus::Manifest.new
24
24
  m.add("foo", manifest_entry_for("foo", "1.2.5", "deadbea0"))
25
25
  m.add("baz", manifest_entry_for("baz", "1.2.4", "deadbeef"))
26
26
  m.add("quux", manifest_entry_for("quux", "1.2.4", "deadbeef"))
@@ -45,7 +45,7 @@ module Omnibus
45
45
  second = ManifestEntry.new("wombat", {})
46
46
  subject.add("foobar", first)
47
47
  subject.add("wombat", second)
48
- expect(subject.entry_names).to eq([:foobar, :wombat])
48
+ expect(subject.entry_names).to eq(%i{foobar wombat})
49
49
  end
50
50
  end
51
51
 
@@ -16,8 +16,7 @@ module Omnibus
16
16
  md5: "abc123",
17
17
  sha1: "abc123",
18
18
  sha256: "abcd1234",
19
- sha512: "abcdef123456"
20
- )
19
+ sha512: "abcdef123456")
21
20
  end
22
21
 
23
22
  let(:project) do
@@ -29,15 +28,13 @@ module Omnibus
29
28
  build_iteration: "1",
30
29
  license: "Apache-2.0",
31
30
  built_manifest: double(Manifest,
32
- to_hash: {
33
- manifest_format: 2,
34
- build_version: "1.2.3",
35
- build_git_revision: "SHA",
36
- license: "Apache-2.0",
37
- }
38
- ),
39
- license_file_path: license_path
40
- )
31
+ to_hash: {
32
+ manifest_format: 2,
33
+ build_version: "1.2.3",
34
+ build_git_revision: "SHA",
35
+ license: "Apache-2.0",
36
+ }),
37
+ license_file_path: license_path)
41
38
  end
42
39
 
43
40
  let(:data) { { foo: "bar" } }
@@ -219,6 +216,7 @@ module Omnibus
219
216
  it_behaves_like "a version manipulator", "fedora", "11.5", "11"
220
217
  it_behaves_like "a version manipulator", "freebsd", "10.0", "10"
221
218
  it_behaves_like "a version manipulator", "gentoo", "4.9.95-gentoo", "rolling"
219
+ it_behaves_like "a version manipulator", "kali", "rolling", "rolling"
222
220
  it_behaves_like "a version manipulator", "mac_os_x", "10.9.1", "10.9"
223
221
  it_behaves_like "a version manipulator", "omnios", "r151010", "r151010"
224
222
  it_behaves_like "a version manipulator", "openbsd", "5.4.4", "5.4"
@@ -15,7 +15,7 @@ describe Omnibus do
15
15
 
16
16
  Omnibus::Config.project_root(File.join(tmp_path, "/foo/bar"))
17
17
  Omnibus::Config.local_software_dirs([File.join(tmp_path, "/local"), File.join(tmp_path, "/other")])
18
- Omnibus::Config.software_gems(["omnibus-software", "custom-omnibus-software"])
18
+ Omnibus::Config.software_gems(%w{omnibus-software custom-omnibus-software})
19
19
  end
20
20
 
21
21
  describe "#which" do
@@ -301,7 +301,7 @@ module Omnibus
301
301
  # A note - the /opt/ here is essentially project.install_dir one level up.
302
302
  # There is nothing magical about 'opt' as a directory.
303
303
  expect(subject).to receive(:shellout!)
304
- .with(/chown -Rh 0:0 #{staging_dir}\/opt$/)
304
+ .with(%r{chown -Rh 0:0 #{staging_dir}/opt$})
305
305
  subject.create_bff_file
306
306
  end
307
307
 
@@ -312,7 +312,7 @@ module Omnibus
312
312
 
313
313
  it "uses the correct command" do
314
314
  expect(subject).to receive(:shellout!)
315
- .with(/\/usr\/sbin\/mkinstallp -d/)
315
+ .with(%r{/usr/sbin/mkinstallp -d})
316
316
  subject.create_bff_file
317
317
  end
318
318
 
@@ -419,7 +419,7 @@ module Omnibus
419
419
  end
420
420
 
421
421
  it "outputs a source.wxs file to the staging directory" do
422
- expect(subject.candle_command).to include("#{subject.windows_safe_path(staging_dir, 'source.wxs')}")
422
+ expect(subject.candle_command).to include("#{subject.windows_safe_path(staging_dir, "source.wxs")}")
423
423
  end
424
424
  end
425
425
 
@@ -433,7 +433,7 @@ module Omnibus
433
433
  end
434
434
 
435
435
  it "outputs a bundle.wxs file to the staging directory" do
436
- expect(subject.candle_command(is_bundle: true)).to include("#{subject.windows_safe_path(staging_dir, 'bundle.wxs')}")
436
+ expect(subject.candle_command(is_bundle: true)).to include("#{subject.windows_safe_path(staging_dir, "bundle.wxs")}")
437
437
  end
438
438
  end
439
439
  end
@@ -109,6 +109,158 @@ module Omnibus
109
109
  end
110
110
  end
111
111
 
112
+ describe "#sign_software_libs_and_bins" do
113
+ context "when pkg signing is disabled" do
114
+ it "does not sign anything" do
115
+ expect(subject).not_to receive(:sign_binary)
116
+ expect(subject).not_to receive(:sign_library)
117
+ subject.sign_software_libs_and_bins
118
+ end
119
+
120
+ it "returns an empty set" do
121
+ expect(subject.sign_software_libs_and_bins).to be_nil
122
+ end
123
+ end
124
+
125
+ context "when pkg signing is enabled" do
126
+ before do
127
+ subject.signing_identity("My Special Identity")
128
+ end
129
+
130
+ context "without software" do
131
+ it "does not sign anything" do
132
+ expect(subject).not_to receive(:sign_binary)
133
+ expect(subject).not_to receive(:sign_library)
134
+ subject.sign_software_libs_and_bins
135
+ end
136
+
137
+ it "returns an empty set" do
138
+ expect(subject.sign_software_libs_and_bins).to eq(Set.new)
139
+ end
140
+ end
141
+
142
+ context "project with software" do
143
+ let(:software) do
144
+ Software.new(project).tap do |software|
145
+ software.name("software-full-name")
146
+ end
147
+ end
148
+
149
+ before do
150
+ allow(project).to receive(:softwares).and_return([software])
151
+ end
152
+
153
+ context "with empty bin_dirs and lib_dirs" do
154
+ before do
155
+ allow(software).to receive(:lib_dirs).and_return([])
156
+ allow(software).to receive(:bin_dirs).and_return([])
157
+ end
158
+
159
+ it "does not sign anything" do
160
+ expect(subject).not_to receive(:sign_binary)
161
+ expect(subject).not_to receive(:sign_library)
162
+ subject.sign_software_libs_and_bins
163
+ end
164
+
165
+ it "returns an empty set" do
166
+ expect(subject.sign_software_libs_and_bins).to eq(Set.new)
167
+ end
168
+ end
169
+
170
+ context "with default bin_dirs and lib_dirs" do
171
+ context "with binaries" do
172
+ let(:bin) { "/opt/#{project.name}/bin/test_bin" }
173
+ let(:embedded_bin) { "/opt/#{project.name}/embedded/bin/test_bin" }
174
+ before do
175
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/bin/*").and_return([bin])
176
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/embedded/bin/*").and_return([embedded_bin])
177
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/embedded/lib/*").and_return([])
178
+ allow(subject).to receive(:is_binary?).with(bin).and_return(true)
179
+ allow(subject).to receive(:is_binary?).with(embedded_bin).and_return(true)
180
+ allow(subject).to receive(:find_linked_libs).with(bin).and_return([])
181
+ allow(subject).to receive(:find_linked_libs).with(embedded_bin).and_return([])
182
+ allow(subject).to receive(:sign_binary).with(bin, true)
183
+ allow(subject).to receive(:sign_binary).with(embedded_bin, true)
184
+ end
185
+
186
+ it "signs the binaries" do
187
+ expect(subject).to receive(:sign_binary).with(bin, true)
188
+ expect(subject).to receive(:sign_binary).with(embedded_bin, true)
189
+ subject.sign_software_libs_and_bins
190
+ end
191
+
192
+ it "returns a set with the signed binaries" do
193
+ expect(subject.sign_software_libs_and_bins).to eq(Set.new [bin, embedded_bin])
194
+ end
195
+ end
196
+
197
+ context "with library" do
198
+ let(:lib) { "/opt/#{project.name}/embedded/lib/test_lib" }
199
+ before do
200
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/bin/*").and_return([])
201
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/embedded/bin/*").and_return([])
202
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/embedded/lib/*").and_return([lib])
203
+ allow(subject).to receive(:is_macho?).with(lib).and_return(true)
204
+ allow(subject).to receive(:find_linked_libs).with(lib).and_return([])
205
+ allow(subject).to receive(:sign_library).with(lib)
206
+ end
207
+
208
+ it "signs the library" do
209
+ expect(subject).to receive(:sign_library).with(lib)
210
+ subject.sign_software_libs_and_bins
211
+ end
212
+ end
213
+
214
+ context "with binaries and libraries with linked libs" do
215
+ let(:bin) { "/opt/#{project.name}/bin/test_bin" }
216
+ let(:bin2) { "/opt/#{project.name}/bin/test_bin2" }
217
+ let(:embedded_bin) { "/opt/#{project.name}/embedded/bin/test_bin" }
218
+ let(:lib) { "/opt/#{project.name}/embedded/lib/test_lib" }
219
+ let(:lib2) { "/opt/#{project.name}/embedded/lib/test_lib2" }
220
+ before do
221
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/bin/*").and_return([bin, bin2])
222
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/embedded/bin/*").and_return([embedded_bin])
223
+ allow(Dir).to receive(:[]).with("/opt/#{project.name}/embedded/lib/*").and_return([lib])
224
+ allow(subject).to receive(:is_binary?).with(bin).and_return(true)
225
+ allow(subject).to receive(:is_binary?).with(bin2).and_return(true)
226
+ allow(subject).to receive(:is_binary?).with(embedded_bin).and_return(true)
227
+ allow(subject).to receive(:is_macho?).with(lib).and_return(true)
228
+ allow(subject).to receive(:is_macho?).with(lib2).and_return(true)
229
+ allow(subject).to receive(:find_linked_libs).with(bin).and_return([lib2])
230
+ allow(subject).to receive(:find_linked_libs).with(bin2).and_return([])
231
+ allow(subject).to receive(:find_linked_libs).with(embedded_bin).and_return([])
232
+ allow(subject).to receive(:find_linked_libs).with(lib).and_return([])
233
+ allow(subject).to receive(:find_linked_libs).with(lib2).and_return([])
234
+ allow(subject).to receive(:sign_binary).with(bin, true)
235
+ allow(subject).to receive(:sign_binary).with(bin2, true)
236
+ allow(subject).to receive(:sign_binary).with(embedded_bin, true)
237
+ allow(subject).to receive(:sign_library).with(lib)
238
+ allow(subject).to receive(:sign_library).with(lib2)
239
+ allow(Digest::SHA256).to receive(:file).with(bin).and_return(Digest::SHA256.new.update(bin))
240
+ allow(Digest::SHA256).to receive(:file).with(bin2).and_return(Digest::SHA256.new.update(bin2))
241
+ allow(Digest::SHA256).to receive(:file).with(embedded_bin).and_return(Digest::SHA256.new.update(embedded_bin))
242
+ allow(Digest::SHA256).to receive(:file).with(lib).and_return(Digest::SHA256.new.update(lib))
243
+ allow(Digest::SHA256).to receive(:file).with(lib2).and_return(Digest::SHA256.new.update(lib2))
244
+ end
245
+
246
+ it "signs the binaries" do
247
+ expect(subject).to receive(:sign_binary).with(bin, true)
248
+ expect(subject).to receive(:sign_binary).with(bin2, true)
249
+ expect(subject).to receive(:sign_binary).with(embedded_bin, true)
250
+ subject.sign_software_libs_and_bins
251
+ end
252
+
253
+ it "signs the libraries" do
254
+ expect(subject).to receive(:sign_library).with(lib)
255
+ expect(subject).to receive(:sign_library).with(lib2)
256
+ subject.sign_software_libs_and_bins
257
+ end
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
263
+
112
264
  describe "#build_component_pkg" do
113
265
  it "executes the pkgbuild command" do
114
266
  expect(subject).to receive(:shellout!).with <<-EOH.gsub(/^ {10}/, "")
@@ -118,6 +270,7 @@ module Omnibus
118
270
  --scripts "#{staging_dir}/Scripts" \\
119
271
  --root "/opt/project-full-name" \\
120
272
  --install-location "/opt/project-full-name" \\
273
+ --preserve-xattr \\
121
274
  "project-full-name-core.pkg"
122
275
  EOH
123
276
 
@@ -267,5 +420,206 @@ module Omnibus
267
420
  end
268
421
  end
269
422
  end
423
+
424
+ describe "#find_linked_libs" do
425
+ context "with linked libs" do
426
+ let(:file) { "/opt/#{project.name}/embedded/bin/test_bin" }
427
+ let(:stdout) do
428
+ <<~EOH
429
+ /opt/#{project.name}/embedded/bin/test_bin:
430
+ /opt/#{project.name}/embedded/lib/lib.dylib (compatibility version 7.0.0, current version 7.4.0)
431
+ /opt/#{project.name}/embedded/lib/lib.6.dylib (compatibility version 7.0.0, current version 7.4.0)
432
+ /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
433
+ EOH
434
+ end
435
+ let(:shellout) { Mixlib::ShellOut.new }
436
+
437
+ before do
438
+ allow(shellout).to receive(:run_command)
439
+ allow(shellout).to receive(:stdout)
440
+ .and_return(stdout)
441
+ allow(subject).to receive(:shellout!)
442
+ .with("otool -L #{file}")
443
+ .and_return(shellout)
444
+ end
445
+
446
+ it "returns empty array" do
447
+ expect(subject.find_linked_libs(file)).to eq([
448
+ "/opt/#{project.name}/embedded/lib/lib.dylib",
449
+ "/opt/#{project.name}/embedded/lib/lib.6.dylib",
450
+ ])
451
+ end
452
+ end
453
+
454
+ context "with only system linked libs" do
455
+ let(:file) { "/opt/#{project.name}/embedded/lib/lib.dylib" }
456
+ let(:stdout) do
457
+ <<~EOH
458
+ /opt/#{project.name}/embedded/lib/lib.dylib:
459
+ /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
460
+ EOH
461
+ end
462
+ let(:shellout) { Mixlib::ShellOut.new }
463
+ before do
464
+ allow(shellout).to receive(:run_command)
465
+ allow(shellout).to receive(:stdout)
466
+ .and_return(stdout)
467
+ allow(subject).to receive(:shellout!)
468
+ .with("otool -L #{file}")
469
+ .and_return(shellout)
470
+ end
471
+
472
+ it "returns empty array" do
473
+ expect(subject.find_linked_libs(file)).to eq([])
474
+ end
475
+ end
476
+
477
+ context "file is just a file" do
478
+ let(:file) { "/opt/#{project.name}/embedded/lib/file.rb" }
479
+ let(:shellout) { Mixlib::ShellOut.new }
480
+ before do
481
+ allow(shellout).to receive(:run_command)
482
+ allow(shellout).to receive(:stdout)
483
+ .and_return("#{file}: is not an object file")
484
+ allow(subject).to receive(:shellout!)
485
+ .with("otool -L #{file}")
486
+ .and_return(shellout)
487
+ end
488
+
489
+ it "returns empty array" do
490
+ expect(subject.find_linked_libs(file)).to eq([])
491
+ end
492
+ end
493
+ end
494
+
495
+ describe "#is_binary?" do
496
+ context "when is a file, executable, and not a symlink" do
497
+ before do
498
+ allow(File).to receive(:file?).with("file").and_return(true)
499
+ allow(File).to receive(:executable?).with("file").and_return(true)
500
+ allow(File).to receive(:symlink?).with("file").and_return(false)
501
+ end
502
+
503
+ it "returns true" do
504
+ expect(subject.is_binary?("file")).to be true
505
+ end
506
+ end
507
+
508
+ context "when not a file" do
509
+ before do
510
+ allow(File).to receive(:file?).with("file").and_return(false)
511
+ allow(File).to receive(:executable?).with("file").and_return(true)
512
+ allow(File).to receive(:symlink?).with("file").and_return(false)
513
+ end
514
+
515
+ it "returns false" do
516
+ expect(subject.is_binary?("file")).to be false
517
+ end
518
+ end
519
+
520
+ context "when not an executable" do
521
+ it "returns false" do
522
+ allow(File).to receive(:file?).with("file").and_return(true)
523
+ allow(File).to receive(:executable?).with("file").and_return(false)
524
+ allow(File).to receive(:symlink?).with("file").and_return(false)
525
+ expect(subject.is_binary?("file")).to be false
526
+ end
527
+ end
528
+
529
+ context "when is symlink" do
530
+ it "returns false" do
531
+ allow(File).to receive(:file?).with("file").and_return(true)
532
+ allow(File).to receive(:executable?).with("file").and_return(true)
533
+ allow(File).to receive(:symlink?).with("file").and_return(true)
534
+ expect(subject.is_binary?("file")).to be false
535
+ end
536
+ end
537
+ end
538
+
539
+ describe "#is_macho?" do
540
+ let(:shellout) { Mixlib::ShellOut.new }
541
+
542
+ context "when is a Mach-O library" do
543
+ before do
544
+ allow(subject).to receive(:is_binary?).with("file").and_return(true)
545
+ expect(subject).to receive(:shellout!).with("file file").and_return(shellout)
546
+ allow(shellout).to receive(:stdout)
547
+ .and_return("file: Mach-O 64-bit dynamically linked shared library x86_64")
548
+ end
549
+
550
+ it "returns true" do
551
+ expect(subject.is_macho?("file")).to be true
552
+ end
553
+ end
554
+
555
+ context "when is a Mach-O Bundle" do
556
+ before do
557
+ allow(subject).to receive(:is_binary?).with("file").and_return(true)
558
+ expect(subject).to receive(:shellout!).with("file file").and_return(shellout)
559
+ allow(shellout).to receive(:stdout)
560
+ .and_return("file: Mach-O 64-bit bundle x86_64")
561
+ end
562
+
563
+ it "returns true" do
564
+ expect(subject.is_macho?("file")).to be true
565
+ end
566
+ end
567
+
568
+ context "when is not a Mach-O Bundle or Mach-O library" do
569
+ before do
570
+ allow(subject).to receive(:is_binary?).with("file").and_return(true)
571
+ expect(subject).to receive(:shellout!).with("file file").and_return(shellout)
572
+ allow(shellout).to receive(:stdout)
573
+ .and_return("file: ASCII text")
574
+ end
575
+
576
+ it "returns true" do
577
+ expect(subject.is_macho?("file")).to be false
578
+ end
579
+ end
580
+ end
581
+
582
+ describe "#sign_library" do
583
+ before do
584
+ subject.signing_identity("My Special Identity")
585
+ end
586
+
587
+ it "calls sign_binary without hardened runtime" do
588
+ expect(subject).to receive(:sign_binary).with("file")
589
+ subject.sign_library("file")
590
+ end
591
+ end
592
+
593
+ describe "#sign_binary" do
594
+ before do
595
+ subject.signing_identity("My Special Identity")
596
+ end
597
+
598
+ it "it signs the binary without hardened runtime" do
599
+ expect(subject).to receive(:shellout!)
600
+ .with("codesign -s '#{subject.signing_identity}' 'file' --force\n")
601
+ subject.sign_binary("file")
602
+ end
603
+
604
+ context "with hardened runtime" do
605
+ it "it signs the binary with hardened runtime" do
606
+ expect(subject).to receive(:shellout!)
607
+ .with("codesign -s '#{subject.signing_identity}' 'file' --options=runtime --force\n")
608
+ subject.sign_binary("file", true)
609
+ end
610
+
611
+ context "with entitlements" do
612
+ let(:entitlements_file) { File.join(tmp_path, "project-full-name/resources/project-full-name/pkg/entitlements.plist") }
613
+
614
+ it "it signs the binary with the entitlements" do
615
+ allow(subject).to receive(:resource_path).with("entitlements.plist").and_return(entitlements_file)
616
+ allow(File).to receive(:exist?).with(entitlements_file).and_return(true)
617
+ expect(subject).to receive(:shellout!)
618
+ .with("codesign -s '#{subject.signing_identity}' 'file' --options=runtime --entitlements #{entitlements_file} --force\n")
619
+ subject.sign_binary("file", true)
620
+ end
621
+ end
622
+ end
623
+ end
270
624
  end
271
625
  end