]>
git.saurik.com Git - apt.git/blob - test/pre-upload-check.py
75a726808e6a9c1d647af8f4a9bc9e6213e177a5
9 from subprocess
import call
, PIPE
13 stdout
= os
.open("/dev/null",0) #sys.stdout
14 stderr
= os
.open("/dev/null",0) # sys.stderr
17 #apt_args = ["-o","Debug::pkgAcquire::Auth=true"]
19 class testAptAuthenticationReliability(unittest
.TestCase
):
21 test if the spec https://wiki.ubuntu.com/AptAuthenticationReliability
22 is properly implemented
24 apt
= "../bin/apt-get"
28 def testRepositorySigFailure(self
):
30 test if a repository that used to be authenticated and fails on
31 apt-get update refuses to update and uses the old state
33 # copy valid signatures into lists (those are ok, even
34 # if the name is "-broken-" ...
35 for f
in glob
.glob("./authReliability/lists/*"):
36 shutil
.copy(f
,"/var/lib/apt/lists")
37 # ensure we do *not* get a I-M-S hit
38 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (0,0))
41 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.failure"
43 stdout
=stdout
, stderr
=stderr
)
44 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg"),
45 "The gpg file disappeared, this should not happen")
46 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages"),
47 "The Packages file disappeared, this should not happen")
48 # the same with i-m-s hit this time
49 for f
in glob
.glob("./authReliability/lists/*"):
50 shutil
.copy(f
,"/var/lib/apt/lists")
51 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (time
.time(),time
.time()))
54 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.failure"
56 stdout
=stdout
, stderr
=stderr
)
57 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg"),
58 "The gpg file disappeared, this should not happen")
59 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages"),
60 "The Packages file disappeared, this should not happen")
61 def testRepositorySigGood(self
):
63 test that a regular repository with good data stays good
67 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good"
69 stdout
=stdout
, stderr
=stderr
)
70 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"),
71 "The gpg file disappeared, this should not happen")
72 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"),
73 "The Packages file disappeared, this should not happen")
74 # test good is still good after non I-M-S hit and a previous files in lists/
75 for f
in glob
.glob("./authReliability/lists/*"):
76 shutil
.copy(f
,"/var/lib/apt/lists")
77 # ensure we do *not* get a I-M-S hit
78 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (0,0))
81 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good"
83 stdout
=stdout
, stderr
=stderr
)
84 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"),
85 "The gpg file disappeared, this should not happen")
86 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"),
87 "The Packages file disappeared, this should not happen")
88 # test good is still good after I-M-S hit
89 for f
in glob
.glob("./authReliability/lists/*"):
90 shutil
.copy(f
,"/var/lib/apt/lists")
91 # ensure we do get a I-M-S hit
92 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (time
.time(),time
.time()))
95 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good"
97 stdout
=stdout
, stderr
=stderr
)
98 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"),
99 "The gpg file disappeared, this should not happen")
100 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"),
101 "The Packages file disappeared, this should not happen")
104 class testAuthentication(unittest
.TestCase
):
106 test if the authentication is working, the repository
107 of the test-data can be found here:
108 bzr get http://people.ubuntu.com/~mvo/bzr/apt/apt-auth-test-suit/
111 # some class wide data
113 pkg
= "libglib2.0-data"
114 pkgver
= "2.13.6-1ubuntu1"
115 pkgpath
= "/var/cache/apt/archives/libglib2.0-data_2.13.6-1ubuntu1_all.deb"
118 for f
in glob
.glob("testkeys/*,key"):
119 call(["apt-key", "add", f
], stdout
=stdout
, stderr
=stderr
)
122 " make sure we get new lists and no i-m-s "
123 call(["rm","-f", "/var/lib/apt/lists/*"])
124 if os
.path
.exists(self
.pkgpath
):
125 os
.unlink(self
.pkgpath
)
127 def _expectedRes(self
, resultstr
):
128 if resultstr
== 'ok':
130 elif resultstr
== 'broken':
134 def testPackages(self
):
135 for f
in glob
.glob("testsources.list/sources.list*package*"):
137 (prefix
, testtype
, result
) = f
.split("-")
138 expected_res
= self
._expectedRes
(result
)
140 call([self
.apt
,"update",
141 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
142 stdout
=stdout
, stderr
=stderr
)
144 cmd
= ["install", "-y", "-d", "--reinstall",
145 "%s=%s" % (self
.pkg
, self
.pkgver
),
146 "-o","Dir::state::Status=./fake-status"]
147 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
148 stdout
=stdout
, stderr
=stderr
)
149 self
.assert_(res
== expected_res
,
150 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
154 for f
in glob
.glob("testsources.list/sources.list*gpg*"):
156 (prefix
, testtype
, result
) = f
.split("-")
157 expected_res
= self
._expectedRes
(result
)
159 call([self
.apt
,"update",
160 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
161 stdout
=stdout
, stderr
=stderr
)
162 cmd
= ["install", "-y", "-d", "--reinstall",
163 "%s=%s" % (self
.pkg
, self
.pkgver
),
164 "-o","Dir::state::Status=./fake-status"]
165 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+
167 stdout
=stdout
, stderr
=stderr
)
168 self
.assert_(res
== expected_res
,
169 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
171 def testRelease(self
):
172 for f
in glob
.glob("testsources.list/sources.list*release*"):
174 (prefix
, testtype
, result
) = f
.split("-")
175 expected_res
= self
._expectedRes
(result
)
177 res
= call([self
.apt
,"-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
178 stdout
=stdout
, stderr
=stderr
)
179 self
.assert_(res
== expected_res
,
180 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
181 if expected_res
== 0:
182 self
.assert_(len(glob
.glob("/var/lib/apt/lists/partial/*")) == 0,
183 "partial/ dir has leftover files: %s" % glob
.glob("/var/lib/apt/lists/partial/*"))
186 class testLocalRepositories(unittest
.TestCase
):
187 " test local repository regressions "
189 repo_dir
= "local-repo"
194 self
.repo
= os
.path
.abspath(os
.path
.join(os
.getcwd(), self
.repo_dir
))
195 self
.sources
= os
.path
.join(self
.repo
, "sources.list")
196 s
= open(self
.sources
,"w")
197 s
.write("deb file://%s/ /\n" % self
.repo
)
200 def testLocalRepoAuth(self
):
201 # two times to get at least one i-m-s hit
203 self
.assert_(os
.path
.exists(self
.sources
))
204 cmd
= [self
.apt
,"update","-o", "Dir::Etc::sourcelist=%s" % self
.sources
]+apt_args
205 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
206 self
.assertEqual(res
, 0, "local repo test failed")
207 self
.assert_(os
.path
.exists(os
.path
.join(self
.repo
,"Packages.gz")),
208 "Packages.gz vanished from local repo")
210 def testInstallFromLocalRepo(self
):
211 apt
= [self
.apt
,"-o", "Dir::Etc::sourcelist=%s"% self
.sources
]+apt_args
213 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
214 self
.assertEqual(res
, 0)
215 res
= call(apt
+["-y","install","--reinstall",self
.pkg
],
216 stdout
=stdout
, stderr
=stderr
)
217 self
.assert_(res
== 0,
218 "installing %s failed (got %s)" % (self
.pkg
, res
))
219 res
= call(apt
+["-y","remove",self
.pkg
],
220 stdout
=stdout
, stderr
=stderr
)
221 self
.assert_(res
== 0,
222 "removing %s failed (got %s)" % (self
.pkg
, res
))
224 def testPythonAptInLocalRepo(self
):
226 apt_pkg
.Config
.Set("Dir::Etc::sourcelist",self
.sources
)
230 self
.assert_(pkg
.name
== 'apt')
234 if __name__
== "__main__":
235 print "Runing simple testsuit on current apt-get and libapt"
236 if len(sys
.argv
) > 1 and sys
.argv
[1] == "-v":
240 # run only one for now
241 #unittest.main(defaultTest="testAptAuthenticationReliability")