Merge lp:~stevenk/launchpad/deal-with-badly-formed-section into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 16008
Proposed branch: lp:~stevenk/launchpad/deal-with-badly-formed-section
Merge into: lp:launchpad
Diff against target: 201 lines (+90/-27)
5 files modified
lib/lp/archiveuploader/changesfile.py (+7/-2)
lib/lp/archiveuploader/nascentuploadfile.py (+3/-3)
lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1.dsc (+21/-0)
lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1_source.changes (+30/-0)
lib/lp/archiveuploader/tests/test_uploadprocessor.py (+29/-22)
To merge this branch: bzr merge lp:~stevenk/launchpad/deal-with-badly-formed-section
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+125908@code.launchpad.net

Commit message

Deal with an inability to parse the file lines from the changes file, and reject the upload.

Description of the change

Deal with an inability to parse the file lines from the changes file. This also means we can't give any context to the user since it's far too early. Given the fields present it is only going to be component, section that are going to trip this up.

dpkg-genchanges also has a bug due to this due to accepting a Section that has a space in it.

I have tried to get this branch loc negative, but will take the ten line hit, I've clawed some of it back.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

14 + yield UploadError("Unable to parse file line, check section.")

That's pretty vague, misleading, and looks bad. Perhaps "Wrong number of fields in Files line in .changes."?

