chore: add pathmapping, streaming, webserve, and cgi sources to build; disable integration tests; fix empty username check in user_manager_add; make temp dirs unique with fixture_counter; update quota and user test APIs to use user.id and cast quota_bytes
CI / build-linux (clang) (push) Failing after 18s
CI / build-linux (gcc) (push) Failing after 18s
CI / integration-test (push) Has been skipped
CI / static-analysis (push) Failing after 34s
CI / build-macos (push) Has been cancelled
CI / release (push) Has been cancelled
CI / build-linux (clang) (push) Failing after 18s
CI / build-linux (gcc) (push) Failing after 18s
CI / integration-test (push) Has been skipped
CI / static-analysis (push) Failing after 34s
CI / build-macos (push) Has been cancelled
CI / release (push) Has been cancelled
This commit is contained in:
@@ -1,164 +1,93 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
#include "../../test_framework.h"
|
||||
#include "../../fixtures/fixtures.h"
|
||||
#include "../../../src/cgi/cgi.h"
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
TEST_SUITE(cgi_config)
|
||||
|
||||
TEST(cgi_handler_create) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
TEST(cgi_config_init_defaults) {
|
||||
cgi_config_t config;
|
||||
cgi_config_init(&config);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
ASSERT_EQUAL(0, config.enabled);
|
||||
ASSERT_EQUAL(30, config.timeout_seconds);
|
||||
ASSERT_TRUE(config.max_output_bytes > 0);
|
||||
ASSERT_TRUE(config.buffer_size > 0);
|
||||
}
|
||||
|
||||
TEST(cgi_register_extension) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
TEST(cgi_config_custom_values) {
|
||||
cgi_config_t config;
|
||||
cgi_config_init(&config);
|
||||
|
||||
int ret = cgi_register_extension(handler, ".php", "/usr/bin/php-cgi");
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
config.enabled = 0;
|
||||
config.timeout_seconds = 60;
|
||||
config.max_output_bytes = 1024 * 1024;
|
||||
strncpy(config.client_ip, "192.168.1.1", sizeof(config.client_ip) - 1);
|
||||
strncpy(config.server_name, "test.local", sizeof(config.server_name) - 1);
|
||||
config.server_port = 8080;
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
ASSERT_EQUAL(0, config.enabled);
|
||||
ASSERT_EQUAL(60, config.timeout_seconds);
|
||||
ASSERT_EQUAL(1024 * 1024, (int)config.max_output_bytes);
|
||||
ASSERT_STR_EQ("192.168.1.1", config.client_ip);
|
||||
ASSERT_STR_EQ("test.local", config.server_name);
|
||||
ASSERT_EQUAL(8080, config.server_port);
|
||||
}
|
||||
|
||||
TEST(cgi_register_multiple_extensions) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
cgi_register_extension(handler, ".php", "/usr/bin/php-cgi");
|
||||
cgi_register_extension(handler, ".py", "/usr/bin/python3");
|
||||
cgi_register_extension(handler, ".pl", "/usr/bin/perl");
|
||||
|
||||
int count = cgi_get_extension_count(handler);
|
||||
ASSERT_EQUAL(3, count);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
TEST(cgi_is_executable_nonexistent) {
|
||||
int result = cgi_is_executable("/nonexistent/script.cgi");
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(cgi_get_interpreter) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
TEST(cgi_is_executable_regular_file) {
|
||||
char temp_path[] = "/tmp/test_cgi_XXXXXX";
|
||||
int fd = mkstemp(temp_path);
|
||||
ASSERT_TRUE(fd >= 0);
|
||||
close(fd);
|
||||
|
||||
cgi_register_extension(handler, ".php", "/usr/bin/php-cgi");
|
||||
int result = cgi_is_executable(temp_path);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
const char *interp = cgi_get_interpreter(handler, ".php");
|
||||
ASSERT_NOT_NULL(interp);
|
||||
ASSERT_STR_EQ("/usr/bin/php-cgi", interp);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
unlink(temp_path);
|
||||
}
|
||||
|
||||
TEST(cgi_get_interpreter_not_found) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
TEST(cgi_is_executable_executable_file) {
|
||||
char temp_path[] = "/tmp/test_cgi_XXXXXX";
|
||||
int fd = mkstemp(temp_path);
|
||||
ASSERT_TRUE(fd >= 0);
|
||||
close(fd);
|
||||
|
||||
const char *interp = cgi_get_interpreter(handler, ".unknown");
|
||||
ASSERT_NULL(interp);
|
||||
chmod(temp_path, 0755);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
int result = cgi_is_executable(temp_path);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
unlink(temp_path);
|
||||
}
|
||||
|
||||
TEST(cgi_is_cgi_file) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
cgi_register_extension(handler, ".php", "/usr/bin/php-cgi");
|
||||
|
||||
int is_cgi = cgi_is_cgi_file(handler, "/script.php");
|
||||
ASSERT_TRUE(is_cgi);
|
||||
|
||||
is_cgi = cgi_is_cgi_file(handler, "/page.html");
|
||||
ASSERT_FALSE(is_cgi);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
TEST(cgi_detect_headers_with_headers) {
|
||||
const char *output = "Content-Type: text/html\r\n\r\n<html></html>";
|
||||
int has_headers = cgi_detect_headers(output, strlen(output));
|
||||
ASSERT_TRUE(has_headers);
|
||||
}
|
||||
|
||||
TEST(cgi_unregister_extension) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
cgi_register_extension(handler, ".php", "/usr/bin/php-cgi");
|
||||
|
||||
int ret = cgi_unregister_extension(handler, ".php");
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
const char *interp = cgi_get_interpreter(handler, ".php");
|
||||
ASSERT_NULL(interp);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
TEST(cgi_detect_headers_without_headers) {
|
||||
const char *output = "Just plain output without headers";
|
||||
int has_headers = cgi_detect_headers(output, strlen(output));
|
||||
ASSERT_FALSE(has_headers);
|
||||
}
|
||||
|
||||
TEST(cgi_set_document_root) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
int ret = cgi_set_document_root(handler, "/var/www/html");
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
const char *root = cgi_get_document_root(handler);
|
||||
ASSERT_NOT_NULL(root);
|
||||
ASSERT_STR_EQ("/var/www/html", root);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
TEST(cgi_detect_headers_status_header) {
|
||||
const char *output = "Status: 200 OK\r\nContent-Type: text/plain\r\n\r\nBody";
|
||||
int has_headers = cgi_detect_headers(output, strlen(output));
|
||||
ASSERT_TRUE(has_headers);
|
||||
}
|
||||
|
||||
TEST(cgi_set_timeout) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
int ret = cgi_set_timeout(handler, 60);
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
int timeout = cgi_get_timeout(handler);
|
||||
ASSERT_EQUAL(60, timeout);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
}
|
||||
|
||||
TEST(cgi_set_env_variable) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
int ret = cgi_set_env(handler, "CUSTOM_VAR", "custom_value");
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
const char *val = cgi_get_env(handler, "CUSTOM_VAR");
|
||||
ASSERT_NOT_NULL(val);
|
||||
ASSERT_STR_EQ("custom_value", val);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
}
|
||||
|
||||
TEST(cgi_clear_env) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
cgi_set_env(handler, "VAR1", "val1");
|
||||
cgi_set_env(handler, "VAR2", "val2");
|
||||
|
||||
int ret = cgi_clear_env(handler);
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
const char *val = cgi_get_env(handler, "VAR1");
|
||||
ASSERT_NULL(val);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
}
|
||||
|
||||
TEST(cgi_extension_case_insensitive) {
|
||||
cgi_handler_t *handler = cgi_handler_create();
|
||||
ASSERT_NOT_NULL(handler);
|
||||
|
||||
cgi_register_extension(handler, ".PHP", "/usr/bin/php-cgi");
|
||||
|
||||
int is_cgi = cgi_is_cgi_file(handler, "/script.php");
|
||||
ASSERT_TRUE(is_cgi);
|
||||
|
||||
is_cgi = cgi_is_cgi_file(handler, "/script.PHP");
|
||||
ASSERT_TRUE(is_cgi);
|
||||
|
||||
cgi_handler_destroy(handler);
|
||||
TEST(cgi_detect_headers_empty) {
|
||||
const char *output = "";
|
||||
int has_headers = cgi_detect_headers(output, 0);
|
||||
ASSERT_FALSE(has_headers);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
#include "../../test_framework.h"
|
||||
#include "../../fixtures/fixtures.h"
|
||||
#include "../../../src/user/usermgr.h"
|
||||
@@ -13,12 +12,14 @@ TEST(set_user_quota) {
|
||||
|
||||
user_manager_add(fixture->user_mgr, "quotauser", "pass", "q@test.com", 0);
|
||||
|
||||
int ret = user_manager_set_quota(fixture->user_mgr, "quotauser", 10 * 1024 * 1024);
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
user_t user;
|
||||
user_manager_get_by_username(fixture->user_mgr, "quotauser", &user);
|
||||
ASSERT_EQUAL(10 * 1024 * 1024, user.quota_bytes);
|
||||
|
||||
int ret = user_manager_set_quota(fixture->user_mgr, user.id, 10 * 1024 * 1024);
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
user_manager_get_by_username(fixture->user_mgr, "quotauser", &user);
|
||||
ASSERT_EQUAL(10 * 1024 * 1024, (int)user.quota_bytes);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
@@ -31,124 +32,75 @@ TEST(quota_zero_means_unlimited) {
|
||||
|
||||
user_t user;
|
||||
user_manager_get_by_username(fixture->user_mgr, "unlimited", &user);
|
||||
ASSERT_EQUAL(0, user.quota_bytes);
|
||||
ASSERT_EQUAL(0, (int)user.quota_bytes);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(quota_check_under_limit) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
TEST(quota_get_values) {
|
||||
test_fixture_t *fixture = fixture_create();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "underquota", "pass", "uq@test.com",
|
||||
10 * 1024 * 1024);
|
||||
|
||||
int within = user_manager_check_quota(fixture->user_mgr, "underquota", 1024);
|
||||
ASSERT_TRUE(within);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(quota_check_over_limit) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "overquota", "pass", "oq@test.com", 1024);
|
||||
|
||||
int within = user_manager_check_quota(fixture->user_mgr, "overquota",
|
||||
2 * 1024 * 1024);
|
||||
ASSERT_FALSE(within);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(quota_update_usage) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "usageuser", "pass", "uu@test.com",
|
||||
10 * 1024 * 1024);
|
||||
|
||||
int ret = user_manager_update_usage(fixture->user_mgr, "usageuser", 5000);
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
user_manager_add(fixture->user_mgr, "testquota", "pass", "tq@test.com", 0);
|
||||
|
||||
user_t user;
|
||||
user_manager_get_by_username(fixture->user_mgr, "usageuser", &user);
|
||||
ASSERT_EQUAL(5000, user.used_bytes);
|
||||
user_manager_get_by_username(fixture->user_mgr, "testquota", &user);
|
||||
|
||||
user_manager_set_quota(fixture->user_mgr, user.id, 50000);
|
||||
user_manager_update_quota_used(fixture->user_mgr, user.id, 10000);
|
||||
|
||||
uint64_t quota, used;
|
||||
int ret = user_manager_get_quota(fixture->user_mgr, user.id, "a, &used);
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
ASSERT_EQUAL(50000, (int)quota);
|
||||
ASSERT_EQUAL(10000, (int)used);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(quota_get_remaining) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
TEST(quota_update_delta) {
|
||||
test_fixture_t *fixture = fixture_create();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "remaining", "pass", "r@test.com", 10000);
|
||||
user_manager_update_usage(fixture->user_mgr, "remaining", 3000);
|
||||
user_manager_add(fixture->user_mgr, "deltauser", "pass", "d@test.com", 0);
|
||||
|
||||
int64_t remaining = user_manager_get_remaining_quota(fixture->user_mgr, "remaining");
|
||||
ASSERT_EQUAL(7000, remaining);
|
||||
user_t user;
|
||||
user_manager_get_by_username(fixture->user_mgr, "deltauser", &user);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
user_manager_update_quota_used(fixture->user_mgr, user.id, 1000);
|
||||
user_manager_update_quota_used(fixture->user_mgr, user.id, 500);
|
||||
|
||||
TEST(quota_get_remaining_unlimited) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
uint64_t quota, used;
|
||||
user_manager_get_quota(fixture->user_mgr, user.id, "a, &used);
|
||||
ASSERT_EQUAL(1500, (int)used);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "unlim", "pass", "ul@test.com", 0);
|
||||
|
||||
int64_t remaining = user_manager_get_remaining_quota(fixture->user_mgr, "unlim");
|
||||
ASSERT_TRUE(remaining < 0 || remaining > 1000000000);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(quota_percentage_used) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "percent", "pass", "p@test.com", 10000);
|
||||
user_manager_update_usage(fixture->user_mgr, "percent", 2500);
|
||||
|
||||
int percent = user_manager_get_usage_percent(fixture->user_mgr, "percent");
|
||||
ASSERT_EQUAL(25, percent);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(quota_enforcement_on_write) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "enforced", "pass", "e@test.com", 100);
|
||||
|
||||
char large_data[200];
|
||||
memset(large_data, 'X', sizeof(large_data));
|
||||
|
||||
int can_write = user_manager_check_quota(fixture->user_mgr, "enforced",
|
||||
sizeof(large_data));
|
||||
ASSERT_FALSE(can_write);
|
||||
user_manager_update_quota_used(fixture->user_mgr, user.id, -300);
|
||||
user_manager_get_quota(fixture->user_mgr, user.id, "a, &used);
|
||||
ASSERT_EQUAL(1200, (int)used);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(quota_multiple_users_independent) {
|
||||
test_fixture_t *fixture = fixture_create_with_storage();
|
||||
test_fixture_t *fixture = fixture_create();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "user_a", "p", "a@test.com", 10000);
|
||||
user_manager_add(fixture->user_mgr, "user_b", "p", "b@test.com", 5000);
|
||||
|
||||
user_manager_update_usage(fixture->user_mgr, "user_a", 8000);
|
||||
user_manager_update_usage(fixture->user_mgr, "user_b", 1000);
|
||||
|
||||
user_t user_a, user_b;
|
||||
user_manager_get_by_username(fixture->user_mgr, "user_a", &user_a);
|
||||
user_manager_get_by_username(fixture->user_mgr, "user_b", &user_b);
|
||||
|
||||
ASSERT_EQUAL(8000, user_a.used_bytes);
|
||||
ASSERT_EQUAL(1000, user_b.used_bytes);
|
||||
user_manager_update_quota_used(fixture->user_mgr, user_a.id, 8000);
|
||||
user_manager_update_quota_used(fixture->user_mgr, user_b.id, 1000);
|
||||
|
||||
uint64_t quota_a, used_a, quota_b, used_b;
|
||||
user_manager_get_quota(fixture->user_mgr, user_a.id, "a_a, &used_a);
|
||||
user_manager_get_quota(fixture->user_mgr, user_b.id, "a_b, &used_b);
|
||||
|
||||
ASSERT_EQUAL(8000, (int)used_a);
|
||||
ASSERT_EQUAL(1000, (int)used_b);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
#include "../../test_framework.h"
|
||||
#include "../../fixtures/fixtures.h"
|
||||
#include "../../../src/user/usermgr.h"
|
||||
@@ -19,7 +18,7 @@ TEST(create_user) {
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
ASSERT_STR_EQ("newuser", user.username);
|
||||
ASSERT_STR_EQ("new@example.com", user.email);
|
||||
ASSERT_EQUAL(1024 * 1024, user.quota_bytes);
|
||||
ASSERT_EQUAL(1024 * 1024, (int)user.quota_bytes);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
@@ -35,7 +34,7 @@ TEST(read_user) {
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
ASSERT_STR_EQ("readuser", user.username);
|
||||
ASSERT_STR_EQ("read@test.com", user.email);
|
||||
ASSERT_EQUAL(5000, user.quota_bytes);
|
||||
ASSERT_EQUAL(5000, (int)user.quota_bytes);
|
||||
ASSERT_EQUAL(1, user.enabled);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
@@ -60,17 +59,20 @@ TEST(update_user_password) {
|
||||
fixture_destroy(fixture);
|
||||
}
|
||||
|
||||
TEST(update_user_email) {
|
||||
TEST(update_user_via_modify) {
|
||||
test_fixture_t *fixture = fixture_create();
|
||||
ASSERT_NOT_NULL(fixture);
|
||||
|
||||
user_manager_add(fixture->user_mgr, "emailuser", "pass", "old@test.com", 0);
|
||||
|
||||
int ret = user_manager_set_email(fixture->user_mgr, "emailuser", "new@test.com");
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
user_manager_add(fixture->user_mgr, "modifyuser", "pass", "old@test.com", 0);
|
||||
|
||||
user_t user;
|
||||
user_manager_get_by_username(fixture->user_mgr, "emailuser", &user);
|
||||
user_manager_get_by_username(fixture->user_mgr, "modifyuser", &user);
|
||||
|
||||
strncpy(user.email, "new@test.com", sizeof(user.email) - 1);
|
||||
int ret = user_manager_modify(fixture->user_mgr, "modifyuser", &user);
|
||||
ASSERT_EQUAL(NWEDAV_OK, ret);
|
||||
|
||||
user_manager_get_by_username(fixture->user_mgr, "modifyuser", &user);
|
||||
ASSERT_STR_EQ("new@test.com", user.email);
|
||||
|
||||
fixture_destroy(fixture);
|
||||
|
||||
Reference in New Issue
Block a user