mirror of https://gitlab.com/bashrc2/epicyon
				
				
				
			Fix unit test
							parent
							
								
									387f68acc9
								
							
						
					
					
						commit
						f188fd3486
					
				|  | @ -245,7 +245,6 @@ from languages import set_actor_languages | |||
| from languages import get_understood_languages | ||||
| from like import update_likes_collection | ||||
| from reaction import update_reaction_collection | ||||
| from utils import get_domain_from_url_in_string | ||||
| from utils import local_network_host | ||||
| from utils import undo_reaction_collection_entry | ||||
| from utils import get_new_post_endpoints | ||||
|  | @ -13472,10 +13471,10 @@ class PubServer(BaseHTTPRequestHandler): | |||
|         referer_domain = None | ||||
|         if self.headers.get('referer'): | ||||
|             referer_domain = \ | ||||
|                 get_domain_from_url_in_string(self.headers['referer']) | ||||
|                 user_agent_domain(self.headers['referer'], self.server.debug) | ||||
|         elif self.headers.get('Referer'): | ||||
|             referer_domain = \ | ||||
|                 get_domain_from_url_in_string(self.headers['Referer']) | ||||
|                 user_agent_domain(self.headers['Referer'], self.server.debug) | ||||
|         elif self.headers.get('Signature'): | ||||
|             if 'keyId="' in self.headers['Signature']: | ||||
|                 referer_domain = self.headers['Signature'].split('keyId="')[1] | ||||
|  | @ -13486,7 +13485,7 @@ class PubServer(BaseHTTPRequestHandler): | |||
|                 elif '"' in referer_domain: | ||||
|                     referer_domain = referer_domain.split('"')[0] | ||||
|         elif ua_str: | ||||
|             referer_domain = get_domain_from_url_in_string(ua_str) | ||||
|             referer_domain = user_agent_domain(ua_str, self.server.debug) | ||||
|         return referer_domain | ||||
| 
 | ||||
|     def _get_user_agent(self) -> str: | ||||
|  |  | |||
|  | @ -10,6 +10,9 @@ echo "Starting static analysis" | |||
| 
 | ||||
| for sourceFile in *.py | ||||
| do | ||||
|     if [[ "$sourceFile" == *"flycheck"* ]]; then | ||||
| 	continue | ||||
|     fi | ||||
|     result=$($cmd "$sourceFile") | ||||
|     if [ "$result" ]; then | ||||
| 	echo '' | ||||
|  |  | |||
							
								
								
									
										5
									
								
								tests.py
								
								
								
								
							
							
						
						
									
										5
									
								
								tests.py
								
								
								
								
							|  | @ -5867,7 +5867,10 @@ def _test_useragent_domain() -> None: | |||
|     print('test_user_agent_domain') | ||||
|     user_agent = \ | ||||
|         'http.rb/4.4.1 (Mastodon/9.10.11; +https://mastodon.something/)' | ||||
|     assert user_agent_domain(user_agent, False) == 'mastodon.something' | ||||
|     agent_domain = user_agent_domain(user_agent, False) | ||||
|     if agent_domain != 'mastodon.something': | ||||
|         print(agent_domain) | ||||
|     assert agent_domain == 'mastodon.something' | ||||
|     user_agent = \ | ||||
|         'Mozilla/70.0 (X11; Linux x86_64; rv:1.0) Gecko/20450101 Firefox/1.0' | ||||
|     assert user_agent_domain(user_agent, False) is None | ||||
|  |  | |||
							
								
								
									
										29
									
								
								utils.py
								
								
								
								
							
							
						
						
									
										29
									
								
								utils.py
								
								
								
								
							|  | @ -2891,11 +2891,13 @@ def user_agent_domain(user_agent: str, debug: bool) -> str: | |||
|     """If the User-Agent string contains a domain | ||||
|     then return it | ||||
|     """ | ||||
|     if 'http' not in user_agent: | ||||
|     if 'https://' not in user_agent and 'http://' not in user_agent: | ||||
|         return None | ||||
|     agent_domain = user_agent.split('http')[1].strip() | ||||
|     if '://' in agent_domain: | ||||
|         agent_domain = agent_domain.split('://')[1] | ||||
|     agent_domain = '' | ||||
|     if 'https://' in user_agent: | ||||
|         agent_domain = user_agent.split('https://')[1].strip() | ||||
|     else: | ||||
|         agent_domain = user_agent.split('http://')[1].strip() | ||||
|     if '/' in agent_domain: | ||||
|         agent_domain = agent_domain.split('/')[0] | ||||
|     if ')' in agent_domain: | ||||
|  | @ -3323,22 +3325,3 @@ def valid_hash_tag(hashtag: str) -> bool: | |||
|     if _is_valid_language(hashtag): | ||||
|         return True | ||||
|     return False | ||||
| 
 | ||||
| 
 | ||||
| def get_domain_from_url_in_string(text: str) -> str: | ||||
|     """Returns the domain from within a string if it exists | ||||
|     """ | ||||
|     domain_str = '' | ||||
|     if 'https://' in text: | ||||
|         domain_str = text.split('https://')[1] | ||||
|         if '/' in domain_str: | ||||
|             domain_str = domain_str.split('/')[0] | ||||
|         elif ')' in domain_str: | ||||
|             domain_str = domain_str.split(')')[0] | ||||
|     elif 'http://' in text: | ||||
|         domain_str = text.split('http://')[1] | ||||
|         if '/' in domain_str: | ||||
|             domain_str = domain_str.split('/')[0] | ||||
|         elif ')' in domain_str: | ||||
|             domain_str = domain_str.split(')')[0] | ||||
|     return domain_str | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue