From 890fb3f86753ab742a98a7b34582af8eb42cc0a6 Mon Sep 17 00:00:00 2001 From: Alessio Ababilov Date: Fri, 25 May 2012 19:27:39 +0300 Subject: [PATCH] [PATCH] Allow [:print:] chars for security group names Fixes bug #1000673 Change-Id: Id1b23d6a0f8d328f65b66f947e8937fa1914a5db --- nova/tests/test_api.py | 46 +++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py index b0367dd8..1970a672 100644 --- a/nova/tests/test_api.py +++ b/nova/tests/test_api.py @@ -35,10 +35,14 @@ from nova import block_device from nova.compute import api as compute_api from nova import context from nova import exception +from nova import flags from nova import test from nova import utils +FLAGS = flags.FLAGS + + class FakeHttplibSocket(object): """a fake socket implementation for httplib.HTTPResponse, trivial""" def __init__(self, response_string): @@ -345,19 +349,37 @@ class ApiEc2TestCase(test.TestCase): def test_group_name_valid_chars_security_group(self): """ Test that we sanely handle invalid security group names. - API Spec states we should only accept alphanumeric characters, - spaces, dashes, and underscores. """ - self.expect_http() - self.mox.ReplayAll() + EC2 API Spec states we should only accept alphanumeric characters, + spaces, dashes, and underscores. Amazon implementation + accepts more characters - so, [:print:] is ok. """ - # Test block group_name of non alphanumeric characters, spaces, - # dashes, and underscores. - security_group_name = "aa #^% -=99" - - self.assertRaises(boto_exc.EC2ResponseError, - self.ec2.create_security_group, - security_group_name, - 'test group') + bad_strict_ec2 = "aa \t\x01\x02\x7f" + bad_amazon_ec2 = "aa #^% -=99" + test_raise = [ + (True, bad_amazon_ec2, "test desc"), + (True, "test name", bad_amazon_ec2), + (False, bad_strict_ec2, "test desc"), + ] + for test in test_raise: + self.expect_http() + self.mox.ReplayAll() + FLAGS.ec2_strict_validation = test[0] + self.assertRaises(boto_exc.EC2ResponseError, + self.ec2.create_security_group, + test[1], + test[2]) + test_accept = [ + (False, bad_amazon_ec2, "test desc"), + (False, "test name", bad_amazon_ec2), + ] + for test in test_accept: + self.expect_http() + self.mox.ReplayAll() + FLAGS.ec2_strict_validation = test[0] + self.ec2.create_security_group(test[1], test[2]) + self.expect_http() + self.mox.ReplayAll() + self.ec2.delete_security_group(test[1]) def test_group_name_valid_length_security_group(self): """Test that we sanely handle invalid security group names.