示例#1
0
void test_KineticSession_Connect_should_connect_to_specified_host(void)
{
    const uint8_t hmacKey[] = {1, 6, 3, 5, 4, 8, 19};

    KineticSession expected = {
        .config = (KineticSessionConfig) {
            .host = "valid-host.com",
            .port = 1234,
            .clusterVersion = 17,
            .identity = 12,
            .hmacKey = {
                .data = expected.config.keyData,
                .len = sizeof(hmacKey)},
        },
        .connected = true,
        .socket = 24,
    };
    memcpy(expected.config.hmacKey.data,
        hmacKey, expected.config.hmacKey.len);

    KineticSession session = {
        .config = (KineticSessionConfig) {
            .host = "valid-host.com",
            .port = expected.config.port,
            .clusterVersion = expected.config.clusterVersion,
            .identity = expected.config.identity,
            .hmacKey = {
                .data = Session.config.keyData,
                .len = sizeof(hmacKey)},
        },
        .connected = true,
        .socket = 24,
    };
    memcpy(session.config.hmacKey.data,
        hmacKey, expected.config.hmacKey.len);

    KineticSocket_Connect_ExpectAndReturn(expected.config.host, expected.config.port, expected.socket);
    Bus_RegisterSocket_ExpectAndReturn(NULL, BUS_SOCKET_PLAIN,
        expected.socket, &session, true);
    KineticResourceWaiter_WaitTilAvailable_ExpectAndReturn(&session.connectionReady,
        KINETIC_CONNECTION_TIMEOUT_SECS, true);

    // Establish connection
    KineticStatus status = KineticSession_Connect(&session);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
    TEST_ASSERT_TRUE(session.connected);
    TEST_ASSERT_EQUAL(expected.socket, session.socket);
    TEST_ASSERT_EQUAL_STRING(expected.config.host, session.config.host);
    TEST_ASSERT_EQUAL(expected.config.port, session.config.port);
    TEST_ASSERT_EQUAL_INT64(expected.config.clusterVersion, session.config.clusterVersion);
    TEST_ASSERT_EQUAL_INT64(expected.config.identity, session.config.identity);
    TEST_ASSERT_EQUAL_ByteArray(expected.config.hmacKey, session.config.hmacKey);
}
示例#2
0
void test_KineticSession_Connect_should_report_a_failed_connection(void)
{
    TEST_ASSERT_EQUAL_STRING(Session.config.host, "somehost.com");
    TEST_ASSERT_EQUAL(17, Session.config.port);

    KineticSocket_Connect_ExpectAndReturn("somehost.com", 17, KINETIC_SOCKET_DESCRIPTOR_INVALID);

    KineticStatus status = KineticSession_Connect(&Session);

    TEST_ASSERT_EQUAL(KINETIC_STATUS_CONNECTION_ERROR, status);
    TEST_ASSERT_FALSE(Session.connected);
    TEST_ASSERT_EQUAL(KINETIC_SOCKET_DESCRIPTOR_INVALID, Session.socket);
}
示例#3
0
void test_KineticSession_Connect_should_report_a_failure_to_receive_initialization_info_from_device(void)
{
    const uint8_t hmacKey[] = {1, 6, 3, 5, 4, 8, 19};
    KineticSession expected = {
        .config = (KineticSessionConfig) {
            .host = "valid-host.com",
            .port = 1234,
            .clusterVersion = 17,
            .identity = 12,
            .hmacKey = {
                .data = expected.config.keyData,
                .len = sizeof(hmacKey)},
        },
        .connected = true,
        .socket = 24,
    };
    memcpy(expected.config.hmacKey.data,
        hmacKey, expected.config.hmacKey.len);

    KineticSession session = {
        .config = (KineticSessionConfig) {
            .host = "valid-host.com",
            .port = expected.config.port,
            .clusterVersion = expected.config.clusterVersion,
            .identity = expected.config.identity,
            .hmacKey = {
                .data = Session.config.keyData,
                .len = sizeof(hmacKey)},
        },
        .connected = true,
        .socket = 24,
    };
    memcpy(session.config.hmacKey.data,
        hmacKey, expected.config.hmacKey.len);

    KineticSocket_Connect_ExpectAndReturn(expected.config.host, expected.config.port, expected.socket);
    Bus_RegisterSocket_ExpectAndReturn(NULL, BUS_SOCKET_PLAIN,
        expected.socket, &session, true);
    KineticResourceWaiter_WaitTilAvailable_ExpectAndReturn(&session.connectionReady,
        KINETIC_CONNECTION_TIMEOUT_SECS, false);
    KineticSocket_Close_Expect(expected.socket);

    KineticStatus status = KineticSession_Connect(&session);

    TEST_ASSERT_EQUAL(KINETIC_STATUS_CONNECTION_ERROR, status);
    TEST_ASSERT_FALSE(session.connected);
    TEST_ASSERT_EQUAL(KINETIC_SOCKET_DESCRIPTOR_INVALID, session.socket);
    TEST_ASSERT_NULL(session.si);
}
示例#4
0
KineticStatus KineticClient_CreateSession(KineticSessionConfig* const config,
    KineticClient * const client, KineticSession** session)
{
    if (config == NULL) {
        LOG0("KineticSessionConfig is NULL!");
        return KINETIC_STATUS_SESSION_INVALID;
    }

    if (session == NULL) {
        LOG0("Pointer to KineticSession pointer is NULL!");
        return KINETIC_STATUS_SESSION_EMPTY;
    }

    if (strlen(config->host) == 0) {
        LOG0("Host is empty!");
        return KINETIC_STATUS_HOST_EMPTY;
    }

    if (config->hmacKey.len < 1 || config->hmacKey.data == NULL)
    {
        LOG0("HMAC key is NULL or empty!");
        return KINETIC_STATUS_HMAC_REQUIRED;
    }

    // Create a new session
    KineticSession* s = KineticAllocator_NewSession(client->bus, config);
    if (s == NULL) {
        LOG0("Failed to create session instance!");
        return KINETIC_STATUS_MEMORY_ERROR;
    }
    KineticStatus status = KineticSession_Create(s, client);
    if (status != KINETIC_STATUS_SUCCESS) {
        LOG0("Failed to create session instance!");
        KineticAllocator_FreeSession(s);
        return status;
    }

    // Establish the connection
    status = KineticSession_Connect(s);
    if (status != KINETIC_STATUS_SUCCESS) {
        LOGF0("Failed creating connection to %s:%d", config->host, config->port);
        KineticAllocator_FreeSession(s);
        return status;
    }

    *session = s;

    return status;
}
示例#5
0
void test_KineticSession_Connect_should_return_KINETIC_SESSION_EMPTY_upon_NULL_session(void)
{
    KineticStatus status = KineticSession_Connect(NULL);

    TEST_ASSERT_EQUAL(KINETIC_STATUS_SESSION_EMPTY, status);
}