Пример #1
0
 def test_handles_referrer(self):
     params = {
         'utm_source': 'brandt',
         'referrer': 'https://duckduckgo.com/privacy'
     }
     final_params = {
         'source': 'brandt',
         'medium': '(direct)',
         'campaign': '(not set)',
         'content': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '37946edae923b50f31f9dc10013dc0d23bed7dc6272611e12af46ff7a8d9d7dc',
     )
Пример #2
0
 def test_handles_referrer_no_source(self):
     params = {
         'referrer': 'https://example.com:5000/searchin',
         'utm_medium': 'aether'
     }
     final_params = {
         'source': 'example.com:5000',
         'medium': 'referral',
         'campaign': '(not set)',
         'content': '(not set)',
         'timestamp': '12345',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '6b3dbb178e9abc22db66530df426b17db8590e8251fc153ba443e81ca60e355e')
Пример #3
0
 def test_handles_referrer_no_source(self):
     params = {
         'referrer': 'https://example.com:5000/searchin',
         'utm_medium': 'aether',
     }
     final_params = {
         'source': 'example.com:5000',
         'medium': 'referral',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '6bd49cd7e1d88f47f2beca56d2216e7c49cb76aee193ff5c5aca34b5318781e8',
     )
Пример #4
0
 def test_no_valid_param_data(self):
     params = {
         'utm_source': 'br@ndt',
         'utm_medium': 'ae<t>her',
         'experiment': 'dfb</p>s',
         'variation': 'ef&bvcv'
     }
     final_params = {
         'source': 'www.mozilla.org',
         'medium': '(none)',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '5560dd96b10040c7c386ae8080233b43b8661c44f249101ecbab8370847962c1',
     )
Пример #5
0
 def test_handles_referrer(self):
     params = {
         'utm_source': 'brandt',
         'referrer': 'https://duckduckgo.com/privacy'
     }
     final_params = {
         'source': 'brandt',
         'medium': '(direct)',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '4e03561fc04c080caf0f9f6b4d8cb24c707a4dc5a8929af65881e166d2cca826',
     )
Пример #6
0
 def test_handles_referrer_no_source(self):
     params = {
         "referrer": "https://example.com:5000/searchin",
         "utm_medium": "aether",
     }
     final_params = {
         "source": "example.com:5000",
         "medium": "referral",
         "campaign": "(not set)",
         "content": "(not set)",
         "experiment": "(not set)",
         "variation": "(not set)",
         "ua": "(not set)",
         "visit_id": "(not set)",
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp["cache-control"] == "max-age=300"
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data["attribution_code"].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data["attribution_sig"],
         "d075cbcbae3bcef5bda3650a259863151586e3a4709d53886ab3cc83a6963d00",
     )
Пример #7
0
 def test_campaign_data_too_long(self):
     """If the code is too long then the utm_campaign value should be truncated"""
     params = {
         'utm_source': 'brandt',
         'utm_medium': 'aether',
         'utm_content': 'A144_A000_0000000',
         'utm_campaign': 'The%7cDude%7cabides%7cI%7cdont%7cknow%7cabout%7cyou%7c'
                         'but%7cI%7ctake%7ccomfort%7cin%7cthat' * 2,
     }
     final_params = {
         'source': 'brandt',
         'medium': 'aether',
         'campaign': 'The|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|'
                     'thatThe|Dude|abides|I|dont|know|about_',
         'content': 'A144_A000_0000000',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     code = querystringsafe_base64.decode(data['attribution_code'])
     assert len(code) <= 200
     attrs = parse_qs(code)
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      '5f4f928ad022b15ce10d6dc962e21e12bbfba924d73a2605f3085760d3f93923')
Пример #8
0
 def test_no_valid_param_data(self):
     params = {
         "utm_source": "br@ndt",
         "utm_medium": "ae<t>her",
         "experiment": "dfb</p>s",
         "variation": "ef&bvcv",
         "visit_id": "14</p>4538.1610<t>957",
     }
     final_params = {
         "source": "www.mozilla.org",
         "medium": "(none)",
         "campaign": "(not set)",
         "content": "(not set)",
         "experiment": "(not set)",
         "variation": "(not set)",
         "ua": "(not set)",
         "visit_id": "(not set)",
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp["cache-control"] == "max-age=300"
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data["attribution_code"].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data["attribution_sig"],
         "135b2245f6b70978bc8142a91521facdb31d70a1bfbdefdc1bd1dee92ce21a22",
     )
