tpkg 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/Portfile +39 -0
  6. data/Portfile.template +39 -0
  7. data/README.md +43 -0
  8. data/Rakefile +468 -18
  9. data/bin/gem2tpkg +2 -2
  10. data/bin/tpkg +18 -13
  11. data/bin/tpkg_uploader +132 -0
  12. data/ca.pem +1 -0
  13. data/control +7 -0
  14. data/depend +3 -0
  15. data/externals-etch/authorized_keys +40 -0
  16. data/externals-etch/group +9 -0
  17. data/externals-etch/iptables +38 -0
  18. data/externals-etch/limits +30 -0
  19. data/externals-etch/nfs +30 -0
  20. data/externals-etch/sudo +30 -0
  21. data/externals-etch/supplemental_groups +8 -0
  22. data/externals-etch/sysctl +30 -0
  23. data/externals-etch/user +41 -0
  24. data/externals/group +39 -0
  25. data/externals/supplemental_groups +48 -0
  26. data/externals/user +39 -0
  27. data/lib/tpkg.rb +260 -991
  28. data/lib/tpkg/os.rb +164 -0
  29. data/lib/tpkg/os/debian.rb +159 -0
  30. data/lib/tpkg/os/freebsd.rb +113 -0
  31. data/lib/tpkg/os/macosx.rb +113 -0
  32. data/lib/tpkg/os/redhat.rb +173 -0
  33. data/lib/tpkg/os/solaris.rb +101 -0
  34. data/lib/tpkg/os/windows.rb +26 -0
  35. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
  36. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
  37. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
  38. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
  39. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
  40. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
  41. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
  42. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
  43. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
  44. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
  45. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
  46. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
  47. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
  48. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
  49. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
  50. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
  51. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
  52. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
  53. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
  54. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
  55. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
  56. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
  57. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
  58. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
  59. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
  60. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
  61. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  62. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  63. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  64. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
  65. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  66. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
  67. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
  68. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
  69. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
  70. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
  71. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
  72. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
  73. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
  74. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
  75. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
  76. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
  77. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
  78. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
  79. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
  80. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
  81. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
  82. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
  83. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
  84. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
  85. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
  86. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
  87. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
  88. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
  89. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
  90. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
  91. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
  92. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
  93. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
  94. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
  95. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
  96. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
  97. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
  98. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
  99. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
  100. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
  101. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  102. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
  103. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  104. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
  105. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  106. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  107. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
  108. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
  109. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  110. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  111. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
  112. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
  113. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
  114. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
  115. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
  116. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
  117. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
  118. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
  119. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
  120. data/lib/tpkg/version.rb +3 -0
  121. data/man/man1/cpan2tpkg.1 +82 -0
  122. data/man/man1/gem2tpkg.1 +120 -0
  123. data/man/man1/tpkg.1 +411 -0
  124. data/pkginfo +8 -0
  125. data/postinstall.solaris +11 -0
  126. data/postremove.solaris +16 -0
  127. data/schema/schema-1.0.5.yml +0 -0
  128. data/schema/schema-1.0.6.yml +0 -0
  129. data/schema/schema-1.0.7.yml +0 -0
  130. data/schema/schema-1.0.8.yml +0 -0
  131. data/schema/schema-1.0.9.yml +0 -0
  132. data/schema/schema.yml +0 -0
  133. data/schema/tpkg-1.0.0.dtd +0 -0
  134. data/schema/tpkg-1.0.1.dtd +0 -0
  135. data/schema/tpkg-1.0.2.dtd +0 -0
  136. data/schema/tpkg-1.0.3.dtd +0 -0
  137. data/schema/tpkg-1.0.4.dtd +0 -0
  138. data/schema/tpkg-1.0.5.dtd +0 -0
  139. data/schema/tpkg-1.0.6.dtd +0 -0
  140. data/schema/tpkg-1.0.7.dtd +0 -0
  141. data/schema/tpkg-1.0.8.dtd +0 -0
  142. data/schema/tpkg-1.0.9.dtd +0 -0
  143. data/schema/tpkg.dtd +0 -0
  144. data/test/TODO +30 -0
  145. data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
  146. data/test/test_checksum.rb +53 -0
  147. data/test/test_compress.rb +55 -0
  148. data/test/test_conflict.rb +41 -0
  149. data/test/test_crontabs.rb +398 -0
  150. data/test/test_dependency.rb +1113 -0
  151. data/test/test_downgrade.rb +80 -0
  152. data/test/test_download.rb +95 -0
  153. data/test/test_encrypt.rb +136 -0
  154. data/test/test_filemetadata.rb +131 -0
  155. data/test/test_initscript.rb +93 -0
  156. data/test/test_install.rb +186 -0
  157. data/test/test_lock.rb +82 -0
  158. data/test/test_make.rb +410 -0
  159. data/test/test_metadata.rb +805 -0
  160. data/test/test_misc.rb +379 -0
  161. data/test/test_options.rb +1711 -0
  162. data/test/test_os.rb +193 -0
  163. data/test/test_os_debian.rb +99 -0
  164. data/test/test_os_freebsd.rb +89 -0
  165. data/test/test_os_macosx.rb +79 -0
  166. data/test/test_os_redhat.rb +124 -0
  167. data/test/test_os_solaris.rb +85 -0
  168. data/test/test_os_windows.rb +26 -0
  169. data/test/test_query.rb +134 -0
  170. data/test/test_remove.rb +539 -0
  171. data/test/test_tar.rb +99 -0
  172. data/test/test_unpack.rb +977 -0
  173. data/test/test_upgrade.rb +398 -0
  174. data/test/test_version.rb +54 -0
  175. data/test/testcmds/crontab +14 -0
  176. data/test/testcmds/debian/apt-cache +145 -0
  177. data/test/testcmds/debian/dpkg-query +16 -0
  178. data/test/testcmds/freebsd/pkg_info +13 -0
  179. data/test/testcmds/macosx/port +35 -0
  180. data/test/testcmds/redhat/rpmbuild +6 -0
  181. data/test/testcmds/redhat/yum +90 -0
  182. data/test/testcmds/solaris/pkginfo +25 -0
  183. data/test/testcmds/solaris/pkgutil +36 -0
  184. data/test/testpkg/reloc/encfile +2 -0
  185. data/test/testpkg/reloc/file +2 -0
  186. data/test/testpkg/reloc/precryptfile +1 -0
  187. data/test/testpkg/reloc/precryptfile.plaintext +3 -0
  188. data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
  189. data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
  190. data/test/testpkg/tpkg-default-perms.xml +28 -0
  191. data/test/testpkg/tpkg-default-perms.yml +20 -0
  192. data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
  193. data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
  194. data/test/testpkg/tpkg-nativedeps.yml +13 -0
  195. data/test/testpkg/tpkg-nofiles.xml +14 -0
  196. data/test/testpkg/tpkg-nofiles.yml +9 -0
  197. data/test/testpkg/tpkg.xml +35 -0
  198. data/test/testpkg/tpkg.yml +25 -0
  199. data/test/tpkgtest.rb +300 -0
  200. data/tpkg.conf +16 -0
  201. data/tpkg.gemspec +24 -0
  202. data/tpkg.spec +28 -0
  203. data/tpkg.xml +17 -0
  204. data/tpkg_profile.sh +32 -0
  205. metadata +306 -31
