Exemplo n.º 1
0
    def test_2_downloads_view(self):
        from shavar.views import downloads_view

        req = "mozpub-track-digest256;a:1-2,7,9-14,16:s:6"
        expected = "n:1800\n" \
                   "i:mozpub-track-digest256\n" \
                   "ad:1,2,7,9,10,11,12,13,14,16\n" \
                   "a:17:32:64\n" \
                   "\xd0\xe1\x96\xa0\xc2]5\xdd\n\x84Y<\xba\xe0\xf3\x833\xaaX" \
                   "R\x996DN\xa2dS\xea\xb2\x8d\xfc\x86\xfdm~\xb5\xf82\x1f" \
                   "\x8a\xden)\\;RW\xcaK\xb0\x90V1Z\x0bz\xe3?\xf6\x00\x81g" \
                   "\xcd\x97"

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)

        # New downloads request means there should be no adddel or subdel
        # entries in the response even if not_publishing_deltas is enabled
        # for the list.
        req = "mozpub-track-digest256;"
        expected = "n:1800\n" \
                   "i:mozpub-track-digest256\n" \
                   "a:17:32:64\n" \
                   "\xd0\xe1\x96\xa0\xc2]5\xdd\n\x84Y<\xba\xe0\xf3\x833\xaaX" \
                   "R\x996DN\xa2dS\xea\xb2\x8d\xfc\x86\xfdm~\xb5\xf82\x1f" \
                   "\x8a\xden)\\;RW\xcaK\xb0\x90V1Z\x0bz\xe3?\xf6\x00\x81g" \
                   "\xcd\x97"

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)
Exemplo n.º 2
0
    def test_2_downloads_view(self):
        from shavar.views import downloads_view

        req = "mozpub-track-digest256;a:1-2,7,9-14,16:s:6"
        expected = "n:1800\n" \
                   "i:mozpub-track-digest256\n" \
                   "ad:1,2,7,9,10,11,12,13,14,16\n" \
                   "a:17:32:64\n" \
                   "\xd0\xe1\x96\xa0\xc2]5\xdd\n\x84Y<\xba\xe0\xf3\x833\xaaX" \
                   "R\x996DN\xa2dS\xea\xb2\x8d\xfc\x86\xfdm~\xb5\xf82\x1f" \
                   "\x8a\xden)\\;RW\xcaK\xb0\x90V1Z\x0bz\xe3?\xf6\x00\x81g" \
                   "\xcd\x97"

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)

        # New downloads request means there should be no adddel or subdel
        # entries in the response even if not_publishing_deltas is enabled
        # for the list.
        req = "mozpub-track-digest256;"
        expected = "n:1800\n" \
                   "i:mozpub-track-digest256\n" \
                   "a:17:32:64\n" \
                   "\xd0\xe1\x96\xa0\xc2]5\xdd\n\x84Y<\xba\xe0\xf3\x833\xaaX" \
                   "R\x996DN\xa2dS\xea\xb2\x8d\xfc\x86\xfdm~\xb5\xf82\x1f" \
                   "\x8a\xden)\\;RW\xcaK\xb0\x90V1Z\x0bz\xe3?\xf6\x00\x81g" \
                   "\xcd\x97"

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)
Exemplo n.º 3
0
    def test_2_downloads_view(self):
        from shavar.views import downloads_view

        req = "mozpub-track-digest256;a:1-2,7,9-14,16:s:6"

        downloads_resp_header = (b"n:1800\n" b"i:mozpub-track-digest256\n")
        chunks_to_add = b"ad:1,2,7,9,10,11,12,13,14,16\n"
        list_header = b"a:17:32:64\n"
        hash_1 = (b"\xd0\xe1\x96\xa0\xc2]5\xdd\n\x84Y<\xba\xe0\xf3\x833\xaaXR"
                  b"\x996DN\xa2dS\xea\xb2\x8d\xfc\x86")
        hash_2 = (b"\xfdm~\xb5\xf82\x1f\x8a\xden)\\;RW\xcaK\xb0\x90V1Z"
                  b"\x0bz\xe3?\xf6\x00\x81g\xcd\x97")
        expected = downloads_resp_header + chunks_to_add + list_header

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(expected, response.body[:len(expected)])
        # In the Chunk class the hash attritube is a set of hashes. Since a set
        # is an unordered collection the order for `b''.join(chunk.hashes)` in
        # format_downloads will vary.
        self.assertIn(hash_1, response.body[len(expected):])
        self.assertIn(hash_2, response.body[len(expected):])

        # New downloads request means there should be no adddel or subdel
        # entries in the response even if not_publishing_deltas is enabled
        # for the list.
        req = "mozpub-track-digest256;"
        expected = downloads_resp_header + list_header

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(expected, response.body[:len(expected)])
        self.assertIn(hash_1, response.body[len(expected):])
        self.assertIn(hash_2, response.body[len(expected):])
