'get_host() makes helpful suggestions if a valid-looking host is not in ALLOWED_HOSTS.'

@override_settings(ALLOWED_HOSTS=[])
def test_get_host_suggestion_of_allowed_host(self):

    msg_invalid_host = u'Invalid    HTTP_HOST    header:    %r.'
    msg_suggestion = (msg_invalid_host + u'You    may    need    to    add    %r    to    ALLOWED_HOSTS.')
    for host in [u'example.com', u'12.34.56.78', u'[2001:19f0:feee::dead:beef:cafe]', u'xn--4ca9at.com']:
        request = HttpRequest()
        request.META = {u'HTTP_HOST': host}
        self.assertRaisesMessage(SuspiciousOperation, (msg_suggestion % (host, host)), request.get_host)
    for (domain, port) in [(u'example.com', 80), (u'12.34.56.78', 443), (u'[2001:19f0:feee::dead:beef:cafe]', 8080)]:
        host = (u'%s:%s' % (domain, port))
        request = HttpRequest()
        request.META = {u'HTTP_HOST': host}
        self.assertRaisesMessage(SuspiciousOperation, (msg_suggestion % (host, domain)), request.get_host)
    for host in [u'example.com@evil.tld', u'example.com:dr.frankenstein@evil.tld', u'example.com:dr.frankenstein@evil.tld:80', u'example.com:80/badpath', u'example.com:    recovermypassword.com']:
        request = HttpRequest()
        request.META = {u'HTTP_HOST': host}
        self.assertRaisesMessage(SuspiciousOperation, (msg_invalid_host % host), request.get_host)