def test_encode_decode(string_num):
    """Check if querystringsafe_base64.encode can be reverted by querystringsafe_base64.decode."""
    original = test_strings[string_num]

    encoded = querystringsafe_base64.encode(original)
    decoded = querystringsafe_base64.decode(encoded)
    assert decoded == original
Пример #10
0
    def test_handles_referrer_utf8(self):
        """Should ignore non-ascii domain names.

        We were getting exceptions when the view was trying to base64 encode
        non-ascii domain names in the referrer. The whitelist for bouncer doesn't
        include any such domains anyway, so we should just ignore them.
        """
        params = {'referrer': 'http://youtubê.com/sorry/'}
        final_params = {
            'source': 'www.mozilla.org',
            'medium': '(none)',
            'campaign': '(not set)',
            'content': '(not set)',
        }
        req = self._get_request(params)
        resp = views.stub_attribution_code(req)
        self.assertEqual(resp.status_code, 200)
        assert resp['cache-control'] == 'max-age=300'
        data = json.loads(resp.content)
        # will it blend?
        attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
        # parse_qs returns a dict with lists for values
        attrs = {k: v[0] for k, v in attrs.items()}
        self.assertDictEqual(attrs, final_params)
        self.assertEqual(data['attribution_sig'],
                         '1cdbee664f4e9ea32f14510995b41729a80eddc94cf26dc3c74894c6264c723c')
Пример #11
0
 def test_returns_valid_data(self):
     params = {
         'utm_source': 'brandt',
         'utm_medium': 'aether',
         'experiment': 'firefox-new',
         'variation': '1'
     }
     final_params = {
         'source': 'brandt',
         'medium': 'aether',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': 'firefox-new',
         'variation': '1',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '33b626262f3520b2fea479a0c922e766918a320bda32c710cb638f02b656c5db',
     )
Пример #12
0
 def test_handles_referrer(self):
     params = {
         'utm_source': 'brandt',
         'referrer': 'https://duckduckgo.com/privacy'
     }
     final_params = {
         'source': 'brandt',
         'medium': '(direct)',
         'campaign': '(not set)',
         'content': '(not set)',
         'timestamp': '12345',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         'bd6c54115eb1f331b64bec83225a667fa0e16090d7d6abb33dab6305cd858a9d')
Пример #13
0
    def test_handles_referrer_utf8(self):
        """Should ignore non-ascii domain names.

        We were getting exceptions when the view was trying to base64 encode
        non-ascii domain names in the referrer. The whitelist for bouncer doesn't
        include any such domains anyway, so we should just ignore them.
        """
        params = {'referrer': 'http://youtubê.com/sorry/'}
        final_params = {
            'source': 'www.mozilla.org',
            'medium': '(none)',
            'campaign': '(not set)',
            'content': '(not set)',
            'experiment': '(not set)',
            'variation': '(not set)',
            'ua': '(not set)',
        }
        req = self._get_request(params)
        resp = views.stub_attribution_code(req)
        self.assertEqual(resp.status_code, 200)
        assert resp['cache-control'] == 'max-age=300'
        data = json.loads(resp.content)
        # will it blend?
        attrs = parse_qs(
            querystringsafe_base64.decode(
                data['attribution_code'].encode()).decode())
        # parse_qs returns a dict with lists for values
        attrs = {k: v[0] for k, v in attrs.items()}
        self.assertDictEqual(attrs, final_params)
        self.assertEqual(
            data['attribution_sig'],
            'e0eff8af228709c6f99d8a57699e36e8152698146e0992c7f491e91905eec5f4',
        )
