void test_specified_user_verifier(void **state) { (void)state; ASSERT_EQUAL(kaa_user_manager_attach_to_user(user_manager, USER_EXTERNAL_ID, ACCESS_TOKEN, USER_VERIFIER), KAA_ERR_NONE); size_t expected_size = 0; ASSERT_EQUAL(kaa_user_request_get_size(user_manager, &expected_size), KAA_ERR_NONE); uint8_t buffer[expected_size]; kaa_platform_message_writer_t *writer = NULL; ASSERT_EQUAL(kaa_platform_message_writer_create(&writer, buffer, expected_size), KAA_ERR_NONE); ASSERT_NOT_NULL(writer); ASSERT_EQUAL(kaa_user_request_serialize(user_manager, writer), KAA_ERR_NONE); uint8_t *buf_cursor = buffer; ASSERT_EQUAL(KAA_EXTENSION_USER, KAA_HTONS(*(uint16_t*)buf_cursor)); buf_cursor += sizeof(uint16_t); char options[] = { 0x00, 0x01 }; ASSERT_EQUAL(memcmp(buf_cursor, options, 2), 0); buf_cursor += 2; ASSERT_EQUAL(*(uint32_t * ) buf_cursor, KAA_HTONL(2 * sizeof(uint32_t) + kaa_aligned_size_get(strlen(USER_EXTERNAL_ID)) + kaa_aligned_size_get(strlen(ACCESS_TOKEN) + kaa_aligned_size_get(strlen(USER_VERIFIER))))); buf_cursor += sizeof(uint32_t); ASSERT_EQUAL(0, *buf_cursor); ++buf_cursor; ASSERT_EQUAL(strlen(USER_EXTERNAL_ID), *buf_cursor); ++buf_cursor; ASSERT_EQUAL(KAA_HTONS(strlen(ACCESS_TOKEN)), *(uint16_t *) buf_cursor); buf_cursor += sizeof(uint16_t); ASSERT_EQUAL(KAA_HTONS(strlen(USER_VERIFIER)), *(uint16_t *) buf_cursor); buf_cursor += sizeof(uint32_t); // + reserved 16B ASSERT_EQUAL(memcmp(buf_cursor, USER_EXTERNAL_ID, strlen(USER_EXTERNAL_ID)), 0); buf_cursor += kaa_aligned_size_get(strlen(USER_EXTERNAL_ID)); ASSERT_EQUAL(memcmp(buf_cursor, ACCESS_TOKEN, strlen(ACCESS_TOKEN)), 0); buf_cursor += kaa_aligned_size_get(strlen(ACCESS_TOKEN)); ASSERT_EQUAL(memcmp(buf_cursor, USER_VERIFIER, strlen(USER_VERIFIER)), 0); buf_cursor += kaa_aligned_size_get(strlen(USER_VERIFIER)); kaa_platform_message_writer_destroy(writer); }
static kaa_error_t kaa_client_sync_serialize(kaa_platform_protocol_t *self , const kaa_service_t services[] , size_t services_count , char* buffer , size_t *size) { kaa_platform_message_writer_t *writer = NULL; kaa_error_t error_code = kaa_platform_message_writer_create(&writer, buffer, *size); KAA_RETURN_IF_ERR(error_code); uint16_t total_services_count = services_count + 1 /* Meta extension */; error_code = kaa_platform_message_header_write(writer, KAA_PLATFORM_PROTOCOL_ID, KAA_PLATFORM_PROTOCOL_VERSION); if (error_code) { KAA_LOG_ERROR(self->logger, error_code, "Failed to write the client sync header"); return error_code; } char *extension_count_p = writer->current; writer->current += KAA_PROTOCOL_EXTENSIONS_COUNT_SIZE; error_code = kaa_meta_data_request_serialize(self->status, writer, self->request_id); while (!error_code && services_count--) { switch (services[services_count]) { case KAA_SERVICE_BOOTSTRAP: { error_code = kaa_channel_manager_bootstrap_request_serialize(self->kaa_context->channel_manager , writer); if (error_code) KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the bootstrap extension"); break; } case KAA_SERVICE_PROFILE: { bool need_resync = false; error_code = kaa_profile_need_profile_resync(self->kaa_context->profile_manager , &need_resync); if (!error_code) { if (need_resync) { error_code = kaa_profile_request_serialize(self->kaa_context->profile_manager, writer); if (error_code) KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the profile extension"); } else { --total_services_count; } } else { KAA_LOG_ERROR(self->logger, error_code, "Failed to read profile's 'need_resync' flag"); } break; } case KAA_SERVICE_USER: { error_code = kaa_user_request_serialize(self->kaa_context->user_manager, writer); if (error_code) KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the user extension"); break; } case KAA_SERVICE_EVENT: { #ifndef KAA_DISABLE_FEATURE_EVENTS error_code = kaa_event_request_serialize(self->kaa_context->event_manager, self->request_id, writer); if (error_code) KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the event extension"); #else --total_services_count; #endif break; } case KAA_SERVICE_LOGGING: { #ifndef KAA_DISABLE_FEATURE_LOGGING bool need_resync = false; error_code = kaa_logging_need_logging_resync(self->kaa_context->log_collector, &need_resync); if (!error_code) { if (need_resync) { error_code = kaa_logging_request_serialize(self->kaa_context->log_collector, writer); if (error_code) KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the logging extension"); } else { --total_services_count; } } else { KAA_LOG_ERROR(self->logger, error_code, "Failed to read logging's 'need_resync' flag"); } #else --total_services_count; #endif break; } case KAA_SERVICE_CONFIGURATION: { #ifndef KAA_DISABLE_FEATURE_CONFIGURATION error_code = kaa_configuration_manager_request_serialize(self->kaa_context->configuration_manager, writer); if (error_code) KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the configuration extension"); #else --total_services_count; #endif break; } case KAA_SERVICE_NOTIFICATION: { #ifndef KAA_DISABLE_FEATURE_NOTIFICATION error_code = kaa_notification_manager_request_serialize(self->kaa_context->notification_manager, writer); if (error_code) KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the configuration extension"); #else --total_services_count; #endif break; } default: break; } } *(uint16_t *) extension_count_p = KAA_HTONS(total_services_count); *size = writer->current - writer->begin; kaa_platform_message_writer_destroy(writer); return error_code; }