~ursinha/launchpad/add-all-fl-tests

« back to all changes in this revision

Viewing changes to lib/canonical/launchpad/doc/hwdb-access.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2009-08-20 12:36:07 UTC
  • mfrom: (9094.2.2 hwdb-device-class-api)
  • Revision ID: launchpad@pqm.canonical.com-20090820123607-w7k7ahwkclxlonh8
[r=cprov][ui=none] allow arbitrary int values for
        HWDeviceClass.main_class and HWDeviceClass.sub_class;
        expose HWDeviceClass to the webservice

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
    >>> sample_person.inTeam(hwdb_team)
14
14
    True
15
15
 
 
16
    >>> from zope.security.interfaces import Unauthorized
 
17
    >>> def check_authorized_for(obj, attribute, person_name_or_address):
 
18
    ...     login(person_name_or_address)
 
19
    ...     has_access = True
 
20
    ...     try:
 
21
    ...         getattr(obj, attribute)
 
22
    ...     except Unauthorized:
 
23
    ...         has_access = False
 
24
    ...         print "Access for %s denied" % person_name_or_address
 
25
    ...     if has_access:
 
26
    ...         print "Access for %s allowed" % person_name_or_address
 
27
    ...     logout()
 
28
 
 
29
    >>> def check_authorized_only_for_hwdb_team(obj, attribute):
 
30
    ...     check_authorized_for(obj, attribute, ANONYMOUS)
 
31
    ...     check_authorized_for(obj, attribute, 'no-priv@canonical.com')
 
32
    ...     check_authorized_for(obj, attribute, 'test@canonical.com')
16
33
 
17
34
HWDriver
18
35
--------
19
36
 
20
37
    >>> from canonical.launchpad.interfaces.hwdb import IHWDriverSet
21
 
    >>> login(ANONYMOUS)
22
 
    >>> for driver in getUtility(IHWDriverSet).search(name='sd'):
23
 
    ...     print driver.name
24
 
    Traceback (most recent call last):
25
 
    ...
26
 
    Unauthorized...
27
 
 
28
 
    >>> logout()
29
 
    >>> login('no-priv@canonical.com')
30
 
    >>> for driver in getUtility(IHWDriverSet).search(name='sd'):
31
 
    ...     print driver.name
32
 
    Traceback (most recent call last):
33
 
    ...
34
 
    Unauthorized...
35
 
 
36
 
    >>> logout()
37
38
    >>> login('test@canonical.com')
38
 
    >>> for driver in getUtility(IHWDriverSet).search(name='sd'):
39
 
    ...     print driver.name
40
 
    sd
 
39
    >>> driver = getUtility(IHWDriverSet).search(name='sd')[0]
 
40
    >>> logout()
 
41
    >>> check_authorized_only_for_hwdb_team(driver, 'name')
 
42
    Access for launchpad.anonymous denied
 
43
    Access for no-priv@canonical.com denied
 
44
    Access for test@canonical.com allowed
41
45
 
42
46
 
43
47
HWDriverName
44
48
------------
45
49
 
46
 
    >>> logout()
47
 
    >>> login(ANONYMOUS)
48
 
    >>> for name in getUtility(IHWDriverSet).all_driver_names():
49
 
    ...     print name.name
50
 
    Traceback (most recent call last):
51
 
    ...
52
 
    Unauthorized...
53
 
 
54
 
    >>> logout()
55
 
    >>> login('no-priv@canonical.com')
56
 
    >>> for name in getUtility(IHWDriverSet).all_driver_names():
57
 
    ...     print name.name
58
 
    Traceback (most recent call last):
59
 
    ...
60
 
    Unauthorized...
61
 
 
62
 
    >>> logout()
63
50
    >>> login('test@canonical.com')
64
 
    >>> for name in getUtility(IHWDriverSet).all_driver_names():
65
 
    ...     print name.name
66
 
    ahci
67
 
    ehci_hcd
68
 
    ...
 
51
    >>> driver_name = getUtility(IHWDriverSet).all_driver_names()[0]
 
52
    >>> logout()
 
53
    >>> check_authorized_only_for_hwdb_team(driver_name, 'name')
 
