test(chat): reproduce invalid JSON for a signed channel name
This commit is contained in:
1 parent
774fb66bb9
commit
5fe66585b6
2 files changed
+28
No files matched your search
@@ -304,6 +304,7 @@ check_PROGRAMS += test_chat_setting
|
||||
check_PROGRAMS += test_chat_channel
|
||||
check_PROGRAMS += test_group_avatar_sql
|
||||
check_PROGRAMS += test_chat_member
|
||||
check_PROGRAMS += test_chat_json
|
||||
check_PROGRAMS += test_instance_contract
|
||||
test_instance_contract_SOURCES = test_instance_contract.c
|
||||
test_instance_contract_LDADD = $(LIBUTUN) $(COMMON_LIBS)
|
||||
@@ -331,6 +332,8 @@ test_chat_member_LDADD = $(LIBUTUN) $(COMMON_LIBS)
|
||||
test_chat_member_LDFLAGS = -Wl,--wrap=sqlite3_finalize -Wl,--wrap=sqlite3_prepare_v2 -Wl,--wrap=sqlite3_bind_int64 \
|
||||
-Wl,--wrap=sqlite3_bind_int -Wl,--wrap=sqlite3_step -Wl,--wrap=sqlite3_changes -Wl,--wrap=sqlite3_exec \
|
||||
-Wl,--wrap=u_malloc_impl -Wl,--wrap=u_realloc_impl
|
||||
test_chat_json_SOURCES = test_chat_json.c
|
||||
test_chat_json_LDADD = $(LIBUTUN) $(COMMON_LIBS)
|
||||
else
|
||||
test_socket_monitor_LDFLAGS += -Wl,--wrap=read
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/* JSON introspection: допустимое имя канала возвращается без потери байтов и с полным escaping. */
|
||||
#include "../src/utun_instance.h"
|
||||
#include "../src/chat/chat_core.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include "../lib/mem.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void) {
|
||||
debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); size_t baseline = u_get_allocated_count();
|
||||
utun_instance_set_tun_init_enabled(0); struct UASYNC* ua = uasync_create(); assert(ua);
|
||||
struct UTUN_INSTANCE* inst = utun_instance_create_from_str(ua,
|
||||
"[ntp]\nenabled=no\n[chatserver]\ngroup_autoconnect=0\nstorage_autoload=0\n");
|
||||
assert(inst && !utun_core_start(inst) && !chat_service_start(inst));
|
||||
const char name[] = "Канал \x01 \"\\\n";
|
||||
assert(chat_core_create_channel_auto(inst, name));
|
||||
char json[4096]; size_t size = 0; assert(!chat_core_get_channels_json(inst, json, sizeof(json), &size));
|
||||
sqlite3_stmt* st = NULL;
|
||||
assert(sqlite3_prepare_v2(inst->topo_sqlite_db, "SELECT json_valid(?)", -1, &st, NULL) == SQLITE_OK);
|
||||
assert(sqlite3_bind_text(st, 1, json, (int)size, SQLITE_STATIC) == SQLITE_OK && sqlite3_step(st) == SQLITE_ROW);
|
||||
int valid = sqlite3_column_int(st, 0); assert(sqlite3_finalize(st) == SQLITE_OK);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "JSON test: channel name with ASCII01 valid=%d bytes=%zu", valid, size); assert(valid);
|
||||
utun_instance_destroy(inst); uasync_poll(ua, 0); uasync_destroy(ua, 0); assert(u_get_allocated_count() == baseline);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user