9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
1 |
= Archive dependencies = |
2 |
||
3 |
`ArchiveDependency` records represent build-dependencies between |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
4 |
archives, and are exposed through the API. |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
5 |
|
6 |
Most of the tests live in |
|
7 |
lib/lp/soyuz/stories/webservice/xx-archive.txt. |
|
8 |
||
9 |
Firstly we need to set some things up: we need a PPA with a dependency. |
|
10 |
We'll use Celso's PPA, and give it a custom dependency on the primary |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
11 |
archive, and then create a private PPA for Celso with a similar custom |
12 |
dependency. |
|
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
13 |
|
14 |
>>> import simplejson |
|
15 |
>>> from zope.component import getUtility |
|
16 |
>>> from lp.registry.interfaces.person import IPersonSet |
|
11716.1.12
by Curtis Hovey
Sorted imports in doctests. |
17 |
>>> from lp.registry.interfaces.pocket import PackagePublishingPocket |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
18 |
>>> from lp.soyuz.interfaces.component import IComponentSet |
19 |
>>> login('foo.bar@canonical.com') |
|
20 |
>>> cprov_db = getUtility(IPersonSet).getByName('cprov') |
|
21 |
>>> cprov_ppa_db = cprov_db.archive |
|
22 |
>>> dep = cprov_ppa_db.addArchiveDependency( |
|
23 |
... cprov_ppa_db.distribution.main_archive, |
|
24 |
... PackagePublishingPocket.RELEASE, |
|
25 |
... component=getUtility(IComponentSet)['universe']) |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
26 |
>>> cprov_private_ppa_db = factory.makeArchive( |
27 |
... private=True, owner=cprov_db, name="p3a", |
|
28 |
... distribution=cprov_ppa_db.distribution, |
|
29 |
... description="packages to help my friends.") |
|
30 |
>>> dep = cprov_private_ppa_db.addArchiveDependency( |
|
31 |
... cprov_ppa_db.distribution.main_archive, |
|
32 |
... PackagePublishingPocket.RELEASE, |
|
33 |
... component=getUtility(IComponentSet)['universe']) |
|
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
34 |
>>> logout() |
35 |
||
36 |
Any user can retrieve a public PPA's dependencies. |
|
37 |
||
38 |
>>> print user_webservice.get( |
|
39 |
... '/~cprov/+archive/ppa/dependencies') |
|
40 |
HTTP/1.1 200 Ok |
|
41 |
... |
|
42 |
||
43 |
>>> print user_webservice.get( |
|
44 |
... '/~cprov/+archive/ppa/+dependency/1') |
|
45 |
HTTP/1.1 200 Ok |
|
46 |
... |
|
47 |
||
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
48 |
The dependencies of a private archive are private. Unprivileged users |
49 |
can't get a list of the dependencies. |
|
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
50 |
|
51 |
>>> print user_webservice.get( |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
52 |
... '/~cprov/+archive/p3a/dependencies') |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
53 |
HTTP/1.1 401 Unauthorized |
54 |
... |
|
12361.1.7
by Tim Penhey
Fix the traceback removal on the webservice tests. |
55 |
(<Archive at ...>, 'dependencies', 'launchpad.View') |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
56 |
|
57 |
Nor can said user craft a URL to a dependency. |
|
58 |
||
59 |
>>> print user_webservice.get( |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
60 |
... '/~cprov/+archive/p3a/+dependency/1') |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
61 |
HTTP/1.1 401 Unauthorized |
62 |
... |
|
12361.1.7
by Tim Penhey
Fix the traceback removal on the webservice tests. |
63 |
(<Archive at ...>, 'getArchiveDependency', 'launchpad.View') |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
64 |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
65 |
Celso can see them if we grant private permissions, of course. |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
66 |
|
67 |
>>> from canonical.launchpad.testing.pages import webservice_for_person |
|
68 |
>>> from canonical.launchpad.webapp.interfaces import OAuthPermission |
|
69 |
>>> cprov_webservice = webservice_for_person( |
|
70 |
... cprov_db, permission=OAuthPermission.WRITE_PRIVATE) |
|
71 |
>>> print cprov_webservice.get( |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
72 |
... '/~cprov/+archive/p3a/dependencies') |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
73 |
HTTP/1.1 200 Ok |
74 |
... |
|
75 |
>>> print cprov_webservice.get( |
|
10316.1.51
by Michael Nelson
Fixed xx-archivedependency.txt |
76 |
... '/~cprov/+archive/p3a/+dependency/1') |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
77 |
HTTP/1.1 200 Ok |
78 |
... |
|
79 |
||
80 |
But even he can't write to a dependency. |
|
81 |
||
9105.3.1
by Brad Crittenden
Changed sample data to remove sabdfl. |
82 |
>>> mark_ppa = cprov_webservice.get( |
83 |
... '/~mark/+archive/ppa').jsonBody() |
|
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
84 |
>>> print cprov_webservice.patch( |
85 |
... '/~cprov/+archive/ppa/+dependency/1', 'application/json', |
|
9105.3.1
by Brad Crittenden
Changed sample data to remove sabdfl. |
86 |
... simplejson.dumps({'archive_link': mark_ppa['self_link']})) |
9032.3.22
by William Grant
Make all attributes of IArchiveDependency readonly. |
87 |
HTTP/1.1 400 Bad Request |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
88 |
... |
9032.3.22
by William Grant
Make all attributes of IArchiveDependency readonly. |
89 |
archive_link: You tried to modify a read-only attribute. |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
90 |
<BLANKLINE> |
91 |
||
92 |
>>> print cprov_webservice.patch( |
|
93 |
... '/~cprov/+archive/ppa/+dependency/1', 'application/json', |
|
9105.3.1
by Brad Crittenden
Changed sample data to remove sabdfl. |
94 |
... simplejson.dumps({'dependency_link': mark_ppa['self_link']})) |
9032.3.22
by William Grant
Make all attributes of IArchiveDependency readonly. |
95 |
HTTP/1.1 400 Bad Request |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
96 |
... |
9032.3.22
by William Grant
Make all attributes of IArchiveDependency readonly. |
97 |
dependency_link: You tried to modify a read-only attribute. |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
98 |
<BLANKLINE> |
99 |
||
100 |
>>> print cprov_webservice.patch( |
|
101 |
... '/~cprov/+archive/ppa/+dependency/1', 'application/json', |
|
102 |
... simplejson.dumps({'pocket': 'Security'})) |
|
9032.3.22
by William Grant
Make all attributes of IArchiveDependency readonly. |
103 |
HTTP/1.1 400 Bad Request |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
104 |
... |
9032.3.22
by William Grant
Make all attributes of IArchiveDependency readonly. |
105 |
pocket: You tried to modify a read-only attribute. |
9032.3.21
by William Grant
Move the ArchiveDependency webservice security tests out. |
106 |
<BLANKLINE> |