1 #!/usr/bin/env python2.3
2 from basetest
import BaseTest
3 import sys
, tempfile
, os
, shutil
7 thomas_fingerprint
= "92429807C9853C0744A68B9AAE07828059A53CC1"
9 sys
.path
.insert(0, '..')
10 from zeroinstall
.injector
import trust
, basedir
11 from zeroinstall
import SafeException
13 class TestTrust(BaseTest
):
15 assert not trust
.trust_db
.is_trusted(thomas_fingerprint
)
16 assert not trust
.trust_db
.is_trusted("1234")
17 assert len(trust
.trust_db
.keys
) == 0
19 def testAddInvalid(self
):
21 trust
.trust_db
.trust_key("hello")
27 assert not trust
.trust_db
.is_trusted("1234")
28 trust
.trust_db
.trust_key("1234")
29 assert trust
.trust_db
.is_trusted("1234")
30 assert not trust
.trust_db
.is_trusted("1236")
32 trust
.trust_db
.untrust_key("1234")
33 assert not trust
.trust_db
.is_trusted("1234")
35 def testAddDomain(self
):
36 assert not trust
.trust_db
.is_trusted("1234", "0install.net")
37 trust
.trust_db
.trust_key("1234")
38 self
.assertEquals(Set(['*']), trust
.trust_db
.get_trust_domains("1234"))
40 assert trust
.trust_db
.is_trusted("1234")
41 assert trust
.trust_db
.is_trusted("1234", "0install.net")
42 assert trust
.trust_db
.is_trusted("1234", "rox.sourceforge.net")
43 assert not trust
.trust_db
.is_trusted("1236")
45 trust
.trust_db
.untrust_key("1234")
46 assert not trust
.trust_db
.is_trusted("1234")
47 assert not trust
.trust_db
.is_trusted("1234", "rox.sourceforge.net")
49 trust
.trust_db
.trust_key("1234", "0install.net")
50 trust
.trust_db
.trust_key("1234", "gimp.org")
51 assert trust
.trust_db
.is_trusted("1234")
52 assert trust
.trust_db
.is_trusted("1234", "0install.net")
53 assert trust
.trust_db
.is_trusted("1234", "gimp.org")
54 assert not trust
.trust_db
.is_trusted("1234", "rox.sourceforge.net")
56 self
.assertEquals(Set(), trust
.trust_db
.get_trust_domains("99877"))
57 self
.assertEquals(Set(['0install.net', 'gimp.org']), trust
.trust_db
.get_trust_domains("1234"))
59 def testParallel(self
):
63 assert b
.is_trusted("1")
66 assert not a
.is_trusted("1")
67 assert a
.is_trusted("2")
70 self
.assertEquals("example.com", trust
.domain_from_url('http://example.com/foo'))
71 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url('/tmp/feed.xml'))
72 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url('http:///foo'))
73 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url('http://*/foo'))
74 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url(''))
77 suite
= unittest
.makeSuite(TestTrust
)
78 if __name__
== '__main__':