def test_get_url_private_dotted_name(botomock): def mock_api_call(self, operation_name, api_params): assert operation_name == 'ListObjectsV2' if api_params['Prefix'].endswith('xxx.sym'): # not found return {} return { 'Contents': [{ 'Key': api_params['Prefix'], }], } urls = ('https://s3.example.com/com.example.private/prefix/', ) downloader = SymbolDownloader(urls) with botomock(mock_api_call): url = downloader.get_symbol_url('xul.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xul.sym') assert ('/com.example.private/prefix/v0/xul.pdb/' '44E4EC8C2F41492B9369D6B9A059577C2/xul.sym?') in url url = downloader.get_symbol_url('xxx.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xxx.sym') assert url is None assert len(botomock.calls) == 2
def test_get_url_private_caching_and_invalidation(botomock): mock_calls = [] def mock_api_call(self, operation_name, api_params): assert operation_name == 'ListObjectsV2' mock_calls.append(api_params['Prefix']) return { 'Contents': [{ 'Key': api_params['Prefix'], }], } urls = ('https://s3.example.com/private/prefix/', ) downloader = SymbolDownloader(urls) with botomock(mock_api_call): assert downloader.get_symbol_url('xul.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xul.sym') assert len(mock_calls) == 1 assert downloader.get_symbol_url('xul.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xul.sym') # This should be cached assert len(mock_calls) == 1 # Now invalidate it downloader.invalidate_cache('xul.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xul.sym') assert downloader.get_symbol_url('xul.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xul.sym') assert len(mock_calls) == 2
def test_get_url_private(botomock): def mock_api_call(self, operation_name, api_params): assert operation_name == 'ListObjectsV2' if api_params['Prefix'].endswith('xxx.sym'): # not found return {} return { 'Contents': [{ 'Key': api_params['Prefix'], }], } urls = ('https://s3.example.com/private/prefix/', ) downloader = SymbolDownloader(urls) with botomock(mock_api_call): url = downloader.get_symbol_url('xul.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xul.sym') # The bucket gets put in the top-domain. assert url.startswith('https://s3.example.com/') assert ('/private/prefix/v0/xul.pdb/' '44E4EC8C2F41492B9369D6B9A059577C2/xul.sym?') in url assert 'Expires=' in url assert 'AWSAccessKeyId=' in url assert 'Signature=' in url url = downloader.get_symbol_url('xxx.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xxx.sym') assert url is None assert len(botomock.calls) == 2
def test_get_url_private(botomock): def mock_api_call(self, operation_name, api_params): assert operation_name == "ListObjectsV2" if api_params["Prefix"].endswith("xxx.sym"): # not found return {} return {"Contents": [{"Key": api_params["Prefix"]}]} urls = ("https://s3.example.com/private/prefix/", ) downloader = SymbolDownloader(urls) with botomock(mock_api_call): url = downloader.get_symbol_url("xul.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xul.sym") # The bucket gets put in the top-domain. assert url.startswith("https://s3.example.com/") assert ("/private/prefix/v0/xul.pdb/" "44E4EC8C2F41492B9369D6B9A059577C2/xul.sym?") in url assert "Expires=" in url assert "AWSAccessKeyId=" in url assert "Signature=" in url url = downloader.get_symbol_url("xxx.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xxx.sym") assert url is None assert len(botomock.calls) == 2
def test_get_url_private_caching_and_invalidation(botomock): mock_calls = [] def mock_api_call(self, operation_name, api_params): assert operation_name == "ListObjectsV2" mock_calls.append(api_params["Prefix"]) return {"Contents": [{"Key": api_params["Prefix"]}]} urls = ("https://s3.example.com/private/prefix/", ) downloader = SymbolDownloader(urls) with botomock(mock_api_call): assert downloader.get_symbol_url("xul.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xul.sym") assert len(mock_calls) == 1 assert downloader.get_symbol_url("xul.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xul.sym") # This should be cached assert len(mock_calls) == 1 # Now invalidate it downloader.invalidate_cache("xul.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xul.sym") assert downloader.get_symbol_url("xul.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xul.sym") assert len(mock_calls) == 2
def test_get_url_public(requestsmock): requestsmock.head( 'https://s3.example.com/public/prefix/v0/xul.pdb/' '44E4EC8C2F41492B9369D6B9A059577C2/xul.sym', text='') requestsmock.head( 'https://s3.example.com/public/prefix/v0/xxx.pdb/' '44E4EC8C2F41492B9369D6B9A059577C2/xxx.sym', text='Page Not Found', status_code=404, ) urls = ('https://s3.example.com/public/prefix/?access=public', ) downloader = SymbolDownloader(urls) url = downloader.get_symbol_url('xul.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xul.sym') assert url == ('https://s3.example.com/public/prefix/v0/xul.pdb/' '44E4EC8C2F41492B9369D6B9A059577C2/xul.sym') url = downloader.get_symbol_url('xxx.pdb', '44E4EC8C2F41492B9369D6B9A059577C2', 'xxx.sym') assert url is None
def test_get_url_private_dotted_name(botomock): def mock_api_call(self, operation_name, api_params): assert operation_name == "ListObjectsV2" if api_params["Prefix"].endswith("xxx.sym"): # not found return {} return {"Contents": [{"Key": api_params["Prefix"]}]} urls = ("https://s3.example.com/com.example.private/prefix/", ) downloader = SymbolDownloader(urls) with botomock(mock_api_call): url = downloader.get_symbol_url("xul.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xul.sym") assert ("/com.example.private/prefix/v0/xul.pdb/" "44E4EC8C2F41492B9369D6B9A059577C2/xul.sym?") in url url = downloader.get_symbol_url("xxx.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xxx.sym") assert url is None assert len(botomock.calls) == 2
def test_get_url_public(requestsmock): requestsmock.head( "https://s3.example.com/public/prefix/v0/xul.pdb/" "44E4EC8C2F41492B9369D6B9A059577C2/xul.sym", text="", ) requestsmock.head( "https://s3.example.com/public/prefix/v0/xxx.pdb/" "44E4EC8C2F41492B9369D6B9A059577C2/xxx.sym", text="Page Not Found", status_code=404, ) urls = ("https://s3.example.com/public/prefix/?access=public", ) downloader = SymbolDownloader(urls) url = downloader.get_symbol_url("xul.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xul.sym") assert url == ("https://s3.example.com/public/prefix/v0/xul.pdb/" "44E4EC8C2F41492B9369D6B9A059577C2/xul.sym") url = downloader.get_symbol_url("xxx.pdb", "44E4EC8C2F41492B9369D6B9A059577C2", "xxx.sym") assert url is None