1 #!/usr/bin/env python2.4
2 from basetest
import BaseTest
3 import sys
, tempfile
, os
, shutil
6 thomas_fingerprint
= "92429807C9853C0744A68B9AAE07828059A53CC1"
8 sys
.path
.insert(0, '..')
9 from zeroinstall
.injector
import trust
10 from zeroinstall
import SafeException
11 from zeroinstall
.support
import basedir
13 class TestTrust(BaseTest
):
15 trust
.trust_db
.untrust_key(thomas_fingerprint
, domain
= '0install.net') # Gets added by default
16 assert not trust
.trust_db
.is_trusted(thomas_fingerprint
)
17 assert not trust
.trust_db
.is_trusted("1234")
18 assert len(trust
.trust_db
.keys
) == 0
20 def testAddInvalid(self
):
22 trust
.trust_db
.trust_key("hello")
28 assert not trust
.trust_db
.is_trusted("1234")
29 trust
.trust_db
.trust_key("1234")
30 assert trust
.trust_db
.is_trusted("1234")
31 assert not trust
.trust_db
.is_trusted("1236")
33 trust
.trust_db
.untrust_key("1234")
34 assert not trust
.trust_db
.is_trusted("1234")
36 def testAddDomain(self
):
37 assert not trust
.trust_db
.is_trusted("1234", "0install.net")
38 trust
.trust_db
.trust_key("1234")
39 self
.assertEquals(set(['*']), trust
.trust_db
.get_trust_domains("1234"))
40 self
.assertEquals(set(['1234']), trust
.trust_db
.get_keys_for_domain("*"))
41 self
.assertEquals(set(), trust
.trust_db
.get_trust_domains("bob"))
43 assert trust
.trust_db
.is_trusted("1234")
44 assert trust
.trust_db
.is_trusted("1234", "0install.net")
45 assert trust
.trust_db
.is_trusted("1234", "rox.sourceforge.net")
46 assert not trust
.trust_db
.is_trusted("1236")
48 trust
.trust_db
.untrust_key("1234")
49 assert not trust
.trust_db
.is_trusted("1234")
50 assert not trust
.trust_db
.is_trusted("1234", "rox.sourceforge.net")
52 trust
.trust_db
.trust_key("1234", "0install.net")
53 trust
.trust_db
.trust_key("1234", "gimp.org")
54 trust
.trust_db
.trust_key("1236", "gimp.org")
55 assert trust
.trust_db
.is_trusted("1234")
56 assert trust
.trust_db
.is_trusted("1234", "0install.net")
57 assert trust
.trust_db
.is_trusted("1234", "gimp.org")
58 assert not trust
.trust_db
.is_trusted("1234", "rox.sourceforge.net")
60 self
.assertEquals(set(['1234', '1236']),
61 trust
.trust_db
.get_keys_for_domain("gimp.org"))
63 self
.assertEquals(set(), trust
.trust_db
.get_trust_domains("99877"))
64 self
.assertEquals(set(['0install.net', 'gimp.org']), trust
.trust_db
.get_trust_domains("1234"))
66 def testParallel(self
):
70 assert b
.is_trusted("1")
73 assert not a
.is_trusted("1")
74 assert a
.is_trusted("2")
77 self
.assertEquals("example.com", trust
.domain_from_url('http://example.com/foo'))
78 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url('/tmp/feed.xml'))
79 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url('http:///foo'))
80 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url('http://*/foo'))
81 self
.assertRaises(SafeException
, lambda: trust
.domain_from_url(''))
84 suite
= unittest
.makeSuite(TestTrust
)
85 if __name__
== '__main__':