Пример #14
0
 def test_campaign_data_too_long(self):
     """If the code is too long then the utm_campaign value should be truncated"""
     params = {
         'utm_source':
         'brandt',
         'utm_medium':
         'aether',
         'utm_content':
         'A144_A000_0000000',
         'utm_campaign':
         'The%7cDude%7cabides%7cI%7cdont%7cknow%7cabout%7cyou%7c'
         'but%7cI%7ctake%7ccomfort%7cin%7cthat' * 6,
         'experiment':
         '(not set)',
         'variation':
         '(not set)',
         'ua':
         'chrome',
         'visit_id':
         '1456954538.1610960957',
     }
     final_params = {
         'source':
         'brandt',
         'medium':
         'aether',
         'campaign':
         'The|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in'
         '|thatThe|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|thatThe'
         '|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|thatThe|Dude|abides'
         '|I|dont|know|about|you|but|I|take|comfort|in|thatThe|Dude|abides|I|dont|know'
         '|about|you|but|I|take|comfort|in|thatT_',
         'content':
         'A144_A000_0000000',
         'experiment':
         '(not set)',
         'variation':
         '(not set)',
         'ua':
         'chrome',
         'visit_id':
         '1456954538.1610960957',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     code = querystringsafe_base64.decode(
         data['attribution_code'].encode()).decode()
     assert len(code) <= 600
     attrs = parse_qs(code)
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '3c1611db912c51a96418eb7806fbaf1400b8d05fbf6ee4f2f1fb3c0ba74a89f4',
     )
Пример #15
0
 def test_no_valid_param_data(self):
     params = {
         'utm_source': 'br@ndt',
         'utm_medium': 'ae<t>her',
         'experiment': 'dfb</p>s',
         'variation': 'ef&bvcv'
     }
     final_params = {
         'source': 'www.mozilla.org',
         'medium': '(none)',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
         'ua': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         'e0eff8af228709c6f99d8a57699e36e8152698146e0992c7f491e91905eec5f4',
     )
Пример #16
0
 def test_handles_referrer(self):
     params = {
         'utm_source': 'brandt',
         'referrer': 'https://duckduckgo.com/privacy'
     }
     final_params = {
         'source': 'brandt',
         'medium': '(direct)',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
         'ua': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '248b763a1848f0a5e4a4ce169b38c5810511b198aed731091e065b8fd6b02e23',
     )
Пример #17
0
 def test_returns_valid_data(self):
     params = {
         "utm_source": "brandt",
         "utm_medium": "aether",
         "experiment": "firefox-new",
         "variation": "1",
         "ua": "chrome",
         "visit_id": "1456954538.1610960957",
     }
     final_params = {
         "source": "brandt",
         "medium": "aether",
         "campaign": "(not set)",
         "content": "(not set)",
         "experiment": "firefox-new",
         "variation": "1",
         "ua": "chrome",
         "visit_id": "1456954538.1610960957",
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp["cache-control"] == "max-age=300"
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data["attribution_code"].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data["attribution_sig"],
         "b2dc555b2914fdec9f9a1247d244520392e4f888961a6fb57a74a1cdf041261f",
     )
Пример #18
0
 def test_handles_referrer(self):
     params = {
         "utm_source": "brandt",
         "referrer": "https://duckduckgo.com/privacy"
     }
     final_params = {
         "source": "brandt",
         "medium": "(direct)",
         "campaign": "(not set)",
         "content": "(not set)",
         "experiment": "(not set)",
         "variation": "(not set)",
         "ua": "(not set)",
         "visit_id": "(not set)",
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp["cache-control"] == "max-age=300"
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data["attribution_code"].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data["attribution_sig"],
         "b53097f17741b75cdd5b737d3c8ba03349a6093148adeada2ee69adf4fe87322",
     )
Пример #19
0
 def test_no_valid_param_data(self):
     params = {
         'utm_source': 'br@ndt',
         'utm_medium': 'ae<t>her',
         'experiment': 'dfb</p>s',
         'variation': 'ef&bvcv',
         'visit_id': '14</p>4538.1610<t>957',
     }
     final_params = {
         'source': 'www.mozilla.org',
         'medium': '(none)',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
         'ua': '(not set)',
         'visit_id': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '135b2245f6b70978bc8142a91521facdb31d70a1bfbdefdc1bd1dee92ce21a22',
     )