54
    Access for launchpad.anonymous denied
 
55
    Access for no-priv@canonical.com denied
 
56
    Access for test@canonical.com allowed
69
57
 
70
58
 
71
59
HWDriverPackageName
72
60
-------------------
73
61
 
74
 
    >>> logout()
75
 
    >>> login(ANONYMOUS)
76
 
    >>> for name in getUtility(IHWDriverSet).all_package_names():
77
 
    ...     print name.package_name
78
 
    Traceback (most recent call last):
79
 
    ...
80
 
    Unauthorized...
81
 
 
82
 
    >>> logout()
83
 
    >>> login('no-priv@canonical.com')
84
 
    >>> for name in getUtility(IHWDriverSet).all_package_names():
85
 
    ...     print name.package_name
86
 
    Traceback (most recent call last):
87
 
    ...
88
 
    Unauthorized...
89
 
 
90
 
    >>> logout()
91
62
    >>> login('test@canonical.com')
92
 
    >>> for name in getUtility(IHWDriverSet).all_package_names():
93
 
    ...     print name.package_name
94
 
    linux-image-2.6.24-19-generic
 
63
    >>> package_name = getUtility(IHWDriverSet).all_package_names()[0]
 
64
    >>> logout()
 
65
    >>> check_authorized_only_for_hwdb_team(package_name, 'package_name')
 
66
    Access for launchpad.anonymous denied
 
67
    Access for no-priv@canonical.com denied
 
68
    Access for test@canonical.com allowed
95
69
 
96
70
 
97
71
HWVendorID
98
72
----------
99
73
 
100
74
    >>> from canonical.launchpad.interfaces.hwdb import HWBus, IHWVendorIDSet
101
 
    >>> logout()
102
 
    >>> login(ANONYMOUS)
103
 
    >>> print getUtility(IHWVendorIDSet).getByBusAndVendorID(
104
 
    ...     HWBus.PCI, '0x10de').bus.title
105
 
    Traceback (most recent call last):
106
 
    ...
107
 
    Unauthorized...
108
 
 
109
 
    >>> logout()
110
 
    >>> login('no-priv@canonical.com')
111
 
    >>> print getUtility(IHWVendorIDSet).getByBusAndVendorID(
112
 
    ...     HWBus.PCI, '0x10de').bus.title
113
 
    Traceback (most recent call last):
114
 
    ...
115
 
    Unauthorized...
116
 
 
117
 
    >>> logout()
118
75
    >>> login('test@canonical.com')
119
 
    >>> print getUtility(IHWVendorIDSet).getByBusAndVendorID(
120
 
    ...     HWBus.PCI, '0x10de').bus.title
121
 
    PCI
 
76
    >>> vendor_id = getUtility(IHWVendorIDSet).getByBusAndVendorID(
 
77
    ...     HWBus.PCI, '0x10de')
 
78
    >>> logout()
 
79
    >>> check_authorized_only_for_hwdb_team(vendor_id, 'bus')
 
80
    Access for launchpad.anonymous denied
 
81
    Access for no-priv@canonical.com denied
 
82
    Access for test@canonical.com allowed
122
83
 
123
84
 
124
85
HWDevice
125
86
--------
126
87
 
127
88
    >>> from canonical.launchpad.interfaces.hwdb import IHWDeviceSet
128
 
    >>> logout()
129
 
    >>> login(ANONYMOUS)
130
 
    >>> print getUtility(IHWDeviceSet).getByDeviceID(
131
 
    ...     HWBus.PCI, '0x10de', '0x0455').name
132
 
    Traceback (most recent call last):
133
 
    ...
134
 
    Unauthorized...
135
 
 
136
 
    >>> logout()
137
 
    >>> login('no-priv@canonical.com')
138
 
    >>> print getUtility(IHWDeviceSet).getByDeviceID(
139
 
    ...     HWBus.PCI, '0x10de', '0x0455').name
140
 
    Traceback (most recent call last):
141
 
    ...
142
 
    Unauthorized...
143
 
 
144
 
    >>> logout()
145
 
    >>> login('test@canonical.com')
