]>
git.saurik.com Git - apt.git/blob - test/pre-upload-check.py
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 if os
.path
.exists("/tmp/autFailure"):
29 os
.unlink("/tmp/authFailure");
30 if os
.path
.exists("/tmp/autFailure2"):
31 os
.unlink("/tmp/authFailure2");
32 def testRepositorySigFailure(self
):
34 test if a repository that used to be authenticated and fails on
35 apt-get update refuses to update and uses the old state
37 # copy valid signatures into lists (those are ok, even
38 # if the name is "-broken-" ...
39 for f
in glob
.glob("./authReliability/lists/*"):
40 shutil
.copy(f
,"/var/lib/apt/lists")
41 # ensure we do *not* get a I-M-S hit
42 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (0,0))
45 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.failure",
46 "-o",'APT::Update::Auth-Failure::=touch /tmp/authFailure',
48 stdout
=stdout
, stderr
=stderr
)
49 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg"),
50 "The gpg file disappeared, this should not happen")
51 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages"),
52 "The Packages file disappeared, this should not happen")
53 self
.assert_(os
.path
.exists("/tmp/authFailure"),
54 "The APT::Update::Auth-Failure script did not run (1)")
55 # the same with i-m-s hit this time
56 for f
in glob
.glob("./authReliability/lists/*"):
57 shutil
.copy(f
,"/var/lib/apt/lists")
58 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (time
.time(),time
.time()))
61 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.failure",
62 "-o",'APT::Update::Auth-Failure::=touch /tmp/authFailure2',
64 stdout
=stdout
, stderr
=stderr
)
65 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg"),
66 "The gpg file disappeared, this should not happen")
67 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages"),
68 "The Packages file disappeared, this should not happen")
69 self
.assert_(os
.path
.exists("/tmp/authFailure2"),
70 "The APT::Update::Auth-Failure script did not run (2)")
71 def testRepositorySigGood(self
):
73 test that a regular repository with good data stays good
77 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good"
79 stdout
=stdout
, stderr
=stderr
)
80 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"),
81 "The gpg file disappeared after a regular download, this should not happen")
82 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"),
83 "The Packages file disappeared, this should not happen")
84 # test good is still good after non I-M-S hit and a previous files in lists/
85 for f
in glob
.glob("./authReliability/lists/*"):
86 shutil
.copy(f
,"/var/lib/apt/lists")
87 # ensure we do *not* get a I-M-S hit
88 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (0,0))
91 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good"
93 stdout
=stdout
, stderr
=stderr
)
94 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"),
95 "The gpg file disappeared after a I-M-S hit, this should not happen")
96 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"),
97 "The Packages file disappeared, this should not happen")
98 # test good is still good after I-M-S hit
99 for f
in glob
.glob("./authReliability/lists/*"):
100 shutil
.copy(f
,"/var/lib/apt/lists")
101 # ensure we do get a I-M-S hit
102 os
.utime("/var/lib/apt/lists/%s" % os
.path
.basename(f
), (time
.time(),time
.time()))
103 res
= call([self
.apt
,
105 "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good"
107 stdout
=stdout
, stderr
=stderr
)
108 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"),
109 "The gpg file disappeared, this should not happen")
110 self
.assert_(os
.path
.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"),
111 "The Packages file disappeared, this should not happen")
114 class testAuthentication(unittest
.TestCase
):
116 test if the authentication is working, the repository
117 of the test-data can be found here:
118 bzr get http://people.ubuntu.com/~mvo/bzr/apt/apt-auth-test-suit/
121 # some class wide data
123 pkg
= "libglib2.0-data"
124 pkgver
= "2.13.6-1ubuntu1"
125 pkgpath
= "/var/cache/apt/archives/libglib2.0-data_2.13.6-1ubuntu1_all.deb"
128 for f
in glob
.glob("testkeys/*,key"):
129 call(["apt-key", "add", f
], stdout
=stdout
, stderr
=stderr
)
132 " make sure we get new lists and no i-m-s "
133 call(["rm","-f", "/var/lib/apt/lists/*"])
134 if os
.path
.exists(self
.pkgpath
):
135 os
.unlink(self
.pkgpath
)
137 def _expectedRes(self
, resultstr
):
138 if resultstr
== 'ok':
140 elif resultstr
== 'broken':
144 def testPackages(self
):
145 for f
in glob
.glob("testsources.list/sources.list*package*"):
147 (prefix
, testtype
, result
) = f
.split("-")
148 expected_res
= self
._expectedRes
(result
)
150 call([self
.apt
,"update",
151 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
152 stdout
=stdout
, stderr
=stderr
)
154 cmd
= ["install", "-y", "-d", "--reinstall",
155 "%s=%s" % (self
.pkg
, self
.pkgver
),
156 "-o","Dir::state::Status=./fake-status"]
157 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
158 stdout
=stdout
, stderr
=stderr
)
159 self
.assert_(res
== expected_res
,
160 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
164 for f
in glob
.glob("testsources.list/sources.list*gpg*"):
166 (prefix
, testtype
, result
) = f
.split("-")
167 expected_res
= self
._expectedRes
(result
)
169 call([self
.apt
,"update",
170 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
171 stdout
=stdout
, stderr
=stderr
)
172 cmd
= ["install", "-y", "-d", "--reinstall",
173 "%s=%s" % (self
.pkg
, self
.pkgver
),
174 "-o","Dir::state::Status=./fake-status"]
175 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+
177 stdout
=stdout
, stderr
=stderr
)
178 self
.assert_(res
== expected_res
,
179 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
181 def testRelease(self
):
182 for f
in glob
.glob("testsources.list/sources.list*release*"):
184 (prefix
, testtype
, result
) = f
.split("-")
185 expected_res
= self
._expectedRes
(result
)
187 res
= call([self
.apt
,"-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
188 stdout
=stdout
, stderr
=stderr
)
189 self
.assert_(res
== expected_res
,
190 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
191 if expected_res
== 0:
192 self
.assert_(len(glob
.glob("/var/lib/apt/lists/partial/*")) == 0,
193 "partial/ dir has leftover files: %s" % glob
.glob("/var/lib/apt/lists/partial/*"))
196 class testLocalRepositories(unittest
.TestCase
):
197 " test local repository regressions "
199 repo_dir
= "local-repo"
204 self
.repo
= os
.path
.abspath(os
.path
.join(os
.getcwd(), self
.repo_dir
))
205 self
.sources
= os
.path
.join(self
.repo
, "sources.list")
206 s
= open(self
.sources
,"w")
207 s
.write("deb file://%s/ /\n" % self
.repo
)
210 def testLocalRepoAuth(self
):
211 # two times to get at least one i-m-s hit
213 self
.assert_(os
.path
.exists(self
.sources
))
214 cmd
= [self
.apt
,"update","-o", "Dir::Etc::sourcelist=%s" % self
.sources
]+apt_args
215 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
216 self
.assertEqual(res
, 0, "local repo test failed")
217 self
.assert_(os
.path
.exists(os
.path
.join(self
.repo
,"Packages.gz")),
218 "Packages.gz vanished from local repo")
220 def testInstallFromLocalRepo(self
):
221 apt
= [self
.apt
,"-o", "Dir::Etc::sourcelist=%s"% self
.sources
]+apt_args
223 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
224 self
.assertEqual(res
, 0)
225 res
= call(apt
+["-y","install","--reinstall",self
.pkg
],
226 stdout
=stdout
, stderr
=stderr
)
227 self
.assert_(res
== 0,
228 "installing %s failed (got %s)" % (self
.pkg
, res
))
229 res
= call(apt
+["-y","remove",self
.pkg
],
230 stdout
=stdout
, stderr
=stderr
)
231 self
.assert_(res
== 0,
232 "removing %s failed (got %s)" % (self
.pkg
, res
))
234 def testPythonAptInLocalRepo(self
):
236 apt_pkg
.Config
.Set("Dir::Etc::sourcelist",self
.sources
)
240 self
.assert_(pkg
.name
== 'apt')
244 if __name__
== "__main__":
245 print "Runing simple testsuit on current apt-get and libapt"
246 if len(sys
.argv
) > 1 and sys
.argv
[1] == "-v":
250 # run only one for now
251 #unittest.main(defaultTest="testAptAuthenticationReliability")