예제 #1
0
 def test_os_already_set(self):
     self.data['contexts'] = {'os': {'name': 'C64', 'version': '1337'}}
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'Chrome'
     assert self.data['contexts']['browser']['version'] == '66.0.3359'
     assert self.data['contexts']['os']['name'] == 'C64'
     assert self.data['contexts']['os']['version'] == '1337'
예제 #2
0
    def _normalize_impl(self):
        if self._normalized:
            raise RuntimeError('Already normalized')
        self._normalized = True

        from semaphore.processing import StoreNormalizer
        rust_normalizer = StoreNormalizer(
            geoip_lookup=rust_geoip,
            project_id=self._project.id if self._project else None,
            client_ip=self._client_ip,
            client=self._auth.client if self._auth else None,
            key_id=six.text_type(self._key.id) if self._key else None,
            grouping_config=self._grouping_config,
            protocol_version=six.text_type(self.version) if self.version is not None else None,
            stacktrace_frames_hard_limit=settings.SENTRY_STACKTRACE_FRAMES_HARD_LIMIT,
            max_stacktrace_frames=settings.SENTRY_MAX_STACKTRACE_FRAMES,
            valid_platforms=list(VALID_PLATFORMS),
            max_secs_in_future=MAX_SECS_IN_FUTURE,
            max_secs_in_past=MAX_SECS_IN_PAST,
            enable_trimming=True,
            is_renormalize=self._is_renormalize,
            remove_other=self._remove_other,
        )

        self._data = CanonicalKeyDict(
            rust_normalizer.normalize_event(dict(self._data))
        )

        normalize_user_agent(self._data)
예제 #3
0
 def test_contexts_none(self):
     self.data['contexts'] = None
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'Chrome'
     assert self.data['contexts']['browser']['version'] == '66.0.3359'
     assert self.data['contexts']['os']['name'] == 'Mac OS X'
     assert self.data['contexts']['os']['version'] == '10.13.4'
예제 #4
0
 def test_browser_already_set(self):
     self.data['contexts'] = {'browser': {'name': 'IE', 'version': '6'}}
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'IE'
     assert self.data['contexts']['browser']['version'] == '6'
     assert self.data['contexts']['os']['name'] == 'Mac OS X'
     assert self.data['contexts']['os']['version'] == '10.13.4'
예제 #5
0
 def test_broken_ua(self):
     self.data = {'request':
                  {'headers': [
                      [
                          'User-Agent',
                          'xx'
                      ]
                  ]}
                  }
     normalize_user_agent(self.data)
     assert self.data['contexts'] == {}
예제 #6
0
 def test_device_none(self):
     self.data = {
         'request': {
             'headers': [[
                 'User-Agent',
                 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
             ]],
         },
     }
     self.data['contexts'] = {'device': None}
     normalize_user_agent(self.data)
     assert self.data['contexts']['device']['brand'] == 'Apple'
     assert self.data['contexts']['device']['family'] == 'iPhone'
     assert self.data['contexts']['device']['model'] == 'iPhone'
예제 #7
0
 def test_partial_browser_ua(self):
     self.data = {'request':
                  {'headers': [
                      [
                          'User-Agent',
                          'Mozilla/5.0  Version/12.0 Mobile/15E148 Safari/604.1'
                      ]
                  ]}
                  }
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'Safari'
     assert self.data['contexts']['browser']['version'] == '12.0'
     assert 'os' not in self.data['contexts']
     assert 'device' not in self.data['contexts']
예제 #8
0
 def test_device_already_set(self):
     self.data = {'request':
                  {'headers': [
                      [
                          'User-Agent',
                          'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1'
                      ]
                  ]}
                  }
     self.data['contexts'] = {'device': {'brand': 'TI Calculator'}}
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'Mobile Safari'
     assert self.data['contexts']['browser']['version'] == '12.0'
     assert self.data['contexts']['os']['name'] == 'iOS'
     assert self.data['contexts']['os']['version'] == '12.1'
     assert self.data['contexts']['device']['brand'] == 'TI Calculator'
예제 #9
0
 def test_browser_device_os_parsed(self):
     self.data = {'request':
                  {'headers': [
                      [
                          'User-Agent',
                          'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1'
                      ]
                  ]}
                  }
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'Mobile Safari'
     assert self.data['contexts']['browser']['version'] == '12.0'
     assert self.data['contexts']['os']['name'] == 'iOS'
     assert self.data['contexts']['os']['version'] == '12.1'
     assert self.data['contexts']['device']['brand'] == 'Apple'
     assert self.data['contexts']['device']['family'] == 'iPhone'
     assert self.data['contexts']['device']['model'] == 'iPhone'
예제 #10
0
 def test_os_none(self):
     self.data['contexts'] = {'os': None}
     normalize_user_agent(self.data)
     assert self.data['contexts']['os']['name'] == 'Mac OS X'
     assert self.data['contexts']['os']['version'] == '10.13.4'
예제 #11
0
 def test_browser_none(self):
     self.data['contexts'] = {'browser': None}
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'Chrome'
     assert self.data['contexts']['browser']['version'] == '66.0.3359'
예제 #12
0
 def test_broken_ua(self):
     self.data = {'request': {'headers': [['User-Agent', 'xx']]}}
     normalize_user_agent(self.data)
     assert self.data['contexts'] == {}
예제 #13
0
 def test_headers_wrong_format(self):
     self.data = {'request': {'headers': ['UA', 'a']}}
     normalize_user_agent(self.data)
     assert 'contexts' not in self.data
예제 #14
0
 def test_headers_wrong_format(self):
     self.data = {'request': {'headers': ['UA', 'a']}}
     normalize_user_agent(self.data)
     assert 'contexts' not in self.data
예제 #15
0
 def test_no_headers(self):
     self.data = {'request': {}}
     normalize_user_agent(self.data)
     assert 'contexts' not in self.data
예제 #16
0
 def test_browser_none(self):
     self.data['contexts'] = {'browser': None}
     normalize_user_agent(self.data)
     assert self.data['contexts']['browser']['name'] == 'Chrome'
     assert self.data['contexts']['browser']['version'] == '66.0.3359'
예제 #17
0
 def test_no_headers(self):
     self.data = {'request': {}}
     normalize_user_agent(self.data)
     assert 'contexts' not in self.data
예제 #18
0
 def test_os_none(self):
     self.data['contexts'] = {'os': None}
     normalize_user_agent(self.data)
     assert self.data['contexts']['os']['name'] == 'Mac OS X'
     assert self.data['contexts']['os']['version'] == '10.13.4'
예제 #19
0
 def test_headers_but_no_ua(self):
     self.data = {'request': {'headers': [['UA', 'a']]}}
     normalize_user_agent(self.data)
     assert 'contexts' not in self.data
예제 #20
0
 def test_headers_but_no_ua(self):
     self.data = {'request': {'headers': [['UA', 'a']]}}
     normalize_user_agent(self.data)
     assert 'contexts' not in self.data