Skip to content

Commit 3d529ba

Browse files
fix: improve validation of submission version. Add submission name validation tests.
Co-authored-by: russhousley <housley@vigilsec.com>
1 parent 95611a4 commit 3d529ba

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

ietf/submit/tests.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2011-2020, All Rights Reserved
1+
# Copyright The IETF Trust 2011-2022, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -24,7 +24,7 @@
2424
import debug # pyflakes:ignore
2525

2626
from ietf.submit.utils import (expirable_submissions, expire_submission, find_submission_filenames,
27-
post_submission)
27+
post_submission, validate_submission_name, validate_submission_rev)
2828
from ietf.doc.factories import DocumentFactory, WgDraftFactory, IndividualDraftFactory, IndividualRfcFactory
2929
from ietf.doc.models import ( Document, DocAlias, DocEvent, State,
3030
BallotPositionDocEvent, DocumentAuthor, SubmissionDocEvent )
@@ -2921,3 +2921,52 @@ def test_post_submission_rebuilds_ref_relations(self, mock_find_filenames, mock_
29212921
args, kwargs = mock_rebuild_reference_relations.call_args
29222922
self.assertEqual(args[1], mock_find_filenames.return_value)
29232923

2924+
2925+
class ValidateSubmissionFilenameTests(BaseSubmitTestCase):
2926+
def test_validate_submission_name(self):
2927+
# This test does not need BaseSubmitTestCase, it could use TestCase
2928+
good_names = (
2929+
'draft-ietf-mars-foobar',
2930+
'draft-ietf-mars-foobar-01',
2931+
'draft-myname-mydraft')
2932+
bad_names = (
2933+
'draft-includes-filename-extension-01.txt',
2934+
'does-not-start-with-draft',
2935+
'draft-Upper-Case',
2936+
'draft-double--dash',
2937+
'draft-trailing-dash-',
2938+
'draft-tooshort',
2939+
'draft-toolong-this-is-a-very-long-name-for-an-internet-draft',
2940+
u'draft-contains-non-ascii-göran')
2941+
2942+
for n in good_names:
2943+
msg = validate_submission_name(n)
2944+
self.assertIsNone(msg)
2945+
2946+
for n in bad_names:
2947+
msg = validate_submission_name(n)
2948+
self.assertIsNotNone(msg)
2949+
2950+
def test_validate_submission_rev(self):
2951+
# This test needs BaseSubmitTestCase
2952+
ind_doc = IndividualDraftFactory()
2953+
old_wg_doc = WgDraftFactory(relations=[('replaces',ind_doc)])
2954+
new_wg_doc = WgDraftFactory(rev='01', relations=[('replaces',old_wg_doc)])
2955+
path = Path(self.archive_dir) / f'{new_wg_doc.name}-{new_wg_doc.rev}.txt'
2956+
path.touch()
2957+
2958+
bad_revs = (None, '', '2', 'aa', '00', '01', '100', '002', u'öö')
2959+
for rev in bad_revs:
2960+
msg = validate_submission_rev(new_wg_doc.name, rev)
2961+
self.assertIsNotNone(msg)
2962+
2963+
new_rev = '%02d' % (int(ind_doc.rev)+1)
2964+
msg = validate_submission_rev(ind_doc.name, new_rev)
2965+
self.assertIsNotNone(msg)
2966+
2967+
new_rev = '%02d' % (int(old_wg_doc.rev)+1)
2968+
msg = validate_submission_rev(old_wg_doc.name, new_rev)
2969+
self.assertIsNotNone(msg)
2970+
2971+
msg = validate_submission_rev(new_wg_doc.name, '02')
2972+
self.assertIsNone(msg)

ietf/submit/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def validate_submission_rev(name, rev):
139139
if not rev:
140140
return 'Revision not found'
141141

142+
if len(rev) != 2:
143+
return 'Revision must be a exactly two digits'
144+
142145
try:
143146
rev = int(rev)
144147
except ValueError:

0 commit comments

Comments
 (0)