Exemplo n.º 1
0
def test_load_elastic_pools_relationships(neo4j_session):
    # Create Test Azure SQL Server
    sql.load_server_data(
        neo4j_session,
        TEST_SUBSCRIPTION_ID,
        DESCRIBE_SERVERS,
        TEST_UPDATE_TAG,
    )

    sql._load_elastic_pools(
        neo4j_session,
        DESCRIBE_ELASTIC_POOLS,
        TEST_UPDATE_TAG,
    )

    expected = {
        (
            server1,
            server1 + "/elasticPools/EP1",
        ),
        (
            server2,
            server2 + "/elasticPools/EP2",
        ),
    }

    # Fetch relationships
    result = neo4j_session.run(
        """
        MATCH (n1:AzureSQLServer)-[:RESOURCE]->(n2:AzureElasticPool) RETURN n1.id, n2.id;
        """, )

    actual = {(r['n1.id'], r['n2.id']) for r in result}

    assert actual == expected
Exemplo n.º 2
0
def test_load_databases_relationships(neo4j_session):
    # Create Test Azure SQL Server
    sql.load_server_data(
        neo4j_session,
        TEST_SUBSCRIPTION_ID,
        DESCRIBE_SERVERS,
        TEST_UPDATE_TAG,
    )

    sql._load_databases(
        neo4j_session,
        DESCRIBE_DATABASES,
        TEST_UPDATE_TAG,
    )

    expected = {
        (
            server1,
            server1 + "/databases/testdb1",
        ),
        (
            server2,
            server2 + "/databases/testdb2",
        ),
    }

    # Fetch relationships
    result = neo4j_session.run(
        """
        MATCH (n1:AzureSQLServer)-[:RESOURCE]->(n2:AzureSQLDatabase) RETURN n1.id, n2.id;
        """, )

    actual = {(r['n1.id'], r['n2.id']) for r in result}

    assert actual == expected
Exemplo n.º 3
0
def test_load_failover_groups_relationships(neo4j_session):
    # Create Test Azure SQL Server
    sql.load_server_data(
        neo4j_session,
        TEST_SUBSCRIPTION_ID,
        DESCRIBE_SERVERS,
        TEST_UPDATE_TAG,
    )

    sql._load_failover_groups(
        neo4j_session,
        DESCRIBE_FAILOVER_GROUPS,
        TEST_UPDATE_TAG,
    )

    expected = {
        (
            server1,
            server1 + "/failoverGroups/FG1",
        ),
        (
            server2,
            server2 + "/failoverGroups/FG1",
        ),
    }

    # Fetch relationships
    result = neo4j_session.run(
        """
        MATCH (n1:AzureSQLServer)-[:RESOURCE]->(n2:AzureFailoverGroup) RETURN n1.id, n2.id;
        """, )

    actual = {(r['n1.id'], r['n2.id']) for r in result}

    assert actual == expected
Exemplo n.º 4
0
def test_load_server_dns_aliases_relationships(neo4j_session):
    # Create Test Azure SQL Server
    sql.load_server_data(
        neo4j_session,
        TEST_SUBSCRIPTION_ID,
        DESCRIBE_SERVERS,
        TEST_UPDATE_TAG,
    )

    sql._load_server_dns_aliases(
        neo4j_session,
        DESCRIBE_DNS_ALIASES,
        TEST_UPDATE_TAG,
    )

    expected = {
        (
            server1,
            server1 + "/dnsAliases/dns-alias-1",
        ),
        (
            server2,
            server2 + "/dnsAliases/dns-alias-2",
        ),
    }

    # Fetch relationships
    result = neo4j_session.run(
        """
        MATCH (n1:AzureSQLServer)-[:USED_BY]->(n2:AzureServerDNSAlias) RETURN n1.id, n2.id;
        """, )

    actual = {(r['n1.id'], r['n2.id']) for r in result}

    assert actual == expected
Exemplo n.º 5
0
def test_load_servers(neo4j_session):
    sql.load_server_data(
        neo4j_session,
        TEST_SUBSCRIPTION_ID,
        DESCRIBE_SERVERS,
        TEST_UPDATE_TAG,
    )

    expected_nodes = {
        server1,
        server2,
    }

    nodes = neo4j_session.run(
        """
        MATCH (r:AzureSQLServer) RETURN r.id;
        """, )
    actual_nodes = {n['r.id'] for n in nodes}

    assert actual_nodes == expected_nodes
Exemplo n.º 6
0
def test_load_server_relationships(neo4j_session):
    # Create Test Azure Subscription
    neo4j_session.run(
        """
        MERGE (as:AzureSubscription{id: {subscription_id}})
        ON CREATE SET as.firstseen = timestamp()
        SET as.lastupdated = {update_tag}
        """,
        subscription_id=TEST_SUBSCRIPTION_ID,
        update_tag=TEST_UPDATE_TAG,
    )

    sql.load_server_data(
        neo4j_session,
        TEST_SUBSCRIPTION_ID,
        DESCRIBE_SERVERS,
        TEST_UPDATE_TAG,
    )

    expected = {
        (
            TEST_SUBSCRIPTION_ID,
            server1,
        ),
        (
            TEST_SUBSCRIPTION_ID,
            server2,
        ),
    }

    # Fetch relationships
    result = neo4j_session.run(
        """
        MATCH (n1:AzureSubscription)-[:RESOURCE]->(n2:AzureSQLServer) RETURN n1.id, n2.id;
        """, )

    actual = {(r['n1.id'], r['n2.id']) for r in result}

    assert actual == expected
Exemplo n.º 7
0
def test_load_server_ad_admins_relationships(neo4j_session):
    # Create Test Azure SQL Server
    sql.load_server_data(
        neo4j_session,
        TEST_SUBSCRIPTION_ID,
        DESCRIBE_SERVERS,
        TEST_UPDATE_TAG,
    )

    sql._load_server_ad_admins(
        neo4j_session,
        DESCRIBE_AD_ADMINS,
        TEST_UPDATE_TAG,
    )

    expected = {
        (
            server1,
            server1 +
            "/providers/Microsoft.Sql/administrators/ActiveDirectory1",
        ),
        (
            server2,
            server2 +
            "/providers/Microsoft.Sql/administrators/ActiveDirectory2",
        ),
    }

    # Fetch relationships
    result = neo4j_session.run(
        """
        MATCH (n1:AzureSQLServer)-[:ADMINISTERED_BY]->(n2:AzureServerADAdministrator) RETURN n1.id, n2.id;
        """, )

    actual = {(r['n1.id'], r['n2.id']) for r in result}

    assert actual == expected