'Origin should be echo\'d when it matches an allowed hostname'

def test_set_cors_headers(self):

    trans = self._new_trans(allowed_origin_hostnames='*,beep.com')
    trans.request.headers['Origin'] = 'http://xxdarkhackerxx.disney.com'
    trans.set_cors_headers()
    self.assert_cors_header_equals(trans.response.headers, 'http://xxdarkhackerxx.disney.com')
    trans = self._new_trans(allowed_origin_hostnames='something.com,/^[\\w\\.]*beep\\.com/')
    trans.request.headers['Origin'] = 'http://boop.beep.com'
    trans.set_cors_headers()
    self.assert_cors_header_equals(trans.response.headers, 'http://boop.beep.com')
    trans = self._new_trans(allowed_origin_hostnames='somethingelse.com,/^[\\w\\.]*beep\\.com/')
    trans.request.headers['Origin'] = 'http://boop.beep.com:8080'
    trans.set_cors_headers()
    self.assert_cors_header_equals(trans.response.headers, 'http://boop.beep.com:8080')
    trans = self._new_trans(allowed_origin_hostnames='/localhost/')
    trans.request.headers['Origin'] = 'http://localhost:8080'
    trans.set_cors_headers()
    self.assert_cors_header_equals(trans.response.headers, 'http://localhost:8080')
    trans.response.headers = {}
    trans.request.headers['Origin'] = 'http://localhost.badstuff.tv'
    trans.set_cors_headers()
    self.assert_cors_header_missing(trans.response.headers)
    trans = self._new_trans(allowed_origin_hostnames='/\xc3\xb6bb\\.at/')
    trans.request.headers['Origin'] = 'http://\xc3\xb6bb.at'
    trans.set_cors_headers()
    self.assertEqual(trans.response.headers['access-control-allow-origin'], 'http://\xc3\xb6bb.at')
