Beispiel #1
0
def test_pymongo_insights():
    tree = generate_ast_from_code("""
import pymongo
import ssl

client = pymongo.MongoClient()
    """)
    violations = insights._check_pymongo_common_misconfig(tree, None)
    assert len(violations) == 2

    tree = generate_ast_from_code("""
import pymongo
import ssl

client = pymongo.MongoClient('example.com', ssl=False, ssl_cert_reqs=ssl.CERT_NONE)
    """)
    violations = insights._check_pymongo_common_misconfig(tree, None)
    assert len(violations) == 3

    tree = generate_ast_from_code("""
import pymongo
import ssl

client = pymongo.MongoClient('mongodb://example.com/?ssl=true')
    """)
    violations = insights._check_pymongo_common_misconfig(tree, None)
    assert len(violations) == 1
Beispiel #2
0
def test_pymongo_insights2():
    tree = generate_ast_from_code(
        """
import pymongo
import ssl
from pymongo.encryption import (Algorithm,
                                ClientEncryption)
from pymongo.encryption_options import AutoEncryptionOpts

client = pymongo.MongoClient('mongodb://example.com/?ssl=true')
    """
    )
    violations = insights._check_pymongo_common_misconfig(tree, None)
    assert len(violations) == 1

    tree = generate_ast_from_code(
        """
import pymongo
import ssl
from pymongo.encryption import (Algorithm,
                                ClientEncryption)
from pymongo.encryption_options import AutoEncryptionOpts

client = pymongo.MongoClient('mongodb://example.com/?ssl=true')

client_encryption = ClientEncryption(
        kms_providers,
        key_vault_namespace,
        client,
        coll.codec_options)
    """
    )
    violations = insights._check_pymongo_common_misconfig(tree, None)
    assert not violations

    tree = generate_ast_from_code(
        """
import pymongo
import ssl
from pymongo.encryption import (Algorithm,
                                ClientEncryption)
from pymongo.encryption_options import AutoEncryptionOpts

client = MongoClient('example.com',
                      username='******',
                      password='******',
                      authMechanism='MONGODB-CR')

client_encryption = ClientEncryption(
        kms_providers,
        key_vault_namespace,
        client,
        coll.codec_options)
    """
    )
    violations = insights._check_pymongo_common_misconfig(tree, None)
    assert len(violations) == 1
Beispiel #3
0
def test_pymongo_insights1():
    tree = generate_ast_from_code("""
from pymongo import MongoClient
client = MongoClient('mongodb://example.com/?ssl=true')
    """)
    violations = insights._check_pymongo_common_misconfig(tree, None)
    assert len(violations) == 1