コード例 #1
0
ファイル: test_cookies.py プロジェクト: AlTune/mitmproxy
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
ファイル: test_cookies.py プロジェクト: firebitsbr/bdfproxy-1
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
ファイル: flow.py プロジェクト: jajp777/mitmproxy
 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
ファイル: test_cookies.py プロジェクト: timmc/mitmproxy
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
ファイル: test_cookies.py プロジェクト: mkagenius/mitmproxy
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