Skip to content

Commit 4d34557

Browse files
committed
Check if any files matching the submitted draft name and revision already exists on disk in the active drafts or archived drafts directories, and if so reject the submission. Fixes issue ietf-tools#2908
- Legacy-Id: 17498
1 parent 778cd8d commit 4d34557

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

ietf/submit/forms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ def format_messages(where, e, log):
339339
except (UnicodeDecodeError, LookupError) as e:
340340
self.add_error('txt', 'Failed decoding the uploaded file: "%s"' % str(e))
341341

342+
rev_error = validate_submission_rev(self.filename, self.revision)
343+
if rev_error:
344+
raise forms.ValidationError(rev_error)
345+
342346
# The following errors are likely noise if we have previous field
343347
# errors:
344348
if self.errors:

ietf/submit/tests.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,38 @@ def test_submit_bad_file_ps(self):
11201120
self.assertIn('Expected the PS file to have extension ".ps"', m)
11211121
self.assertIn('Expected an PS file of type "application/postscript"', m)
11221122

1123+
def test_submit_file_in_archive(self):
1124+
name = "draft-authorname-testing-file-exists"
1125+
rev = '00'
1126+
formats = ['txt', 'xml']
1127+
group = None
1128+
1129+
# break early in case of missing configuration
1130+
self.assertTrue(os.path.exists(settings.IDSUBMIT_IDNITS_BINARY))
1131+
1132+
# get
1133+
url = urlreverse('ietf.submit.views.upload_submission')
1134+
r = self.client.get(url)
1135+
self.assertEqual(r.status_code, 200)
1136+
q = PyQuery(r.content)
1137+
1138+
# submit
1139+
for dir in [self.repository_dir, self.archive_dir, ]:
1140+
files = {}
1141+
for format in formats:
1142+
fn = os.path.join(dir, "%s-%s.%s" % (name, rev, format))
1143+
with io.open(fn, 'w') as f:
1144+
f.write("a" * 2000)
1145+
files[format], author = submission_file(name, rev, group, format, "test_submission.%s" % format)
1146+
1147+
r = self.client.post(url, files)
1148+
1149+
self.assertEqual(r.status_code, 200)
1150+
q = PyQuery(r.content)
1151+
m = q('div.alert-danger').text()
1152+
1153+
self.assertIn('Unexpected files already in the archive', m)
1154+
11231155
def test_submit_nonascii_name(self):
11241156
name = "draft-authorname-testing-nonascii"
11251157
rev = "00"

ietf/submit/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datetime
88
import io
99
import os
10+
import pathlib
1011
import re
1112
import six # pyflakes:ignore
1213
if six.PY3:
@@ -142,6 +143,15 @@ def validate_submission_rev(name, rev):
142143
if rev != expected:
143144
return 'Invalid revision (revision %02d is expected)' % expected
144145

146+
for dirname in [settings.INTERNET_DRAFT_PATH, settings.INTERNET_DRAFT_ARCHIVE_DIR, ]:
147+
dir = pathlib.Path(dirname)
148+
pattern = '%s-%02d.*' % (name, rev)
149+
existing = list(dir.glob(pattern))
150+
if existing:
151+
plural = '' if len(existing) == 1 else 's'
152+
files = ', '.join([ f.name for f in existing ])
153+
return 'Unexpected file%s already in the archive: %s' % (plural, files)
154+
145155
replaced_by=has_been_replaced_by(name)
146156
if replaced_by:
147157
return 'This document has been replaced by %s' % ",".join(rd.name for rd in replaced_by)

0 commit comments

Comments
 (0)