tpkg 2.3.3 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/Portfile +39 -0
- data/Portfile.template +39 -0
- data/README.md +43 -0
- data/Rakefile +468 -18
- data/bin/gem2tpkg +2 -2
- data/bin/tpkg +18 -13
- data/bin/tpkg_uploader +132 -0
- data/ca.pem +1 -0
- data/control +7 -0
- data/depend +3 -0
- data/externals-etch/authorized_keys +40 -0
- data/externals-etch/group +9 -0
- data/externals-etch/iptables +38 -0
- data/externals-etch/limits +30 -0
- data/externals-etch/nfs +30 -0
- data/externals-etch/sudo +30 -0
- data/externals-etch/supplemental_groups +8 -0
- data/externals-etch/sysctl +30 -0
- data/externals-etch/user +41 -0
- data/externals/group +39 -0
- data/externals/supplemental_groups +48 -0
- data/externals/user +39 -0
- data/lib/tpkg.rb +260 -991
- data/lib/tpkg/os.rb +164 -0
- data/lib/tpkg/os/debian.rb +159 -0
- data/lib/tpkg/os/freebsd.rb +113 -0
- data/lib/tpkg/os/macosx.rb +113 -0
- data/lib/tpkg/os/redhat.rb +173 -0
- data/lib/tpkg/os/solaris.rb +101 -0
- data/lib/tpkg/os/windows.rb +26 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
- data/lib/tpkg/version.rb +3 -0
- data/man/man1/cpan2tpkg.1 +82 -0
- data/man/man1/gem2tpkg.1 +120 -0
- data/man/man1/tpkg.1 +411 -0
- data/pkginfo +8 -0
- data/postinstall.solaris +11 -0
- data/postremove.solaris +16 -0
- data/schema/schema-1.0.5.yml +0 -0
- data/schema/schema-1.0.6.yml +0 -0
- data/schema/schema-1.0.7.yml +0 -0
- data/schema/schema-1.0.8.yml +0 -0
- data/schema/schema-1.0.9.yml +0 -0
- data/schema/schema.yml +0 -0
- data/schema/tpkg-1.0.0.dtd +0 -0
- data/schema/tpkg-1.0.1.dtd +0 -0
- data/schema/tpkg-1.0.2.dtd +0 -0
- data/schema/tpkg-1.0.3.dtd +0 -0
- data/schema/tpkg-1.0.4.dtd +0 -0
- data/schema/tpkg-1.0.5.dtd +0 -0
- data/schema/tpkg-1.0.6.dtd +0 -0
- data/schema/tpkg-1.0.7.dtd +0 -0
- data/schema/tpkg-1.0.8.dtd +0 -0
- data/schema/tpkg-1.0.9.dtd +0 -0
- data/schema/tpkg.dtd +0 -0
- data/test/TODO +30 -0
- data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
- data/test/test_checksum.rb +53 -0
- data/test/test_compress.rb +55 -0
- data/test/test_conflict.rb +41 -0
- data/test/test_crontabs.rb +398 -0
- data/test/test_dependency.rb +1113 -0
- data/test/test_downgrade.rb +80 -0
- data/test/test_download.rb +95 -0
- data/test/test_encrypt.rb +136 -0
- data/test/test_filemetadata.rb +131 -0
- data/test/test_initscript.rb +93 -0
- data/test/test_install.rb +186 -0
- data/test/test_lock.rb +82 -0
- data/test/test_make.rb +410 -0
- data/test/test_metadata.rb +805 -0
- data/test/test_misc.rb +379 -0
- data/test/test_options.rb +1711 -0
- data/test/test_os.rb +193 -0
- data/test/test_os_debian.rb +99 -0
- data/test/test_os_freebsd.rb +89 -0
- data/test/test_os_macosx.rb +79 -0
- data/test/test_os_redhat.rb +124 -0
- data/test/test_os_solaris.rb +85 -0
- data/test/test_os_windows.rb +26 -0
- data/test/test_query.rb +134 -0
- data/test/test_remove.rb +539 -0
- data/test/test_tar.rb +99 -0
- data/test/test_unpack.rb +977 -0
- data/test/test_upgrade.rb +398 -0
- data/test/test_version.rb +54 -0
- data/test/testcmds/crontab +14 -0
- data/test/testcmds/debian/apt-cache +145 -0
- data/test/testcmds/debian/dpkg-query +16 -0
- data/test/testcmds/freebsd/pkg_info +13 -0
- data/test/testcmds/macosx/port +35 -0
- data/test/testcmds/redhat/rpmbuild +6 -0
- data/test/testcmds/redhat/yum +90 -0
- data/test/testcmds/solaris/pkginfo +25 -0
- data/test/testcmds/solaris/pkgutil +36 -0
- data/test/testpkg/reloc/encfile +2 -0
- data/test/testpkg/reloc/file +2 -0
- data/test/testpkg/reloc/precryptfile +1 -0
- data/test/testpkg/reloc/precryptfile.plaintext +3 -0
- data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-default-perms.xml +28 -0
- data/test/testpkg/tpkg-default-perms.yml +20 -0
- data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-nativedeps.yml +13 -0
- data/test/testpkg/tpkg-nofiles.xml +14 -0
- data/test/testpkg/tpkg-nofiles.yml +9 -0
- data/test/testpkg/tpkg.xml +35 -0
- data/test/testpkg/tpkg.yml +25 -0
- data/test/tpkgtest.rb +300 -0
- data/tpkg.conf +16 -0
- data/tpkg.gemspec +24 -0
- data/tpkg.spec +28 -0
- data/tpkg.xml +17 -0
- data/tpkg_profile.sh +32 -0
- metadata +306 -31
data/test/test_tar.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#
|
2
|
+
# Test tpkg's basic tar functionality
|
3
|
+
#
|
4
|
+
|
5
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
class TpkgTarTests < Test::Unit::TestCase
|
8
|
+
include TpkgTests
|
9
|
+
|
10
|
+
def setup
|
11
|
+
Tpkg.set_prompt(false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_find_tar
|
15
|
+
# Verify that find_tar finds GNU tar or bsdtar
|
16
|
+
good_tar = false
|
17
|
+
tar = Tpkg.find_tar
|
18
|
+
IO.popen("#{tar} --version") do |pipe|
|
19
|
+
pipe.each_line do |line|
|
20
|
+
if line.include?('GNU tar') || line.include?('bsdtar')
|
21
|
+
good_tar = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
assert(good_tar, 'find_tar returns GNU tar or bsdtar')
|
26
|
+
|
27
|
+
# Muck with ENV['PATH'] and verify that find_tar throws an exception
|
28
|
+
oldpath = ENV['PATH']
|
29
|
+
begin
|
30
|
+
ENV['PATH'] = Tempfile.new('tpkgtest').path
|
31
|
+
Tpkg.clear_cached_tar
|
32
|
+
assert_raise(RuntimeError, 'find tar with bogus path') { Tpkg.find_tar }
|
33
|
+
ensure
|
34
|
+
ENV['PATH'] = oldpath
|
35
|
+
end
|
36
|
+
|
37
|
+
# Muck with the returned variable and ensure that doesn't stick
|
38
|
+
tar = Tpkg.find_tar
|
39
|
+
goodtar = tar.dup
|
40
|
+
tar << 'junk'
|
41
|
+
assert_equal(goodtar, Tpkg.find_tar)
|
42
|
+
|
43
|
+
# Verify that the returned path is wrapped in quotes if it contains spaces
|
44
|
+
testdirtmp = Tempfile.new('tpkgtest')
|
45
|
+
testdir = testdirtmp.path
|
46
|
+
testdirtmp.close
|
47
|
+
File.unlink(testdir)
|
48
|
+
testsubdir = File.join(testdir, 'a b')
|
49
|
+
FileUtils.mkdir_p(testsubdir)
|
50
|
+
Tpkg.clear_cached_tar
|
51
|
+
tar = Tpkg.find_tar
|
52
|
+
tar.sub!(/^"/, '')
|
53
|
+
tar.sub!(/"$/, '')
|
54
|
+
FileUtils.cp(tar, testsubdir)
|
55
|
+
if File.basename(tar) == 'bsdtar.exe'
|
56
|
+
# Dir.glob and Windows-style paths with \ seem incompatible, even with
|
57
|
+
# File::FNM_NOESCAPE
|
58
|
+
tardir = File.dirname(tar).gsub('\\', '/')
|
59
|
+
Dir.glob(File.join(tardir, '*.dll')).each do |dll|
|
60
|
+
FileUtils.cp(dll, testsubdir)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
Tpkg.clear_cached_tar
|
64
|
+
oldpath = ENV['PATH']
|
65
|
+
begin
|
66
|
+
ENV['PATH'] = testsubdir
|
67
|
+
expected_tar_path = nil
|
68
|
+
if RUBY_PLATFORM == 'i386-mingw32'
|
69
|
+
expected_tar_path =
|
70
|
+
testsubdir.gsub('/', '\\') + '\\' + File.basename(tar)
|
71
|
+
else
|
72
|
+
expected_tar_path = File.join(testsubdir, File.basename(tar))
|
73
|
+
end
|
74
|
+
assert_equal('"' + expected_tar_path + '"', Tpkg.find_tar)
|
75
|
+
FileUtils.rm_rf(testdir)
|
76
|
+
ensure
|
77
|
+
ENV['PATH'] = oldpath
|
78
|
+
end
|
79
|
+
Tpkg.clear_cached_tar
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_clear_cached_tar
|
83
|
+
tar = Tpkg.find_tar
|
84
|
+
Tpkg.clear_cached_tar
|
85
|
+
Dir.mktmpdir('pathdir') do |pathdir|
|
86
|
+
mytar = File.join(pathdir, 'tar')
|
87
|
+
File.symlink(tar, mytar)
|
88
|
+
oldpath = ENV['PATH']
|
89
|
+
begin
|
90
|
+
ENV['PATH'] = "#{pathdir}:#{oldpath}"
|
91
|
+
assert_equal(mytar, Tpkg.find_tar)
|
92
|
+
ensure
|
93
|
+
ENV['PATH'] = oldpath
|
94
|
+
end
|
95
|
+
end
|
96
|
+
Tpkg.clear_cached_tar
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
data/test/test_unpack.rb
ADDED
@@ -0,0 +1,977 @@
|
|
1
|
+
#
|
2
|
+
# Test tpkg's ability to unpack packages
|
3
|
+
#
|
4
|
+
|
5
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
6
|
+
require 'find'
|
7
|
+
|
8
|
+
class TpkgUnpackTests < Test::Unit::TestCase
|
9
|
+
include TpkgTests
|
10
|
+
|
11
|
+
def setup
|
12
|
+
Tpkg::set_prompt(false)
|
13
|
+
|
14
|
+
# temp dir that will automatically get deleted at end of test run, can be
|
15
|
+
# used for storing packages
|
16
|
+
@tempoutdir = Dir.mktmpdir('tempoutdir')
|
17
|
+
# Make up a package with both relocatable and non-relocatable
|
18
|
+
# directory trees so that we can ensure both types are unpacked
|
19
|
+
# properly.
|
20
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
21
|
+
# The stock test package has a reloc directory we can use
|
22
|
+
system("#{Tpkg::find_tar} -C #{TESTPKGDIR} --exclude .svn -cf - . | #{Tpkg::find_tar} -C #{srcdir} -xf -")
|
23
|
+
# Then add a root directory
|
24
|
+
FileUtils.mkdir_p(File.join(srcdir, 'root', 'etc'))
|
25
|
+
File.open(File.join(srcdir, 'root', 'etc', 'rootfile'), 'w') do |file|
|
26
|
+
file.puts "Hello"
|
27
|
+
end
|
28
|
+
@pkgfile = make_package(:output_directory => @tempoutdir, :source_directory => srcdir, :files => {'/etc/rootfile' => {'perms' => '0666'}})
|
29
|
+
end
|
30
|
+
|
31
|
+
# Pretend to be an OS with init script support
|
32
|
+
fact = Facter::Util::Fact.new('operatingsystem')
|
33
|
+
fact.stubs(:value).returns('RedHat')
|
34
|
+
Facter.stubs(:[]).returns(fact)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_unpack
|
38
|
+
Dir.mktmpdir('testroot') do |testroot|
|
39
|
+
FileUtils.mkdir_p(File.join(testroot, 'home', 'tpkg'))
|
40
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
|
41
|
+
assert_nothing_raised { tpkg.unpack(@pkgfile, :passphrase => PASSPHRASE) }
|
42
|
+
# This file should have the default 0444 perms
|
43
|
+
assert(File.exist?(File.join(testroot, 'home', 'tpkg', 'file')))
|
44
|
+
assert_equal(0444, File.stat(File.join(testroot, 'home', 'tpkg', 'file')).mode & 07777)
|
45
|
+
# This file should have the 0400 perms specified specifically for it in the stock test tpkg.xml
|
46
|
+
assert(File.exist?(File.join(testroot, 'home', 'tpkg', 'encfile')))
|
47
|
+
assert_equal(0400, File.stat(File.join(testroot, 'home', 'tpkg', 'encfile')).mode & 07777)
|
48
|
+
assert_equal(IO.read(File.join(TESTPKGDIR, 'reloc', 'encfile')), IO.read(File.join(testroot, 'home', 'tpkg', 'encfile')))
|
49
|
+
# This file should have the 0666 perms we specified above
|
50
|
+
assert(File.exist?(File.join(testroot, 'etc', 'rootfile')))
|
51
|
+
assert_equal(0666, File.stat(File.join(testroot, 'etc', 'rootfile')).mode & 07777)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Change the package base and unpack
|
55
|
+
Dir.mktmpdir('testroot2') do |testroot2|
|
56
|
+
tpkg2 = Tpkg.new(:file_system_root => testroot2, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
|
57
|
+
assert_nothing_raised { tpkg2.unpack(@pkgfile, :passphrase => PASSPHRASE) }
|
58
|
+
# Check that the files from the package ended up in the right place
|
59
|
+
assert(File.exist?(File.join(testroot2, 'home', 'tpkg', 'file')))
|
60
|
+
end
|
61
|
+
|
62
|
+
# Pass a nil passphrase to unpack and verify that it installs the
|
63
|
+
# package, skipping the unencrypted files
|
64
|
+
Dir.mktmpdir('testroot') do |testroot|
|
65
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
|
66
|
+
assert_nothing_raised { tpkg.unpack(@pkgfile) }
|
67
|
+
# Check that the files from the package ended up in the right place
|
68
|
+
assert(File.exist?(File.join(testroot, 'home', 'tpkg', 'file')))
|
69
|
+
assert(!File.exist?(File.join(testroot, 'home', 'tpkg', 'encfile')))
|
70
|
+
end
|
71
|
+
|
72
|
+
# Test permissions with no default permissions specified in tpkg.xml
|
73
|
+
# The stock test package has default permissions specified, so start
|
74
|
+
# with the -nofiles template which doesn't have default permissions.
|
75
|
+
pkg = nil
|
76
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
77
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
78
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'etc'))
|
79
|
+
# Set non-standard permissions on the directory so that we can
|
80
|
+
# ensure that the default permissions are applied by tpkg
|
81
|
+
File.chmod(0775, File.join(srcdir, 'reloc', 'etc'))
|
82
|
+
File.open(File.join(srcdir, 'reloc', 'etc', '666file'), 'w') do |file|
|
83
|
+
file.puts "Hello"
|
84
|
+
end
|
85
|
+
File.open(File.join(srcdir, 'reloc', 'etc', '400file'), 'w') do |file|
|
86
|
+
file.puts "Hello"
|
87
|
+
end
|
88
|
+
File.open(File.join(srcdir, 'reloc', 'etc', 'nopermsfile'), 'w') do |file|
|
89
|
+
file.puts "Hello"
|
90
|
+
end
|
91
|
+
# Set some crazy perms on this file so that we can be sure they
|
92
|
+
# are preserved (there are no default permissions for files)
|
93
|
+
File.chmod(0666, File.join(srcdir, 'reloc', 'etc', 'nopermsfile'))
|
94
|
+
pkg = make_package(:change => { 'name' => 'no-default-perms' }, :output_directory => @tempoutdir, :source_directory => srcdir, :files => {'etc/666file' => {'perms' => '0666'}, 'etc/400file' => {'perms' => '0400'}})
|
95
|
+
end
|
96
|
+
Dir.mktmpdir('testroot') do |testroot|
|
97
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
98
|
+
# Standard umask settings might be the same as the default permissions,
|
99
|
+
# which would mask failure here. Set an extreme umask so that we know
|
100
|
+
# tpkg is enforcing the desired permissions.
|
101
|
+
oldumask = File.umask
|
102
|
+
File.umask(0)
|
103
|
+
assert_nothing_raised { tpkg.unpack(pkg) }
|
104
|
+
File.umask(oldumask)
|
105
|
+
# This file should have the 0666 perms we specified above
|
106
|
+
assert_equal(0666, File.stat(File.join(testroot, 'home', 'tpkg', 'etc', '666file')).mode & 07777)
|
107
|
+
# This file should have the default 0400 perms we specified above
|
108
|
+
assert_equal(0400, File.stat(File.join(testroot, 'home', 'tpkg', 'etc', '400file')).mode & 07777)
|
109
|
+
# This file should have the 0666 perms we set on the file itself
|
110
|
+
assert_equal(0666, File.stat(File.join(testroot, 'home', 'tpkg', 'etc', 'nopermsfile')).mode & 07777)
|
111
|
+
# This directory should have the default 0755 tpkg directory perms
|
112
|
+
assert_equal(0755, File.stat(File.join(testroot, 'home', 'tpkg', 'etc')).mode & 07777)
|
113
|
+
end
|
114
|
+
FileUtils.rm_f(pkg)
|
115
|
+
|
116
|
+
# Test file_defaults and dir_defaults usage in a package
|
117
|
+
pkg = nil
|
118
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
119
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-default-perms.xml'), File.join(srcdir, 'tpkg.xml'))
|
120
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
|
121
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'dir1'))
|
122
|
+
File.open(File.join(srcdir, 'reloc', 'dir1', 'file1'), 'w') do |file|
|
123
|
+
file.puts 'Testing file_defaults'
|
124
|
+
end
|
125
|
+
# Ensure that the file goes into the package with permissions different
|
126
|
+
# from what we specify in the metadata so that we know tpkg set the
|
127
|
+
# permissions requested by the metadata and not that the file just came
|
128
|
+
# out of tar with the right permissions already.
|
129
|
+
File.chmod(0640, File.join(srcdir, 'reloc', 'dir1', 'file1'))
|
130
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'dir1', 'subdir1'))
|
131
|
+
File.chmod(0750, File.join(srcdir, 'reloc', 'dir1', 'subdir1'))
|
132
|
+
pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'default-perms' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
133
|
+
end
|
134
|
+
Dir.mktmpdir('testroot') do |testroot|
|
135
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
136
|
+
FileUtils.mkdir_p(testbase)
|
137
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
138
|
+
# Standard umask settings might be the same as the default permissions,
|
139
|
+
# which would mask failure here. Set an extreme umask so that we know
|
140
|
+
# tpkg is enforcing the desired permissions.
|
141
|
+
oldumask = File.umask
|
142
|
+
File.umask(0)
|
143
|
+
assert_nothing_raised { tpkg.unpack(pkg) }
|
144
|
+
File.umask(oldumask)
|
145
|
+
# This file should have the 0444 perms we specified in the
|
146
|
+
# tpkg-default-perms.xml file
|
147
|
+
assert_equal(0444, File.stat(File.join(testbase, 'dir1', 'file1')).mode & 07777)
|
148
|
+
# These directories should have the 0555 perms we specified
|
149
|
+
assert_equal(0555, File.stat(File.join(testbase, 'dir1')).mode & 07777)
|
150
|
+
assert_equal(0555, File.stat(File.join(testbase, 'dir1', 'subdir1')).mode & 07777)
|
151
|
+
# The mktmpdir cleanup process doesn't seem to like cleaning up
|
152
|
+
# non-writeable directories and links. Note that any assertion failures
|
153
|
+
# will cause this to get skipped. So if you start getting permission
|
154
|
+
# errors from the cleanup process look to see if you might have caused
|
155
|
+
# an assertion to fail.
|
156
|
+
Find.find(testroot) do |f|
|
157
|
+
if File.symlink?(f)
|
158
|
+
begin
|
159
|
+
File.lchmod(0700, f)
|
160
|
+
rescue NotImplementedError
|
161
|
+
end
|
162
|
+
else
|
163
|
+
File.chmod(0700, f)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
FileUtils.rm_f(pkg)
|
168
|
+
|
169
|
+
# Test that applying standard default permissions works in the face of
|
170
|
+
# symlinks in the package
|
171
|
+
pkg = nil
|
172
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
173
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
174
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
|
175
|
+
# Broken link to ensure that nothing attempts to traverse the link and
|
176
|
+
# fails as a result
|
177
|
+
File.symlink('/path/to/nowhere', File.join(srcdir, 'reloc', 'brokenlink'))
|
178
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'dir'))
|
179
|
+
File.symlink('dir', File.join(srcdir, 'reloc', 'dirlink'))
|
180
|
+
File.open(File.join(srcdir, 'reloc', 'file'), 'w') do |file|
|
181
|
+
file.puts 'Hello'
|
182
|
+
end
|
183
|
+
# Set some crazy perms on this file so that we can be sure they
|
184
|
+
# are preserved (there are no default permissions for files)
|
185
|
+
File.chmod(0777, File.join(srcdir, 'reloc', 'file'))
|
186
|
+
File.symlink('file', File.join(srcdir, 'reloc', 'filelink'))
|
187
|
+
pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'no-default-perms-with-links' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
188
|
+
end
|
189
|
+
Dir.mktmpdir('testroot') do |testroot|
|
190
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
191
|
+
FileUtils.mkdir_p(testbase)
|
192
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
193
|
+
assert_nothing_raised { tpkg.unpack(pkg) }
|
194
|
+
assert_equal(0777, File.stat(File.join(testbase, 'file')).mode & 07777)
|
195
|
+
assert_equal(Tpkg::DEFAULT_DIR_PERMS, File.stat(File.join(testbase, 'dir')).mode & 07777)
|
196
|
+
end
|
197
|
+
FileUtils.rm_f(pkg)
|
198
|
+
|
199
|
+
# Test that applying specified default permissions works in the face of
|
200
|
+
# symlinks in the package
|
201
|
+
pkg = nil
|
202
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
203
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-default-perms.xml'), File.join(srcdir, 'tpkg.xml'))
|
204
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
|
205
|
+
# Broken link to ensure that nothing attempts to traverse the link and
|
206
|
+
# fails as a result
|
207
|
+
File.symlink('/path/to/nowhere', File.join(srcdir, 'reloc', 'brokenlink'))
|
208
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'dir'))
|
209
|
+
File.symlink('dir', File.join(srcdir, 'reloc', 'dirlink'))
|
210
|
+
File.open(File.join(srcdir, 'reloc', 'file'), 'w') do |file|
|
211
|
+
file.puts 'Hello'
|
212
|
+
end
|
213
|
+
File.chmod(0777, File.join(srcdir, 'reloc', 'file'))
|
214
|
+
File.symlink('file', File.join(srcdir, 'reloc', 'filelink'))
|
215
|
+
pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'default-perms-with-links' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
216
|
+
end
|
217
|
+
Dir.mktmpdir('testroot') do |testroot|
|
218
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
219
|
+
FileUtils.mkdir_p(testbase)
|
220
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
221
|
+
assert_nothing_raised { tpkg.unpack(pkg) }
|
222
|
+
assert_equal(0444, File.stat(File.join(testbase, 'file')).mode & 07777)
|
223
|
+
assert_equal(0555, File.stat(File.join(testbase, 'dir')).mode & 07777)
|
224
|
+
begin
|
225
|
+
# Test to see if lchmod is implemented on this platform. If not then
|
226
|
+
# tpkg won't have been able to use it and we can't check if it worked.
|
227
|
+
lchmodtestfile = Tempfile.new('lchmodtest')
|
228
|
+
File.lchmod(0555, lchmodtestfile.path)
|
229
|
+
# If that didn't raise an exception then we can proceed with
|
230
|
+
# assertions related to lchmod
|
231
|
+
assert_equal(0444, File.lstat(File.join(testbase, 'brokenlink')).mode & 07777)
|
232
|
+
assert_equal(0444, File.lstat(File.join(testbase, 'filelink')).mode & 07777)
|
233
|
+
assert_equal(0444, File.lstat(File.join(testbase, 'dirlink')).mode & 07777)
|
234
|
+
rescue NotImplementedError
|
235
|
+
warn "lchmod not available on this platform, link permissions not tested"
|
236
|
+
end
|
237
|
+
# The mktmpdir cleanup process doesn't seem to like cleaning up
|
238
|
+
# non-writeable directories and links. Note that any assertion failures
|
239
|
+
# will cause this to get skipped. So if you start getting permission
|
240
|
+
# errors from the cleanup process look to see if you might have caused
|
241
|
+
# an assertion to fail.
|
242
|
+
Find.find(testroot) do |f|
|
243
|
+
if File.symlink?(f)
|
244
|
+
begin
|
245
|
+
File.lchmod(0700, f)
|
246
|
+
rescue NotImplementedError
|
247
|
+
end
|
248
|
+
else
|
249
|
+
File.chmod(0700, f)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
FileUtils.rm_f(pkg)
|
254
|
+
|
255
|
+
# Test that symlinks are not followed when applying permissions to
|
256
|
+
# specific files
|
257
|
+
pkg = nil
|
258
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
259
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
260
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
|
261
|
+
# Broken link to ensure that nothing attempts to traverse the link and
|
262
|
+
# fails as a result
|
263
|
+
File.symlink('/path/to/nowhere', File.join(srcdir, 'reloc', 'brokenlink'))
|
264
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'dir'))
|
265
|
+
File.symlink('dir', File.join(srcdir, 'reloc', 'dirlink'))
|
266
|
+
File.open(File.join(srcdir, 'reloc', 'file'), 'w') do |file|
|
267
|
+
file.puts 'Hello'
|
268
|
+
end
|
269
|
+
File.chmod(0400, File.join(srcdir, 'reloc', 'file'))
|
270
|
+
File.symlink('file', File.join(srcdir, 'reloc', 'filelink'))
|
271
|
+
pkg = make_package(:change => { 'name' => 'specific-perms-with-links' }, :files => {'brokenlink' => {'perms' => '0555'}, 'dirlink' => {'perms' => '0770'}, 'filelink' => {'perms' => '0666'}}, :source_directory => srcdir, :output_directory => @tempoutdir, :remove => ['operatingsystem', 'architecture'])
|
272
|
+
end
|
273
|
+
Dir.mktmpdir('testroot') do |testroot|
|
274
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
275
|
+
FileUtils.mkdir_p(testbase)
|
276
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
277
|
+
assert_nothing_raised { tpkg.unpack(pkg) }
|
278
|
+
assert_equal(Tpkg::DEFAULT_DIR_PERMS, File.stat(File.join(testbase, 'dir')).mode & 07777)
|
279
|
+
assert_equal(0400, File.stat(File.join(testbase, 'file')).mode & 07777)
|
280
|
+
begin
|
281
|
+
# Test to see if lchmod is implemented on this platform. If not then
|
282
|
+
# tpkg won't have been able to use it and we can't check if it worked.
|
283
|
+
lchmodtestfile = Tempfile.new('lchmodtest')
|
284
|
+
File.lchmod(0555, lchmodtestfile.path)
|
285
|
+
# If that didn't raise an exception then we can proceed with
|
286
|
+
# assertions related to lchmod
|
287
|
+
assert_equal(0555, File.lstat(File.join(testbase, 'brokenlink')).mode & 07777)
|
288
|
+
assert_equal(0666, File.lstat(File.join(testbase, 'filelink')).mode & 07777)
|
289
|
+
assert_equal(0770, File.lstat(File.join(testbase, 'dirlink')).mode & 07777)
|
290
|
+
rescue NotImplementedError
|
291
|
+
warn "lchmod not available on this platform, link permissions not tested"
|
292
|
+
end
|
293
|
+
end
|
294
|
+
FileUtils.rm_f(pkg)
|
295
|
+
|
296
|
+
# Test that preinstall/postinstall are run at the right points
|
297
|
+
# Make up a package with scripts that create files so we can check timestamps
|
298
|
+
# Also, test that tpkg will chdir to package unpack directory before
|
299
|
+
# calling pre/post/install/remove scripts
|
300
|
+
scriptfiles = {}
|
301
|
+
pkgfile = nil
|
302
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
303
|
+
# Include the stock test package contents
|
304
|
+
system("#{Tpkg::find_tar} -C #{TESTPKGDIR} --exclude .svn -cf - . | #{Tpkg::find_tar} -C #{srcdir} -xf -")
|
305
|
+
|
306
|
+
# Add some dummy file for testing relative path
|
307
|
+
File.open(File.join(srcdir, "dummyfile"), 'w') do |file|
|
308
|
+
file.puts("hello world")
|
309
|
+
end
|
310
|
+
|
311
|
+
# Then add scripts
|
312
|
+
['preinstall', 'postinstall'].each do |script|
|
313
|
+
File.open(File.join(srcdir, script), 'w') do |scriptfile|
|
314
|
+
# We have each script write to a temporary file (so that we can
|
315
|
+
# check the timestamp of that file to ensure proper ordering) and
|
316
|
+
# print out the name of the file (just to aid debugging)
|
317
|
+
tmpfile = Tempfile.new('tpkgtest_script')
|
318
|
+
scriptfiles[script] = tmpfile
|
319
|
+
scriptfile.puts('#!/bin/sh')
|
320
|
+
scriptfile.puts('set -e')
|
321
|
+
# Test that tpkg set $TPKG_HOME before running the script
|
322
|
+
scriptfile.puts('test -n "$TPKG_HOME"')
|
323
|
+
# Test that we had chdir'ed to package unpack directory
|
324
|
+
scriptfile.puts('test -e dummyfile')
|
325
|
+
scriptfile.puts("echo #{script} > #{tmpfile.path}")
|
326
|
+
scriptfile.puts('sleep 1')
|
327
|
+
end
|
328
|
+
File.chmod(0755, File.join(srcdir, script))
|
329
|
+
end
|
330
|
+
# Change name of package so that the file doesn't conflict with @pkgfile
|
331
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :source_directory => srcdir, :change => {'name' => 'scriptpkg'})
|
332
|
+
end
|
333
|
+
# Install the script package
|
334
|
+
Dir.mktmpdir('testroot') do |testroot|
|
335
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
336
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkgfile])
|
337
|
+
assert_nothing_raised { tpkg.unpack(pkgfile, :passphrase => PASSPHRASE) }
|
338
|
+
# FIXME: Need a way to test that the package install occurred between the two scripts
|
339
|
+
assert(File.stat(scriptfiles['preinstall'].path).mtime < File.stat(scriptfiles['postinstall'].path).mtime)
|
340
|
+
end
|
341
|
+
FileUtils.rm_f(pkgfile)
|
342
|
+
|
343
|
+
# Test init script handling
|
344
|
+
pkg = nil
|
345
|
+
pkg2 = nil
|
346
|
+
pkg3 = nil
|
347
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
348
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
349
|
+
FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
|
350
|
+
# These packages have different init scripts of the same name
|
351
|
+
(1..3).each do | i |
|
352
|
+
FileUtils.mkdir(File.join(srcdir, 'reloc', i.to_s))
|
353
|
+
File.open(File.join(srcdir, 'reloc', i.to_s, "myinit"), 'w') do |file|
|
354
|
+
file.puts('init script')
|
355
|
+
end
|
356
|
+
end
|
357
|
+
pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'initpkg' }, :source_directory => srcdir, :files => { File.join('1','myinit') => { 'init' => {} } }, :remove => ['operatingsystem', 'architecture'])
|
358
|
+
pkg2 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'initpkg2' }, :source_directory => srcdir, :files => { File.join('2','myinit') => { 'init' => {} } }, :remove => ['operatingsystem', 'architecture'])
|
359
|
+
pkg3 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'initpkg3' }, :source_directory => srcdir, :files => { File.join('3','myinit') => { 'init' => {} } }, :remove => ['operatingsystem', 'architecture'])
|
360
|
+
end
|
361
|
+
Dir.mktmpdir('testroot') do |testroot|
|
362
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
363
|
+
FileUtils.mkdir_p(testbase)
|
364
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg,pkg2,pkg3])
|
365
|
+
metadata = Tpkg::metadata_from_package(pkg)
|
366
|
+
metadata2 = Tpkg::metadata_from_package(pkg2)
|
367
|
+
metadata3 = Tpkg::metadata_from_package(pkg3)
|
368
|
+
tpkg.install([pkg], PASSPHRASE)
|
369
|
+
tpkg.init_links(metadata).each do |link, init_script|
|
370
|
+
assert(File.symlink?(link))
|
371
|
+
assert_equal(init_script, File.readlink(link))
|
372
|
+
end
|
373
|
+
# Test the handling of packages with conflicting init scripts.
|
374
|
+
# We should end up with a link named with a '1' at the end and a
|
375
|
+
# link named with a '2' at the end.
|
376
|
+
tpkg.install([pkg2], PASSPHRASE)
|
377
|
+
tpkg.install([pkg3], PASSPHRASE)
|
378
|
+
tpkg.init_links(metadata2).each do |link, init_script|
|
379
|
+
assert(File.symlink?(link + '1'))
|
380
|
+
assert_equal(init_script, File.readlink(link + '1'))
|
381
|
+
end
|
382
|
+
tpkg.init_links(metadata3).each do |link, init_script|
|
383
|
+
assert(File.symlink?(link + '2'))
|
384
|
+
assert_equal(init_script, File.readlink(link + '2'))
|
385
|
+
end
|
386
|
+
end
|
387
|
+
FileUtils.rm_f(pkg)
|
388
|
+
FileUtils.rm_f(pkg2)
|
389
|
+
FileUtils.rm_f(pkg3)
|
390
|
+
|
391
|
+
# Test external handling
|
392
|
+
extname = 'testext'
|
393
|
+
extdata = "This is a test of an external hook\nwith multiple lines\nof data"
|
394
|
+
pkg = nil
|
395
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
396
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
397
|
+
pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'externalpkg' }, :externals => { extname => { 'data' => extdata } }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
398
|
+
end
|
399
|
+
Dir.mktmpdir('testroot') do |testroot|
|
400
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
401
|
+
FileUtils.mkdir_p(testbase)
|
402
|
+
# Make an external script which writes the data it receives to a temporary
|
403
|
+
# file, so that we can verify the external script received the data
|
404
|
+
# properly.
|
405
|
+
exttmpfile = Tempfile.new('tpkgtest_external')
|
406
|
+
externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
|
407
|
+
FileUtils.mkdir_p(externalsdir)
|
408
|
+
extscript = File.join(externalsdir, extname)
|
409
|
+
File.open(extscript, 'w') do |file|
|
410
|
+
file.puts('#!/bin/sh')
|
411
|
+
file.puts("cat >> #{exttmpfile.path}")
|
412
|
+
end
|
413
|
+
File.chmod(0755, extscript)
|
414
|
+
# And run the test
|
415
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
416
|
+
metadata = Tpkg::metadata_from_package(pkg)
|
417
|
+
assert_nothing_raised { tpkg.unpack(pkg, :passphrase => PASSPHRASE) }
|
418
|
+
assert_equal(extdata, IO.read(exttmpfile.path))
|
419
|
+
end
|
420
|
+
FileUtils.rm_f(pkg)
|
421
|
+
|
422
|
+
# Test handling of external with datafile
|
423
|
+
extname = 'testext'
|
424
|
+
extdata = "This is a test of an external hook\nwith multiple lines\nof data from a datafile"
|
425
|
+
pkg = nil
|
426
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
427
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
428
|
+
# Create the datafile
|
429
|
+
File.open(File.join(srcdir, 'datafile'), 'w') do |file|
|
430
|
+
file.print(extdata)
|
431
|
+
end
|
432
|
+
File.chmod(0755, File.join(srcdir, 'datafile'))
|
433
|
+
pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'externalpkg' }, :externals => { extname => { 'datafile' => './datafile' } }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
434
|
+
end
|
435
|
+
Dir.mktmpdir('testroot') do |testroot|
|
436
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
437
|
+
FileUtils.mkdir_p(testbase)
|
438
|
+
# Make an external script which writes the data it receives to a temporary
|
439
|
+
# file, so that we can verify the external script received the data
|
440
|
+
# properly.
|
441
|
+
exttmpfile = Tempfile.new('tpkgtest_external')
|
442
|
+
externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
|
443
|
+
FileUtils.mkdir_p(externalsdir)
|
444
|
+
extscript = File.join(externalsdir, extname)
|
445
|
+
File.open(extscript, 'w') do |file|
|
446
|
+
file.puts('#!/bin/sh')
|
447
|
+
file.puts("cat > #{exttmpfile.path}")
|
448
|
+
end
|
449
|
+
File.chmod(0755, extscript)
|
450
|
+
# And run the test
|
451
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
452
|
+
metadata = Tpkg::metadata_from_package(pkg)
|
453
|
+
assert_nothing_raised { tpkg.unpack(pkg, :passphrase => PASSPHRASE) }
|
454
|
+
assert_equal(extdata, IO.read(exttmpfile.path))
|
455
|
+
end
|
456
|
+
FileUtils.rm_f(pkg)
|
457
|
+
|
458
|
+
# Test handling of external with datascript
|
459
|
+
extname = 'testext'
|
460
|
+
extdata = "This is a test of an external hook\nwith multiple lines\nof data from a datascript"
|
461
|
+
pkg = nil
|
462
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
463
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
464
|
+
# Create the datascript
|
465
|
+
File.open(File.join(srcdir, 'datascript'), 'w') do |file|
|
466
|
+
file.puts('#!/bin/sh')
|
467
|
+
# echo may or may not add a trailing \n depending on which echo we end
|
468
|
+
# up, so use printf, which doesn't add things.
|
469
|
+
file.puts("printf \"#{extdata}\"")
|
470
|
+
end
|
471
|
+
File.chmod(0755, File.join(srcdir, 'datascript'))
|
472
|
+
pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'externalpkg' }, :externals => { extname => { 'datascript' => './datascript' } }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
473
|
+
end
|
474
|
+
Dir.mktmpdir('testroot') do |testroot|
|
475
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
476
|
+
FileUtils.mkdir_p(testbase)
|
477
|
+
# Make an external script which writes the data it receives to a temporary
|
478
|
+
# file, so that we can verify the external script received the data
|
479
|
+
# properly.
|
480
|
+
exttmpfile = Tempfile.new('tpkgtest_external')
|
481
|
+
externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
|
482
|
+
FileUtils.mkdir_p(externalsdir)
|
483
|
+
extscript = File.join(externalsdir, extname)
|
484
|
+
File.open(extscript, 'w') do |file|
|
485
|
+
file.puts('#!/bin/sh')
|
486
|
+
file.puts("cat > #{exttmpfile.path}")
|
487
|
+
end
|
488
|
+
File.chmod(0755, extscript)
|
489
|
+
# And run the test
|
490
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
|
491
|
+
metadata = Tpkg::metadata_from_package(pkg)
|
492
|
+
assert_nothing_raised { tpkg.unpack(pkg, :passphrase => PASSPHRASE) }
|
493
|
+
assert_equal(extdata, IO.read(exttmpfile.path))
|
494
|
+
end
|
495
|
+
FileUtils.rm_f(pkg)
|
496
|
+
|
497
|
+
# Test that existing files/directories' perm and ownership are preserved
|
498
|
+
# unless specified by user
|
499
|
+
Dir.mktmpdir('testroot') do |testroot|
|
500
|
+
FileUtils.mkdir_p(File.join(testroot, 'home', 'tpkg'))
|
501
|
+
FileUtils.mkdir_p(File.join(testroot, 'etc'))
|
502
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
|
503
|
+
|
504
|
+
# set up 2 existing files for the test
|
505
|
+
File.open(File.join(testroot, 'home', 'tpkg', 'file'), 'w') do |file|
|
506
|
+
file.puts "Hello"
|
507
|
+
end
|
508
|
+
#system("chmod 707 #{File.join(testroot, 'home', 'tpkg', 'file')}")
|
509
|
+
File.chmod(0707, File.join(testroot, 'home', 'tpkg', 'file'))
|
510
|
+
|
511
|
+
File.open(File.join(testroot, 'etc', 'rootfile'), 'w') do |file|
|
512
|
+
file.puts "Hello"
|
513
|
+
end
|
514
|
+
File.chmod(0707, File.join(testroot, 'etc', 'rootfile'))
|
515
|
+
# system("chmod 707 #{File.join(testroot, 'etc', 'rootfile')}")
|
516
|
+
|
517
|
+
assert_nothing_raised { tpkg.unpack(@pkgfile, :passphrase => PASSPHRASE) }
|
518
|
+
|
519
|
+
# This file should have the default 0444 perms
|
520
|
+
# but the file already exists. So it should keep its old perms, which is 707
|
521
|
+
assert(File.exist?(File.join(testroot, 'home', 'tpkg', 'file')))
|
522
|
+
assert_equal(0707, File.stat(File.join(testroot, 'home', 'tpkg', 'file')).mode & 07777)
|
523
|
+
|
524
|
+
# Even if this file exists, we specifically set the perm. So the perm should be set to what
|
525
|
+
# we want
|
526
|
+
assert(File.exist?(File.join(testroot, 'etc', 'rootfile')))
|
527
|
+
assert_equal(0666, File.stat(File.join(testroot, 'etc', 'rootfile')).mode & 07777)
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
# Test that the unpack method calls install_crontabs as appropriate
|
532
|
+
def test_unpack_install_crontabs
|
533
|
+
# FIXME
|
534
|
+
end
|
535
|
+
|
536
|
+
# Check that if a config file already existed in the system, then we don't
|
537
|
+
# overwrite it. Instead we save the new one with a .tpkgnew extension.
|
538
|
+
def test_config_files_handling
|
539
|
+
pkgfile = nil
|
540
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
541
|
+
# The stock test package has a reloc directory we can use
|
542
|
+
system("#{Tpkg::find_tar} -C #{TESTPKGDIR} --exclude .svn -cf - . | #{Tpkg::find_tar} -C #{srcdir} -xf -")
|
543
|
+
# Then add some configuration files
|
544
|
+
FileUtils.mkdir_p(File.join(srcdir, 'root'))
|
545
|
+
['conf1', 'conf2'].each do |conf|
|
546
|
+
File.open(File.join(srcdir, 'root', conf), 'w') do |file|
|
547
|
+
file.puts conf
|
548
|
+
end
|
549
|
+
end
|
550
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :source_directory => srcdir,
|
551
|
+
:files => {'/conf1' => {'config' => true}, '/conf2' => {'config' => true}})
|
552
|
+
end
|
553
|
+
|
554
|
+
Dir.mktmpdir('testroot') do |testroot|
|
555
|
+
# Create an existing configuration file
|
556
|
+
File.open(File.join(testroot, 'conf1'), 'w') do |file|
|
557
|
+
file.puts "Existing conf file"
|
558
|
+
end
|
559
|
+
|
560
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
|
561
|
+
assert_nothing_raised { tpkg.unpack(pkgfile, :passphrase => PASSPHRASE) }
|
562
|
+
assert(File.exists?(File.join(testroot, 'conf1.tpkgnew')))
|
563
|
+
assert(!File.exists?(File.join(testroot, 'conf2.tpkgnew')))
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
def test_install_init_scripts
|
568
|
+
metadata = nil
|
569
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
570
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
571
|
+
create_metadata_file(File.join(srcdir, 'tpkg.xml'), :change => { 'name' => 'initpkg' }, :files => { 'etc/init.d/initscript' => { 'init' => {} } })
|
572
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
573
|
+
end
|
574
|
+
|
575
|
+
Dir.mktmpdir('testroot') do |testroot|
|
576
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
577
|
+
FileUtils.mkdir_p(testbase)
|
578
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'))
|
579
|
+
|
580
|
+
link = nil
|
581
|
+
init_script = nil
|
582
|
+
tpkg.init_links(metadata).each do |l, is|
|
583
|
+
link = l
|
584
|
+
init_script = is
|
585
|
+
end
|
586
|
+
|
587
|
+
# init_links returns an empty list on platforms where tpkg doesn't have
|
588
|
+
# init script support
|
589
|
+
if link
|
590
|
+
# Directory for link doesn't exist, directory and link are created
|
591
|
+
tpkg.install_init_scripts(metadata)
|
592
|
+
assert(File.symlink?(link))
|
593
|
+
assert_equal(init_script, File.readlink(link))
|
594
|
+
|
595
|
+
# Link already exists, nothing is done
|
596
|
+
sleep 2
|
597
|
+
beforetime = File.lstat(link).mtime
|
598
|
+
tpkg.install_init_scripts(metadata)
|
599
|
+
assert(File.symlink?(link))
|
600
|
+
assert_equal(init_script, File.readlink(link))
|
601
|
+
assert_equal(beforetime, File.lstat(link).mtime)
|
602
|
+
|
603
|
+
# Existing files or links up to 8 already exist, link created with appropriate suffix
|
604
|
+
File.delete(link)
|
605
|
+
File.symlink('somethingelse', link)
|
606
|
+
0.upto(8) do |i|
|
607
|
+
File.delete(link + i.to_s) if (i != 0)
|
608
|
+
File.symlink('somethingelse', link + i.to_s)
|
609
|
+
tpkg.install_init_scripts(metadata)
|
610
|
+
assert(File.symlink?(link + (i + 1).to_s))
|
611
|
+
assert_equal(init_script, File.readlink(link + (i + 1).to_s))
|
612
|
+
end
|
613
|
+
|
614
|
+
# Existing files or links up to 9 already exist, exception raised
|
615
|
+
File.delete(link + '9')
|
616
|
+
File.symlink('somethingelse', link + '9')
|
617
|
+
assert_raise(RuntimeError) { tpkg.install_init_scripts(metadata) }
|
618
|
+
|
619
|
+
# Running as non-root, permissions issues prevent link creation, warning
|
620
|
+
FileUtils.rm(Dir.glob(link + '*'))
|
621
|
+
File.chmod(0000, File.dirname(link))
|
622
|
+
# assert_nothing_raised { tpkg.install_init_scripts(metadata) }
|
623
|
+
tpkg.install_init_scripts(metadata)
|
624
|
+
# FIXME: look for warning in stderr
|
625
|
+
assert(!File.exist?(link) && !File.symlink?(link))
|
626
|
+
File.chmod(0755, File.dirname(link))
|
627
|
+
|
628
|
+
# Running as root, permissions issues prevent link creation, exception raised
|
629
|
+
# FIXME: I don't actually know of a way to trigger EACCES in this
|
630
|
+
# situation when running as root, and we never run the unit tests as
|
631
|
+
# root anyway.
|
632
|
+
end
|
633
|
+
end
|
634
|
+
end
|
635
|
+
def test_install_init_script
|
636
|
+
# FIXME
|
637
|
+
end
|
638
|
+
|
639
|
+
def test_run_preinstall
|
640
|
+
Dir.mktmpdir('testroot') do |testroot|
|
641
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
642
|
+
FileUtils.mkdir_p(testbase)
|
643
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'))
|
644
|
+
|
645
|
+
Dir.mktmpdir('test_run_preinstall') do |workdir|
|
646
|
+
FileUtils.mkdir(File.join(workdir, 'tpkg'))
|
647
|
+
|
648
|
+
# workdir/preinstall doesn't exist, nothing done
|
649
|
+
assert_nothing_raised { tpkg.run_preinstall('mypkg.tpkg', workdir) }
|
650
|
+
|
651
|
+
# Now test when preinstall does exist
|
652
|
+
outputfile = Tempfile.new('test_run_preinstall')
|
653
|
+
File.open(File.join(workdir, 'tpkg', 'preinstall'), 'w') do |file|
|
654
|
+
file.puts '#!/bin/sh'
|
655
|
+
file.puts "echo preinstall >> #{outputfile.path}"
|
656
|
+
file.puts "cat otherfile >> #{outputfile.path}"
|
657
|
+
end
|
658
|
+
File.chmod(0755, File.join(workdir, 'tpkg', 'preinstall'))
|
659
|
+
File.open(File.join(workdir, 'tpkg', 'otherfile'), 'w') do |file|
|
660
|
+
file.puts 'otherfile contents'
|
661
|
+
end
|
662
|
+
pwd = Dir.pwd
|
663
|
+
r = tpkg.run_preinstall('mypkg.tpkg', workdir)
|
664
|
+
# Verify that the script was run and the working directory was changed
|
665
|
+
# such that the script's relative path to otherfile was valid.
|
666
|
+
assert_match(/preinstall/, File.read(outputfile.path))
|
667
|
+
assert_match(/otherfile contents/, File.read(outputfile.path))
|
668
|
+
# Verify that our pwd was restored
|
669
|
+
assert_equal(pwd, Dir.pwd)
|
670
|
+
|
671
|
+
# Ensure that the user is warned of a non-executable script
|
672
|
+
File.chmod(0644, File.join(workdir, 'tpkg', 'preinstall'))
|
673
|
+
assert_raise(RuntimeError) { tpkg.run_preinstall('mypkg.tpkg', workdir) }
|
674
|
+
# FIXME: need to capture stderr to confirm that a warning was displayed
|
675
|
+
|
676
|
+
# Verify that by default run_preinstall raises an exception if the script
|
677
|
+
# did not run succesfully
|
678
|
+
File.open(File.join(workdir, 'tpkg', 'preinstall'), 'w') do |file|
|
679
|
+
file.puts '#!/bin/sh'
|
680
|
+
file.puts "exit 1"
|
681
|
+
end
|
682
|
+
File.chmod(0755, File.join(workdir, 'tpkg', 'preinstall'))
|
683
|
+
assert_raise(RuntimeError) { tpkg.run_preinstall('mypkg.tpkg', workdir) }
|
684
|
+
# And verify that our pwd was restored
|
685
|
+
assert_equal(pwd, Dir.pwd)
|
686
|
+
|
687
|
+
# Verify that run_preinstall only displays a warning if the script
|
688
|
+
# did not run succesfully and the user specified the force option.
|
689
|
+
tpkgforce = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :force => true)
|
690
|
+
assert_nothing_raised { tpkg.run_postinstall('mypkg.tpkg', workdir) }
|
691
|
+
# FIXME: need to capture stderr to confirm that a warning was displayed
|
692
|
+
# And verify that our pwd was restored
|
693
|
+
assert_equal(pwd, Dir.pwd)
|
694
|
+
end
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
def test_run_postinstall
|
699
|
+
Dir.mktmpdir('testroot') do |testroot|
|
700
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
701
|
+
FileUtils.mkdir_p(testbase)
|
702
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'))
|
703
|
+
|
704
|
+
Dir.mktmpdir('test_run_postinstall') do |workdir|
|
705
|
+
FileUtils.mkdir(File.join(workdir, 'tpkg'))
|
706
|
+
|
707
|
+
# workdir/postinstall doesn't exist, nothing done
|
708
|
+
assert_nothing_raised { tpkg.run_postinstall('mypkg.tpkg', workdir) }
|
709
|
+
|
710
|
+
# Now test when postinstall does exist
|
711
|
+
outputfile = Tempfile.new('test_run_postinstall')
|
712
|
+
File.open(File.join(workdir, 'tpkg', 'postinstall'), 'w') do |file|
|
713
|
+
file.puts '#!/bin/sh'
|
714
|
+
file.puts "echo postinstall >> #{outputfile.path}"
|
715
|
+
file.puts "cat otherfile >> #{outputfile.path}"
|
716
|
+
end
|
717
|
+
File.chmod(0755, File.join(workdir, 'tpkg', 'postinstall'))
|
718
|
+
File.open(File.join(workdir, 'tpkg', 'otherfile'), 'w') do |file|
|
719
|
+
file.puts 'otherfile contents'
|
720
|
+
end
|
721
|
+
pwd = Dir.pwd
|
722
|
+
r = tpkg.run_postinstall('mypkg.tpkg', workdir)
|
723
|
+
# Verify that the script was run and the working directory was changed
|
724
|
+
# such that the script's relative path to otherfile was valid.
|
725
|
+
assert_match(/postinstall/, File.read(outputfile.path))
|
726
|
+
assert_match(/otherfile contents/, File.read(outputfile.path))
|
727
|
+
# Verify that run_postinstall returns 0 if the script ran succesfully
|
728
|
+
assert_equal(0, r)
|
729
|
+
# Verify that our pwd was restored
|
730
|
+
assert_equal(pwd, Dir.pwd)
|
731
|
+
|
732
|
+
# Ensure that the user is warned of a non-executable script
|
733
|
+
File.chmod(0644, File.join(workdir, 'tpkg', 'postinstall'))
|
734
|
+
tpkg.run_postinstall('mypkg.tpkg', workdir)
|
735
|
+
# FIXME: need to capture stderr to confirm that a warning was displayed
|
736
|
+
|
737
|
+
# Verify that run_postinstall returns Tpkg::POSTINSTALL_ERR if the script
|
738
|
+
# did not run succesfully
|
739
|
+
File.open(File.join(workdir, 'tpkg', 'postinstall'), 'w') do |file|
|
740
|
+
file.puts '#!/bin/sh'
|
741
|
+
file.puts "exit 1"
|
742
|
+
end
|
743
|
+
File.chmod(0755, File.join(workdir, 'tpkg', 'postinstall'))
|
744
|
+
r = tpkg.run_postinstall('mypkg.tpkg', workdir)
|
745
|
+
assert_equal(Tpkg::POSTINSTALL_ERR, r)
|
746
|
+
# And verify that our pwd was restored
|
747
|
+
assert_equal(pwd, Dir.pwd)
|
748
|
+
end
|
749
|
+
end
|
750
|
+
end
|
751
|
+
|
752
|
+
def test_run_externals_for_install
|
753
|
+
Dir.mktmpdir('testroot') do |testroot|
|
754
|
+
testbase = File.join(testroot, 'home', 'tpkg')
|
755
|
+
FileUtils.mkdir_p(testbase)
|
756
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'))
|
757
|
+
tpkg_force = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :force => true)
|
758
|
+
|
759
|
+
Dir.mktmpdir('run_externals_for_install') do |workdir|
|
760
|
+
FileUtils.mkdir(File.join(workdir, 'tpkg'))
|
761
|
+
|
762
|
+
pwd = Dir.pwd
|
763
|
+
|
764
|
+
# No metadata[:externals], no problem
|
765
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(workdir, 'tpkg', 'tpkg.xml'))
|
766
|
+
create_metadata_file(File.join(workdir, 'tpkg', 'tpkg.xml'), :change => { 'name' => 'run_externals_for_install' })
|
767
|
+
metadata = Metadata.new(File.read(File.join(workdir, 'tpkg', 'tpkg.xml')), 'xml')
|
768
|
+
# value is nil
|
769
|
+
metadata[:externals] = nil
|
770
|
+
assert_nothing_raised { tpkg.run_externals_for_install(metadata, workdir) }
|
771
|
+
assert_equal(pwd, Dir.pwd)
|
772
|
+
# value is empty array
|
773
|
+
metadata[:externals] = []
|
774
|
+
assert_nothing_raised { tpkg.run_externals_for_install(metadata, workdir) }
|
775
|
+
assert_equal(pwd, Dir.pwd)
|
776
|
+
|
777
|
+
# Make up a package metadata with a mix of externals with inline data, a
|
778
|
+
# datafile, and a datascript
|
779
|
+
output = {}
|
780
|
+
# Inline data
|
781
|
+
inlineextname = 'inlineextname'
|
782
|
+
inlinedata = "This is a test of an external hook\nwith multiple lines\nof data"
|
783
|
+
output[inlineextname] = {}
|
784
|
+
output[inlineextname][:data] = inlinedata
|
785
|
+
# datafile
|
786
|
+
fileextname = 'fileextname'
|
787
|
+
filedata = "This is a test of an external hook\nwith multiple lines\nof data from a datafile"
|
788
|
+
File.open(File.join(workdir, 'tpkg', 'datafile'), 'w') do |file|
|
789
|
+
file.print(filedata)
|
790
|
+
end
|
791
|
+
output[fileextname] = {}
|
792
|
+
output[fileextname][:data] = filedata
|
793
|
+
# datascript
|
794
|
+
scriptextname = 'scriptextname'
|
795
|
+
scriptdata = "This is a test of an external hook\nwith multiple lines\nof data from a datascript"
|
796
|
+
File.open(File.join(workdir, 'tpkg', 'datascript'), 'w') do |file|
|
797
|
+
file.puts('#!/bin/sh')
|
798
|
+
# echo may or may not add a trailing \n depending on which echo we end
|
799
|
+
# up, so use printf, which doesn't add things.
|
800
|
+
file.puts("printf \"#{scriptdata}\"")
|
801
|
+
end
|
802
|
+
File.chmod(0755, File.join(workdir, 'tpkg', 'datascript'))
|
803
|
+
output[scriptextname] = {}
|
804
|
+
output[scriptextname][:data] = scriptdata
|
805
|
+
|
806
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(workdir, 'tpkg', 'tpkg.xml'))
|
807
|
+
create_metadata_file(File.join(workdir, 'tpkg', 'tpkg.xml'),
|
808
|
+
:change => { 'name' => 'run_externals_for_install' },
|
809
|
+
:externals => { inlineextname => { 'data' => inlinedata },
|
810
|
+
fileextname => { 'datafile' => 'datafile' },
|
811
|
+
scriptextname => { 'datascript' => './datascript' } })
|
812
|
+
metadata = Metadata.new(File.read(File.join(workdir, 'tpkg', 'tpkg.xml')), 'xml')
|
813
|
+
metadata[:filename] = 'test_run_externals_for_install'
|
814
|
+
|
815
|
+
# We need a copy of these later
|
816
|
+
original_externals = metadata[:externals].collect {|e| e.dup}
|
817
|
+
|
818
|
+
# Make external scripts which write the data they receive to temporary
|
819
|
+
# files so that we can verify that run_externals_for_install called
|
820
|
+
# run_external with the proper parameters.
|
821
|
+
externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
|
822
|
+
FileUtils.mkdir_p(externalsdir)
|
823
|
+
[inlineextname, fileextname, scriptextname].each do |extname|
|
824
|
+
exttmpfile = Tempfile.new('tpkgtest_external')
|
825
|
+
extscript = File.join(externalsdir, extname)
|
826
|
+
File.open(extscript, 'w') do |file|
|
827
|
+
file.puts('#!/bin/sh')
|
828
|
+
file.puts("cat >> #{exttmpfile.path}")
|
829
|
+
end
|
830
|
+
File.chmod(0755, extscript)
|
831
|
+
output[extname][:file] = exttmpfile
|
832
|
+
end
|
833
|
+
|
834
|
+
# Make sure the hash keys we expect are in metadata, so that when we check
|
835
|
+
# later that they are gone we know run_externals_for_install removed them.
|
836
|
+
fileext = metadata[:externals].find {|e| e[:name] == fileextname}
|
837
|
+
assert(fileext.has_key?(:datafile))
|
838
|
+
assert(!fileext.has_key?(:data))
|
839
|
+
scriptext = metadata[:externals].find {|e| e[:name] == scriptextname}
|
840
|
+
assert(scriptext.has_key?(:datascript))
|
841
|
+
assert(!scriptext.has_key?(:data))
|
842
|
+
|
843
|
+
tpkg.run_externals_for_install(metadata, workdir)
|
844
|
+
|
845
|
+
assert_equal(pwd, Dir.pwd)
|
846
|
+
output.each do |extname, extinfo|
|
847
|
+
assert_equal(extinfo[:data], File.read(extinfo[:file].path))
|
848
|
+
end
|
849
|
+
|
850
|
+
# Make sure run_externals_for_install performed the expected switcheroo on
|
851
|
+
# these hash entries
|
852
|
+
fileext = metadata[:externals].find {|e| e[:name] == fileextname}
|
853
|
+
assert(!fileext.has_key?(:datafile))
|
854
|
+
assert(fileext.has_key?(:data))
|
855
|
+
fileext = metadata[:externals].find {|e| e[:name] == scriptextname}
|
856
|
+
assert(!scriptext.has_key?(:datascript))
|
857
|
+
assert(scriptext.has_key?(:data))
|
858
|
+
|
859
|
+
# Cleanup for another run
|
860
|
+
output.each do |extname, extinfo|
|
861
|
+
File.delete(extinfo[:file].path)
|
862
|
+
end
|
863
|
+
|
864
|
+
# externals_to_skip skipped
|
865
|
+
tpkg.run_externals_for_install(metadata, workdir, [scriptext])
|
866
|
+
assert_equal(pwd, Dir.pwd)
|
867
|
+
output.each do |extname, extinfo|
|
868
|
+
if extname != scriptextname
|
869
|
+
assert_equal(extinfo[:data], File.read(extinfo[:file].path))
|
870
|
+
else
|
871
|
+
assert(!File.exist?(extinfo[:file].path))
|
872
|
+
end
|
873
|
+
end
|
874
|
+
|
875
|
+
# Error reading datafile raises exception
|
876
|
+
FileUtils.mv(File.join(workdir, 'tpkg', 'datafile'), File.join(workdir, 'datafile'))
|
877
|
+
# Previous runs of run_externals_for_install using metadata will have
|
878
|
+
# resulted in the data for the datafile and datascript externals being
|
879
|
+
# read in and cached. Revert to a copy where that hasn't been done yet so
|
880
|
+
# this test is effective.
|
881
|
+
metadata[:externals] = original_externals
|
882
|
+
assert_raise(Errno::ENOENT) { tpkg.run_externals_for_install(metadata, workdir) }
|
883
|
+
assert_equal(pwd, Dir.pwd)
|
884
|
+
# Unless forced
|
885
|
+
assert_nothing_raised { tpkg_force.run_externals_for_install(metadata, workdir) }
|
886
|
+
# Put datafile back
|
887
|
+
FileUtils.mv(File.join(workdir, 'datafile'), File.join(workdir, 'tpkg', 'datafile'))
|
888
|
+
|
889
|
+
# Error running datascript raises exception
|
890
|
+
FileUtils.mv(File.join(workdir, 'tpkg', 'datascript'), File.join(workdir, 'datascript'))
|
891
|
+
# Same deal as last test, revert to unmodified copy
|
892
|
+
metadata[:externals] = original_externals
|
893
|
+
# RuntimeError in ruby 1.8 as popen doesn't fail, so the failure is
|
894
|
+
# caught by our exit status check
|
895
|
+
# Errno::ENOENT in ruby 1.9, raised by popen
|
896
|
+
assert_raise(RuntimeError, Errno::ENOENT) { tpkg.run_externals_for_install(metadata, workdir) }
|
897
|
+
assert_equal(pwd, Dir.pwd)
|
898
|
+
# Unless forced
|
899
|
+
assert_nothing_raised { tpkg_force.run_externals_for_install(metadata, workdir) }
|
900
|
+
# Put datascript back
|
901
|
+
FileUtils.mv(File.join(workdir, 'datascript'), File.join(workdir, 'tpkg', 'datascript'))
|
902
|
+
|
903
|
+
# Check non-executable datascript permissions case too
|
904
|
+
File.chmod(0644, File.join(workdir, 'tpkg', 'datascript'))
|
905
|
+
metadata[:externals] = original_externals
|
906
|
+
# RuntimeError in ruby 1.8 as popen doesn't fail, so the failure is
|
907
|
+
# caught by our exit status check
|
908
|
+
# Errno::EACCES in ruby 1.9, raised by popen
|
909
|
+
assert_raise(RuntimeError, Errno::EACCES) { tpkg.run_externals_for_install(metadata, workdir) }
|
910
|
+
assert_equal(pwd, Dir.pwd)
|
911
|
+
# Unless forced
|
912
|
+
assert_nothing_raised { tpkg_force.run_externals_for_install(metadata, workdir) }
|
913
|
+
# Restore permissions
|
914
|
+
File.chmod(0755, File.join(workdir, 'tpkg', 'datascript'))
|
915
|
+
|
916
|
+
# Datascript that exits with error raises exception
|
917
|
+
File.open(File.join(workdir, 'tpkg', 'datascript'), 'w') do |file|
|
918
|
+
file.puts('#!/bin/sh')
|
919
|
+
file.puts("exit 1")
|
920
|
+
end
|
921
|
+
File.chmod(0755, File.join(workdir, 'tpkg', 'datascript'))
|
922
|
+
# Same deal as last test, revert to unmodified copy
|
923
|
+
metadata[:externals] = original_externals
|
924
|
+
assert_raise(RuntimeError) { tpkg.run_externals_for_install(metadata, workdir) }
|
925
|
+
assert_equal(pwd, Dir.pwd)
|
926
|
+
# Unless forced
|
927
|
+
assert_nothing_raised { tpkg_force.run_externals_for_install(metadata, workdir) }
|
928
|
+
end
|
929
|
+
end
|
930
|
+
end
|
931
|
+
|
932
|
+
# This method only tests that we can save pkg metadata and pkg file metadata. The rest of the
|
933
|
+
# unit tests for file metadata are in test_filemetadata.rb
|
934
|
+
def test_save_package_metadata
|
935
|
+
metadata = nil
|
936
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
937
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
938
|
+
create_metadata_file(File.join(srcdir, 'tpkg.xml'), :change => { 'name' => 'save_pkg_metadata' })
|
939
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
940
|
+
end
|
941
|
+
|
942
|
+
Dir.mktmpdir('testroot') do |testroot|
|
943
|
+
package_file = '/tmp/save_pkg_metadata-1.0-1.tpkg'
|
944
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'))
|
945
|
+
|
946
|
+
Dir.mktmpdir('workdir') do |workdir|
|
947
|
+
FileUtils.cp_r(File.join(TESTPKGDIR, 'reloc'), workdir)
|
948
|
+
|
949
|
+
# FIXME: add in some test data for these hashes
|
950
|
+
# generate files_info
|
951
|
+
files_info = {}
|
952
|
+
# generate checksums_of_decrypted_files
|
953
|
+
checksums_of_decrypted_files = {}
|
954
|
+
|
955
|
+
FileUtils.mkdir_p(File.join(workdir, 'tpkg'))
|
956
|
+
File.open(File.join(File.join(workdir, 'tpkg', 'file_metadata.bin')), 'w') do |f|
|
957
|
+
filemetadata = Tpkg::get_filemetadata_from_directory(workdir)
|
958
|
+
data = filemetadata.to_hash.recursively{|h| h.stringify_keys }
|
959
|
+
Marshal::dump(data, f)
|
960
|
+
end
|
961
|
+
|
962
|
+
tpkg.save_package_metadata(package_file, workdir, metadata, files_info, checksums_of_decrypted_files)
|
963
|
+
|
964
|
+
# verify metadata and file_metadata are actually there
|
965
|
+
assert(File.exists?(File.join(tpkg.instance_variable_get(:@metadata_directory), 'save_pkg_metadata-1.0-1', 'tpkg.yml')))
|
966
|
+
assert(File.exists?(File.join(tpkg.instance_variable_get(:@metadata_directory), 'save_pkg_metadata-1.0-1', 'file_metadata.bin')))
|
967
|
+
end
|
968
|
+
end
|
969
|
+
end
|
970
|
+
|
971
|
+
def teardown
|
972
|
+
Facter.unstub(:[])
|
973
|
+
FileUtils.rm_f(@pkgfile)
|
974
|
+
FileUtils.rm_rf(@tempoutdir)
|
975
|
+
end
|
976
|
+
end
|
977
|
+
|