Пример #20
0
 def test_campaign_data_too_long(self):
     """If the code is too long then the utm_campaign value should be truncated"""
     params = {
         "utm_source":
         "brandt",
         "utm_medium":
         "aether",
         "utm_content":
         "A144_A000_0000000",
         "utm_campaign":
         "The%7cDude%7cabides%7cI%7cdont%7cknow%7cabout%7cyou%7cbut%7cI%7ctake%7ccomfort%7cin%7cthat"
         * 6,
         "experiment":
         "(not set)",
         "variation":
         "(not set)",
         "ua":
         "chrome",
         "visit_id":
         "1456954538.1610960957",
     }
     final_params = {
         "source":
         "brandt",
         "medium":
         "aether",
         "campaign":
         "The|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in"
         "|thatThe|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|thatThe"
         "|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|thatThe|Dude|abides"
         "|I|dont|know|about|you|but|I|take|comfort|in|thatThe|Dude|abides|I|dont|know"
         "|about|you|but|I|take|comfort|in|thatT_",
         "content":
         "A144_A000_0000000",
         "experiment":
         "(not set)",
         "variation":
         "(not set)",
         "ua":
         "chrome",
         "visit_id":
         "1456954538.1610960957",
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp["cache-control"] == "max-age=300"
     data = json.loads(resp.content)
     # will it blend?
     code = querystringsafe_base64.decode(
         data["attribution_code"].encode()).decode()
     assert len(code) <= 600
     attrs = parse_qs(code)
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data["attribution_sig"],
         "3c1611db912c51a96418eb7806fbaf1400b8d05fbf6ee4f2f1fb3c0ba74a89f4",
     )
Пример #21
0
 def test_handles_referrer_no_source(self):
     params = {
         'referrer': 'https://example.com:5000/searchin',
         'utm_medium': 'aether',
     }
     final_params = {
         'source': 'example.com:5000',
         'medium': 'referral',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
         'ua': '(not set)',
         'visit_id': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         'd075cbcbae3bcef5bda3650a259863151586e3a4709d53886ab3cc83a6963d00',
     )
Пример #22
0
 def test_handles_referrer(self):
     params = {
         'utm_source': 'brandt',
         'referrer': 'https://duckduckgo.com/privacy'
     }
     final_params = {
         'source': 'brandt',
         'medium': '(direct)',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
         'ua': '(not set)',
         'visit_id': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         'b53097f17741b75cdd5b737d3c8ba03349a6093148adeada2ee69adf4fe87322',
     )
Пример #23
0
 def test_returns_valid_data(self):
     params = {
         'utm_source': 'brandt',
         'utm_medium': 'aether',
         'experiment': 'firefox-new',
         'variation': '1',
         'ua': 'chrome',
         'visit_id': '1456954538.1610960957',
     }
     final_params = {
         'source': 'brandt',
         'medium': 'aether',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': 'firefox-new',
         'variation': '1',
         'ua': 'chrome',
         'visit_id': '1456954538.1610960957'
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         'b2dc555b2914fdec9f9a1247d244520392e4f888961a6fb57a74a1cdf041261f',
     )
