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,80 @@
1
+ #
2
+ # Test tpkg's ability to upgrade packages
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+
7
+ class TpkgDowngradeTests < Test::Unit::TestCase
8
+ include TpkgTests
9
+
10
+ def setup
11
+ Tpkg::set_prompt(false)
12
+
13
+ @pkgfiles = []
14
+ Dir.mktmpdir('srcdir') do |srcdir|
15
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
16
+ FileUtils.mkdir(File.join(srcdir, 'reloc'))
17
+
18
+ # Creating packages that will be used for testing
19
+
20
+ # Package a-1 and a-2. No dependency.
21
+ @pkgfiles << make_package(:change => {'name' => 'a', 'version' => '1', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
22
+ @pkgfiles << make_package(:change => {'name' => 'a', 'version' => '2', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
23
+
24
+ # Package b-1 and b-2. b-1 depends on c-1
25
+ @pkgfiles << make_package(:change => {'name' => 'b', 'version' => '1', 'package_version' => '1'}, :dependencies => {'c' => {}}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
26
+ @pkgfiles << make_package(:change => {'name' => 'b', 'version' => '2', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
27
+ @pkgfiles << make_package(:change => {'name' => 'c', 'version' => '1', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
28
+
29
+ # Package d-1 and d-2. d-1 depends on nonexistingpkg
30
+ @pkgfiles << make_package(:change => {'name' => 'd', 'version' => '1', 'package_version' => '1'}, :dependencies => {'nonexistingpkg' => {}}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
31
+ @pkgfiles << make_package(:change => {'name' => 'd', 'version' => '2', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
32
+
33
+ # Package e-1, e-2 and f-1. f-1 depends on e-2
34
+ @pkgfiles << make_package(:change => {'name' => 'e', 'version' => '1', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
35
+ @pkgfiles << make_package(:change => {'name' => 'e', 'version' => '2', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
36
+ @pkgfiles << make_package(:change => {'name' => 'f', 'version' => '1', 'package_version' => '1'}, :dependencies => {'e' => {'minimum_version' => '2.0', 'maximum_version' => '2.0'}}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
37
+ end
38
+
39
+ @testroot = Dir.mktmpdir('testroot')
40
+ @testbase = File.join(@testroot, 'home', 'tpkg')
41
+ FileUtils.mkdir_p(@testbase)
42
+ @tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => @pkgfiles)
43
+ @tpkg.install(['a', 'b', 'd', 'e', 'f'], PASSPHRASE)
44
+ end
45
+
46
+ def test_downgrade
47
+
48
+ # should be able to downgrade to a-1
49
+ assert_nothing_raised {@tpkg.upgrade(['a=1'], PASSPHRASE, {:downgrade => true})}
50
+
51
+ # should be able to downgrade to b-1,
52
+ assert_nothing_raised {@tpkg.upgrade(['b=1'], PASSPHRASE, {:downgrade => true})}
53
+
54
+ # should not be able to downgrade to d-1 since it depends on non-existing pkg
55
+ assert_raise(RuntimeError) {@tpkg.upgrade(['d=1'], PASSPHRASE, {:downgrade => true})}
56
+
57
+ # should not be able to downgrade to e-1 since f-1 depends on e-2
58
+ assert_raise(RuntimeError) {@tpkg.upgrade(['e=1'], PASSPHRASE, {:downgrade => true})}
59
+
60
+ # There should be 6 packages installed
61
+ metadata = @tpkg.metadata_for_installed_packages
62
+ assert_equal(6, metadata.size)
63
+ # a, b, c and f should be version 1
64
+ metadata.each do | m |
65
+ if ['a','b','c','f'].include?(m[:name])
66
+ assert_equal('1', m[:version])
67
+ elsif ['d', 'e'].include?(m[:name])
68
+ assert_equal('2', m[:version])
69
+ else
70
+ assert(false)
71
+ end
72
+ end
73
+ end
74
+
75
+ def teardown
76
+ @pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
77
+ FileUtils.rm_rf(@testroot)
78
+ end
79
+ end
80
+
@@ -0,0 +1,95 @@
1
+ #
2
+ # Test tpkg's ability to download packages
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+ require 'webrick'
7
+
8
+ class TpkgDownloadTests < Test::Unit::TestCase
9
+ include TpkgTests
10
+
11
+ def setup
12
+ Tpkg::set_prompt(false)
13
+
14
+ # Make up our regular test package
15
+ @pkgfile = make_package
16
+
17
+ # Copy the package into a directory to test directory-related operations
18
+ @pkgdir = Dir.mktmpdir('pkgdir')
19
+ FileUtils.cp(@pkgfile, @pkgdir)
20
+ end
21
+
22
+ def test_download
23
+ Tpkg::extract_metadata(@pkgdir)
24
+
25
+ s = WEBrick::HTTPServer.new(:Port => 3500, :DocumentRoot => @pkgdir)
26
+ # There may be an easier way to push WEBrick into the background, but
27
+ # the WEBrick docs are mostly non-existent so I'm taking the quick and
28
+ # dirty route.
29
+ t = Thread.new { s.start }
30
+
31
+ Dir.mktmpdir('testbase') do |testbase|
32
+ source = 'http://localhost:3500/'
33
+ tpkg = Tpkg.new(:base => testbase, :sources => [source])
34
+ # Download and verify
35
+ assert_nothing_raised { tpkg.download(source, File.basename(@pkgfile)) }
36
+ localpath = File.join(tpkg.source_to_local_directory(source), File.basename(@pkgfile))
37
+ assert(File.exist?(localpath))
38
+ assert_equal(0644, File.stat(localpath).mode & 07777)
39
+ assert(Tpkg::verify_package_checksum(localpath))
40
+
41
+ # Mess with the package so that it doesn't verify, then confirm that
42
+ # calling download again re-downloads it
43
+ File.open(localpath, 'w') do |file|
44
+ file.puts "Bogus package now"
45
+ end
46
+ assert_raise(RuntimeError, NoMethodError) { Tpkg::verify_package_checksum(localpath) }
47
+ assert_nothing_raised { tpkg.download(source, File.basename(@pkgfile)) }
48
+ assert(File.exist?(localpath))
49
+ assert(Tpkg::verify_package_checksum(localpath))
50
+ end
51
+
52
+ s.shutdown
53
+ t.kill
54
+ end
55
+
56
+ def test_download_pkgs
57
+ # set up multiple packages
58
+ ['pkga', 'pkgb'].each do |name|
59
+ pkgfile = make_package(:change => {'name' => name}, :remove => ['operatingsystem', 'architecture'])
60
+ FileUtils.cp(pkgfile, @pkgdir)
61
+ end
62
+
63
+ Tpkg::extract_metadata(@pkgdir)
64
+
65
+ s = WEBrick::HTTPServer.new(:Port => 3500, :DocumentRoot => @pkgdir)
66
+ # There may be an easier way to push WEBrick into the background, but
67
+ # the WEBrick docs are mostly non-existent so I'm taking the quick and
68
+ # dirty route.
69
+ t = Thread.new { s.start }
70
+
71
+ Dir.mktmpdir('testbase') do |testbase|
72
+ Dir.mktmpdir('destdir') do |destdir|
73
+ source = 'http://localhost:3500/'
74
+ tpkg = Tpkg.new(:base => testbase, :sources => [source])
75
+
76
+ # Try to request a download of a non-existing package
77
+ result = tpkg.download_pkgs(['non-existing'], {:out => destdir})
78
+ assert_equal(Tpkg::GENERIC_ERR, result)
79
+
80
+ # Try to request a download of existing packages
81
+ result = tpkg.download_pkgs(['pkga', 'pkgb'], {:out => destdir})
82
+ assert_equal(0, result)
83
+ assert_equal(2, Dir.glob(File.join(destdir, '*')).size) # we have downloaded 2 packages
84
+ end
85
+ end
86
+
87
+ s.shutdown
88
+ t.kill
89
+ end
90
+
91
+ def teardown
92
+ FileUtils.rm_f(@pkgfile)
93
+ FileUtils.rm_rf(@pkgdir)
94
+ end
95
+ end
@@ -0,0 +1,136 @@
1
+
2
+
3
+ #
4
+ # Test tpkg's encrypt/decrypt methods
5
+ #
6
+ # The methods are supposed to be compatible with openssl's 'enc' utility,
7
+ # so we test them by encrypting some plaintext with openssl and then using
8
+ # the method to decrypt it or vice-versa.
9
+ #
10
+
11
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
12
+
13
+ class TpkgEncryptTests < Test::Unit::TestCase
14
+ include TpkgTests
15
+
16
+ def setup
17
+ Tpkg::set_prompt(false)
18
+ end
19
+
20
+ def test_encrypt
21
+ plaintext = 'This is the plaintext'
22
+ cipher = 'aes-256-cbc'
23
+
24
+ tmpfile = Tempfile.new('tpkgtest')
25
+ tmpfile.write(plaintext)
26
+ tmpfile.close
27
+ File.chmod(0604, tmpfile.path)
28
+
29
+ # Test encrypt
30
+ Tpkg::encrypt('tpkgtest', tmpfile.path, PASSPHRASE, cipher)
31
+ decrypted = `openssl enc -d -#{cipher} -pass pass:#{PASSPHRASE} -in #{tmpfile.path}`
32
+ assert_equal(plaintext, decrypted)
33
+ assert_equal(0604, File.stat(tmpfile.path).mode & 07777)
34
+
35
+ # Test using a callback to supply the passphrase
36
+ File.open(tmpfile.path, 'w') do |file|
37
+ file.write(plaintext)
38
+ end
39
+ callback = lambda { |pkgname| PASSPHRASE }
40
+ Tpkg::encrypt('tpkgtest', tmpfile.path, callback, cipher)
41
+ decrypted = `openssl enc -d -#{cipher} -pass pass:#{PASSPHRASE} -in #{tmpfile.path}`
42
+ assert_equal(plaintext, decrypted)
43
+
44
+ # Test encrypting on a directory
45
+ Dir.mktmpdir('testdir') do |testdir|
46
+ File.open(File.join(testdir, 'file1'), 'w') do |file|
47
+ file.write(plaintext)
48
+ end
49
+ File.open(File.join(testdir, 'file2'), 'w') do |file|
50
+ file.write(plaintext)
51
+ end
52
+ Tpkg::encrypt('tpkgtest', testdir, PASSPHRASE, cipher)
53
+ decrypted = `openssl enc -d -#{cipher} -pass pass:#{PASSPHRASE} -in #{File.join(testdir, 'file1')}`
54
+ assert_equal(plaintext, decrypted)
55
+ decrypted = `openssl enc -d -#{cipher} -pass pass:#{PASSPHRASE} -in #{File.join(testdir, 'file2')}`
56
+ assert_equal(plaintext, decrypted)
57
+ end
58
+
59
+ # Test encrypting an empty file
60
+ File.open(tmpfile.path, 'w') do |file|
61
+ end
62
+ Tpkg::encrypt('tpkgtest', tmpfile.path, callback, cipher)
63
+ end
64
+
65
+ def test_decrypt
66
+ plaintext = 'This is the plaintext'
67
+ cipher = 'aes-256-cbc'
68
+
69
+ tmpfile = Tempfile.new('tpkgtest')
70
+ tmpfile.close
71
+ File.chmod(0604, tmpfile.path)
72
+
73
+ # Test decrypt
74
+ IO.popen(
75
+ "openssl enc -#{cipher} -salt -pass pass:#{PASSPHRASE} -out #{tmpfile.path}",
76
+ 'w') do |pipe|
77
+ pipe.write(plaintext)
78
+ end
79
+ Tpkg::decrypt('tpkgtest', tmpfile.path, PASSPHRASE, cipher)
80
+ decrypted = IO.read(tmpfile.path)
81
+ assert_equal(plaintext, decrypted)
82
+ assert_equal(0604, File.stat(tmpfile.path).mode & 07777)
83
+
84
+ # Test using a callback to supply the passphrase
85
+ IO.popen(
86
+ "openssl enc -#{cipher} -salt -pass pass:#{PASSPHRASE} -out #{tmpfile.path}",
87
+ 'w') do |pipe|
88
+ pipe.write(plaintext)
89
+ end
90
+ callback = lambda { |pkgname| PASSPHRASE }
91
+ Tpkg::decrypt('tpkgtest', tmpfile.path, callback, cipher)
92
+ decrypted = IO.read(tmpfile.path)
93
+ assert_equal(plaintext, decrypted)
94
+
95
+ # Test decrypting on a directory
96
+ Dir.mktmpdir('testdir') do |testdir|
97
+ IO.popen(
98
+ "openssl enc -#{cipher} -salt -pass pass:#{PASSPHRASE} -out #{File.join(testdir, 'file1')}",
99
+ 'w') do |pipe|
100
+ pipe.write(plaintext)
101
+ end
102
+ Tpkg::decrypt('tpkgtest', testdir, PASSPHRASE, cipher)
103
+ decrypted = IO.read(File.join(testdir, 'file1'))
104
+ assert_equal(plaintext, decrypted)
105
+ end
106
+
107
+ # Test decrypting an empty file
108
+ IO.popen(
109
+ "openssl enc -#{cipher} -salt -pass pass:#{PASSPHRASE} -out #{tmpfile.path}",
110
+ 'w') do |pipe|
111
+ end
112
+ Tpkg::decrypt('tpkgtest', tmpfile.path, callback, cipher)
113
+ end
114
+
115
+ def test_verify_precrypt_file
116
+ plaintext = 'This is the plaintext'
117
+ cipher = 'aes-256-cbc'
118
+
119
+ tmpfile = Tempfile.new('tpkgtest')
120
+ tmpfile.close
121
+
122
+ IO.popen(
123
+ "openssl enc -#{cipher} -salt -pass pass:#{PASSPHRASE} -out #{tmpfile.path}",
124
+ 'w') do |pipe|
125
+ pipe.write(plaintext)
126
+ end
127
+
128
+ assert(Tpkg::verify_precrypt_file(tmpfile.path))
129
+
130
+ File.open(tmpfile.path, 'w') do |file|
131
+ file.puts plaintext
132
+ end
133
+
134
+ assert_raise(RuntimeError) { Tpkg::verify_precrypt_file(tmpfile.path) }
135
+ end
136
+ end
@@ -0,0 +1,131 @@
1
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
2
+
3
+ class TpkgFileMetadataTests < Test::Unit::TestCase
4
+ include TpkgTests
5
+
6
+ def setup
7
+ Tpkg::set_prompt(false)
8
+
9
+ # Make up our regular test package
10
+ @pkgfile = make_package(:remove => ['operatingsystem', 'architecture'], :files => {'file' => {'perms' => '0641'}})
11
+ end
12
+
13
+ def test_file_metadata
14
+ Dir.mktmpdir('testroot') do |testroot|
15
+ testbase = File.join(testroot, 'home', 'tpkg')
16
+ FileUtils.mkdir_p(testbase)
17
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
18
+
19
+ assert_nothing_raised { tpkg.install([@pkgfile], PASSPHRASE) }
20
+
21
+ # check that we can get read file_metadata for the newly installed package
22
+ assert_nothing_raised { @file_metadata = tpkg.file_metadata_for_installed_packages[File.basename(@pkgfile)]}
23
+
24
+ # checking content of file_metadata
25
+ assert_equal(@file_metadata[:package_file], File.basename(@pkgfile))
26
+
27
+ # check file's ownership and permissions are ok
28
+ assert_nothing_raised { @errors = tpkg.verify_file_metadata(['testpkg']) }
29
+ puts @errors.inspect
30
+ @errors.each do | file, error |
31
+ assert(error.empty?)
32
+ end
33
+
34
+ # modify a file's perms and verify that tpkg can detect it
35
+ File.chmod(07777, File.join(testroot, 'home','tpkg','file'))
36
+ assert_nothing_raised { @errors = tpkg.verify_file_metadata(['testpkg'])}
37
+ @errors.each do | file, error |
38
+ if File.basename(file) == "file"
39
+ assert(!error.empty?)
40
+ else
41
+ assert(error.empty?)
42
+ end
43
+ end
44
+
45
+ # modify a file content and verify that tpkg can detect it
46
+ File.open(File.join(testroot, 'home','tpkg','file'), 'w') do |file|
47
+ file.puts "Hello"
48
+ end
49
+ assert_nothing_raised { @errors = tpkg.verify_file_metadata(['testpkg'])}
50
+ @errors.each do | file, error |
51
+ if File.basename(file) == "file"
52
+ assert(!error.empty?)
53
+ assert(error.length == 2) # error 1 is for bad perm, error 2 is for bad checksum
54
+ else
55
+ assert(error.empty?)
56
+ end
57
+ end
58
+
59
+ # remove a file and verify that tpkg can detect it
60
+ FileUtils.rm(File.join(testroot, 'home','tpkg','file'))
61
+ assert_nothing_raised { @errors = tpkg.verify_file_metadata(['testpkg'])}
62
+ @errors.each do | file, error |
63
+ if File.basename(file) == "file"
64
+ assert(!error.empty?)
65
+ else
66
+ assert(error.empty?)
67
+ end
68
+ end
69
+ end
70
+
71
+ # TODO: modify a file owner, group and verify that tpkg can detect it
72
+ # Dir.mktmpdir('testroot') do |testroot|
73
+ # testbase = File.join(testroot, 'home', 'tpkg')
74
+ # FileUtils.mkdir_p(testbase)
75
+ # tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
76
+ # assert_nothing_raised { tpkg.install([@pkgfile], PASSPHRASE) }
77
+ # uid = Tpkg::lookup_uid("bogus")
78
+ # gid = Tpkg::lookup_gid("bogus")
79
+ # File.chown(uid, gid, File.join(testroot, 'home','tpkg','file'))
80
+ # assert_nothing_raised { @errors = tpkg.verify_file_metadata(['testpkg'])}
81
+ # @errors.each do | file, error |
82
+ # if File.basename(file) == "file"
83
+ # assert(!error.empty?)
84
+ # assert(error.length == 2) # 2 errors: 1 for gid and 1 for uid
85
+ # else
86
+ # assert(error.empty?)
87
+ # end
88
+ # end
89
+ # end
90
+ end
91
+
92
+ def test_backward_compatibility
93
+ # Test that tpkg doesn't break when user wants to verify old installed packages
94
+ # that were created without file_metadata.xml
95
+ Dir.mktmpdir('testroot') do |testroot|
96
+ testbase = File.join(testroot, 'home', 'tpkg')
97
+ FileUtils.mkdir_p(testbase)
98
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@pkgfile])
99
+
100
+ assert_nothing_raised { tpkg.install([@pkgfile], PASSPHRASE) }
101
+
102
+ # remove file_metadata
103
+ pkgname = File.basename(@pkgfile, File.extname(@pkgfile))
104
+ FileUtils.rm(File.join(testroot, 'home','tpkg', 'var', 'tpkg', 'installed', 'metadata', pkgname, 'file_metadata.bin'))
105
+
106
+ # verify nothing bad when user try to run -V
107
+ assert_nothing_raised { @errors = tpkg.verify_file_metadata(['testpkg'])}
108
+
109
+ # remove metadata directory and check the verify method doesn't break
110
+ FileUtils.rm_r(File.join(testroot, 'home','tpkg', 'var', 'tpkg', 'installed', 'metadata', pkgname))
111
+ assert_nothing_raised { @errors = tpkg.verify_file_metadata(['testpkg'])}
112
+
113
+ # Test that tpkg doesn't break when user try to install old packages that were created without file_metadata.xml
114
+ pkg_without_file_metadata = File.join(File.dirname(__FILE__), 'premadetestpkg', 'pkg_without_file_metadata-1.0-1.tpkg')
115
+ assert_nothing_raised { tpkg.install([pkg_without_file_metadata], PASSPHRASE) }
116
+ # Check that the files from the package ended up in the right place
117
+ assert(File.exist?(File.join(testbase, 'file')))
118
+ assert_equal(IO.read(File.join(TESTPKGDIR, 'reloc', 'file')), IO.read(File.join(testbase, 'file')))
119
+ assert(File.exist?(File.join(testbase, 'encfile')))
120
+ assert_equal(IO.read(File.join(TESTPKGDIR, 'reloc', 'encfile')), IO.read(File.join(testbase, 'encfile')))
121
+
122
+ # verify nothing bad when user try to run -V
123
+ assert_nothing_raised { @errors = tpkg.verify_file_metadata(['pkg_without_file_metadata'])}
124
+ end
125
+ end
126
+
127
+ def teardown
128
+ FileUtils.rm_f(@pkgfile)
129
+ end
130
+ end
131
+
@@ -0,0 +1,93 @@
1
+
2
+
3
+ #
4
+ # Test tpkg's ability to execute init scripts
5
+ #
6
+
7
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
8
+
9
+ class TpkgInitScriptsTests < Test::Unit::TestCase
10
+ include TpkgTests
11
+
12
+ def setup
13
+ Tpkg::set_prompt(false)
14
+
15
+ # temp dir that will automatically get deleted at end of test run, can be
16
+ # used for storing packages
17
+ @tempoutdir = Dir.mktmpdir('tempoutdir')
18
+ # Make up a package with both relocatable and non-relocatable
19
+ # directory trees so that we can ensure both types are unpacked
20
+ # properly.
21
+ Dir.mktmpdir('srcdir') do |srcdir|
22
+ # The stock test package has a reloc directory we can use
23
+ system("#{Tpkg::find_tar} -C #{TESTPKGDIR} --exclude .svn -cf - . | #{Tpkg::find_tar} -C #{srcdir} -xf -")
24
+ # Then add a root directory
25
+ FileUtils.mkdir_p(File.join(srcdir, 'root', 'etc'))
26
+ File.open(File.join(srcdir, 'root', 'etc', 'rootfile'), 'w') do |file|
27
+ file.puts "Hello"
28
+ end
29
+ @pkgfile = make_package(:output_directory => @tempoutdir, :source_directory => srcdir, :files => {'/etc/rootfile' => {'perms' => '0666'}})
30
+ end
31
+ end
32
+
33
+ # Test init script start/stop init scripts in correct order
34
+ def test_order
35
+ pkg = nil
36
+ tmpfile = Tempfile.new('initscripttest')
37
+ Dir.mktmpdir('srcdir') do |srcdir|
38
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
39
+ FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
40
+ (1..3).each do | i |
41
+ File.open(File.join(srcdir, 'reloc', "myinit#{i}"), 'w') do |file|
42
+ file.puts("#!/bin/sh\necho myinit#{i} >> #{tmpfile.path}")
43
+ end
44
+ File.chmod(0755, File.join(srcdir, 'reloc', "myinit#{i}"))
45
+ end
46
+
47
+ pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'initpkg' }, :source_directory => srcdir,
48
+ :files => { "myinit1" => { 'init' => {'start' => '1' }} , "myinit2" => { 'init' => {'start' => '2' }}, "myinit3" => { 'init' => {'start' => '3' }}},
49
+ :remove => ['operatingsystem', 'architecture'])
50
+ end
51
+ Dir.mktmpdir('testroot') do |testroot|
52
+ testbase = File.join(testroot, 'home', 'tpkg')
53
+ FileUtils.mkdir_p(testbase)
54
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
55
+ metadata = Tpkg::metadata_from_package(pkg)
56
+ begin
57
+ tpkg.install([pkg], PASSPHRASE)
58
+ tpkg.init_links(metadata).each do |link, init_script|
59
+ assert(File.symlink?(link))
60
+ assert_equal(init_script, File.readlink(link))
61
+ end
62
+
63
+ # check that init scripts are started in correct order
64
+ tpkg.execute_init(["initpkg"], "start")
65
+ lines = File.open(tmpfile.path).readlines
66
+ assert_equal("myinit1", lines[0].chomp)
67
+ assert_equal("myinit2", lines[1].chomp)
68
+ assert_equal("myinit3", lines[2].chomp)
69
+
70
+ # clear out the file
71
+ system("cat /dev/null > #{tmpfile.path}")
72
+ # check that init scripts are stopped in correct order
73
+ tpkg.execute_init(["initpkg"], "stop")
74
+ lines = File.open(tmpfile.path).readlines
75
+ assert_equal("myinit3", lines[0].chomp)
76
+ assert_equal("myinit2", lines[1].chomp)
77
+ assert_equal("myinit1", lines[2].chomp)
78
+ rescue RuntimeError => e
79
+ if e.message =~ /No init script support/
80
+ warn "No init script support on this platform, init script handling will not be tested (#{e.message})"
81
+ else
82
+ raise
83
+ end
84
+ end
85
+ end
86
+ FileUtils.rm_f(pkg)
87
+ end
88
+
89
+ def teardown
90
+ FileUtils.rm_rf(@tempoutdir)
91
+ end
92
+ end
93
+