Merge lp:~roadmr/checkbox/1357338-hexr-share into lp:checkbox

Proposed by Daniel Manrique
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 3200
Merged at revision: 3206
Proposed branch: lp:~roadmr/checkbox/1357338-hexr-share
Merge into: lp:checkbox
Diff against target: 88 lines (+51/-0)
2 files modified
checkbox-ng/checkbox_ng/certification.py (+31/-0)
checkbox-ng/checkbox_ng/test_certification.py (+20/-0)
To merge this branch: bzr merge lp:~roadmr/checkbox/1357338-hexr-share
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+231459@code.launchpad.net

Commit message

    checkbox-ng:transports: Set X_SHARE_WITH_HEXR header

    If the option string to the transport contains submit_to_hexr=1,
    then send the X_SHARE_WITH_HEXR http header when uploading.
    (LP: #1357338)

Description of the change

    checkbox-ng:transports: Set X_SHARE_WITH_HEXR header

    If the option string to the transport contains submit_to_hexr=1,
    then send the X_SHARE_WITH_HEXR http header when uploading.
    (LP: #1357338)

the GUI and dbus are propagating the tick mark's setting properly into a transport option; the problem is that the certification transport (part of the plainbox library) wasn't actually translating that option into the HTTP header required for hexr to slurp the submission.

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Just two minor comments, have a look

review: Needs Fixing
3200. By Daniel Manrique

checkbox-ng:transports: Set X_SHARE_WITH_HEXR header

If the option string to the transport contains submit_to_hexr=1,
then send the X_SHARE_WITH_HEXR http header when uploading.
(LP: #1357338)

Revision history for this message
Daniel Manrique (roadmr) wrote :

Resubmitted with requested changes, fun with the exception.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Thanks, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-ng/checkbox_ng/certification.py'
2--- checkbox-ng/checkbox_ng/certification.py 2014-07-29 16:05:54 +0000
3+++ checkbox-ng/checkbox_ng/certification.py 2014-08-20 14:49:26 +0000
4@@ -65,8 +65,22 @@
5
6 The options string may contain 'secure_id' which must be
7 a 15- or 18-character alphanumeric ID for the system.
8+
9+ It may also contain a submit_to_hexr boolean, set to 1
10+ to enable submission to hexr.
11 """
12 super().__init__(where, options)
13+ # Interpret this setting here
14+ submit_to_hexr = self.options.get('submit_to_hexr')
15+ self._submit_to_hexr = False
16+ try:
17+ if submit_to_hexr and (submit_to_hexr.lower() in
18+ ('yes', 'true') or
19+ int(submit_to_hexr) == 1):
20+ self._submit_to_hexr = True
21+ except ValueError:
22+ # Just leave it at False
23+ pass
24 self._secure_id = self.options.get('secure_id')
25 if self._secure_id is not None:
26 self._validate_secure_id(self._secure_id)
27@@ -123,6 +137,23 @@
28 logger.debug(
29 _("Sending to %s, hardware id is %s"), self.url, secure_id)
30 headers = {"X_HARDWARE_ID": secure_id}
31+ # Similar handling for submit_to_hexr
32+ submit_to_hexr = False
33+ if config is not None and hasattr(config, 'submit_to_hexr'):
34+ submit_to_hexr = config.submit_to_hexr
35+ logger.debug(_("submit_to_hexr set to %s by config"),
36+ submit_to_hexr)
37+ if self._submit_to_hexr:
38+ submit_to_hexr = self._submit_to_hexr
39+ logger.debug(_("submit_to_hexr set to %s by UI"), submit_to_hexr)
40+ # We could always set this header since hexr will only process a value
41+ # of 'True', but this avoids injecting that extraneous knowledge into
42+ # the tests.
43+ # Note that hexr will only process a submission with this header's
44+ # value set to 'True', so this boolean conversion should be ok.
45+ if submit_to_hexr:
46+ headers["X-Share-With-HEXR"] = submit_to_hexr
47+
48 # Requests takes care of properly handling a file-like data.
49 form_payload = {"data": data}
50 try:
51
52=== modified file 'checkbox-ng/checkbox_ng/test_certification.py'
53--- checkbox-ng/checkbox_ng/test_certification.py 2014-02-25 16:58:04 +0000
54+++ checkbox-ng/checkbox_ng/test_certification.py 2014-08-20 14:49:26 +0000
55@@ -65,6 +65,11 @@
56 self.assertEqual(self.valid_secure_id,
57 transport.options['secure_id'])
58
59+ def test_submit_to_hexr_interpretation(self):
60+ transport = CertificationTransport(
61+ self.valid_url, "submit_to_hexr=1")
62+ self.assertTrue(transport._submit_to_hexr is True)
63+
64 def test_invalid_length_secure_id_are_rejected(self):
65 for length in (14, 16, 20):
66 dummy_id = "a" * length
67@@ -105,6 +110,21 @@
68 self.valid_secure_id},
69 proxies=None)
70
71+ @mock.patch('checkbox_ng.certification.logger')
72+ def test_share_with_hexr_header_sent(self, mock_logger):
73+ transport = CertificationTransport(
74+ self.valid_url, self.valid_option_string+",submit_to_hexr=1")
75+ dummy_data = BytesIO(b"some data to send")
76+ result = transport.send(dummy_data)
77+ self.assertIsNotNone(result)
78+ requests.post.assert_called_with(self.valid_url,
79+ files={'data': dummy_data},
80+ headers={'X_HARDWARE_ID':
81+ self.valid_secure_id,
82+ 'X-Share-With-HEXR':
83+ True},
84+ proxies=None)
85+
86 def test_send_success(self):
87 transport = CertificationTransport(
88 self.valid_url, self.valid_option_string)

Subscribers

People subscribed via source and target branches