コード例 #1
0
    def test_no_cookie_change_for_same_user(self):
        request_handler = mock_request_handler(ip='192.168.21.13')

        identification = IpBasedIdentification([])

        identification.identify(request_handler)
        cookie1 = request_handler.get_cookie(COOKIE_KEY)
        identification.identify(request_handler)
        cookie2 = request_handler.get_cookie(COOKIE_KEY)

        self.assertEqual(cookie1, cookie2)
コード例 #2
0
    def test_proxied_ip_behind_untrusted(self):
        identification = IpBasedIdentification([])

        request_handler = mock_request_handler(ip='127.0.0.1', x_forwarded_for='192.168.21.13')
        id = identification.identify(request_handler)
        self.assertNotEqual('192.168.21.13', id)
        self.assertNotEqual('127.0.0.1', id)
コード例 #3
0
    def test_ip_untrusted_identification_same_connection(self):
        identification = IpBasedIdentification([])

        request_handler = mock_request_handler(ip='192.168.21.13')
        id1 = identification.identify(request_handler)
        id2 = identification.identify(request_handler)
        self.assertEqual(id1, id2)
コード例 #4
0
    def test_ip_untrusted_identification_for_different_connections(self):
        identification = IpBasedIdentification([])

        ids = set()
        for _ in range(0, 100):
            ids.add(identification.identify(mock_request_handler(ip='192.168.21.13')))

        self.assertEqual(100, len(ids))
コード例 #5
0
    def test_change_to_trusted(self):
        request_handler = mock_request_handler(ip='192.168.21.13')

        old_id = IpBasedIdentification([]).identify(request_handler)

        trusted_identification = IpBasedIdentification(['192.168.21.13'])
        new_id = trusted_identification.identify(request_handler)

        self.assertNotEqual(old_id, new_id)
        self.assertEqual(new_id, '192.168.21.13')
        self.assertIsNone(request_handler.get_cookie(COOKIE_KEY))
コード例 #6
0
    def test_refresh_old_cookie_with_same_id(self):
        request_handler = mock_request_handler(ip='192.168.21.13')

        identification = IpBasedIdentification([])

        id = '1234567'
        token_expiry = str(date_utils.get_current_millis() + date_utils.days_to_ms(2))
        old_token = id + '&' + token_expiry
        request_handler.set_secure_cookie(COOKIE_KEY, old_token)

        new_id = identification.identify(request_handler)
        new_token = request_handler.get_cookie(COOKIE_KEY)

        self.assertEqual(new_id, id)
        self.assertNotEqual(old_token, new_token)
コード例 #7
0
 def test_ip_untrusted_identification(self):
     identification = IpBasedIdentification([])
     id = identification.identify(mock_request_handler(ip='192.168.21.13'))
     self.assertNotEqual('192.168.21.13', id)
コード例 #8
0
 def test_localhost_ip_trusted_identification(self):
     identification = IpBasedIdentification(['127.0.0.1'])
     id = identification.identify(mock_request_handler(ip='127.0.0.1'))
     self.assertEqual('127.0.0.1', id)
コード例 #9
0
 def test_some_ip_trusted_identification(self):
     identification = IpBasedIdentification(['192.168.21.13'], None)
     id = identification.identify(mock_request_handler(ip='192.168.21.13'))
     self.assertEqual('192.168.21.13', id)
コード例 #10
0
    def test_proxied_ip_behind_trusted(self):
        identification = IpBasedIdentification(TrustedIpValidator(['127.0.0.1']), None)

        request_handler = mock_request_handler(ip='127.0.0.1', x_forwarded_for='192.168.21.13')
        id = identification.identify(request_handler)
        self.assertEqual('192.168.21.13', id)