void test_KineticAdminClient_GetLog_should_return_INVALID_LOG_TYPE_if_out_of_range(void)
{
    KineticLogInfo* info;

    KineticStatus status = KineticAdminClient_GetLog(&Session,
        (KineticLogInfo_Type)1000, &info, NULL);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_INVALID_LOG_TYPE, status);
}
void test_KineticAdminClient_GetLog_should_request_the_specified_log_data_from_the_device(void)
{
    KineticLogInfo* info;
    KineticOperation operation;

    KineticAllocator_NewOperation_ExpectAndReturn(&Session, &operation);
    KineticBuilder_BuildGetLog_ExpectAndReturn(&operation, KINETIC_DEVICE_INFO_TYPE_UTILIZATIONS, BYTE_ARRAY_NONE, &info, KINETIC_STATUS_SUCCESS);
    KineticController_ExecuteOperation_ExpectAndReturn(&operation, NULL, KINETIC_STATUS_SUCCESS);

    KineticStatus status = KineticAdminClient_GetLog(&Session,
        KINETIC_DEVICE_INFO_TYPE_UTILIZATIONS, &info, NULL);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
}
}


void test_KineticAdminClient_GetLog_should_request_the_specified_log_data_from_the_device(void)
{
    KineticSession session = {
        .config = (KineticSessionConfig) {.port = 4321},
    };
    KineticLogInfo* info;
    KineticOperation operation;

    KineticAllocator_NewOperation_ExpectAndReturn(&session, &operation);
    KineticBuilder_BuildGetLog_ExpectAndReturn(&operation, KINETIC_DEVICE_INFO_TYPE_UTILIZATIONS, BYTE_ARRAY_NONE, &info, KINETIC_STATUS_SUCCESS);
    KineticController_ExecuteOperation_ExpectAndReturn(&operation, NULL, KINETIC_STATUS_SUCCESS);

    KineticStatus status = KineticAdminClient_GetLog(&session, KINETIC_DEVICE_INFO_TYPE_UTILIZATIONS, &info, NULL);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
}


