Пример #1
0
def test_parse_set_cookie_header():
    vals = [
        [
            "", None
        ],
        [
            ";", None
        ],
        [
            "one=uno",
            ("one", "uno", ())
        ],
        [
            "one=uno; foo=bar",
            ("one", "uno", (("foo", "bar"),))
        ],
        [
            "one=uno; foo=bar; foo=baz",
            ("one", "uno", (("foo", "bar"), ("foo", "baz")))
        ],
    ]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            assert ret[0] == expected[0]
            assert ret[1] == expected[1]
            assert ret[2].items(multi=True) == expected[2]
            s2 = cookies.format_set_cookie_header(*ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            assert ret2[0] == expected[0]
            assert ret2[1] == expected[1]
            assert ret2[2].items(multi=True) == expected[2]
        else:
            assert ret is None
Пример #2
0
def test_parse_set_cookie_header():
    vals = [
        [
            "", None
        ],
        [
            ";", None
        ],
        [
            "one=uno",
            ("one", "uno", [])
        ],
        [
            "one=uno; foo=bar",
            ("one", "uno", [["foo", "bar"]])
        ]
    ]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            assert ret[0] == expected[0]
            assert ret[1] == expected[1]
            assert ret[2].lst == expected[2]
            s2 = cookies.format_set_cookie_header(*ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            assert ret2[0] == expected[0]
            assert ret2[1] == expected[1]
            assert ret2[2].lst == expected[2]
        else:
            assert ret is None
Пример #3
0
def test_parse_set_cookie_header():
    def set_cookie_equal(obs, exp):
        assert obs[0] == exp[0]
        assert obs[1] == exp[1]
        assert obs[2].items(multi=True) == exp[2]

    vals = [
        ["", []],
        [";", []],
        ["one=uno", [("one", "uno", ())]],
        ["one=uno; foo=bar", [("one", "uno", (("foo", "bar"), ))]],
        [
            "one=uno; foo=bar; foo=baz",
            [("one", "uno", (("foo", "bar"), ("foo", "baz")))]
        ],
        # Comma Separated Variant of Set-Cookie Headers
        ["foo=bar, doo=dar", [
            ("foo", "bar", ()),
            ("doo", "dar", ()),
        ]],
        [
            "foo=bar; path=/, doo=dar; roo=rar; zoo=zar",
            [
                ("foo", "bar", (("path", "/"), )),
                ("doo", "dar", (("roo", "rar"), ("zoo", "zar"))),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037",
            [
                ("foo", "bar", (("expires", "Mon, 24 Aug 2037"), )),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037 00:00:00 GMT, doo=dar",
            [
                ("foo", "bar", (("expires",
                                 "Mon, 24 Aug 2037 00:00:00 GMT"), )),
                ("doo", "dar", ()),
            ]
        ],
    ]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            for i in range(len(expected)):
                set_cookie_equal(ret[i], expected[i])

            s2 = cookies.format_set_cookie_header(ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            for i in range(len(expected)):
                set_cookie_equal(ret2[i], expected[i])
        else:
            assert not ret
Пример #4
0
def test_parse_set_cookie_header():
    vals = [["", None], [";", None], ["one=uno", ("one", "uno", [])],
            ["one=uno; foo=bar", ("one", "uno", [["foo", "bar"]])]]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            assert ret[0] == expected[0]
            assert ret[1] == expected[1]
            assert ret[2].lst == expected[2]
            s2 = cookies.format_set_cookie_header(*ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            assert ret2[0] == expected[0]
            assert ret2[1] == expected[1]
            assert ret2[2].lst == expected[2]
        else:
            assert ret is None
Пример #5
0
 def handle_response(self, f):
     for i in f.response.headers.get_all("set-cookie"):
         # FIXME: We now know that Cookie.py screws up some cookies with
         # valid RFC 822/1123 datetime specifications for expiry. Sigh.
         name, value, attrs = cookies.parse_set_cookie_header(str(i))
         a = self.ckey(attrs, f)
         if self.domain_match(f.request.host, a[0]):
             b = attrs.lst
             b.insert(0, [name, value])
             self.jar[a][name] = odict.ODictCaseless(b)
Пример #6
0
def test_parse_set_cookie_header():
    vals = [
        ["", None],
        [";", None],
        ["one=uno", ("one", "uno", ())],
        ["one=uno; foo=bar", ("one", "uno", (("foo", "bar"), ))],
        [
            "one=uno; foo=bar; foo=baz",
            ("one", "uno", (("foo", "bar"), ("foo", "baz")))
        ],
    ]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            assert ret[0] == expected[0]
            assert ret[1] == expected[1]
            assert ret[2].items(multi=True) == expected[2]
            s2 = cookies.format_set_cookie_header(*ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            assert ret2[0] == expected[0]
            assert ret2[1] == expected[1]
            assert ret2[2].items(multi=True) == expected[2]
        else:
            assert ret is None
Пример #7
0
def test_parse_set_cookie_header():
    def set_cookie_equal(obs, exp):
        assert obs[0] == exp[0]
        assert obs[1] == exp[1]
        assert obs[2].items(multi=True) == exp[2]

    vals = [
        [
            "", []
        ],
        [
            ";", []
        ],
        [
            "one=uno",
            [
                ("one", "uno", ())
            ]
        ],
        [
            "one=uno; foo=bar",
            [
                ("one", "uno", (("foo", "bar"),))
            ]
        ],
        [
            "one=uno; foo=bar; foo=baz",
            [
                ("one", "uno", (("foo", "bar"), ("foo", "baz")))
            ]
        ],
        # Comma Separated Variant of Set-Cookie Headers
        [
            "foo=bar, doo=dar",
            [
                ("foo", "bar", ()),
                ("doo", "dar", ()),
            ]
        ],
        [
            "foo=bar; path=/, doo=dar; roo=rar; zoo=zar",
            [
                ("foo", "bar", (("path", "/"),)),
                ("doo", "dar", (("roo", "rar"), ("zoo", "zar"))),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037",
            [
                ("foo", "bar", (("expires", "Mon, 24 Aug 2037"),)),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037 00:00:00 GMT, doo=dar",
            [
                ("foo", "bar", (("expires", "Mon, 24 Aug 2037 00:00:00 GMT"),)),
                ("doo", "dar", ()),
            ]
        ],
    ]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            for i in range(len(expected)):
                set_cookie_equal(ret[i], expected[i])

            s2 = cookies.format_set_cookie_header(ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            for i in range(len(expected)):
                set_cookie_equal(ret2[i], expected[i])
        else:
            assert not ret