Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/test_discord_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ static int test_route_message_create_fixture(void)
return 0;
}

static int test_route_message_create_rejects_edge_cases(void)
{
const char *allowed[] = { "user-42" };
const char *bot_author = "{\"author\":{\"id\":\"user-42\",\"bot\":true},\"channel_id\":\"chan-1\"}";
const char *empty_author_id = "{\"author\":{\"id\":\"\",\"bot\":false},\"channel_id\":\"chan-1\"}";
const char *guild_empty_bot = "{\"author\":{\"id\":\"user-42\",\"bot\":false},"
"\"guild_id\":\"g1\",\"channel_id\":\"chan-2\","
"\"mentions\":[{\"id\":\"bot-9\"}]}";
cJSON *bot = cJSON_Parse(bot_author);
cJSON *empty_id = cJSON_Parse(empty_author_id);
cJSON *guild = cJSON_Parse(guild_empty_bot);
char sess[128];
ASSERT(bot && empty_id && guild);
ASSERT(discord_helpers_route_message_create(NULL, allowed, 1, "bot-9", sess, sizeof(sess)) == -1);
ASSERT(discord_helpers_route_message_create(bot, allowed, 1, "bot-9", sess, sizeof(sess)) == 0);
ASSERT(discord_helpers_route_message_create(empty_id, allowed, 1, "bot-9", sess, sizeof(sess)) == 0);
ASSERT(discord_helpers_route_message_create(guild, allowed, 1, "", sess, sizeof(sess)) == 0);
ASSERT(discord_helpers_route_message_create(guild, allowed, 1, NULL, sess, sizeof(sess)) == 0);
cJSON_Delete(bot);
cJSON_Delete(empty_id);
cJSON_Delete(guild);
return 0;
}

int main(void)
{
RUN(test_allow_entry_equals());
Expand All @@ -108,6 +132,7 @@ int main(void)
RUN(test_backoff_math());
RUN(test_lifecycle_str());
RUN(test_route_message_create_fixture());
RUN(test_route_message_create_rejects_edge_cases());
printf("test_discord_helpers: all tests passed\n");
return 0;
}
Loading