void test_KineticAdminClient_SecureErase_should_build_and_execute_a_SECURE_ERASE_operation(void)
{
    ByteArray pin = ByteArray_CreateWithCString("abc123");
    KineticSession session = {
        .config = (KineticSessionConfig) {.port = 4321},
    };
    KineticOperation operation;

    KineticAuth_EnsureSslEnabled_ExpectAndReturn(&session.config, KINETIC_STATUS_SUCCESS);
    KineticAllocator_NewOperation_ExpectAndReturn(&session, &operation);
Esempio n. 4
0
KineticStatus ExecuteOperation(
    struct UtilConfig * cfg)
{
    KineticStatus status = KINETIC_STATUS_INVALID;
    KineticLogInfo * logInfo;
    ByteArray tmpArray;

    switch (cfg->opID) {

        case OPT_NOOP:
            status = KineticClient_NoOp(cfg->session);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("NoOp operation completed successfully."
                    " Kinetic Device is alive and well!\n"); }
            break;

        case OPT_PUT:
            status = KineticClient_Put(cfg->session, &cfg->entry, NULL);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("Put operation completed successfully."
                       " Your data has been stored!\n");
                PrintEntry(&cfg->entry);
            }
            break;

        case OPT_GET:
            status = KineticClient_Get(cfg->session, &cfg->entry, NULL);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("Get executed successfully.\n");
                PrintEntry(&cfg->entry);
            }
            break;

        case OPT_GETNEXT:
            status = KineticClient_GetNext(cfg->session, &cfg->entry, NULL);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("GetNext executed successfully.\n");
                PrintEntry(&cfg->entry);
            }
            break;

        case OPT_GETPREVIOUS:
            status = KineticClient_GetPrevious(cfg->session, &cfg->entry, NULL);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("GetPrevious executed successfully.\n");
                PrintEntry(&cfg->entry);
            }
            break;

        case OPT_DELETE:
            status = KineticClient_Delete(cfg->session, &cfg->entry, NULL);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("Delete executed successfully. The entry has been destroyed!\n");
                PrintEntry(&cfg->entry);
            }
            break;

        case OPT_GETLOG:
            status = KineticAdminClient_GetLog(cfg->adminSession, cfg->logType, &logInfo, NULL);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("GetLog executed successfully.\n"
                       "The device log info has been retrieved!\n");
                PrintLogInfo(cfg->logType, logInfo);
            }
            break;

        case OPT_GETDEVICESPECIFICLOG:
            if (strlen(cfg->deviceLogName) == 0) {
                fprintf(stderr, "Device-specific log type requires '--devicelogname' to be set!\n");
                exit(1);
            }
            tmpArray.data = (uint8_t*)cfg->deviceLogName;
            tmpArray.len = strlen(cfg->deviceLogName);
            status = KineticAdminClient_GetDeviceSpecificLog(cfg->adminSession, tmpArray, &logInfo, NULL);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("GetDeviceSpecificLog executed successfully."
                       "The device-specific device log info has been retrieved!\n");
                printf("Device-Specific Log Info:\n");
                char* dev = calloc(1, logInfo->device->name.len + 1);
                memcpy(dev, logInfo->device->name.data, logInfo->device->name.len);
                printf("  %s\n", dev);
                free(dev);
            }
            else if (status == KINETIC_STATUS_NOT_FOUND) {
                fprintf(stderr, "The specified device-specific log '%s' was not found on the device!\n", cfg->deviceLogName);
                status = KINETIC_STATUS_SUCCESS;
            }
            break;

        case OPT_SETERASEPIN:
            status = KineticAdminClient_SetErasePin(cfg->adminSession,
                ByteArray_Create(cfg->pin, strlen(cfg->pin)),
                ByteArray_Create(cfg->newPin, strlen(cfg->newPin)));
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("SetErasePin executed successfully.\n"
                       "The kinetic device erase pin has been changed!\n"); }
            break;

        case OPT_INSTANTERASE:
            status = KineticAdminClient_InstantErase(cfg->adminSession,
                ByteArray_Create(cfg->pin, strlen(cfg->pin)));
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("InstantErase executed successfully.\n"
                       "The kinetic device has been erased!\n"); }
            break;

        case OPT_SECUREERASE:
            status = KineticAdminClient_SecureErase(cfg->adminSession,
                ByteArray_Create(cfg->pin, strlen(cfg->pin)));
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("SecureErase executed successfully.\n"
                       "The kinetic device has been erased!\n"); }
            break;

        case OPT_SETLOCKPIN:
            status = KineticAdminClient_SetLockPin(cfg->adminSession,
                ByteArray_Create(cfg->pin, strlen(cfg->pin)),
                ByteArray_Create(cfg->newPin, strlen(cfg->newPin)));
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("SetLockPin executed successfully.\n"
                       "The kinetic device lock/unlock pin has been changed!\n"); }
            break;

        case OPT_LOCKDEVICE:
            status = KineticAdminClient_LockDevice(cfg->adminSession,
                ByteArray_Create(cfg->pin, strlen(cfg->pin)));
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("LockDevice executed successfully.\n"
                       "The kinetic device is now locked!\n"); }
            break;

        case OPT_UNLOCKDEVICE:
            status = KineticAdminClient_UnlockDevice(cfg->adminSession,
                ByteArray_Create(cfg->pin, strlen(cfg->pin)));
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("UnlockDevice executed successfully.\n"
                       "The kinetic device is now unlocked!\n"); }
            break;

        case OPT_SETCLUSTERVERSION:
            status = KineticAdminClient_SetClusterVersion(cfg->adminSession, cfg->newClusterVersion);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("SetClusterVersion executed successfully.\n"
                       "The kinetic device's cluster version has been updated!\n"); }
            break;

        case OPT_SETACL:
            status = KineticAdminClient_SetACL(cfg->adminSession, cfg->file);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("SetACL executed successfully.\n"
                       "The kinetic device ACLs have been replaced!\n"); }
            break;

        case OPT_UPDATEFIRMWARE:
            status = KineticAdminClient_UpdateFirmware(cfg->session, cfg->file);
            if (status == KINETIC_STATUS_SUCCESS) {
                printf("SecureErase executed successfully.\n"
                       "The kinetic device has been restored to empty status!\n"); }
            break;

        default:
            fprintf(stderr, "Specified operation '%d' is invalid!\n",
                (int)cfg->opID);
            exit(-1);
    };

    // Print out status code description if operation was not successful
    if (status != KINETIC_STATUS_SUCCESS) {
        fprintf(stderr, "\nERROR: Operation '%s' failed with status '%s'\n",
            GetOptString(cfg->opID), Kinetic_GetStatusDescription(status));
    }

    return status;
}