diff --git a/moto/ec2/responses/tags.py b/moto/ec2/responses/tags.py index 0e01e13bc..effb4faf9 100644 --- a/moto/ec2/responses/tags.py +++ b/moto/ec2/responses/tags.py @@ -1,10 +1,9 @@ from __future__ import unicode_literals -from jinja2 import Template +from xml.sax.saxutils import escape from moto.core.responses import BaseResponse from moto.ec2.models import validate_resource_ids from moto.ec2.utils import sequence_from_querystring, tags_from_query_string, filters_from_querystring -from xml.sax.saxutils import escape class TagResponse(BaseResponse): @@ -29,7 +28,7 @@ class TagResponse(BaseResponse): tags = self.ec2_backend.describe_tags(filters=filters) for tag in tags: tag['value'] = escape(tag['value']) - template = Template(DESCRIBE_RESPONSE) + template = self.response_template(DESCRIBE_RESPONSE) return template.render(tags=tags) diff --git a/tests/test_ec2/test_tags.py b/tests/test_ec2/test_tags.py index 72e72fb86..d8b585842 100644 --- a/tests/test_ec2/test_tags.py +++ b/tests/test_ec2/test_tags.py @@ -44,6 +44,7 @@ def test_remove_tag(): conn.get_all_tags().should.have.length_of(1) instance.remove_tag("a key", "some value") + @mock_ec2 def test_get_all_tags(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -58,6 +59,20 @@ def test_get_all_tags(): tag.value.should.equal("some value") +@mock_ec2 +def test_get_all_tags_with_special_characters(): + conn = boto.connect_ec2('the_key', 'the_secret') + reservation = conn.run_instances('ami-1234abcd') + instance = reservation.instances[0] + + instance.add_tag("a key", "some<> value") + + tags = conn.get_all_tags() + tag = tags[0] + tag.name.should.equal("a key") + tag.value.should.equal("some<> value") + + @mock_ec2 def test_create_tags(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -280,10 +295,10 @@ def test_retrieved_instances_must_contain_their_tags(): instance = reservations[0].instances[0] retrieved_tags = instance.tags - #Cleanup of instance + # Cleanup of instance conn.terminate_instances([instances[0].id]) - #Check whether tag is present with correct value + # Check whether tag is present with correct value retrieved_tags[tag_key].should.equal(tag_value) @@ -299,14 +314,14 @@ def test_retrieved_volumes_must_contain_their_tags(): volume = all_volumes[0] conn.create_tags([volume.id], tags_to_be_set) - #Fetch the volume again + # Fetch the volume again all_volumes = conn.get_all_volumes() volume = all_volumes[0] retrieved_tags = volume.tags volume.delete() - #Check whether tag is present with correct value + # Check whether tag is present with correct value retrieved_tags[tag_key].should.equal(tag_value) @@ -320,7 +335,7 @@ def test_retrieved_snapshots_must_contain_their_tags(): snapshot = conn.create_snapshot(volume.id) conn.create_tags([snapshot.id], tags_to_be_set) - #Fetch the snapshot again + # Fetch the snapshot again all_snapshots = conn.get_all_snapshots() snapshot = all_snapshots[0] retrieved_tags = snapshot.tags @@ -328,5 +343,5 @@ def test_retrieved_snapshots_must_contain_their_tags(): conn.delete_snapshot(snapshot.id) volume.delete() - #Check whether tag is present with correct value + # Check whether tag is present with correct value retrieved_tags[tag_key].should.equal(tag_value)