def test_auth_good_get_with_vars(self):
     pwdhash = calculate_pwdhash("tester", "testing", "test")
     plugin = DigestAuthPlugin("test", get_pwdhash=lambda u, r: pwdhash)
     environ = make_environ(REQUEST_METHOD="GET", PATH_INFO="/hi?who=me")
     params = get_challenge(plugin, environ)
     params = build_response(environ, params, "tester", "testing")
     self.assertNotEquals(plugin.authenticate(environ, params), None)
Exemplo n.º 2
0
    def authenticate(self, environ, identity):
        """Authenticate the provided identity.

        If one of the "get_password" or "get_pwdhash" callbacks were provided
        then this class is capable of authenticating the identity for itself.
        It will calculate the expected digest response and compare it to that
        provided by the client.  The client is authenticated only if it has
        provided the correct response.
        """
        # Grab the username.
        # If there isn't one, we can't use this identity.
        username = identity.get("username")
        if username is None:
            return None
        # Grab the realm.
        # If there isn't one or it doesn't match, we can't use this identity.
        realm = identity.get("realm")
        if realm is None or realm != self.realm:
            return None
        # Obtain the pwdhash via one of the callbacks.
        if self.get_pwdhash is not None:
            pwdhash = self.get_pwdhash(username, realm)
        elif self.get_password is not None:
            password = self.get_password(username)
            pwdhash = calculate_pwdhash(username, password, realm)
        else:
            return None
        # Validate the digest response.
        if not check_digest_response(identity, pwdhash=pwdhash):
            return None
        # Looks good!
        return username
Exemplo n.º 3
0
 def test_auth_good_get_with_vars(self):
     pwdhash = calculate_pwdhash("tester", "testing", "test")
     plugin = DigestAuthPlugin("test", get_pwdhash=lambda u, r: pwdhash)
     environ = make_environ(REQUEST_METHOD="GET", PATH_INFO="/hi?who=me")
     params = get_challenge(plugin, environ)
     params = build_response(environ, params, "tester", "testing")
     self.assertNotEquals(plugin.authenticate(environ, params), None)
Exemplo n.º 4
0
    def test_make_plugin(self):
        def ref(class_name):
            return __name__ + ":" + class_name

        plugin = make_plugin(realm="test",
                             nonce_manager=ref("EasyNonceManager"),
                             domain="http://example.com",
                             get_pwdhash=ref("get_pwdhash"),
                             get_password=ref("get_password"))
        self.assertEquals(plugin.realm, "test")
        self.assertEquals(plugin.domain, "http://example.com")
        self.failUnless(isinstance(plugin.nonce_manager, EasyNonceManager))
        self.failUnless(plugin.get_pwdhash is get_pwdhash)
        self.assertEquals(plugin.get_pwdhash("test", "test"),
                          calculate_pwdhash("test", "test", "test"))
        self.failUnless(plugin.get_password is get_password)
        self.assertEquals(plugin.get_password("test"), "test")
    def test_make_plugin(self):
        def ref(class_name):
            return __name__ + ":" + class_name

        plugin = make_plugin(
            realm="test",
            nonce_manager=ref("EasyNonceManager"),
            domain="http://example.com",
            get_pwdhash=ref("get_pwdhash"),
            get_password=ref("get_password"),
        )
        self.assertEquals(plugin.realm, "test")
        self.assertEquals(plugin.domain, "http://example.com")
        self.failUnless(isinstance(plugin.nonce_manager, EasyNonceManager))
        self.failUnless(plugin.get_pwdhash is get_pwdhash)
        self.assertEquals(plugin.get_pwdhash("test", "test"), calculate_pwdhash("test", "test", "test"))
        self.failUnless(plugin.get_password is get_password)
        self.assertEquals(plugin.get_password("test"), "test")
def get_pwdhash(username, realm):
    return calculate_pwdhash(username, username, realm)
Exemplo n.º 7
0
def get_pwdhash(username, realm):
    return calculate_pwdhash(username, username, realm)