Exemplo n.º 4
0
    def test_1_downloads_view(self):
        from shavar.views import downloads_view
        req = "moz-abp-shavar;a:1-2,5:s:3\n"
        req += "mozpub-track-digest256;a:1-2:s:6"
        expected = "n:1800\n" \
                   "i:mozpub-track-digest256\n" \
                   "a:4:32:64\n" \
                   "\xd9\xa7\xffA\xe0\xd8\x92\xbe\x17\xb3\xc3\x04\xf3fA\xf4:" \
                   "\xc1\x1d$\xbe\x13\xa6\x19\xd2\x14\x02DW\xc8\x02\xf2" \
                   "\xdaw\xc4\xd1\xe3\xf8\x10\xbaz\x0b\x83&l\x7f\xaeI\xba" \
                   "\xcf\x0b\xe0\xd2\x86F>k68\xee\xe7\xea+\xeb" \
                   "a:5:32:64\n" \
                   "\x82\x7f2\x0e\x94\xc2\xaf,\xc9\xc7d\x9d\x9e\xc9\t\x06<J" \
                   "\xf5\xe7\xebsh\x86\n3\xfe\xe0\xab\xdc?\xb1" \
                   "%\x85\xf3\xc9\xc0?j\xf2\x9f\xeeC\x90_`\x10j\xc8\x1c\x9d" \
                   "\xe5\xea\xa5\xd1,\xf0\x92\xa0\x93\x17o\x82\x83" \
                   "s:3:32:32\n" \
                   "\t\xa8\xb90\xc8\xb7\x9e|1>^t\x1e\x1dY\xc3\x9a\xe9\x1b" \
                   "\xc1\xf1\x0c\xde\xfah\xb4{\xf7u\x19\xbeW" \
                   "i:moz-abp-shavar\n" \
                   "u:https://tracking.services.mozilla.com/moz-abp-shavar/4" \
                   "\n" \
                   "u:https://tracking.services.mozilla.com/moz-abp-shavar/6\n"

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)

        # Make sure redirects on an empty list are working correctly
        baseurl = "tracking.services.mozilla.com/test-redir-digest256"
        req = "test-redir-digest256;"
        expected = "n:1800\n" \
                   "i:test-redir-digest256\n" \
                   "u:{baseurl}/1\n" \
                   "u:{baseurl}/2\n" \
                   "u:{baseurl}/4\n" \
                   "u:{baseurl}/5\n" \
                   "u:{baseurl}/3\n" \
                   "u:{baseurl}/6\n".format(baseurl=baseurl)

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)
Exemplo n.º 5
0
    def test_1_downloads_view(self):
        from shavar.views import downloads_view
        req = "moz-abp-shavar;a:1-2,5:s:3\n"
        req += "mozpub-track-digest256;a:1-2:s:6"
        expected = "n:1800\n" \
                   "i:mozpub-track-digest256\n" \
                   "a:4:32:64\n" \
                   "\xd9\xa7\xffA\xe0\xd8\x92\xbe\x17\xb3\xc3\x04\xf3fA\xf4:" \
                   "\xc1\x1d$\xbe\x13\xa6\x19\xd2\x14\x02DW\xc8\x02\xf2" \
                   "\xdaw\xc4\xd1\xe3\xf8\x10\xbaz\x0b\x83&l\x7f\xaeI\xba" \
                   "\xcf\x0b\xe0\xd2\x86F>k68\xee\xe7\xea+\xeb" \
                   "a:5:32:64\n" \
                   "\x82\x7f2\x0e\x94\xc2\xaf,\xc9\xc7d\x9d\x9e\xc9\t\x06<J" \
                   "\xf5\xe7\xebsh\x86\n3\xfe\xe0\xab\xdc?\xb1" \
                   "%\x85\xf3\xc9\xc0?j\xf2\x9f\xeeC\x90_`\x10j\xc8\x1c\x9d" \
                   "\xe5\xea\xa5\xd1,\xf0\x92\xa0\x93\x17o\x82\x83" \
                   "s:3:32:32\n" \
                   "\t\xa8\xb90\xc8\xb7\x9e|1>^t\x1e\x1dY\xc3\x9a\xe9\x1b" \
                   "\xc1\xf1\x0c\xde\xfah\xb4{\xf7u\x19\xbeW" \
                   "i:moz-abp-shavar\n" \
                   "u:https://tracking.services.mozilla.com/moz-abp-shavar/4" \
                   "\n" \
                   "u:https://tracking.services.mozilla.com/moz-abp-shavar/6\n"

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)

        # Make sure redirects on an empty list are working correctly
        baseurl = "tracking.services.mozilla.com/test-redir-digest256"
        req = "test-redir-digest256;"
        expected = "n:1800\n" \
                   "i:test-redir-digest256\n" \
                   "u:{baseurl}/1\n" \
                   "u:{baseurl}/2\n" \
                   "u:{baseurl}/4\n" \
                   "u:{baseurl}/5\n" \
                   "u:{baseurl}/3\n" \
                   "u:{baseurl}/6\n".format(baseurl=baseurl)

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected)
Exemplo n.º 6
0
    def test_1_downloads_view(self):
        from shavar.views import downloads_view
        req = "moz-abp-shavar;a:1-2,5:s:3\n"
        req += "mozpub-track-digest256;a:1-2:s:6"

        # expected response
        n_header = b"n:1800\n"
        abp_i_header = b"i:moz-abp-shavar\n"
        abp_chunk_download_urls = [
            b"u:https://tracking.services.mozilla.com/moz-abp-shavar/4\n",
            b"u:https://tracking.services.mozilla.com/moz-abp-shavar/6\n"
        ]
        mozpub_i_header = b"i:mozpub-track-digest256\n"
        # chunk 4
        mozpub_chunk_4_list_header = b'a:4:32:64\n'
        mozpub_chunk_4_hashes = [
            (b'\xd9\xa7\xffA\xe0\xd8\x92\xbe\x17\xb3\xc3\x04\xf3fA\xf4:\xc1'
             b'\x1d$\xbe\x13\xa6\x19\xd2\x14\x02DW\xc8\x02\xf2'),
            (b'\xdaw\xc4\xd1\xe3\xf8\x10\xbaz\x0b\x83&l\x7f\xaeI\xba\xcf\x0b'
             b'\xe0\xd2\x86F>k68\xee\xe7\xea+\xeb')
        ]
        # chunk 5
        mozpub_chunk_5_list_header = b"a:5:32:64\n"
        mozpub_chunk_5_hashes = [
            (b'\x82\x7f2\x0e\x94\xc2\xaf,\xc9\xc7d\x9d\x9e\xc9\t\x06<J\xf5\xe7'
             b'\xebsh\x86\n3\xfe\xe0\xab\xdc?\xb1'),
            (b'%\x85\xf3\xc9\xc0?j\xf2\x9f\xeeC\x90_`\x10j\xc8\x1c\x9d\xe5\xea'
             b'\xa5\xd1,\xf0\x92\xa0\x93\x17o\x82\x83')
        ]
        # chunk 3
        mozpub_chunk_3_list_header = b"s:3:32:32\n"
        mozpub_sub_hash_1 = (
            b'\t\xa8\xb90\xc8\xb7\x9e|1>^t\x1e\x1dY\xc3\x9a\xe9\x1b\xc1\xf1'
            b'\x0c\xde\xfah\xb4{\xf7u\x19\xbeW'
        )

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        actual = response.body
        self.assertEqual(actual[:len(n_header)], n_header)
        actual = actual.replace(n_header, b'')
        self.assertEqual(actual[:len(abp_i_header)], abp_i_header)
        actual = actual.replace(abp_i_header, b'')
        urls_len = len(abp_chunk_download_urls[0] + abp_chunk_download_urls[0])
        self.assertIn(abp_chunk_download_urls[0], actual[:urls_len])
        self.assertIn(abp_chunk_download_urls[1], actual[:urls_len])
        actual = actual[urls_len:]

        self.assertEqual(actual[:len(mozpub_i_header)], mozpub_i_header)
        actual = actual.replace(mozpub_i_header, b'')
        self.assertEqual(actual[:len(mozpub_chunk_4_list_header)],
                         mozpub_chunk_4_list_header)
        actual = actual.replace(mozpub_chunk_4_list_header, b'')
        chunk_len = len(mozpub_chunk_4_hashes[0] + mozpub_chunk_4_hashes[1])
        self.assertIn(mozpub_chunk_4_hashes[0], actual[:chunk_len])
        self.assertIn(mozpub_chunk_4_hashes[1], actual[:chunk_len])
        actual = actual[chunk_len:]
        self.assertEqual(actual[:len(mozpub_chunk_5_list_header)],
                         mozpub_chunk_5_list_header)
        actual = actual.replace(mozpub_chunk_5_list_header, b'')
        chunk_len = len(mozpub_chunk_5_hashes[0] + mozpub_chunk_5_hashes[1])
        self.assertIn(mozpub_chunk_5_hashes[0], actual[:chunk_len])
        self.assertIn(mozpub_chunk_5_hashes[1], actual[:chunk_len])
        actual = actual[chunk_len:]
        self.assertEqual(actual,
                         mozpub_chunk_3_list_header + mozpub_sub_hash_1)

        # Make sure redirects on an empty list are working correctly
        baseurl = "tracking.services.mozilla.com/test-redir-digest256"
        req = "test-redir-digest256;"
        expected = "n:1800\n" \
                   "i:test-redir-digest256\n" \
                   "u:{baseurl}/1\n" \
                   "u:{baseurl}/2\n" \
                   "u:{baseurl}/4\n" \
                   "u:{baseurl}/5\n" \
                   "u:{baseurl}/3\n" \
                   "u:{baseurl}/6\n".format(baseurl=baseurl)

        request = dummy(req, path='/downloads')
        response = downloads_view(request)
        self.assertEqual(response.body, expected.encode())