Merge lp:~allenap/maas/no-string-in-mime into lp:maas/trunk

Proposed by Gavin Panella on 2012-09-25
Status: Merged
Approved by: Gavin Panella on 2012-09-25
Approved revision: 1073
Merged at revision: 1072
Proposed branch: lp:~allenap/maas/no-string-in-mime
Merge into: lp:maas/trunk
Diff against target: 30 lines (+12/-1)
1 file modified
src/provisioningserver/tests/test_start_cluster_controller.py (+12/-1)
To merge this branch: bzr merge lp:~allenap/maas/no-string-in-mime
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) 2012-09-25 Approve on 2012-09-25
Review via email: mp+126248@code.launchpad.net

Commit Message

Check the body being dispatched by parsing it with Django's multipart parser.

Previously the check was along the lines of "needle in multipart/form-data haystack", but now the haystack is mostly base64 encoded this does not work.

To post a comment you must log in.
Jeroen T. Vermeulen (jtv) wrote :

Thanks! One tiny thing: the comment conveys your frustration very nicely, but the technical details may puzzle some readers. A few more words about what goes on perhaps?

review: Approve
lp:~allenap/maas/no-string-in-mime updated on 2012-09-25
1073. By Gavin Panella on 2012-09-25

Expand on why Django is annoying.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/tests/test_start_cluster_controller.py'
2--- src/provisioningserver/tests/test_start_cluster_controller.py 2012-09-25 10:42:00 +0000
3+++ src/provisioningserver/tests/test_start_cluster_controller.py 2012-09-25 14:19:20 +0000
4@@ -23,6 +23,8 @@
5 )
6
7 from apiclient.maas_client import MAASDispatcher
8+from apiclient.testing.django import parse_headers_and_body_with_django
9+from fixtures import EnvironmentVariableFixture
10 from maastesting.factory import factory
11 from provisioningserver import start_cluster_controller
12 from provisioningserver.testing.testcase import PservTestCase
13@@ -162,7 +164,16 @@
14 (args, kwargs) = MAASDispatcher.dispatch_query.call_args
15 self.assertEqual(url + 'api/1.0/nodegroups', args[0])
16 self.assertEqual('POST', kwargs['method'])
17- self.assertIn('refresh_workers', kwargs['data'])
18+
19+ # Make Django STFU; just using Django's multipart code causes it to
20+ # pull in a settings module, and it will throw up if it can't.
21+ self.useFixture(
22+ EnvironmentVariableFixture(
23+ "DJANGO_SETTINGS_MODULE", __name__))
24+
25+ headers, body = kwargs["headers"], kwargs["data"]
26+ post, files = parse_headers_and_body_with_django(headers, body)
27+ self.assertEqual("refresh_workers", post["op"])
28
29 def test_start_up_ignores_failure_on_refresh_secrets(self):
30 self.patch(start_cluster_controller, 'Popen')