Merge lp:~clint-fewbar/pyjuju/fix-ssl-for-charm-store into lp:pyjuju

Proposed by Clint Byrum
Status: Merged
Approved by: Kapil Thangavelu
Approved revision: 565
Merged at revision: 565
Proposed branch: lp:~clint-fewbar/pyjuju/fix-ssl-for-charm-store
Merge into: lp:pyjuju
Diff against target: 109 lines (+20/-8)
3 files modified
juju/charm/repository.py (+5/-2)
juju/charm/tests/test_repository.py (+10/-4)
juju/control/tests/test_upgrade_charm.py (+5/-2)
To merge this branch: bzr merge lp:~clint-fewbar/pyjuju/fix-ssl-for-charm-store
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+118422@code.launchpad.net

Description of the change

Ensure charm store SSL is authenticated

Use VerifyingContextFactory to ensure charm store interaction is authenticated

https://codereview.appspot.com/6443090/

To post a comment you must log in.
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

lgtm, with these minors

https://codereview.appspot.com/6443090/diff/1/juju/charm/repository.py
File juju/charm/repository.py (right):

https://codereview.appspot.com/6443090/diff/1/juju/charm/repository.py#newcode130
juju/charm/repository.py:130: host = url.split('/')[2]
this would be more robust with
urlparse.urlparse(url).hostname

https://codereview.appspot.com/6443090/diff/1/juju/charm/repository.py#newcode152
juju/charm/repository.py:152: host = url.split('/')[2]
same with this one.

https://codereview.appspot.com/6443090/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/charm/repository.py'
2--- juju/charm/repository.py 2012-05-03 18:42:09 +0000
3+++ juju/charm/repository.py 2012-08-06 20:21:19 +0000
4@@ -8,6 +8,7 @@
5 from twisted.internet.defer import fail, inlineCallbacks, returnValue, succeed
6 from twisted.web.client import downloadPage, getPage
7 from twisted.web.error import Error
8+from txaws.client.ssl import VerifyingContextFactory
9
10 from juju.charm.provider import get_charm_from_path
11 from juju.charm.url import CharmURL
12@@ -126,7 +127,8 @@
13 url = "%s/charm-info?charms=%s" % (
14 self.url_base, urllib.quote(charm_id))
15 try:
16- all_info = json.loads((yield getPage(url)))
17+ host = url.split('/')[2]
18+ all_info = json.loads((yield getPage(url, contextFactory=VerifyingContextFactory(host))))
19 charm_info = all_info[charm_id]
20 for warning in charm_info.get("warnings", []):
21 log.warning("%s: %s", charm_id, warning)
22@@ -147,8 +149,9 @@
23 delete=False)
24 f.close()
25 downloading_path = f.name
26+ host = url.split('/')[2]
27 try:
28- yield downloadPage(url, downloading_path)
29+ yield downloadPage(url, downloading_path, contextFactory=VerifyingContextFactory(host))
30 except Error:
31 raise CharmNotFound(self.url_base, charm_url)
32 os.rename(downloading_path, cache_path)
33
34=== modified file 'juju/charm/tests/test_repository.py'
35--- juju/charm/tests/test_repository.py 2012-07-01 22:20:22 +0000
36+++ juju/charm/tests/test_repository.py 2012-08-06 20:21:19 +0000
37@@ -5,6 +5,8 @@
38
39 from twisted.internet.defer import fail, inlineCallbacks, succeed
40 from twisted.web.error import Error
41+from txaws.client.ssl import VerifyingContextFactory
42+
43
44 from juju.charm.directory import CharmDirectory
45 from juju.charm.errors import CharmNotFound, CharmURLError, RepositoryNotFound
46@@ -16,7 +18,7 @@
47 from juju.lib import under
48
49 from juju.charm import tests
50-from juju.lib.mocker import ANY
51+from juju.lib.mocker import ANY, MATCH
52 from juju.lib.testing import TestCase
53
54
55@@ -280,15 +282,19 @@
56 return json.dumps({url_str: info})
57
58 def mock_charm_info(self, url, result):
59- self.getPage(url)
60+ def match_context(value):
61+ return isinstance(value, VerifyingContextFactory)
62+ self.getPage(url, contextFactory=MATCH(match_context))
63 self.mocker.result(result)
64
65 def mock_download(self, url, error=None):
66- self.downloadPage(url, ANY)
67+ def match_context(value):
68+ return isinstance(value, VerifyingContextFactory)
69+ self.downloadPage(url, ANY, contextFactory=MATCH(match_context))
70 if error:
71 return self.mocker.result(fail(error))
72
73- def download(_, path):
74+ def download(_, path, contextFactory):
75 self.assertTrue(path.startswith(self.download_path))
76 with open(path, "wb") as f:
77 f.write(self.bundle_data)
78
79=== modified file 'juju/control/tests/test_upgrade_charm.py'
80--- juju/control/tests/test_upgrade_charm.py 2012-05-04 22:43:40 +0000
81+++ juju/control/tests/test_upgrade_charm.py 2012-08-06 20:21:19 +0000
82@@ -12,6 +12,7 @@
83 from juju.errors import FileNotFound
84 from juju.environment.environment import Environment
85 from juju.unit.workflow import UnitWorkflowState
86+from juju.lib.mocker import ANY
87
88 from .common import MachineControlToolTest
89
90@@ -481,7 +482,8 @@
91 self.setup_exit(0)
92 getPage = self.mocker.replace("twisted.web.client.getPage")
93 getPage(
94- CS_STORE_URL + "/charm-info?charms=cs%3Aseries/mysql")
95+ CS_STORE_URL + "/charm-info?charms=cs%3Aseries/mysql",
96+ contextFactory=ANY)
97 self.mocker.result(succeed(json.dumps(
98 {"cs:series/mysql": {"revision": 1, "sha256": "whatever"}})))
99 self.mocker.replay()
100@@ -502,7 +504,8 @@
101 self.setup_exit(0)
102
103 getPage = self.mocker.replace("twisted.web.client.getPage")
104- getPage(CS_STORE_URL + "/charm-info?charms=cs%3Aseries/mysql")
105+ getPage(CS_STORE_URL + "/charm-info?charms=cs%3Aseries/mysql",
106+ contextFactory=ANY)
107
108 self.mocker.result(succeed(json.dumps(
109 {"cs:series/mysql": {"revision": 1, "sha256": "whatever"}})))

Subscribers

People subscribed via source and target branches

to status/vote changes: