index 77828e6a8c4220d482a1eaaf69c6ec03b142fca0..13ae221a0f509e6f8402c2c5c10e838f4df8b2ef 100644 (file)
#include "frontend/connection.h"
#include "frontend/connection-private.h"
#include "utils/proto.h"
+#include "utils/os.h"
#include "libsysdb_test.h"
#include "utils/strbuf.h"
+#include <assert.h>
#include <check.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
+static char username[1024];
+
/*
* private helper functions
*/
unlink(tmp_file);
+ conn->username = strdup(username);
+ assert(conn->username);
+
conn->cmd = SDB_CONNECTION_IDLE;
conn->cmd_len = 0;
return conn;
{
ssize_t check, expected;
- expected = 2 * sizeof(uint32_t) + strlen("fakeuser");
+ expected = 2 * sizeof(uint32_t) + strlen(username);
check = sdb_connection_send(conn, SDB_CONNECTION_STARTUP,
- (uint32_t)strlen("fakeuser"), "fakeuser");
+ (uint32_t)strlen(username), username);
fail_unless(check == expected,
- "sdb_connection_send(STARTUP, fakeuser) = %zi; expected: %zi",
- check, expected);
+ "sdb_connection_send(STARTUP, %s) = %zi; expected: %zi",
+ username, check, expected);
mock_conn_rewind(conn);
check = sdb_connection_read(conn);
fail_unless(sdb_strbuf_len(conn->errbuf) == 0,
"sdb_connection_read() left %zu bytes in the error "
- "buffer; expected: 0", sdb_strbuf_len(conn->errbuf));
+ "buffer (%s); expected: 0", sdb_strbuf_len(conn->errbuf),
+ sdb_strbuf_string(conn->errbuf));
mock_conn_truncate(conn);
} /* connection_startup */
{ UINT32_MAX, NULL, NULL },
{ SDB_CONNECTION_IDLE, "fakedata", "Authentication required" },
{ SDB_CONNECTION_PING, NULL, "Authentication required" },
- { SDB_CONNECTION_STARTUP, "fakeuser", NULL },
+ { SDB_CONNECTION_STARTUP, username, NULL },
{ SDB_CONNECTION_PING, NULL, NULL },
{ SDB_CONNECTION_IDLE, NULL, "Invalid command 0" },
{ SDB_CONNECTION_PING, "fakedata", NULL },
else
fail_unless(sdb_strbuf_len(conn->errbuf) == 0,
"sdb_connection_read() left %zu bytes in the error "
- "buffer; expected: 0", sdb_strbuf_len(conn->errbuf));
+ "buffer (%s); expected: 0", sdb_strbuf_len(conn->errbuf),
+ sdb_strbuf_string(conn->errbuf));
}
mock_conn_destroy(conn);
Suite *s = suite_create("frontend::connection");
TCase *tc;
+ char *tmp = sdb_get_current_user();
+ assert(tmp);
+ strcpy(username, tmp);
+ free(tmp);
+
tc = tcase_create("core");
tcase_add_test(tc, test_conn_accept);
tcase_add_test(tc, test_conn_setup);