@@ -0,0 +1,186 @@
1
+
2
+
3
+ #
4
+ # Test tpkg's ability to install packages
5
+ #
6
+
7
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
8
+
9
+ class TpkgInstallTests < Test::Unit::TestCase
10
+ include TpkgTests
11
+
12
+ def setup
13
+ Tpkg::set_prompt(false)
14
+
15
+ # Make up our regular test package
16
+ @pkgfile = make_package(:remove => ['operatingsystem', 'architecture'])
17
+ @testroot = Dir.mktmpdir('testroot')
18
+ end
19
+
20
+ def test_install_by_filename
21
+ testbase = File.join(@testroot, 'home', 'tpkg')
22
+ FileUtils.mkdir_p(testbase)
23
+ tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
24
+
25
+ assert_nothing_raised { tpkg.install([@pkgfile], PASSPHRASE) }
26
+
27
+ # Check that the files from the package ended up in the right place
28
+ assert(File.exist?(File.join(testbase, 'file')))
29
+ assert_equal(IO.read(File.join(TESTPKGDIR, 'reloc', 'file')), IO.read(File.join(testbase, 'file')))
30
+ assert(File.exist?(File.join(testbase, 'encfile')))
31
+ assert_equal(IO.read(File.join(TESTPKGDIR, 'reloc', 'encfile')), IO.read(File.join(testbase, 'encfile')))
32
+ end
33
+
34
+ def test_install_by_pkg_name
35
+ testbase = File.join(@testroot, 'home', 'tpkg')
36
+ FileUtils.mkdir_p(testbase)
37
+ tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
38
+
39
+ assert_nothing_raised { tpkg.install(['testpkg'], PASSPHRASE) }
40
+
41
+ # Check that the files from the package ended up in the right place
42
+ assert(File.exist?(File.join(testbase, 'file')))
43
+ assert_equal(IO.read(File.join(TESTPKGDIR, 'reloc', 'file')), IO.read(File.join(testbase, 'file')))
44
+ assert(File.exist?(File.join(testbase, 'encfile')))
45
+ assert_equal(IO.read(File.join(TESTPKGDIR, 'reloc', 'encfile')), IO.read(File.join(testbase, 'encfile')))
46
+
47
+ end
48
+
49
+ # Test that if packages have dependencies on each others, then they
50
+ # should installed in the correct order
51
+ def test_install_order
52
+
53
+ @pkgfiles = []
54
+ ['a', 'b', 'c'].each do |pkgname|
55
+ Dir.mktmpdir('srcdir') do |srcdir|
56
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
57
+ FileUtils.mkdir(File.join(srcdir, 'reloc'))
58
+ File.open(File.join(srcdir, 'reloc', pkgname), 'w') do |file|
59
+ file.puts pkgname
60
+ end
61
+
62
+ # make a depends on c and c depends on b
63
+ deps = {}
64
+ if pkgname == 'a'
65
+ deps['c'] = {}
66
+ elsif pkgname == 'c'
67
+ deps['b'] = {}
68
+ end
69
+
70
+ # make a postinstall script that sleeps for 1 second. That way we
71
+ # have enough time between each installation to determine the order of how they
72
+ # were installed
73
+ File.open(File.join(srcdir, 'postinstall'), 'w') do | file |
74
+ file.puts "#!/bin/bash\nsleep 1"
75
+ end
76
+ File.chmod(0755, File.join(srcdir, 'postinstall'))
77
+
78
+ @pkgfiles << make_package(:change => {'name' => pkgname}, :source_directory => srcdir, :dependencies => deps, :remove => ['operatingsystem', 'architecture'])
79
+ end
80
+ end
81
+
82
+ tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => @pkgfiles)
83
+ tpkg.install(['a'], PASSPHRASE)
84
+
85
+ actime = File.new(File.join(File.join(@testroot,'home','tpkg', 'a'))).ctime
86
+ bctime = File.new(File.join(File.join(@testroot,'home','tpkg', 'b'))).ctime
87
+ cctime = File.new(File.join(File.join(@testroot,'home','tpkg', 'c'))).ctime
88
+ assert(actime > cctime)
89
+ assert(cctime > bctime)
90
+
91
+ end
92
+
93
+ # Verify that we can install multiple versions of the same package
94
+ def test_install_multiple_versions
95
+ pkgfiles = []
96
+ ['1', '2'].each do |pkgver|
97
+ pkgfiles << make_package(:change => {'version' => pkgver, 'name' => 'versiontest'}, :remove => ['operatingsystem', 'architecture'])
98
+ end
99
+
100
+ Dir.mktmpdir('testroot') do |testroot|
101
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => pkgfiles)
102
+ assert_nothing_raised { tpkg.install(['versiontest=1'], PASSPHRASE) }
103
+ assert_nothing_raised { tpkg.install(['versiontest=2'], PASSPHRASE) }
104
+ metadata = tpkg.metadata_for_installed_packages
105
+ # verify that both of them are installed
106
+ assert_equal(metadata.size, 2)
107
+ end
108
+
109
+ # verify we can install in reverse order
110
+ Dir.mktmpdir('testroot') do |testroot|
111
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => pkgfiles)
112
+ assert_nothing_raised { tpkg.install(['versiontest=2'], PASSPHRASE) }
113
+ assert_nothing_raised { tpkg.install(['versiontest=1'], PASSPHRASE) }
114
+ metadata = tpkg.metadata_for_installed_packages
115
+ # verify that both of them are installed
116
+ assert_equal(metadata.size, 2)
117
+ end
118
+
119
+ pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
120
+ end
121
+
122
+ def test_install_with_externals
123
+ externalspkg = nil
124
+ extname1 = 'testext1'
125
+ extdata1 = "This is a test of an external hook\nwith multiple lines\nof data"
126
+ extname2 = 'testext2'
127
+ extdata2 = "This is a test of a different external hook\nwith multiple lines\nof different data"
128
+ Dir.mktmpdir('srcdir') do |srcdir|
129
+ FileUtils.cp(
130
+ File.join(TESTPKGDIR, 'tpkg-nofiles.xml'),
131
+ File.join(srcdir, 'tpkg.xml'))
132
+ externalspkg = make_package(
133
+ :change => { 'name' => 'externalpkg', 'version' => '1' },
134
+ :externals => { extname1 => {'data' => extdata1},
135
+ extname2 => {'data' => extdata2} },
136
+ :source_directory => srcdir,
137
+ :remove => ['operatingsystem', 'architecture'])
138
+ end
139
+ Dir.mktmpdir('testroot') do |testroot|
140
+ # Make external scripts which write the data they receive to temporary
141
+ # files, so that we can verify the external scripts received the data
142
+ # properly.
143
+ exttmpfile1 = Tempfile.new('tpkgtest_external')
144
+ exttmpfile2 = Tempfile.new('tpkgtest_external')
145
+ externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
146
+ FileUtils.mkdir_p(externalsdir)
147
+ extscript1 = File.join(externalsdir, extname1)
148
+ extscript2 = File.join(externalsdir, extname2)
149
+ File.open(extscript1, 'w') do |file|
150
+ file.puts('#!/bin/sh')
151
+ # Operation (install/remove)
152
+ file.puts("echo $2 >> #{exttmpfile1.path}")
153
+ # Data
154
+ file.puts("cat >> #{exttmpfile1.path}")
155
+ end
156
+ File.open(extscript2, 'w') do |file|
157
+ file.puts('#!/bin/sh')
158
+ # Operation (install/remove)
159
+ file.puts("echo $2 >> #{exttmpfile2.path}")
160
+ # Data
161
+ file.puts("cat >> #{exttmpfile2.path}")
162
+ end
163
+ File.chmod(0755, extscript1)
164
+ File.chmod(0755, extscript2)
165
+ # And run the test
166
+ tpkg = Tpkg.new(
167
+ :file_system_root => testroot,
168
+ :base => File.join('home', 'tpkg'),
169
+ :sources => [externalspkg])
170
+ assert_nothing_raised { tpkg.install([externalspkg], PASSPHRASE) }
171
+ assert_equal("install\n#{extdata1}", IO.read(exttmpfile1.path))
172
+ assert_equal("install\n#{extdata2}", IO.read(exttmpfile2.path))
173
+ end
174
+ FileUtils.rm_f(externalspkg)
175
+ end
176
+
177
+ def test_stub_native_pkg
178
+ # FIXME
179
+ end
180
+
181
+ def teardown
182
+ FileUtils.rm_f(@pkgfile)
183
+ FileUtils.rm_rf(@testroot)
184
+ end
185
+ end
186
+
@@ -0,0 +1,82 @@
1
+
2
+
3
+ #
4
+ # Test tpkg's ability to lock/unlock the package repository
5
+ #
6
+
7
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
8
+
9
+ class TpkgLockTests < Test::Unit::TestCase
10
+ include TpkgTests
11
+
12
+ def setup
13
+ Tpkg::set_prompt(false)
14
+
15
+ # Make up our regular test package
16
+ @pkgfile = make_package(:remove => ['operatingsystem', 'architecture'])
17
+
18
+ # Make a test repository
19
+ @testbase = Dir.mktmpdir('testbase')
20
+ end
21
+
22
+ def test_lock
23
+ # Lock the repo
24
+ tpkg = Tpkg.new(:base => @testbase)
25
+ assert_nothing_raised('lock') { tpkg.lock }
26
+
27
+ # Verify that an operation requiring a lock works with this instance
28
+ assert_nothing_raised('install') { tpkg.install([@pkgfile], PASSPHRASE) }
29
+
30
+ # Make a seperate instance of Tpkg using the same repo
31
+ tpkg2 = Tpkg.new(:base => @testbase)
32
+ # Verify that attempting a lock with this instance fails
33
+ assert_raise(RuntimeError, 'lock in other instance') { tpkg2.lock }
34
+ # Verify that an operation requiring a lock fails with this instance
35
+ assert_raise(RuntimeError, 'install in other instance') { tpkg2.install([@pkgfile], PASSPHRASE) }
36
+ # Verify that attempting to unlock this instance fails
37
+ # Decided to have it just warn rather than throw an exception
38
+ #assert_raise(RuntimeError, 'unlock in other instance') { tpkg2.unlock }
39
+
40
+ # Re-verify that things work with the original instance
41
+ assert_nothing_raised('remove') { tpkg.remove(['testpkg']) }
42
+
43
+ # Unlock the repo
44
+ assert_nothing_raised('unlock') { tpkg.unlock }
45
+ end
46
+
47
+ def test_old_lock
48
+ # Create a lock that is more than 2 hours old
49
+ FileUtils.mkdir_p(File.join(@testbase, 'var', 'tpkg', 'lock'))
50
+ File.open(File.join(@testbase, 'var', 'tpkg', 'lock', 'pid'), 'w') { |file| file.puts($$) }
51
+ threehoursago = Time.at(Time.now - 60*60*3)
52
+ File.utime(threehoursago, threehoursago, File.join(@testbase, 'var', 'tpkg', 'lock'))
53
+
54
+ tpkg = Tpkg.new(:base => @testbase)
55
+
56
+ # Verify that tpkg will lock, removing the stale lock file
57
+ assert_nothing_raised('lock') { tpkg.lock }
58
+ assert_nothing_raised('unlock') { tpkg.unlock }
59
+ end
60
+
61
+ def test_lock_force
62
+ # Create a lock
63
+ FileUtils.mkdir_p(File.join(@testbase, 'var', 'tpkg', 'lock'))
64
+ File.open(File.join(@testbase, 'var', 'tpkg', 'lock', 'pid'), 'w') { |file| file.puts($$) }
65
+
66
+ # Verify that locking fails without the :lockforce option
67
+ tpkg = Tpkg.new(:base => @testbase)
68
+ assert_raise(RuntimeError) { tpkg.lock }
69
+
70
+ # Set the :lockforce option
71
+ tpkg = Tpkg.new(:base => @testbase, :lockforce => true)
72
+
73
+ # Verify that tpkg will lock, removing the lock file
74
+ assert_nothing_raised('lock') { tpkg.lock }
75
+ assert_nothing_raised('unlock') { tpkg.unlock }
76
+ end
77
+
78
+ def teardown
79
+ FileUtils.rm_f(@pkgfile)
80
+ FileUtils.rm_rf(@testbase)
81
+ end
82
+ end
@@ -0,0 +1,410 @@
1
+ #
2
+ # Test tpkg's ability to make packages
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+
7
+ class TpkgMakeTests < Test::Unit::TestCase
8
+ include TpkgTests
9
+
10
+ def setup
11
+ Tpkg::set_prompt(false)
12
+
13
+ @tar = Tpkg::find_tar
14
+
15
+ @pkgdir = Dir.mktmpdir('pkgdir')
16
+ system("#{@tar} -C #{TESTPKGDIR} --exclude .svn --exclude tpkg-*.xml --exclude tpkg*.yml -cf - . | #{@tar} -C #{@pkgdir} -xf -")
17
+ # Set special permissions on a file so that we can verify they are
18
+ # preserved
19
+ File.chmod(0400, File.join(@pkgdir, 'reloc', 'file'))
20
+ @srcmode = File.stat(File.join(@pkgdir, 'reloc', 'file')).mode
21
+ @srcmtime = File.stat(File.join(@pkgdir, 'reloc', 'file')).mtime
22
+ # Insert a directory and symlink so that we can verify they are
23
+ # properly included in the package
24
+ Dir.mkdir(File.join(@pkgdir, 'reloc', 'directory'))
25
+ File.symlink('linktarget', File.join(@pkgdir, 'reloc', 'directory', 'link'))
26
+ end
27
+
28
+ def verify_pkg(pkgfile)
29
+ Dir.mktmpdir('workdir') do |workdir|
30
+ assert(!pkgfile.nil? && pkgfile.kind_of?(String) && !pkgfile.empty?, 'make_package returned package filename')
31
+ assert(File.exist?(pkgfile), 'make_package returned package filename that exists')
32
+
33
+ # Verify checksum.xml
34
+ # We test verify_package_checksum in checksum.rb to make sure it works
35
+ assert_nothing_raised('checksum verify') { Tpkg::verify_package_checksum(pkgfile) }
36
+
37
+ # Unpack the package
38
+ assert(system("#{@tar} -C #{workdir} -xf #{pkgfile}"), 'unpack package')
39
+ unpackdir = File.join(workdir, 'testpkg-1.0-1-os-architecture')
40
+ # Packages consist of directory containing checksum.xml and a tpkg.tar
41
+ # with the rest of the package contents. Ensure that the package
42
+ # contains the right files and nothing else.
43
+ assert(File.exist?(File.join(unpackdir, 'checksum.xml')), 'checksum.xml in package')
44
+ tpkgfile = File.join(unpackdir, 'tpkg.tar')
45
+ assert(File.exist?(tpkgfile), 'tpkg.tar in package')
46
+ assert_equal(3, Dir.entries(workdir).length, 'nothing else in package top level')
47
+ assert_equal(4, Dir.entries(unpackdir).length, 'nothing else in package directory')
48
+ # Now unpack the tarball with the rest of the package contents
49
+ assert(system("#{@tar} -C #{unpackdir} -xf #{File.join(unpackdir, 'tpkg.tar')}"), 'unpack tpkg.tar')
50
+
51
+ # Verify that tpkg.xml and our various test files were included in the
52
+ # package
53
+ assert(File.exist?(File.join(unpackdir, 'tpkg', 'tpkg.xml')), 'tpkg.xml in package')
54
+ assert(File.directory?(File.join(unpackdir, 'tpkg', 'reloc')), 'reloc in package')
55
+ assert_equal(5, Dir.entries(File.join(unpackdir, 'tpkg')).length, 'nothing else in tpkg directory') # ., .., reloc|root, tpkg.xml, file_metadata.bin
56
+ assert(File.exist?(File.join(unpackdir, 'tpkg', 'reloc', 'file')), 'generic file in package')
57
+ assert(File.directory?(File.join(unpackdir, 'tpkg', 'reloc', 'directory')), 'directory in package')
58
+ assert(File.symlink?(File.join(unpackdir, 'tpkg', 'reloc', 'directory', 'link')), 'link in package')
59
+ # Verify that permissions and modification timestamps were preserved
60
+ dstmode = File.stat(File.join(unpackdir, 'tpkg', 'reloc', 'file')).mode
61
+ assert_equal(@srcmode, dstmode, 'mode preserved')
62
+ dstmtime = File.stat(File.join(unpackdir, 'tpkg', 'reloc', 'file')).mtime
63
+ assert_equal(@srcmtime, dstmtime, 'mtime preserved')
64
+
65
+ # Verify that the file we specified should be encrypted was encrypted
66
+ testname = 'encrypted file is encrypted'
67
+ encrypted_contents = IO.read(File.join(unpackdir, 'tpkg', 'reloc', 'encfile'))
68
+ unencrypted_contents = IO.read(File.join(TESTPKGDIR, 'reloc', 'encfile'))
69
+ assert_not_equal(unencrypted_contents, encrypted_contents, testname)
70
+ testname = 'encrypted file can be decrypted'
71
+ Tpkg::decrypt('testpkg', File.join(unpackdir, 'tpkg', 'reloc', 'encfile'), PASSPHRASE)
72
+ decrypted_contents = IO.read(File.join(unpackdir, 'tpkg', 'reloc', 'encfile'))
73
+ assert_equal(unencrypted_contents, decrypted_contents, testname)
74
+ # Verify that the precrypt file can still be decrypted
75
+ testname = 'precrypt file can be decrypted'
76
+ Tpkg::decrypt('testpkg', File.join(unpackdir, 'tpkg', 'reloc', 'precryptfile'), PASSPHRASE)
77
+ decrypted_contents = IO.read(File.join(unpackdir, 'tpkg', 'reloc', 'precryptfile'))
78
+ unencrypted_contents = IO.read(File.join(TESTPKGDIR, 'reloc', 'precryptfile.plaintext'))
79
+ assert_equal(unencrypted_contents, decrypted_contents, testname)
80
+ end
81
+ end
82
+
83
+ def test_make_required_fields
84
+ # Verify that you can't make a package without one of the required fields
85
+ Metadata::REQUIRED_FIELDS.each do |r|
86
+ testname = "make package without required field #{r}"
87
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
88
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
89
+ if line !~ /^\s*<#{r}>/
90
+ pkgxmlfile.print(line)
91
+ end
92
+ end
93
+ end
94
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, PASSPHRASE) }
95
+ end
96
+ # Verify that you can't make a package with one of the required fields empty
97
+ Metadata::REQUIRED_FIELDS.each do |r|
98
+ testname = "make package with empty required field #{r}"
99
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
100
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
101
+ line.sub!(/^(\s*<#{r}>).*(<\/#{r}>.*)/, '\1\2')
102
+ pkgxmlfile.print(line)
103
+ end
104
+ end
105
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, PASSPHRASE) }
106
+ end
107
+ end
108
+
109
+ def test_make_optional_fields
110
+ # Verify that you can make a package without the optional fields
111
+ testname = 'make package without optional fields'
112
+ pkgfile = nil
113
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
114
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
115
+ if line =~ /^<?xml/ || line =~ /^<!DOCTYPE/ || line =~ /^<\/?tpkg>/
116
+ # XML headers and document root
117
+ pkgxmlfile.print(line)
118
+ elsif Metadata::REQUIRED_FIELDS.any? { |r| line =~ /^\s*<\/?#{r}>/ }
119
+ # Include just the required fields
120
+ pkgxmlfile.print(line)
121
+ end
122
+ end
123
+ end
124
+ assert_nothing_raised(testname) { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
125
+ FileUtils.rm_rf(pkgfile)
126
+ end
127
+
128
+ def test_make_nonexistent_file
129
+ # Insert a non-existent file into tpkg.xml and verify that it throws
130
+ # an exception
131
+ testname = 'make package with non-existent file'
132
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
133
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
134
+ # Insert our files entry right before the end of the file
135
+ if line =~ /^\s*<\/tpkg>/
136
+ pkgxmlfile.puts('<files>')
137
+ pkgxmlfile.puts(' <file>')
138
+ pkgxmlfile.puts(' <path>does-not-exist</path>')
139
+ pkgxmlfile.puts(' </file>')
140
+ pkgxmlfile.puts('</files>')
141
+ end
142
+ pkgxmlfile.print(line)
143
+ end
144
+ end
145
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, PASSPHRASE) }
146
+ end
147
+
148
+ def test_group_owner
149
+ # Ensure a warning given if file owner and group set to non-existing accounts
150
+ FileUtils.cp("#{TESTPKGDIR}/tpkg-bad-ownergroup.xml", "#{@pkgdir}/tpkg.xml")
151
+ out = capture_stdout do
152
+ Tpkg.make_package(@pkgdir,nil)
153
+ end
154
+ expectederr = "Package requests user baduser, but that user can't be found. Using UID 0.\nPackage requests group badgroup, but that group can't be found. Using GID 0.\n"
155
+ assert_equal(expectederr,out.string)
156
+ FileUtils.cp("#{TESTPKGDIR}/tpkg-good-ownergroup.xml", "#{@pkgdir}/tpkg.xml")
157
+ out = capture_stdout do
158
+ Tpkg.make_package(@pkgdir,nil)
159
+ end
160
+ assert_equal("",out.string)
161
+ end
162
+
163
+
164
+ def test_make_nil_passphrase
165
+ # Pass a nil passphrase with a package that requests encryption,
166
+ # verify that it throws an exception
167
+ testname = 'make package with encryption but nil passphrase'
168
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
169
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
170
+ # Insert our files entry right before the end of the file
171
+ if line =~ /^\s*<\/tpkg>/
172
+ pkgxmlfile.puts('<files>')
173
+ pkgxmlfile.puts(' <file>')
174
+ pkgxmlfile.puts(' <path>encfile</path>')
175
+ pkgxmlfile.puts(' <encrypt/>')
176
+ pkgxmlfile.puts(' </file>')
177
+ pkgxmlfile.puts('</files>')
178
+ end
179
+ pkgxmlfile.print(line)
180
+ end
181
+ end
182
+ FileUtils.cp(File.join(TESTPKGDIR, 'reloc', 'encfile'), File.join(@pkgdir, 'reloc'))
183
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, nil) }
184
+ end
185
+
186
+ def test_make_bad_precrypt
187
+ # Include an unencrypted file flagged as precrypt=true,
188
+ # verify that it throws an exception
189
+ testname = 'make package with plaintext precrypt'
190
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
191
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
192
+ # Insert our files entry right before the end of the file
193
+ if line =~ /^\s*<\/tpkg>/
194
+ pkgxmlfile.puts('<files>')
195
+ pkgxmlfile.puts(' <file>')
196
+ pkgxmlfile.puts(' <path>precryptfile</path>')
197
+ pkgxmlfile.puts(' <encrypt precrypt="true"/>')
198
+ pkgxmlfile.puts(' </file>')
199
+ pkgxmlfile.puts('</files>')
200
+ end
201
+ pkgxmlfile.print(line)
202
+ end
203
+ end
204
+ FileUtils.cp(File.join(TESTPKGDIR, 'reloc', 'precryptfile.plaintext'), File.join(@pkgdir, 'reloc', 'precryptfile'))
205
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, nil) }
206
+ end
207
+
208
+ def test_make_already_exists
209
+ # Try to make a package where the output file already exists, verify that it is overwritten
210
+ pkgfile = File.join(Dir::tmpdir, 'testpkg-1.0-1.tpkg')
211
+ existing_contents = 'Hello world'
212
+ File.open(pkgfile, 'w') do |file|
213
+ file.puts existing_contents
214
+ end
215
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(@pkgdir, 'tpkg.xml'))
216
+ assert_nothing_raised { Tpkg.make_package(@pkgdir, PASSPHRASE) }
217
+ assert_not_equal(existing_contents, IO.read(pkgfile))
218
+ FileUtils.rm_f(pkgfile)
219
+ # It would be nice to test that if the user is prompted and answers no that the file is not overwritten
220
+ end
221
+
222
+ def test_make_full_path
223
+ # Test using a full path to the package directory
224
+ pkgfile = nil
225
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
226
+ begin
227
+ verify_pkg(pkgfile)
228
+ ensure
229
+ FileUtils.rm_f(pkgfile)
230
+ end
231
+ end
232
+
233
+ def test_make_relative_path
234
+ # Test using a relative path to the directory
235
+ pkgfile = nil
236
+ pwd = Dir.pwd
237
+ Dir.chdir(File.dirname(@pkgdir))
238
+ assert_nothing_raised { pkgfile = Tpkg.make_package(File.basename(@pkgdir), PASSPHRASE) }
239
+ pkgfile = File.join(Dir.pwd, pkgfile)
240
+ Dir.chdir(pwd)
241
+ begin
242
+ verify_pkg(pkgfile)
243
+ ensure
244
+ FileUtils.rm_f(pkgfile)
245
+ end
246
+ end
247
+
248
+ def test_make_dot_path
249
+ # Test from within the directory, passing '.' to make_package
250
+ pkgfile = nil
251
+ pwd = Dir.pwd
252
+ Dir.chdir(@pkgdir)
253
+ assert_nothing_raised { pkgfile = Tpkg.make_package('.', PASSPHRASE) }
254
+ pkgfile = File.join(Dir.pwd, pkgfile)
255
+ Dir.chdir(pwd)
256
+ begin
257
+ verify_pkg(pkgfile)
258
+ ensure
259
+ FileUtils.rm_f(pkgfile)
260
+ end
261
+ end
262
+
263
+ def test_make_passphrase_callback
264
+ # Test using a callback to supply the passphrase
265
+ callback = lambda { |pkgname| PASSPHRASE }
266
+ pkgfile = nil
267
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, callback) }
268
+ begin
269
+ verify_pkg(pkgfile)
270
+ ensure
271
+ FileUtils.rm_f(pkgfile)
272
+ end
273
+ end
274
+
275
+ def test_make_osarch_names
276
+ # Test that make_package properly names packages that are specific to
277
+ # particular operating systems or architectures.
278
+ pkgfile = nil
279
+
280
+ # The default tpkg.xml is tied to OS "OS" and architecture "Architecture"
281
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
282
+ FileUtils.rm_f(pkgfile)
283
+ assert_match(/testpkg-1.0-1-os-architecture.tpkg/, pkgfile)
284
+
285
+ # Add another OS
286
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
287
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
288
+ if line =~ /operatingsystem/
289
+ line << "<operatingsystem>otheros</operatingsystem>\n"
290
+ end
291
+ pkgxmlfile.print(line)
292
+ end
293
+ end
294
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
295
+ FileUtils.rm_f(pkgfile)
296
+ assert_match(/testpkg-1.0-1-multios-architecture.tpkg/, pkgfile)
297
+
298
+ # Add another architecture
299
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
300
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
301
+ if line =~ /architecture/
302
+ line << "<architecture>otherarch</architecture>\n"
303
+ end
304
+ pkgxmlfile.print(line)
305
+ end
306
+ end
307
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
308
+ FileUtils.rm_f(pkgfile)
309
+ assert_match(/testpkg-1.0-1-os-multiarch.tpkg/, pkgfile)
310
+
311
+ # Remove the OS
312
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
313
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
314
+ if line !~ /operatingsystem/
315
+ pkgxmlfile.print(line)
316
+ end
317
+ end
318
+ end
319
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
320
+ FileUtils.rm_f(pkgfile)
321
+ assert_match(/testpkg-1.0-1-architecture.tpkg/, pkgfile)
322
+
323
+ # Remove the architecture
324
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
325
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
326
+ if line !~ /architecture/
327
+ pkgxmlfile.print(line)
328
+ end
329
+ end
330
+ end
331
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
332
+ FileUtils.rm_f(pkgfile)
333
+ assert_match(/testpkg-1.0-1-os.tpkg/, pkgfile)
334
+
335
+ # Set OS to a set of Red Hat variants, they get special treatment
336
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
337
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
338
+ if line =~ /operatingsystem/
339
+ line = "<operatingsystem>RedHat-5,CentOS-5</operatingsystem>\n"
340
+ end
341
+ pkgxmlfile.print(line)
342
+ end
343
+ end
344
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
345
+ FileUtils.rm_f(pkgfile)
346
+ assert_match(/testpkg-1.0-1-redhat5-architecture.tpkg/, pkgfile)
347
+
348
+ # Red Hat variants with different versions
349
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
350
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
351
+ if line =~ /operatingsystem/
352
+ line = "<operatingsystem>RedHat-5,CentOS-5,RedHat-4</operatingsystem>\n"
353
+ end
354
+ pkgxmlfile.print(line)
355
+ end
356
+ end
357
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
358
+ FileUtils.rm_f(pkgfile)
359
+ assert_match(/testpkg-1.0-1-redhat-architecture.tpkg/, pkgfile)
360
+
361
+ # Same OS with different versions
362
+ File.open(File.join(@pkgdir, 'tpkg.xml'), 'w') do |pkgxmlfile|
363
+ IO.foreach(File.join(TESTPKGDIR, 'tpkg-nofiles.xml')) do |line|
364
+ if line =~ /operatingsystem/
365
+ line = "<operatingsystem>Solaris-5.8,Solaris-5.9</operatingsystem>\n"
366
+ end
367
+ pkgxmlfile.print(line)
368
+ end
369
+ end
370
+ assert_nothing_raised { pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE) }
371
+ FileUtils.rm_f(pkgfile)
372
+ assert_match(/testpkg-1.0-1-solaris-architecture.tpkg/, pkgfile)
373
+ end
374
+
375
+ def test_make_output_dir
376
+ testname = "Trying to output to a non-existing directory"
377
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, PASSPHRASE, :out => 'bogus/direc/tory') }
378
+
379
+ outdir = Tempfile.new('testfile')
380
+ testname = "Trying to output to something that is not a directory"
381
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, PASSPHRASE, :out => outdir.path) }
382
+
383
+ testname = "Trying to output to a directory that is not writable"
384
+ Dir.mktmpdir('outdir') do |outdir|
385
+ FileUtils.chmod 0555, outdir
386
+ assert_raise(RuntimeError, testname) { Tpkg.make_package(@pkgdir, PASSPHRASE, :out => outdir) }
387
+ end
388
+
389
+ # Trying to output to a good directory
390
+ Dir.mktmpdir('outdir') do |outdir|
391
+ pkgfile = Tpkg.make_package(@pkgdir, PASSPHRASE, :out => outdir)
392
+ assert(File.exists?(pkgfile))
393
+ end
394
+ end
395
+
396
+ def test_make_tpkg_version
397
+ # FIXME
398
+ testname = 'make_package added tpkg_version to metadata'
399
+ # The source directory from which the package is made may not be writeable
400
+ # by the user making the package. As such attempting to add tpkg_version
401
+ # to the metadata file will fail. We expect tpkg to warn the user about
402
+ # that fact but not fail.
403
+ testname = 'make_package warned if adding tpkg_version failed due to permissions'
404
+ end
405
+
406
+ def teardown
407
+ FileUtils.rm_rf(@pkgdir)
408
+ end
409
+ end
410
+