Beispiel #1
0
 def unauthenticated_userid(self, request):
     if not check_ip_address(request, self.ipaddrs, self.proxies):
         return None
     if self.get_userid is not None:
         userid = self.get_userid(get_ip_address(request, self.proxies))
     else:
         userid = self.userid
     return userid
 def unauthenticated_userid(self, request):
     if not check_ip_address(request, self.ipaddrs, self.proxies):
         return None
     if self.get_userid is not None:
         userid = self.get_userid(get_ip_address(request, self.proxies))
     else:
         userid = self.userid
     return userid
Beispiel #3
0
 def test_get_ip_address(self):
     # Testing without X-Forwarded-For
     request = DummyRequest(environ={"REMOTE_ADDR": "192.168.0.1"})
     self.assertEquals(get_ip_address(request),
                       IPAddress("192.168.0.1"))
     # Testing with X-Forwaded-For and no trusted proxies
     request = DummyRequest(environ={"REMOTE_ADDR": "192.168.0.1",
                            "HTTP_X_FORWARDED_FOR": "123.123.0.1"})
     self.assertEquals(get_ip_address(request),
                       IPAddress("192.168.0.1"))
     # Testing with an untrusted proxy
     self.assertEquals(get_ip_address(request, "192.168.1.1"),
                       IPAddress("192.168.0.1"))
     # Testing with a trusted proxy
     self.assertEquals(get_ip_address(request, "192.168.0.1"),
                       IPAddress("123.123.0.1"))
     # Testing with a malformed XFF header
     request = DummyRequest(environ={"REMOTE_ADDR": "192.168.0.1",
                        "HTTP_X_FORWARDED_FOR": "124.124.0.1 123.123.0.1"})
     self.assertEquals(get_ip_address(request, "192.168.0.1"),
                       IPAddress("192.168.0.1"))
     # Testing with a trusted proxy and untrusted proxy
     request = DummyRequest(environ={"REMOTE_ADDR": "192.168.0.1",
                        "HTTP_X_FORWARDED_FOR": "124.124.0.1, 123.123.0.1"})
     self.assertEquals(get_ip_address(request, "192.168.0.1"),
                       IPAddress("123.123.0.1"))
     # Testing with several trusted proxies
     request = DummyRequest(environ={"REMOTE_ADDR": "192.168.0.1",
                        "HTTP_X_FORWARDED_FOR": "124.124.0.1, 123.123.0.1"})
     self.assertEquals(get_ip_address(request, "192.168.0.1 123.123.0.1"),
                       IPAddress("124.124.0.1"))
Beispiel #4
0
    def effective_principals(self, request):
        principals = [Everyone]
        if not check_ip_address(request, self.ipaddrs, self.proxies):
            return principals
        
        if self.get_userid is not None:
            userid = self.get_userid(get_ip_address(request, self.proxies))
        else:
            userid = self.userid

        if userid is not None:
            principals.insert(0, userid)
            principals.append(Authenticated)
            
        if self.get_principals is not None:
            addr = get_ip_address(request, self.proxies)
            principals.extend(self.get_principals(userid, addr))
        elif self.principals is not None:
            principals.extend(self.principals)
                
        return principals
    def effective_principals(self, request):
        principals = [Everyone]
        if not check_ip_address(request, self.ipaddrs, self.proxies):
            return principals

        if self.get_userid is not None:
            userid = self.get_userid(get_ip_address(request, self.proxies))
        else:
            userid = self.userid

        if userid is not None:
            principals.insert(0, userid)
            principals.append(Authenticated)

        if self.get_principals is not None:
            addr = get_ip_address(request, self.proxies)
            principals.extend(self.get_principals(userid, addr))
        elif self.principals is not None:
            principals.extend(self.principals)

        return principals
Beispiel #6
0
 def test_get_ip_address(self):
     # Testing without X-Forwarded-For
     request = DummyRequest(environ={"REMOTE_ADDR": "192.168.0.1"})
     self.assertEqual(get_ip_address(request), IPAddress("192.168.0.1"))
     # Testing with X-Forwaded-For and no trusted proxies
     request = DummyRequest(environ={
         "REMOTE_ADDR": "192.168.0.1",
         "HTTP_X_FORWARDED_FOR": "123.123.0.1"
     })
     self.assertEqual(get_ip_address(request), IPAddress("192.168.0.1"))
     # Testing with an untrusted proxy
     self.assertEqual(get_ip_address(request, "192.168.1.1"),
                      IPAddress("192.168.0.1"))
     # Testing with a trusted proxy
     self.assertEqual(get_ip_address(request, "192.168.0.1"),
                      IPAddress("123.123.0.1"))
     # Testing with a malformed XFF header
     request = DummyRequest(
         environ={
             "REMOTE_ADDR": "192.168.0.1",
             "HTTP_X_FORWARDED_FOR": "124.124.0.1 123.123.0.1"
         })
     self.assertEqual(get_ip_address(request, "192.168.0.1"),
                      IPAddress("192.168.0.1"))
     # Testing with a trusted proxy and untrusted proxy
     request = DummyRequest(
         environ={
             "REMOTE_ADDR": "192.168.0.1",
             "HTTP_X_FORWARDED_FOR": "124.124.0.1, 123.123.0.1"
         })
     self.assertEqual(get_ip_address(request, "192.168.0.1"),
                      IPAddress("123.123.0.1"))
     # Testing with several trusted proxies
     request = DummyRequest(
         environ={
             "REMOTE_ADDR": "192.168.0.1",
             "HTTP_X_FORWARDED_FOR": "124.124.0.1, 123.123.0.1"
         })
     self.assertEqual(get_ip_address(request, "192.168.0.1 123.123.0.1"),
                      IPAddress("124.124.0.1"))