File: test_password_manager.special_doctest

package info (click to toggle)
python-mechanize 1%3A0.4.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,224 kB
  • sloc: python: 16,718; makefile: 23
file content (148 lines) | stat: -rw-r--r-- 4,539 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
Features common to HTTPPasswordMgr and HTTPProxyPasswordMgr
===========================================================

(mgr_class gets here through globs argument)

>>> mgr = mgr_class()
>>> add = mgr.add_password

>>> add("Some Realm", "http://example.com/", "joe", "password")
>>> add("Some Realm", "http://example.com/ni", "ni", "ni")
>>> add("c", "http://example.com/foo", "foo", "ni")
>>> add("c", "http://example.com/bar", "bar", "nini")
>>> add("b", "http://example.com/", "first", "blah")
>>> add("b", "http://example.com/", "second", "spam")
>>> add("a", "http://example.com", "1", "a")
>>> add("Some Realm", "http://c.example.com:3128", "3", "c")
>>> add("Some Realm", "d.example.com", "4", "d")
>>> add("Some Realm", "e.example.com:3128", "5", "e")

>>> mgr.find_user_password("Some Realm", "example.com")
('joe', 'password')
>>> mgr.find_user_password("Some Realm", "http://example.com")
('joe', 'password')
>>> mgr.find_user_password("Some Realm", "http://example.com/")
('joe', 'password')
>>> mgr.find_user_password("Some Realm", "http://example.com/spam")
('joe', 'password')
>>> mgr.find_user_password("Some Realm", "http://example.com/spam/spam")
('joe', 'password')
>>> mgr.find_user_password("c", "http://example.com/foo")
('foo', 'ni')
>>> mgr.find_user_password("c", "http://example.com/bar")
('bar', 'nini')

Actually, this is really undefined ATM
#Currently, we use the highest-level path where more than one match:
#
#>>> mgr.find_user_password("Some Realm", "http://example.com/ni")
#('joe', 'password')

Use latest add_password() in case of conflict:

>>> mgr.find_user_password("b", "http://example.com/")
('second', 'spam')

No special relationship between a.example.com and example.com:

>>> mgr.find_user_password("a", "http://example.com/")
('1', 'a')
>>> mgr.find_user_password("a", "http://a.example.com/")
(None, None)

Ports:

>>> mgr.find_user_password("Some Realm", "c.example.com")
(None, None)
>>> mgr.find_user_password("Some Realm", "c.example.com:3128")
('3', 'c')
>>> mgr.find_user_password("Some Realm", "http://c.example.com:3128")
('3', 'c')
>>> mgr.find_user_password("Some Realm", "d.example.com")
('4', 'd')
>>> mgr.find_user_password("Some Realm", "e.example.com:3128")
('5', 'e')


Default port tests
------------------

>>> mgr = mgr_class()
>>> add = mgr.add_password

The point to note here is that we can't guess the default port if there's
no scheme.  This applies to both add_password and find_user_password.

>>> add("f", "http://g.example.com:80", "10", "j")
>>> add("g", "http://h.example.com", "11", "k")
>>> add("h", "i.example.com:80", "12", "l")
>>> add("i", "j.example.com", "13", "m")
>>> mgr.find_user_password("f", "g.example.com:100")
(None, None)
>>> mgr.find_user_password("f", "g.example.com:80")
('10', 'j')
>>> mgr.find_user_password("f", "g.example.com")
(None, None)
>>> mgr.find_user_password("f", "http://g.example.com:100")
(None, None)
>>> mgr.find_user_password("f", "http://g.example.com:80")
('10', 'j')
>>> mgr.find_user_password("f", "http://g.example.com")
('10', 'j')
>>> mgr.find_user_password("g", "h.example.com")
('11', 'k')
>>> mgr.find_user_password("g", "h.example.com:80")
('11', 'k')
>>> mgr.find_user_password("g", "http://h.example.com:80")
('11', 'k')
>>> mgr.find_user_password("h", "i.example.com")
(None, None)
>>> mgr.find_user_password("h", "i.example.com:80")
('12', 'l')
>>> mgr.find_user_password("h", "http://i.example.com:80")
('12', 'l')
>>> mgr.find_user_password("i", "j.example.com")
('13', 'm')
>>> mgr.find_user_password("i", "j.example.com:80")
(None, None)
>>> mgr.find_user_password("i", "http://j.example.com")
('13', 'm')
>>> mgr.find_user_password("i", "http://j.example.com:80")
(None, None)


Features specific to HTTPProxyPasswordMgr
=========================================

Default realm:

>>> mgr = mechanize.HTTPProxyPasswordMgr()
>>> add = mgr.add_password

>>> mgr.find_user_password("d", "f.example.com")
(None, None)
>>> add(None, "f.example.com", "6", "f")
>>> mgr.find_user_password("d", "f.example.com")
('6', 'f')

Default host/port:

>>> mgr.find_user_password("e", "g.example.com")
(None, None)
>>> add("e", None, "7", "g")
>>> mgr.find_user_password("e", "g.example.com")
('7', 'g')

Default realm and host/port:

>>> mgr.find_user_password("f", "h.example.com")
(None, None)
>>> add(None, None, "8", "h")
>>> mgr.find_user_password("f", "h.example.com")
('8', 'h')

Default realm beats default host/port:

>>> add("d", None, "9", "i")
>>> mgr.find_user_password("d", "f.example.com")
('6', 'f')