Example #1
0
async def cli_deps(
    filled_graph_db: ArangoGraphDB,
    message_bus: MessageBus,
    event_sender: InMemoryEventSender,
    foo_model: Model,
    task_queue: WorkerTaskQueue,
    worker: Tuple[WorkerTaskDescription, WorkerTaskDescription, WorkerTaskDescription],
    expander: TemplateExpander,
    config_handler: ConfigHandler,
    cert_handler: CertificateHandler,
) -> AsyncIterator[CLIDependencies]:
    db_access = DbAccess(filled_graph_db.db.db, event_sender, NoAdjust(), empty_config())
    model_handler = ModelHandlerStatic(foo_model)
    config = empty_config(["--graphdb-database", "test", "--graphdb-username", "test", "--graphdb-password", "test"])
    deps = CLIDependencies(
        message_bus=message_bus,
        event_sender=event_sender,
        db_access=db_access,
        model_handler=model_handler,
        worker_task_queue=task_queue,
        config=config,
        template_expander=expander,
        forked_tasks=Queue(),
        config_handler=config_handler,
        cert_handler=cert_handler,
    )
    yield deps
    await deps.stop()
Example #2
0
def test_not_existing(system_db: StandardDatabase, test_db: StandardDatabase) -> None:
    access = DbAccess(test_db, NoEventSender(), NoAdjust(), empty_config())

    # foo db and pass does not exist
    foodb = ["--graphdb-username", "foo", "--graphdb-password", "test", "--graphdb-database", "foo"]
    system_db.delete_user("foo", ignore_missing=True)
    system_db.delete_database("foo", ignore_missing=True)
    access.connect(parse_args(foodb), timedelta(seconds=5), sleep_time=0.1)
    assert system_db.has_user("foo")
    assert system_db.has_database("foo")
Example #3
0
def test_already_existing(test_db: StandardDatabase) -> None:
    access = DbAccess(test_db, NoEventSender(), NoAdjust())

    # test db and user already exist
    testdb = [
        "--graphdb-username", "test", "--graphdb-password", "test",
        "--graphdb-database", "test"
    ]
    access.connect(parse_args(testdb),
                   timedelta(seconds=0.01),
                   sleep_time=0.01)
Example #4
0
def test_no_adjust() -> None:
    adjuster = NoAdjust()
    created_at = datetime(2021, 1, 1)
    expires_at = datetime(2022, 2, 1)
    reported: Json = {"ctime": utc_str(created_at)}

    def expect_expires(reported: Json, expires: Optional[str]) -> None:
        result = adjuster.adjust({"reported": reported})
        assert value_in_path(result, ["metadata", "expires"]) == expires

    expect_expires({"tags": {"expires": utc_str(expires_at)}}, None)
    expect_expires({"tags": {"resoto:expires": "2w3d4h5m"}, **reported}, None)
Example #5
0
def test_not_existing_and_default_root_account(
    local_client: ArangoClient, system_db: StandardDatabase, test_db: StandardDatabase
) -> None:
    access = DbAccess(test_db, NoEventSender(), NoAdjust(), empty_config())
    # foo db and pass does not exist
    foodb = ["--graphdb-username", "foo", "--graphdb-password", "bombproof", "--graphdb-database", "foo"]
    system_db.delete_user("foo", ignore_missing=True)
    system_db.delete_database("foo", ignore_missing=True)
    access.connect(parse_args(foodb), timedelta(seconds=5), sleep_time=0.1)

    # The default root account is used and a valid password is given -> also the root account uses this password
    changed_root = local_client.db(username="******", password="******")
    # Rest the password to the default one, to reset the state before the test
    changed_root.replace_user("root", "", True)
Example #6
0
async def graph_db(test_db: StandardDatabase) -> ArangoGraphDB:
    async_db = AsyncArangoDB(test_db)
    graph_db = ArangoGraphDB(async_db, "ns", NoAdjust())
    await graph_db.create_update_schema()
    await async_db.truncate(graph_db.in_progress)
    return graph_db