| 
 | 1 | +"""  | 
 | 2 | +Testing overall configuration of the MCP server.  | 
 | 3 | +"""  | 
 | 4 | + | 
 | 5 | + | 
 | 6 | +def test_api_url_format() -> None:  | 
 | 7 | +    """  | 
 | 8 | +    Test that the API URL is formatted correctly.  | 
 | 9 | +    This test checks if the public API URL is constructed properly  | 
 | 10 | +    when the old API format is not used.  | 
 | 11 | +    """  | 
 | 12 | +    from utils.sysdig.client_config import _get_public_api_url  | 
 | 13 | + | 
 | 14 | +    # URL regions refer to https://docs.sysdig.com/en/administration/saas-regions-and-ip-ranges/  | 
 | 15 | +    region_urls = {  | 
 | 16 | +        "us1": {"url": "https://secure.sysdig.com", "public_url": "https://api.us1.sysdig.com"},  | 
 | 17 | +        "us2": {"url": "https://us2.app.sysdig.com", "public_url": "https://api.us2.sysdig.com"},  | 
 | 18 | +        "eu1": {"url": "https://eu1.app.sysdig.com", "public_url": "https://api.eu1.sysdig.com"},  | 
 | 19 | +        "au1": {"url": "https://app.au1.sysdig.com", "public_url": "https://api.au1.sysdig.com"},  | 
 | 20 | +        "me2": {"url": "https://app.me2.sysdig.com", "public_url": "https://api.me2.sysdig.com"},  | 
 | 21 | +        # Edge case that does not follow the standard pattern it should return the same passed URL  | 
 | 22 | +        "edge": {"url": "https://edge.something.com", "public_url": "https://edge.something.com"},  | 
 | 23 | +    }  | 
 | 24 | + | 
 | 25 | +    # Check if the public API URL is formatted correctly  | 
 | 26 | +    public_api_us1 = _get_public_api_url(region_urls["us1"]["url"])  | 
 | 27 | +    public_api_us2 = _get_public_api_url(region_urls["us2"]["url"])  | 
 | 28 | +    public_api_eu1 = _get_public_api_url(region_urls["eu1"]["url"])  | 
 | 29 | +    public_api_au1 = _get_public_api_url(region_urls["au1"]["url"])  | 
 | 30 | +    public_api_me2 = _get_public_api_url(region_urls["me2"]["url"])  | 
 | 31 | +    public_api_edge = _get_public_api_url(region_urls["edge"]["url"])  | 
 | 32 | + | 
 | 33 | +    assert public_api_us1 == region_urls["us1"]["public_url"], (  | 
 | 34 | +        f"Expected {region_urls['us1']['public_url']}, got {public_api_us1}"  | 
 | 35 | +    )  | 
 | 36 | +    assert public_api_us2 == region_urls["us2"]["public_url"], (  | 
 | 37 | +        f"Expected {region_urls['us2']['public_url']}, got {public_api_us2}"  | 
 | 38 | +    )  | 
 | 39 | +    assert public_api_eu1 == region_urls["eu1"]["public_url"], (  | 
 | 40 | +        f"Expected {region_urls['eu1']['public_url']}, got {public_api_eu1}"  | 
 | 41 | +    )  | 
 | 42 | +    assert public_api_au1 == region_urls["au1"]["public_url"], (  | 
 | 43 | +        f"Expected {region_urls['au1']['public_url']}, got {public_api_au1}"  | 
 | 44 | +    )  | 
 | 45 | +    assert public_api_me2 == region_urls["me2"]["public_url"], (  | 
 | 46 | +        f"Expected {region_urls['me2']['public_url']}, got {public_api_me2}"  | 
 | 47 | +    )  | 
 | 48 | +    assert public_api_edge == region_urls["edge"]["public_url"], (  | 
 | 49 | +        f"Expected {region_urls['edge']['public_url']}, got {public_api_edge}"  | 
 | 50 | +    )  | 
 | 51 | +    print("All public API URLs are formatted correctly.")  | 
0 commit comments