Пример #24
0
 def test_campaign_data_too_long(self):
     """If the code is too long then the utm_campaign value should be truncated"""
     params = {
         'utm_source': 'brandt',
         'utm_medium': 'aether',
         'utm_content': 'A144_A000_0000000',
         'utm_campaign': 'The%7cDude%7cabides%7cI%7cdont%7cknow%7cabout%7cyou%7c'
                         'but%7cI%7ctake%7ccomfort%7cin%7cthat' * 2,
     }
     final_params = {
         'source': 'brandt',
         'medium': 'aether',
         'campaign': 'The|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|'
                     'thatThe|Dude|abides|I|dont|know|about_',
         'content': 'A144_A000_0000000',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     code = querystringsafe_base64.decode(data['attribution_code'])
     assert len(code) <= 200
     attrs = parse_qs(code)
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      '5f4f928ad022b15ce10d6dc962e21e12bbfba924d73a2605f3085760d3f93923')
Пример #25
0
    def test_handles_referrer_utf8(self):
        """Should ignore non-ascii domain names.

        We were getting exceptions when the view was trying to base64 encode
        non-ascii domain names in the referrer. The whitelist for bouncer doesn't
        include any such domains anyway, so we should just ignore them.
        """
        params = {'referrer': 'http://youtubê.com/sorry/'}
        final_params = {
            'source': 'www.mozilla.org',
            'medium': '(none)',
            'campaign': '(not set)',
            'content': '(not set)',
        }
        req = self._get_request(params)
        resp = views.stub_attribution_code(req)
        self.assertEqual(resp.status_code, 200)
        assert resp['cache-control'] == 'max-age=300'
        data = json.loads(resp.content)
        # will it blend?
        attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
        # parse_qs returns a dict with lists for values
        attrs = {k: v[0] for k, v in attrs.items()}
        self.assertDictEqual(attrs, final_params)
        self.assertEqual(data['attribution_sig'],
                         '1cdbee664f4e9ea32f14510995b41729a80eddc94cf26dc3c74894c6264c723c')
Пример #26
0
 def test_handles_referrer_no_source(self):
     params = {
         'referrer': 'https://example.com:5000/searchin',
         'utm_medium': 'aether',
     }
     final_params = {
         'source': 'example.com:5000',
         'medium': 'referral',
         'campaign': '(not set)',
         'content': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(data['attribution_code'].encode()).decode()
     )
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '70e177b822f24fa9f8bc8e1caa382204632b3b2548db19bb32b97042c0ef0d47',
     )
Пример #27
0
    def test_handles_referrer_utf8(self):
        """Should ignore non-ascii domain names.

        We were getting exceptions when the view was trying to base64 encode
        non-ascii domain names in the referrer. The allowed list for bouncer
        doesn't include any such domains anyway, so we should just ignore them.
        """
        params = {"referrer": "http://youtubê.com/sorry/"}
        final_params = {
            "source": "www.mozilla.org",
            "medium": "(none)",
            "campaign": "(not set)",
            "content": "(not set)",
            "experiment": "(not set)",
            "variation": "(not set)",
            "ua": "(not set)",
            "visit_id": "(not set)",
        }
        req = self._get_request(params)
        resp = views.stub_attribution_code(req)
        self.assertEqual(resp.status_code, 200)
        assert resp["cache-control"] == "max-age=300"
        data = json.loads(resp.content)
        # will it blend?
        attrs = parse_qs(
            querystringsafe_base64.decode(
                data["attribution_code"].encode()).decode())
        # parse_qs returns a dict with lists for values
        attrs = {k: v[0] for k, v in attrs.items()}
        self.assertDictEqual(attrs, final_params)
        self.assertEqual(
            data["attribution_sig"],
            "135b2245f6b70978bc8142a91521facdb31d70a1bfbdefdc1bd1dee92ce21a22",
        )
Пример #28
0
 def test_returns_valid_data(self):
     params = {
         'utm_source': 'brandt',
         'utm_medium': 'aether',
         'experiment': 'firefox-new',
         'variation': '1',
         'ua': 'chrome'
     }
     final_params = {
         'source': 'brandt',
         'medium': 'aether',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': 'firefox-new',
         'variation': '1',
         'ua': 'chrome',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '8987babc249a7128b3cd32b11623645cc490ae1709e560249176a2622f288a79',
     )
def test_encode_decode(string_num):
    """Check if querystringsafe_base64.encode can be reverted by querystringsafe_base64.decode."""
    original = test_strings[string_num]

    encoded = querystringsafe_base64.encode(original)
    decoded = querystringsafe_base64.decode(encoded)
    assert decoded == original