I'd also really prefer that we stopped creating malformed uploads for this. Unit tests are good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/changesfile.py'
2--- lib/lp/archiveuploader/changesfile.py 2012-06-29 08:40:05 +0000
3+++ lib/lp/archiveuploader/changesfile.py 2012-09-24 01:48:20 +0000
4@@ -177,8 +177,13 @@
5 for fileline in self._dict['Files'].strip().split("\n"):
6 # files lines from a changes file are always of the form:
7 # CHECKSUM SIZE [COMPONENT/]SECTION PRIORITY FILENAME
8- digest, size, component_and_section, priority_name, filename = (
9- fileline.strip().split())
10+ try:
11+ digest, size, component_and_section, priority_name, filename = (
12+ fileline.strip().split())
13+ except ValueError as e:
14+ yield UploadError(
15+ "Wrong number of fields in Files line in .changes.")
16+ continue
17 filepath = os.path.join(self.dirname, filename)
18 try:
19 if self.isCustom(component_and_section):
20
21=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
22--- lib/lp/archiveuploader/nascentuploadfile.py 2012-07-24 06:39:54 +0000
23+++ lib/lp/archiveuploader/nascentuploadfile.py 2012-09-24 01:48:20 +0000
24@@ -335,9 +335,9 @@
25 SourcePackageRelease creation, so component and section need to exist.
26 Even if they might be overridden in the future.
27 """
28- NascentUploadFile.__init__(
29- self, filepath, digest, size, component_and_section,
30- priority_name, policy, logger)
31+ super(PackageUploadFile, self).__init__(
32+ filepath, digest, size, component_and_section, priority_name,
33+ policy, logger)
34 self.package = package
35 self.version = version
36 self.changes = changes
37
38=== added directory 'lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section'
39=== added file 'lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1.diff.gz'
40Binary files lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1.diff.gz 1970-01-01 00:00:00 +0000 and lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1.diff.gz 2012-09-24 01:48:20 +0000 differ
41=== added file 'lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1.dsc'
42--- lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1.dsc 1970-01-01 00:00:00 +0000
43+++ lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1.dsc 2012-09-24 01:48:20 +0000
44@@ -0,0 +1,21 @@
45+-----BEGIN PGP SIGNED MESSAGE-----
46+Hash: SHA1
47+
48+Format: 1.0
49+Source: bar
50+Version: 1.0-1
51+Binary: bar
52+Maintainer: Launchpad team <launchpad@lists.canonical.com>
53+Architecture: any
54+Standards-Version: 3.6.2
55+Files:
56+ fc1464e5985b962a042d5354452f361d 164 bar_1.0.orig.tar.gz
57+ 1e35b810764f140af9616de8274e6e73 537 bar_1.0-1.diff.gz
58+
59+-----BEGIN PGP SIGNATURE-----
60+Version: GnuPG v1.4.3 (GNU/Linux)
61+
62+iD8DBQFFt7Cojn63CGxkqMURAo6FAJ9ZUagUNtYpmZrqFwL6LXDKOUSOPwCdFqPa
63+BdrMeT+0Hg+yMS69uO+qJRI=
64+=mjFU
65+-----END PGP SIGNATURE-----
66
67=== added file 'lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1_source.changes'
68--- lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1_source.changes 1970-01-01 00:00:00 +0000
69+++ lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0-1_source.changes 2012-09-24 01:48:20 +0000
70@@ -0,0 +1,30 @@
71+-----BEGIN PGP SIGNED MESSAGE-----
72+Hash: SHA1
73+
74+Format: 1.7
75+Date: Thu, 16 Feb 2006 15:34:09 +0000
76+Source: bar
77+Binary: bar
78+Architecture: source
79+Version: 1.0-1
80+Distribution: breezy
81+Urgency: low
82+Maintainer: Launchpad team <launchpad@lists.canonical.com>
83+Changed-By: Daniel Silverstone <daniel.silverstone@canonical.com>
84+Description:
85+ bar - Stuff for testing
86+Changes:
87+ bar (1.0-1) breezy; urgency=low
88+ .
89+ * Initial version
90+Files:
91+ 5d533778b698edc1a122098a98c8490e 512 universe/utils, lol optional bar_1.0-1.dsc
92+ fc1464e5985b962a042d5354452f361d 164 universe/utils, lol optional bar_1.0.orig.tar.gz
93+ 1e35b810764f140af9616de8274e6e73 537 universe/utils, lol optional bar_1.0-1.diff.gz
94+-----BEGIN PGP SIGNATURE-----
95+Version: GnuPG v1.4.11 (GNU/Linux)
96+
97+iEYEARECAAYFAlBfq5YACgkQjn63CGxkqMWHHQCfejRqEMreaVmYyK54nnABF1mI
98++40AoJq+sgIHCMR53dtQH1+axuqyHqjn
99+=M3hQ
100+-----END PGP SIGNATURE-----
101
102=== added file 'lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0.orig.tar.gz'
103Binary files lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0.orig.tar.gz 1970-01-01 00:00:00 +0000 and lib/lp/archiveuploader/tests/data/suite/bar_1.0-1_malformed_section/bar_1.0.orig.tar.gz 2012-09-24 01:48:20 +0000 differ
104=== modified file 'lib/lp/archiveuploader/tests/test_uploadprocessor.py'
105--- lib/lp/archiveuploader/tests/test_uploadprocessor.py 2012-07-03 08:04:35 +0000
106+++ lib/lp/archiveuploader/tests/test_uploadprocessor.py 2012-09-24 01:48:20 +0000
107@@ -221,9 +221,9 @@
108 def assertLogContains(self, line):
109 """Assert if a given line is present in the log messages."""
110 log_lines = self.log.getLogBuffer()
111- self.assertTrue(line in log_lines,
112- "'%s' is not in logged output\n\n%s"
113- % (line, log_lines))
114+ self.assertTrue(
115+ line in log_lines, "'%s' is not in logged output\n\n%s" % (
116+ line, log_lines))
117
118 def assertRaisesAndReturnError(self, excClass, callableObj, *args,
119 **kwargs):
120@@ -1264,29 +1264,40 @@
121 self.layer.txn.commit()
122 self._uploadPartnerToNonReleasePocketAndCheckFail()
123
124+ def assertRejectionMessage(self, uploadprocessor, msg, with_file=True):
125+ expected = ''
126+ for part in ('-1.dsc', '.orig.tar.gz', '-1.diff.gz'):
127+ if with_file:
128+ expected += 'bar_1.0%s: %s\n' % (part, msg)
129+ else:
130+ expected += '%s\n' % msg
131+ expected += ('Further error processing not possible because of a '
132+ 'critical previous error.')
133+ self.assertEqual(
134+ expected, uploadprocessor.last_processed_upload.rejection_message)
135+
136 def testUploadWithUnknownSectionIsRejected(self):
137 uploadprocessor = self.setupBreezyAndGetUploadProcessor()
138 upload_dir = self.queueUpload("bar_1.0-1_bad_section")
139 self.processUpload(uploadprocessor, upload_dir)
140- self.assertEqual(
141- uploadprocessor.last_processed_upload.rejection_message,
142- "bar_1.0-1.dsc: Unknown section 'badsection'\n"
143- "bar_1.0.orig.tar.gz: Unknown section 'badsection'\n"
144- "bar_1.0-1.diff.gz: Unknown section 'badsection'\n"
145- "Further error processing not possible because of a "
146- "critical previous error.")
147+ self.assertRejectionMessage(
148+ uploadprocessor, "Unknown section 'badsection'")
149+
150+ def testUploadWithMalformedSectionIsRejected(self):
151+ uploadprocessor = self.setupBreezyAndGetUploadProcessor()
152+ upload_dir = self.queueUpload("bar_1.0-1_malformed_section")
153+ self.processUpload(uploadprocessor, upload_dir)
154+ self.assertRejectionMessage(
155+ uploadprocessor,
156+ 'Wrong number of fields in Files line in .changes.',
157+ with_file=False)
158
159 def testUploadWithUnknownComponentIsRejected(self):
160 uploadprocessor = self.setupBreezyAndGetUploadProcessor()
161 upload_dir = self.queueUpload("bar_1.0-1_contrib_component")
162 self.processUpload(uploadprocessor, upload_dir)
163- self.assertEqual(
164- uploadprocessor.last_processed_upload.rejection_message,
165- "bar_1.0-1.dsc: Unknown component 'contrib'\n"
166- "bar_1.0.orig.tar.gz: Unknown component 'contrib'\n"
167- "bar_1.0-1.diff.gz: Unknown component 'contrib'\n"
168- "Further error processing not possible because of a "
169- "critical previous error.")
170+ self.assertRejectionMessage(
171+ uploadprocessor, "Unknown component 'contrib'")
172
173 def testSourceUploadToBuilddPath(self):
174 """Source uploads to buildd upload paths are not permitted."""
175@@ -1340,8 +1351,6 @@
176 # The component contrib does not exist in the sample data, so
177 # add it here.
178 Component(name='contrib')
179-
180- # Test it.
181 self.checkComponentOverride(
182 "bar_1.0-1_contrib_component", "multiverse")
183
184@@ -1350,8 +1359,6 @@
185 # The component non-free does not exist in the sample data, so
186 # add it here.
187 Component(name='non-free')
188-
189- # Test it.
190 self.checkComponentOverride(
191 "bar_1.0-1_nonfree_component", "multiverse")
192
193@@ -1902,7 +1909,7 @@
194 should both have the PGP signature removed.
195 """
196 uploadprocessor = self.setupBreezyAndGetUploadProcessor(
197- policy='insecure')
198+ policy='insecure')
199 upload_dir = self.queueUpload("bar_1.0-1")
200 self.processUpload(uploadprocessor, upload_dir)
201 # ACCEPT the upload