A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/django/django/commit/c613af4d6485586c79d692b70a9acac429f3ca9d below:

[1.2.X] Added protection against spoofing of X_FORWARDED_HOST headers… · django/django@c613af4 · GitHub

2 2

import time

3 3

import unittest

4 4 5 +

from django.conf import settings

5 6

from django.http import HttpRequest, HttpResponse, parse_cookie

6 7

from django.core.handlers.wsgi import WSGIRequest

7 8

from django.core.handlers.modpython import ModPythonRequest

8 9

from django.utils.http import cookie_date

9 10 11 + 10 12

class RequestsTests(unittest.TestCase):

11 13 12 14

def test_httprequest(self):

@@ -57,3 +59,91 @@ def test_httprequest_location(self):

57 59

request.path = ''

58 60

self.assertEqual(request.build_absolute_uri(location="/path/with:colons"),

59 61

'http://www.example.com/path/with:colons')

62 + 63 +

def test_http_get_host(self):

64 +

old_USE_X_FORWARDED_HOST = settings.USE_X_FORWARDED_HOST

65 +

try:

66 +

settings.USE_X_FORWARDED_HOST = False

67 + 68 +

# Check if X_FORWARDED_HOST is provided.

69 +

request = HttpRequest()

70 +

request.META = {

71 +

u'HTTP_X_FORWARDED_HOST': u'forward.com',

72 +

u'HTTP_HOST': u'example.com',

73 +

u'SERVER_NAME': u'internal.com',

74 +

u'SERVER_PORT': 80,

75 +

}

76 +

# X_FORWARDED_HOST is ignored.

77 +

self.assertEqual(request.get_host(), 'example.com')

78 + 79 +

# Check if X_FORWARDED_HOST isn't provided.

80 +

request = HttpRequest()

81 +

request.META = {

82 +

u'HTTP_HOST': u'example.com',

83 +

u'SERVER_NAME': u'internal.com',

84 +

u'SERVER_PORT': 80,

85 +

}

86 +

self.assertEqual(request.get_host(), 'example.com')

87 + 88 +

# Check if HTTP_HOST isn't provided.

89 +

request = HttpRequest()

90 +

request.META = {

91 +

u'SERVER_NAME': u'internal.com',

92 +

u'SERVER_PORT': 80,

93 +

}

94 +

self.assertEqual(request.get_host(), 'internal.com')

95 + 96 +

# Check if HTTP_HOST isn't provided, and we're on a nonstandard port

97 +

request = HttpRequest()

98 +

request.META = {

99 +

u'SERVER_NAME': u'internal.com',

100 +

u'SERVER_PORT': 8042,

101 +

}

102 +

self.assertEqual(request.get_host(), 'internal.com:8042')

103 + 104 +

finally:

105 +

settings.USE_X_FORWARDED_HOST = old_USE_X_FORWARDED_HOST

106 + 107 +

def test_http_get_host_with_x_forwarded_host(self):

108 +

old_USE_X_FORWARDED_HOST = settings.USE_X_FORWARDED_HOST

109 +

try:

110 +

settings.USE_X_FORWARDED_HOST = True

111 + 112 +

# Check if X_FORWARDED_HOST is provided.

113 +

request = HttpRequest()

114 +

request.META = {

115 +

u'HTTP_X_FORWARDED_HOST': u'forward.com',

116 +

u'HTTP_HOST': u'example.com',

117 +

u'SERVER_NAME': u'internal.com',

118 +

u'SERVER_PORT': 80,

119 +

}

120 +

# X_FORWARDED_HOST is obeyed.

121 +

self.assertEqual(request.get_host(), 'forward.com')

122 + 123 +

# Check if X_FORWARDED_HOST isn't provided.

124 +

request = HttpRequest()

125 +

request.META = {

126 +

u'HTTP_HOST': u'example.com',

127 +

u'SERVER_NAME': u'internal.com',

128 +

u'SERVER_PORT': 80,

129 +

}

130 +

self.assertEqual(request.get_host(), 'example.com')

131 + 132 +

# Check if HTTP_HOST isn't provided.

133 +

request = HttpRequest()

134 +

request.META = {

135 +

u'SERVER_NAME': u'internal.com',

136 +

u'SERVER_PORT': 80,

137 +

}

138 +

self.assertEqual(request.get_host(), 'internal.com')

139 + 140 +

# Check if HTTP_HOST isn't provided, and we're on a nonstandard port

141 +

request = HttpRequest()

142 +

request.META = {

143 +

u'SERVER_NAME': u'internal.com',

144 +

u'SERVER_PORT': 8042,

145 +

}

146 +

self.assertEqual(request.get_host(), 'internal.com:8042')

147 + 148 +

finally:

149 +

settings.USE_X_FORWARDED_HOST = old_USE_X_FORWARDED_HOST


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4