Skip to content

Commit

Permalink
Add unit tests for iam_user_name validator (cloudtools#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
markpeek authored and covataamos committed Oct 24, 2016
1 parent b861b0b commit b090288
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from troposphere.validators import positive_integer, network_port
from troposphere.validators import s3_bucket_name, encoding, status
from troposphere.validators import iam_path, iam_names, iam_role_name
from troposphere.validators import iam_group_name
from troposphere.validators import iam_group_name, iam_user_name


class TestValidators(unittest.TestCase):
Expand Down Expand Up @@ -115,5 +115,12 @@ def test_iam_group_name(self):
with self.assertRaises(ValueError):
iam_group_name(s)

def test_iam_user_name(self):
for s in ['a', 'a'*64, 'A', 'Aa', 'A=,.@-']:
iam_user_name(s)
for s in ['', 'a'*65, 'a%', 'a#', 'A a']:
with self.assertRaises(ValueError):
iam_user_name(s)

if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions troposphere/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def iam_names(b):


def iam_user_name(user_name):
if not user_name:
raise ValueError(
"AWS::IAM::User property 'UserName' may not be empty")

if len(user_name) > 64:
raise ValueError(
"AWS::IAM::User property 'UserName' may not exceed 64 characters")
Expand Down

0 comments on commit b090288

Please sign in to comment.