Merge "Do not add 80,443 ports to dashboard url"
diff --git a/_modules/runtest/tempest_sections/dashboard.py b/_modules/runtest/tempest_sections/dashboard.py
index 008af2b..b28781e 100644
--- a/_modules/runtest/tempest_sections/dashboard.py
+++ b/_modules/runtest/tempest_sections/dashboard.py
@@ -30,7 +30,15 @@
                 port = self.get_item_when_condition_match('horizon.server.bind.port', horizon_enable)
                 protocol = 'http'
                 ip = self.get_item_when_condition_match('_param.cluster_local_address', horizon_enable)
-            return "{}://{}:{}".format(protocol, ip, port)
+            # When CSRF protection is enabled Refferer and Host header should match.
+            # Common browsers doesn't add default ports like 80 and 443 to the headers
+            # Use the same logic here to make sure test passed when CSRF protection is enabled and
+            # we using default port numbers. More info may be found here:
+            # * https://code.djangoproject.com/ticket/26037
+            # * https://stackoverflow.com/questions/27533011/django-csrf-error-casused-by-nginx-x-forwarded-host
+            if str(port) not in ['80', '443']:
+               return "{}://{}:{}".format(protocol, ip, port)
+            return "{}://{}".format(protocol, ip)
 
     @property
     def login_url(self):