def test_update_aws_account(self):
        from security_monkey.account_manager import account_registry

        for name, account_manager in account_registry.items():
            manager.add_command("add_account_%s" % name.lower(), AddAccount(account_manager()))

        # Create the account:
        from security_monkey.account_manager import account_registry
        for name, am in account_registry.items():
            if name == "AWS":
                break

        account_manager = am()
        account_manager.create(account_manager.account_type, "test", True, False, "Tests", "99999999999",
                               custom_fields=dict(canonical_id="bcaf1ffd86f41161ca5fb16fd081034f", s3_id=None))

        # Create a second account:
        account_manager.create(account_manager.account_type, "test2", True, False, "Tests", "99999999990",
                               custom_fields=dict(canonical_id="bcaf1ffd86f41161ca5fb16fd081asdf", s3_id=None))

        # Get the ID of the first account:
        id = Account.query.filter(Account.name == "test").one().id

        # Try to rename the account:
        account_manager.update(id, account_manager.account_type, "lololol", True, False, "Tests", "99999999999",
                               custom_fields=dict(canonical_id="bcaf1ffd86f41161ca5fb16fd081034f", s3_id=None))

        assert not Account.query.filter(Account.name == "test").first()
        assert Account.query.filter(Account.name == "lololol").first().id == id

        # Try to update it to an existing name:
        with self.assertRaises(AccountNameExists):
            account_manager.update(id, account_manager.account_type, "test2", True, False, "Tests", "99999999999",
                                   custom_fields=dict(canonical_id="bcaf1ffd86f41161ca5fb16fd081034f", s3_id=None))
示例#2
0
def main():
    from security_monkey.account_manager import account_registry

    for name, account_manager in account_registry.items():
        manager.add_command("add_account_%s" % name.lower(), AddAccount(account_manager()))
    manager.add_command("run_api_server", APIServer())
    manager.run()
    def test_create_aws_account(self):
        from security_monkey.account_manager import account_registry

        for name, account_manager in list(account_registry.items()):
            manager.add_command("add_account_%s" % name.lower(),
                                AddAccount(account_manager()))

        manager.handle("manage.py", [
            "add_account_aws", "-n", "test", "--active", "--id", "99999999999",
            "--canonical_id", "bcaf1ffd86f41161ca5fb16fd081034f",
            "--role_name", "SecurityMonkey"
        ])

        account = Account.query.filter(Account.name == "test").first()
        assert account
        assert account.identifier == "99999999999"
        assert account.active
        assert len(account.custom_fields) == 4

        # Get the canonical ID field:
        c_id = AccountTypeCustomValues.query.filter(
            AccountTypeCustomValues.name == "canonical_id",
            AccountTypeCustomValues.account_id == account.id).first()

        assert c_id
        assert c_id.value == "bcaf1ffd86f41161ca5fb16fd081034f"

        # Already exists:
        assert manager.handle("manage.py", [
            "add_account_aws", "-n", "test", "--active", "--id", "99999999999",
            "--canonical_id", "bcaf1ffd86f41161ca5fb16fd081034f",
            "--role_name", "SecurityMonkey"
        ]) == -1
示例#4
0
    def test_update_account_with_canonical(self):
        from security_monkey.account_manager import account_registry

        for name, account_manager in list(account_registry.items()):
            manager.add_command("add_account_%s" % name.lower(),
                                AddAccount(account_manager()))

        # Update:
        manager.handle("manage.py", [
            "add_account_aws", "-n", "account0", "--active", "--id",
            "012345678910", "--canonical_id",
            "bcaf1ffd86f41161ca5fb16fd081034f", "--s3_name", "test",
            "--role_name", "SecurityMonkey", "--update-existing"
        ])

        account = Account.query.filter(Account.name == "account0").first()
        assert account
        assert account.identifier == "012345678910"
        assert account.active
        assert len(account.custom_fields) == 4

        # Get the canonical ID field:
        c_id = AccountTypeCustomValues.query.filter(
            AccountTypeCustomValues.name == "canonical_id",
            AccountTypeCustomValues.account_id == account.id).first()

        assert c_id
        assert c_id.value == "bcaf1ffd86f41161ca5fb16fd081034f"
    def test_create_account_with_canonical(self):
        from security_monkey.account_manager import account_registry

        for name, account_manager in account_registry.items():
            manager.add_command("add_account_%s" % name.lower(), AddAccount(account_manager()))

        manager.handle("manage.py", ["add_account_aws", "-n", "test", "--active", "--id", "99999999999",
                                     "--canonical_id", "bcaf1ffd86f41161ca5fb16fd081034f", "--s3_name", "test",
                                     "--role_name", "SecurityMonkey"])

        account = Account.query.filter(Account.name == "test").first()
        assert account
        assert account.identifier == "99999999999"
        assert account.active
        assert len(account.custom_fields) == 3

        # Get the canonical ID field:
        c_id = AccountTypeCustomValues.query.filter(AccountTypeCustomValues.name == "canonical_id",
                                                    AccountTypeCustomValues.account_id == account.id).first()

        assert c_id
        assert c_id.value == "bcaf1ffd86f41161ca5fb16fd081034f"

        assert manager.handle("manage.py", ["add_account_aws", "-n", "test", "--active", "--id", "99999999999",
                                            "--canonical_id", "bcaf1ffd86f41161ca5fb16fd081034f", "--s3_name", "test",
                                            "--role_name", "SecurityMonkey"]) == -1
def main():
    from security_monkey.account_manager import account_registry

    for name, account_manager in list(account_registry.items()):
        manager.add_command("add_account_%s" % name.lower(), AddAccount(account_manager()))
    manager.add_command("run_api_server", APIServer())
    manager.run()
    def test_update_aws_account(self):
        from security_monkey.account_manager import account_registry

        for name, account_manager in list(account_registry.items()):
            manager.add_command("add_account_%s" % name.lower(),
                                AddAccount(account_manager()))

        # Create the account:
        from security_monkey.account_manager import account_registry
        for name, am in list(account_registry.items()):
            if name == "AWS":
                break

        account_manager = am()
        account_manager.create(
            account_manager.account_type,
            "test",
            True,
            False,
            "Tests",
            "99999999999",
            custom_fields=dict(canonical_id="bcaf1ffd86f41161ca5fb16fd081034f",
                               s3_id=None))

        # Create a second account:
        account_manager.create(
            account_manager.account_type,
            "test2",
            True,
            False,
            "Tests",
            "99999999990",
            custom_fields=dict(canonical_id="bcaf1ffd86f41161ca5fb16fd081asdf",
                               s3_id=None))

        # Get the ID of the first account:
        id = Account.query.filter(Account.name == "test").one().id

        # Try to rename the account:
        account_manager.update(
            id,
            account_manager.account_type,
            "lololol",
            True,
            False,
            "Tests",
            "99999999999",
            custom_fields=dict(canonical_id="bcaf1ffd86f41161ca5fb16fd081034f",
                               s3_id=None))

        assert not Account.query.filter(Account.name == "test").first()
        assert Account.query.filter(Account.name == "lololol").first().id == id

        # Try to update it to an existing name:
        with self.assertRaises(AccountNameExists):
            account_manager.update(
                id,
                account_manager.account_type,
                "test2",
                True,
                False,
                "Tests",
                "99999999999",
                custom_fields=dict(
                    canonical_id="bcaf1ffd86f41161ca5fb16fd081034f",
                    s3_id=None))