def test_validate_parameters(self):
     params = dict(scheme="SRP-HMAC", realm="testrealm", username="******",
                   nonce="abcdef", response="123456", uri="/my/page",
                   cnonce="98765", ckey="abcdef", algorithm="SRP-1024-SHA1")
     # Missing "nc"
     self.failIf(validate_parameters(params))
     params["nc"] = "0001"
     self.failUnless(validate_parameters(params))
     # Wrong realm
     self.failIf(validate_parameters(params, realm="otherrealm"))
     self.failUnless(validate_parameters(params, realm="testrealm"))
     # Unknown algorithm
     params["algorithm"] = "SRP-UNDEFINED"
     self.failIf(validate_parameters(params))
     params["algorithm"] = "SRP-1024-SHA1"
     self.failUnless(validate_parameters(params))
    def _get_auth_params(self, request):
        """Extract srp-hmac-auth parameters from the request.

        This method extracts srp-hmac-auth parameters from the Authorization
        header and returns them as a dict.  If they are missing then None
        is returned.
        """
        params = self._get_unvalidated_auth_params(request)
        if params is None:
            return None
        # Check that they're valid srp-hmac-auth parameters.
        if not validate_parameters(params, self.realm):
            return None
        # Check that the digest is applied to the correct URI.
        if not validate_uri(request, params):
            return None
        # Check that the provided nonce is valid.
        # If this looks like a stale request, mark it in the request
        # so we can include that information in the challenge.
        if not validate_nonce(self.nonce_manager, request, params):
            request.environ[_ENVKEY_STALE_NONCE] = True
            return None
        return params
    def _get_auth_params(self, request):
        """Extract srp-hmac-auth parameters from the request.

        This method extracts srp-hmac-auth parameters from the Authorization
        header and returns them as a dict.  If they are missing then None
        is returned.
        """
        params = self._get_unvalidated_auth_params(request)
        if params is None:
            return None
        # Check that they're valid srp-hmac-auth parameters.
        if not validate_parameters(params, self.realm):
            return None
        # Check that the digest is applied to the correct URI.
        if not validate_uri(request, params):
            return None
        # Check that the provided nonce is valid.
        # If this looks like a stale request, mark it in the request
        # so we can include that information in the challenge.
        if not validate_nonce(self.nonce_manager, request, params):
            request.environ[_ENVKEY_STALE_NONCE] = True
            return None
        return params
 def test_validate_parameters(self):
     params = dict(scheme="SRP-HMAC",
                   realm="testrealm",
                   username="******",
                   nonce="abcdef",
                   response="123456",
                   uri="/my/page",
                   cnonce="98765",
                   ckey="abcdef",
                   algorithm="SRP-1024-SHA1")
     # Missing "nc"
     self.failIf(validate_parameters(params))
     params["nc"] = "0001"
     self.failUnless(validate_parameters(params))
     # Wrong realm
     self.failIf(validate_parameters(params, realm="otherrealm"))
     self.failUnless(validate_parameters(params, realm="testrealm"))
     # Unknown algorithm
     params["algorithm"] = "SRP-UNDEFINED"
     self.failIf(validate_parameters(params))
     params["algorithm"] = "SRP-1024-SHA1"
     self.failUnless(validate_parameters(params))