Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

Commit

Permalink
http: add integration test for http using local dns server
Browse files Browse the repository at this point in the history
  • Loading branch information
fAuernigg committed Oct 4, 2022
1 parent 474a5c2 commit 4283e42
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
46 changes: 34 additions & 12 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ enum large_body_test {
REQ_HTTP_REQUESTS = 2
};

enum {
IP_127_0_0_1 = 0x7f000001,
};

static int test_http_response_no_reasonphrase(void)
{
Expand Down Expand Up @@ -392,13 +395,15 @@ static size_t http_req_long_body_handler(struct mbuf *mb, void *arg)
}


static int test_http_loop_base(bool secure, const char *met, bool http_conn)
static int test_http_loop_base(bool secure, const char *met, bool http_conn,
bool dns_srv_query)
{
struct http_sock *sock = NULL;
struct http_cli *cli = NULL;
struct http_req *req = NULL;
struct http_reqconn *conn = NULL;
struct dnsc *dnsc = NULL;
struct dns_server *dns_srv = NULL;
struct sa srv, dns;
struct test t;
char url[256];
Expand All @@ -416,10 +421,18 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn)

t.secure = secure;

if (dns_srv_query) {
/* Setup Mocking DNS Server */
err = dns_server_alloc(&dns_srv, false);
TEST_ERR(err);

err = dns_server_add_a(dns_srv, "test1.example.net",
IP_127_0_0_1, 1);
TEST_ERR(err);
}

err |= sa_set_str(&srv, "127.0.0.1", 0);
err |= sa_set_str(&dns, "127.0.0.1", 53); /* note: unused */
if (err)
goto out;

if (secure) {

Expand All @@ -440,7 +453,7 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn)
if (err)
goto out;

err = dnsc_alloc(&dnsc, NULL, &dns, 1);
err = dnsc_alloc(&dnsc, NULL, dns_srv ? &dns_srv->addr : &dns, 1);
if (err)
goto out;

Expand All @@ -460,8 +473,10 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn)
#endif

(void)re_snprintf(url, sizeof(url),
"http%s://127.0.0.1:%u/index.html",
secure ? "s" : "", sa_port(&srv));
"http%s://%s:%u/index.html",
secure ? "s" : "",
dns_srv_query ? "test1.example.net" : "127.0.0.1",
sa_port(&srv));

for (i = 1; i <= REQ_HTTP_REQUESTS; i++) {
t.i_req_body = 0;
Expand Down Expand Up @@ -553,6 +568,7 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn)
mem_deref(cli);
mem_deref(dnsc);
mem_deref(sock);
mem_deref(dns_srv);

return err;
}
Expand Down Expand Up @@ -625,39 +641,45 @@ int test_http_client_set_tls(void)

int test_http_loop(void)
{
return test_http_loop_base(false, "GET", false);
return test_http_loop_base(false, "GET", false, false);
}


#ifdef USE_TLS
int test_https_loop(void)
{
return test_http_loop_base(true, "GET", false);
return test_http_loop_base(true, "GET", false, false);
}
#endif


int test_http_large_body(void)
{
return test_http_loop_base(false, "PUT", false);
return test_http_loop_base(false, "PUT", false, false);
}


#ifdef USE_TLS
int test_https_large_body(void)
{
return test_http_loop_base(true, "PUT", false);
return test_http_loop_base(true, "PUT", false, false);
}
#endif


int test_http_conn(void)
{
return test_http_loop_base(false, "GET", true);
return test_http_loop_base(false, "GET", true, false);
}


int test_http_conn_large_body(void)
{
return test_http_loop_base(false, "PUT", true);
return test_http_loop_base(false, "PUT", true, false);
}


int test_dns_http_integration(void)
{
return test_http_loop_base(false, "GET", true, true);
}
5 changes: 2 additions & 3 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ static const struct test tests_integration[] = {
TEST(test_tmr_jiffies),
TEST(test_tmr_jiffies_usec),
TEST(test_dns_integration),
TEST(test_dns_http_integration),
};


Expand Down Expand Up @@ -333,9 +334,7 @@ static const struct test *find_test(const char *name)

static const struct test *find_test_int(const char *name)
{
size_t i;

for (i=0; i<ARRAY_SIZE(tests_integration); i++) {
for (size_t i=0; i<ARRAY_SIZE(tests_integration); i++) {

if (0 == str_casecmp(name, tests_integration[i].name))
return &tests_integration[i];
Expand Down
1 change: 1 addition & 0 deletions src/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ int test_http_loop(void);
int test_http_large_body(void);
int test_http_conn(void);
int test_http_conn_large_body(void);
int test_dns_http_integration(void);
#ifdef USE_TLS
int test_https_loop(void);
int test_http_client_set_tls(void);
Expand Down

0 comments on commit 4283e42

Please sign in to comment.