def test_parse_auth_header(self):
        # Test parsing of a single unquoted parameter.
        params = parse_auth_header("Digest realm=hello")
        self.assertEquals(params["scheme"], "Digest")
        self.assertEquals(params["realm"], "hello")

        # Test parsing of multiple parameters with mixed quotes.
        params = parse_auth_header('Digest test=one, again="two"')
        self.assertEquals(params["scheme"], "Digest")
        self.assertEquals(params["test"], "one")
        self.assertEquals(params["again"], "two")

        # Test parsing of an escaped quote and empty string.
        params = parse_auth_header('Digest test="\\"",again=""')
        self.assertEquals(params["scheme"], "Digest")
        self.assertEquals(params["test"], '"')
        self.assertEquals(params["again"], "")

        # Test parsing of embedded commas, escaped and non-escaped.
        params = parse_auth_header('Digest one="1\\,2", two="3,4"')
        self.assertEquals(params["scheme"], "Digest")
        self.assertEquals(params["one"], "1,2")
        self.assertEquals(params["two"], "3,4")

        # Test parsing on various malformed inputs
        self.assertRaises(ValueError, parse_auth_header, "")
        self.assertRaises(ValueError, parse_auth_header, " ")
        self.assertRaises(ValueError, parse_auth_header, "Broken raw-token")
        self.assertRaises(ValueError, parse_auth_header, 'Broken realm="unclosed-quote')
        self.assertRaises(ValueError, parse_auth_header, 'Broken realm=unopened-quote"')
        self.assertRaises(ValueError, parse_auth_header, 'Broken realm="unescaped"quote"')
        self.assertRaises(ValueError, parse_auth_header, 'Broken realm="escaped-end-quote\\"')
        self.assertRaises(ValueError, parse_auth_header, 'Broken realm="duplicated",,what=comma')
Beispiel #2
0
    def test_parse_auth_header(self):
        # Test parsing of a single unquoted parameter.
        params = parse_auth_header('Digest realm=hello')
        self.assertEquals(params['scheme'], 'Digest')
        self.assertEquals(params['realm'], 'hello')

        # Test parsing of multiple parameters with mixed quotes.
        params = parse_auth_header('Digest test=one, again="two"')
        self.assertEquals(params['scheme'], 'Digest')
        self.assertEquals(params['test'], 'one')
        self.assertEquals(params['again'], 'two')

        # Test parsing of an escaped quote and empty string.
        params = parse_auth_header('Digest test="\\"",again=""')
        self.assertEquals(params['scheme'], 'Digest')
        self.assertEquals(params['test'], '"')
        self.assertEquals(params['again'], '')

        # Test parsing of embedded commas, escaped and non-escaped.
        params = parse_auth_header('Digest one="1\\,2", two="3,4"')
        self.assertEquals(params['scheme'], 'Digest')
        self.assertEquals(params['one'], '1,2')
        self.assertEquals(params['two'], '3,4')

        # Test parsing on various malformed inputs
        self.assertRaises(ValueError, parse_auth_header, "")
        self.assertRaises(ValueError, parse_auth_header, " ")
        self.assertRaises(ValueError, parse_auth_header, 'Broken raw-token')
        self.assertRaises(ValueError, parse_auth_header,
                          'Broken realm="unclosed-quote')
        self.assertRaises(ValueError, parse_auth_header,
                          'Broken realm=unopened-quote"')
        self.assertRaises(ValueError, parse_auth_header,
                          'Broken realm="unescaped"quote"')
        self.assertRaises(ValueError, parse_auth_header,
                          'Broken realm="escaped-end-quote\\"')
        self.assertRaises(ValueError, parse_auth_header,
                          'Broken realm="duplicated",,what=comma')
def get_challenge(plugin, environ):
    """Get a new digest-auth challenge from the plugin."""
    for name, value in plugin.forget(environ, {}):
        if name == "WWW-Authenticate":
            return parse_auth_header(value)
    raise ValueError("plugin didn't issue a challenge")  # pragma: nocover
Beispiel #4
0
def get_challenge(plugin, environ):
    """Get a new digest-auth challenge from the plugin."""
    for name, value in plugin.forget(environ, {}):
        if name == "WWW-Authenticate":
            return parse_auth_header(value)
    raise ValueError("plugin didn't issue a challenge")  # pragma: nocover