Пример #30
0
 def test_handles_referrer_no_source(self):
     params = {
         'referrer': 'https://example.com:5000/searchin',
         'utm_medium': 'aether',
     }
     final_params = {
         'source': 'example.com:5000',
         'medium': 'referral',
         'campaign': '(not set)',
         'content': '(not set)',
         'experiment': '(not set)',
         'variation': '(not set)',
         'ua': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(
         querystringsafe_base64.decode(
             data['attribution_code'].encode()).decode())
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         '70461f833cc24a4c16a68fda95629c3f5d6bb377d64ae032679a49b4de016679',
     )
def test_encode_decode_unpad(string_num):
    """Check if querystringsafe_base64.encode can be reverted by querystringsafe_base64.decode with padding removed."""
    original = test_strings[string_num]

    encoded = querystringsafe_base64.encode(original)
    assert len(encoded) % 4 != 0  # make sure it would end with padding
    decoded = querystringsafe_base64.decode(encoded.rstrip())
    assert decoded == original
def test_decode_accepts_regular_base64():
    """Check if querystringsafe_base64.decode can also decode standard base64."""
    # Check if we test with a regular base64 that has all the unsafe chars:
    for char in [b'+', b'/', b'=']:
        assert char in base64_string_with_all_allowed_chars

    assert (querystringsafe_base64.decode(base64_string_with_all_allowed_chars)
            == string_encoding_to_base64_with_all_allowed_characters)
Пример #33
0
 def test_campaign_data_too_long(self):
     """If the code is too long then the utm_campaign value should be truncated"""
     params = {
         'utm_source':
         'brandt',
         'utm_medium':
         'aether',
         'utm_content':
         'A144_A000_0000000',
         'utm_campaign':
         'The%7cDude%7cabides%7cI%7cdont%7cknow%7cabout%7cyou%7c'
         'but%7cI%7ctake%7ccomfort%7cin%7cthat' * 6,
         'experiment':
         '(not set)',
         'variation':
         '(not set)',
         'ua':
         'chrome',
     }
     final_params = {
         'source':
         'brandt',
         'medium':
         'aether',
         'campaign':
         'The|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in'
         '|thatThe|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|thatThe'
         '|Dude|abides|I|dont|know|about|you|but|I|take|comfort|in|thatThe|Dude|abides'
         '|I|dont|know|about|you|but|I|take|comfort|in|thatThe|Dude|abides|I|dont|know'
         '|about|you|but|I|take|comfort|in|thatThe|Dude|abides|I|dont|_',
         'content':
         'A144_A000_0000000',
         'experiment':
         '(not set)',
         'variation':
         '(not set)',
         'ua':
         'chrome',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     code = querystringsafe_base64.decode(
         data['attribution_code'].encode()).decode()
     assert len(code) <= 600
     attrs = parse_qs(code)
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(
         data['attribution_sig'],
         'ed35e1ed1167806f7744bdbb62c4e1d781c8800df6f2dca09fe63877caa9e167',
     )
def test_decode_accepts_regular_base64():
    """Check if querystringsafe_base64.decode can also decode standard base64."""
    # Check if we test with a regular base64 that has all the unsafe chars:
    for char in ['+', '/', '=']:
        assert char in base64_string_with_all_allowed_chars

    assert (
        querystringsafe_base64.decode(
            base64_string_with_all_allowed_chars
        ) == string_encoding_to_base64_with_all_allowed_characters)
def test_querystringsafe_base64_decode_handles_unicode():
    """
    Base64.urlsafe_b64decode called by querystringsafe_base64.decode complains about unicode being passed.

    Check if querystringsafe_base64.decodefixes it.
    """
    base64_unicode = u'DD=='
    base64_str = str(base64_unicode)
    base64dotted_unicode = u'DD..'
    base64dotted_str = str(base64_unicode)

    # urlsafe_b64decode can handle str but breaks on unicode.
    decoded_str = urlsafe_b64decode(base64_str)
    with pytest.raises(TypeError):
        urlsafe_b64decode(base64_unicode)

    # querystringsafe_base64.decode handles str and unicode in both formats.
    assert querystringsafe_base64.decode(base64_unicode) == decoded_str
    assert querystringsafe_base64.decode(base64_str) == decoded_str
    assert querystringsafe_base64.decode(base64dotted_unicode) == decoded_str
    assert querystringsafe_base64.decode(base64dotted_str) == decoded_str
Пример #36
0
 def test_no_valid_param_names(self):
     final_params = {
         'source': 'www.mozilla.org',
         'medium': '(none)',
         'campaign': '(not set)',
         'content': '(not set)',
     }
     req = self._get_request({'dude': 'abides'})
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      '1cdbee664f4e9ea32f14510995b41729a80eddc94cf26dc3c74894c6264c723c')
Пример #37
0
 def test_no_valid_param_names(self):
     final_params = {
         'source': 'www.mozilla.org',
         'medium': '(none)',
         'campaign': '(not set)',
         'content': '(not set)',
         'timestamp': '12345',
     }
     req = self._get_request({'dude': 'abides'})
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      '153c1e8b7d4a582fa245d57d9c28ca9d6bcb65957e41924f826f1e7a5a2f8de9')
Пример #38
0
 def test_some_valid_param_data(self):
     params = {'utm_source': 'brandt', 'utm_content': 'ae<t>her'}
     final_params = {
         'source': 'brandt',
         'medium': '(direct)',
         'campaign': '(not set)',
         'content': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      '37946edae923b50f31f9dc10013dc0d23bed7dc6272611e12af46ff7a8d9d7dc')