146
 
    >>> print getUtility(IHWDeviceSet).getByDeviceID(
147
 
    ...     HWBus.PCI, '0x10de', '0x0455').name
148
 
    MCP65 USB Controller
 
89
    >>> login('test@canonical.com')
 
90
    >>> device = getUtility(IHWDeviceSet).getByDeviceID(
 
91
    ...     HWBus.PCI, '0x10de', '0x0455')
 
92
    >>> logout()
 
93
    >>> check_authorized_only_for_hwdb_team(device, 'name')
 
94
    Access for launchpad.anonymous denied
 
95
    Access for no-priv@canonical.com denied
 
96
    Access for test@canonical.com allowed
 
97
 
 
98
 
 
99
HWDeviceClass
 
100
-------------
 
101
 
 
102
The access to most HWDB tables is restricted to members of the team
 
103
"canonical". the current user, Sample Person, is a member of this team,
 
104
No-Priv is not (see above).
 
105
 
 
106
    >>> login('test@canonical.com')
 
107
    >>> device_class = device.getOrCreateDeviceClass(12, 3)
 
108
    >>> logout()
 
109
    >>> check_authorized_only_for_hwdb_team(device_class, 'main_class')
 
110
    Access for launchpad.anonymous denied
 
111
    Access for no-priv@canonical.com denied
 
112
    Access for test@canonical.com allowed
149
113
 
150
114
 
151
115
HWSubmissionDevice
152
116
------------------
153
117
 
154
118
    >>> from canonical.launchpad.interfaces.hwdb import IHWSubmissionDeviceSet
155
 
    >>> logout()
156
 
    >>> login(ANONYMOUS)
157
 
    >>> print getUtility(IHWSubmissionDeviceSet).get(1).hal_device_id
158
 
    Traceback (most recent call last):
159
 
    ...
160
 
    Unauthorized...
161
 
 
162
 
    >>> logout()
163
 
    >>> login('no-priv@canonical.com')
164
 
    >>> print getUtility(IHWSubmissionDeviceSet).get(1).hal_device_id
165
 
    Traceback (most recent call last):
166
 
    ...
167
 
    Unauthorized...
168
 
 
169
 
    >>> logout()
170
119
    >>> login('test@canonical.com')
171
 
    >>> print getUtility(IHWSubmissionDeviceSet).get(1).hal_device_id
172
 
    11
 
120
    >>> submission_device = getUtility(IHWSubmissionDeviceSet).get(1)
 
121
    >>> logout()
 
122
    >>> check_authorized_only_for_hwdb_team(
 
123
    ...     submission_device, 'hal_device_id')
 
124
    Access for launchpad.anonymous denied
 
125
    Access for no-priv@canonical.com denied
 
126
    Access for test@canonical.com allowed
173
127
 
174
128
 
175
129
Methods of IHWDBApplication
177
131
 
178
132
    >>> from canonical.launchpad.interfaces.hwdb import IHWDBApplication
179
133
    >>> app = getUtility(IHWDBApplication)
180
 
    >>> logout()
181
 
    >>> login(ANONYMOUS)
182
 
    >>> print app.numOwnersOfDevice(
183
 
    ...     bus=HWBus.PCI, vendor_id='0x10de', product_id='0x0455')
184
 
    Traceback (most recent call last):
185
 
    ...
186
 
    Unauthorized...
187
 
 
188
 
    >>> logout()
189
 
    >>> login('no-priv@canonical.com')
190
 
    >>> print app.numOwnersOfDevice(
191
 
    ...     bus=HWBus.PCI, vendor_id='0x10de', product_id='0x0455')
192
 
    Traceback (most recent call last):
193
 
    ...
194
 
    Unauthorized...
195
 
 
196
 
    >>> logout()
197
 
    >>> login('test@canonical.com')
198
 
    >>> print app.numOwnersOfDevice(
199
 
    ...     bus=HWBus.PCI, vendor_id='0x10de', product_id='0x0455')
200
 
    {...}
 
134
    >>> check_authorized_only_for_hwdb_team(app, 'numOwnersOfDevice')
 
135
    Access for launchpad.anonymous denied
 
136
    Access for no-priv@canonical.com denied
 
137
    Access for test@canonical.com allowed