Merge "Ensure Sink Handlers encode UTF8 names"

This commit is contained in:
Jenkins 2015-05-07 20:10:28 +00:00 committed by Gerrit Code Review
commit b674cbf6ac
2 changed files with 41 additions and 0 deletions

View File

@ -66,6 +66,8 @@ class NotificationHandler(ExtensionPlugin):
def _find_or_create_recordset(self, context, domain_id, name, type,
ttl=None):
name = name.encode('idna')
try:
recordset = self.central_api.find_recordset(context, {
'domain_id': domain_id,

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Managed I.T.
#
# Author: Kiall Mac Innes <kiall@managedit.ie>
@ -59,6 +60,44 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin):
self.assertEqual(3, len(records))
def test_instance_create_end_utf8(self):
self.config(format='%(display_name)s.%(domain)s',
group='handler:nova_fixed')
event_type = 'compute.instance.create.end'
fixture = self.get_notification_fixture('nova', event_type)
# Set the instance display_name to a string containing UTF8.
fixture['payload']['display_name'] = u'Test↟Instance'
self.assertIn(event_type, self.plugin.get_event_types())
criterion = {'domain_id': self.domain_id}
# Ensure we start with 2 records
recordsets = self.central_service.find_recordsets(
self.admin_context, criterion)
# Should only be SOA and NS recordsets
self.assertEqual(2, len(recordsets))
self.plugin.process_notification(
self.admin_context, event_type, fixture['payload'])
# Ensure we now have exactly 1 more recordset
recordsets = self.central_service.find_recordsets(
self.admin_context, criterion)
self.assertEqual(3, len(recordsets))
# Ensure the created record was correctly converted per IDN rules.
criterion['type'] = 'A'
recordsets = self.central_service.find_recordsets(
self.admin_context, criterion)
self.assertEqual('xn--testinstance-q83g.example.com.',
recordsets[0].name)
def test_instance_delete_start(self):
# Prepare for the test
start_event_type = 'compute.instance.create.end'