Пример #39
0
 def test_returns_valid_data(self):
     params = {'utm_source': 'brandt', 'utm_medium': 'aether'}
     final_params = {
         'source': 'brandt',
         'medium': 'aether',
         'campaign': '(not set)',
         'content': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      'abcbb028f97d08b7f85d194e6d51b8a2d96823208fdd167ff5977786b562af66')
Пример #40
0
 def test_handles_referrer_no_source(self):
     params = {'referrer': 'https://example.com:5000/searchin', 'utm_medium': 'aether'}
     final_params = {
         'source': 'example.com:5000',
         'medium': 'referral',
         'campaign': '(not set)',
         'content': '(not set)',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      '70e177b822f24fa9f8bc8e1caa382204632b3b2548db19bb32b97042c0ef0d47')
Пример #41
0
 def test_returns_valid_data(self):
     params = {'utm_source': 'brandt', 'utm_medium': 'aether'}
     final_params = {
         'source': 'brandt',
         'medium': 'aether',
         'campaign': '(not set)',
         'content': '(not set)',
         'timestamp': '12345',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      'ab55c9b24e230f08d3ad50bf9a3a836ef4405cfb6919cb1df8efe208be38e16d')
Пример #42
0
 def test_handles_referrer_no_source(self):
     params = {'referrer': 'https://example.com:5000/searchin', 'utm_medium': 'aether'}
     final_params = {
         'source': 'example.com:5000',
         'medium': 'referral',
         'campaign': '(not set)',
         'content': '(not set)',
         'timestamp': '12345',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      '6b3dbb178e9abc22db66530df426b17db8590e8251fc153ba443e81ca60e355e')
Пример #43
0
 def test_some_valid_param_data(self):
     params = {'utm_source': 'brandt', 'utm_content': 'ae<t>her'}
     final_params = {
         'source': 'brandt',
         'medium': '(direct)',
         'campaign': '(not set)',
         'content': '(not set)',
         'timestamp': '12345',
     }
     req = self._get_request(params)
     resp = views.stub_attribution_code(req)
     self.assertEqual(resp.status_code, 200)
     assert resp['cache-control'] == 'max-age=300'
     data = json.loads(resp.content)
     # will it blend?
     attrs = parse_qs(querystringsafe_base64.decode(data['attribution_code']))
     # parse_qs returns a dict with lists for values
     attrs = {k: v[0] for k, v in attrs.items()}
     self.assertDictEqual(attrs, final_params)
     self.assertEqual(data['attribution_sig'],
                      'bd6c54115eb1f331b64bec83225a667fa0e16090d7d6abb33dab6305cd858a9d')