Debian Codegraph @

test/test_password_manager.special_doctest

raw
1 Features common to HTTPPasswordMgr and HTTPProxyPasswordMgr
2 ===========================================================
3
4 (mgr_class gets here through globs argument)
5
6 >>> mgr = mgr_class()
7 >>> add = mgr.add_password
8
9 >>> add("Some Realm", "http://example.com/", "joe", "password")
10 >>> add("Some Realm", "http://example.com/ni", "ni", "ni")
11 >>> add("c", "http://example.com/foo", "foo", "ni")
12 >>> add("c", "http://example.com/bar", "bar", "nini")
13 >>> add("b", "http://example.com/", "first", "blah")
14 >>> add("b", "http://example.com/", "second", "spam")
15 >>> add("a", "http://example.com", "1", "a")
16 >>> add("Some Realm", "http://c.example.com:3128", "3", "c")
17 >>> add("Some Realm", "d.example.com", "4", "d")
18 >>> add("Some Realm", "e.example.com:3128", "5", "e")
19
20 >>> mgr.find_user_password("Some Realm", "example.com")
21 ('joe', 'password')
22 >>> mgr.find_user_password("Some Realm", "http://example.com")
23 ('joe', 'password')
24 >>> mgr.find_user_password("Some Realm", "http://example.com/")
25 ('joe', 'password')
26 >>> mgr.find_user_password("Some Realm", "http://example.com/spam")
27 ('joe', 'password')
28 >>> mgr.find_user_password("Some Realm", "http://example.com/spam/spam")
29 ('joe', 'password')
30 >>> mgr.find_user_password("c", "http://example.com/foo")
31 ('foo', 'ni')
32 >>> mgr.find_user_password("c", "http://example.com/bar")
33 ('bar', 'nini')
34
35 Actually, this is really undefined ATM
36 #Currently, we use the highest-level path where more than one match:
37 #
38 #>>> mgr.find_user_password("Some Realm", "http://example.com/ni")
39 #('joe', 'password')
40
41 Use latest add_password() in case of conflict:
42
43 >>> mgr.find_user_password("b", "http://example.com/")
44 ('second', 'spam')
45
46 No special relationship between a.example.com and example.com:
47
48 >>> mgr.find_user_password("a", "http://example.com/")
49 ('1', 'a')
50 >>> mgr.find_user_password("a", "http://a.example.com/")
51 (None, None)
52
53 Ports:
54
55 >>> mgr.find_user_password("Some Realm", "c.example.com")
56 (None, None)
57 >>> mgr.find_user_password("Some Realm", "c.example.com:3128")
58 ('3', 'c')
59 >>> mgr.find_user_password("Some Realm", "http://c.example.com:3128")
60 ('3', 'c')
61 >>> mgr.find_user_password("Some Realm", "d.example.com")
62 ('4', 'd')
63 >>> mgr.find_user_password("Some Realm", "e.example.com:3128")
64 ('5', 'e')
65
66
67 Default port tests
68 ------------------
69
70 >>> mgr = mgr_class()
71 >>> add = mgr.add_password
72
73 The point to note here is that we can't guess the default port if there's
74 no scheme. This applies to both add_password and find_user_password.
75
76 >>> add("f", "http://g.example.com:80", "10", "j")
77 >>> add("g", "http://h.example.com", "11", "k")
78 >>> add("h", "i.example.com:80", "12", "l")
79 >>> add("i", "j.example.com", "13", "m")
80 >>> mgr.find_user_password("f", "g.example.com:100")
81 (None, None)
82 >>> mgr.find_user_password("f", "g.example.com:80")
83 ('10', 'j')
84 >>> mgr.find_user_password("f", "g.example.com")
85 (None, None)
86 >>> mgr.find_user_password("f", "http://g.example.com:100")
87 (None, None)
88 >>> mgr.find_user_password("f", "http://g.example.com:80")
89 ('10', 'j')
90 >>> mgr.find_user_password("f", "http://g.example.com")
91 ('10', 'j')
92 >>> mgr.find_user_password("g", "h.example.com")
93 ('11', 'k')
94 >>> mgr.find_user_password("g", "h.example.com:80")
95 ('11', 'k')
96 >>> mgr.find_user_password("g", "http://h.example.com:80")
97 ('11', 'k')
98 >>> mgr.find_user_password("h", "i.example.com")
99 (None, None)
100 >>> mgr.find_user_password("h", "i.example.com:80")
101 ('12', 'l')
102 >>> mgr.find_user_password("h", "http://i.example.com:80")
103 ('12', 'l')
104 >>> mgr.find_user_password("i", "j.example.com")
105 ('13', 'm')
106 >>> mgr.find_user_password("i", "j.example.com:80")
107 (None, None)
108 >>> mgr.find_user_password("i", "http://j.example.com")
109 ('13', 'm')
110 >>> mgr.find_user_password("i", "http://j.example.com:80")
111 (None, None)
112
113
114 Features specific to HTTPProxyPasswordMgr
115 =========================================
116
117 Default realm:
118
119 >>> mgr = mechanize.HTTPProxyPasswordMgr()
120 >>> add = mgr.add_password
121
122 >>> mgr.find_user_password("d", "f.example.com")
123 (None, None)
124 >>> add(None, "f.example.com", "6", "f")
125 >>> mgr.find_user_password("d", "f.example.com")
126 ('6', 'f')
127
128 Default host/port:
129
130 >>> mgr.find_user_password("e", "g.example.com")
131 (None, None)
132 >>> add("e", None, "7", "g")
133 >>> mgr.find_user_password("e", "g.example.com")
134 ('7', 'g')
135
136 Default realm and host/port:
137
138 >>> mgr.find_user_password("f", "h.example.com")
139 (None, None)
140 >>> add(None, None, "8", "h")
141 >>> mgr.find_user_password("f", "h.example.com")
142 ('8', 'h')
143
144 Default realm beats default host/port:
145
146 >>> add("d", None, "9", "i")
147 >>> mgr.find_user_password("d", "f.example.com")
148 ('6', 'f')