Commit 065493eb authored by Pekka Pessi's avatar Pekka Pessi

nth: fixed subdir handling with nth server.

darcs-hash:20061110072836-65a35-dfc7bb425768ae399314a9ef5449e7670a8ed796.gz
parent 13343bc8
......@@ -11,6 +11,7 @@
INCLUDES = -I$(srcdir)/../ipt -I../ipt \
-I$(srcdir)/../iptsec -I../iptsec \
-I$(srcdir)/../msg -I../msg \
-I$(srcdir)/../bnf -I../bnf \
-I$(srcdir)/../http -I../http \
-I$(srcdir)/../sresolv -I../sresolv \
-I$(srcdir)/../tport -I../tport \
......
This diff is collapsed.
......@@ -86,7 +86,7 @@ static int init_engine(tester_t *t);
struct site
{
site_t *s_next;
site_t *s_next, *s_parent;
tester_t *s_tester;
url_string_t *s_url;
nth_site_t *s_ns;
......@@ -110,6 +110,7 @@ struct tester
nth_engine_t *t_engine;
char const *t_srcdir;
char const *t_pem;
su_sockaddr_t t_addr[1];
socklen_t t_addrlen;
......@@ -123,16 +124,29 @@ struct tester
site_t *t_master;
};
static int site_create(tester_t *t, int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...)
static int test_site(site_t *t,
nth_site_t *server,
nth_request_t *req,
http_t const *http,
char const *path);
static site_t *site_create(tester_t *t, site_t *parent,
char const *url,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...)
{
nth_site_t *pns = parent ? parent->s_ns : NULL;
site_t *s;
ta_list ta;
BEGIN();
if (url == NULL)
return NULL;
s = su_zalloc(t->t_home, sizeof *s); TEST_1(s);
s = su_zalloc(t->t_home, sizeof *s);
if (s == NULL)
return NULL;
s->s_url = URL_STRING_MAKE(url);
s->s_tester = t;
s->s_next = t->t_sites;
s->s_status = status;
......@@ -142,17 +156,24 @@ static int site_create(tester_t *t, int status, char const *phrase,
s->s_tags = tl_adup(t->t_home, ta_args(ta));
ta_end(ta);
TEST_1(s->s_tags);
if (!s->s_tags)
return NULL;
t->t_sites = s;
s->s_ns = nth_site_create(pns, test_site, s,
(url_string_t *)s->s_url,
NTHTAG_ROOT(t->t_root),
TAG_END());
END();
if (s->s_ns == NULL)
return NULL;
t->t_sites = s;
return s;
}
static int init_test(tester_t *t)
{
su_socket_t s;
char const *agent_pem;
BEGIN();
......@@ -170,21 +191,7 @@ static int init_test(tester_t *t)
TEST_1(t->t_addr->su_port != 0);
TEST_1(su_close(s) != -1);
agent_pem = su_sprintf(t->t_home, "%s/agent.pem", t->t_srcdir);
TEST_1(site_create(t,
HTTP_200_OK,
HTTPTAG_CONTENT_TYPE_STR("text/html"),
HTTPTAG_PAYLOAD_STR("<html><body>Hello</body></html>\n"),
TPTAG_CERTIFICATE(agent_pem),
TAG_END()) == 0);
TEST_1(t->t_master = t->t_sites);
t->t_master->s_url = (url_string_t *)
su_sprintf(t->t_home, "HTTP://127.0.0.1:%u", htons(t->t_addr->su_port));
TEST_1(t->t_master->s_url);
t->t_pem = su_sprintf(t->t_home, "%s/agent.pem", t->t_srcdir);
END();
}
......@@ -337,12 +344,6 @@ static int test_nth_client_api(tester_t *t)
END();
}
static int nth_test_site(site_t *t,
nth_site_t *server,
nth_request_t *req,
http_t const *http,
char const *path);
static int site_check_all(site_t *t,
nth_site_t *server,
nth_request_t *req,
......@@ -353,17 +354,19 @@ static int test_nth_server_api(tester_t *t)
{
char const *v;
site_t *s = t->t_master;
site_t s[1];
BEGIN();
memset(s, 0, sizeof s);
v = nth_site_server_version();
TEST_1(v); TEST_1(strlen(v)); TEST_S(v, "nth/" NTH_SERVER_VERSION);
s = t->t_sites;
/* Fails because no parent site, no root */
TEST_1(!nth_site_create(NULL, nth_test_site, s, s->s_url, TAG_END()));
TEST_1(!nth_site_create(NULL, test_site, s,
URL_STRING_MAKE("http://127.0.0.1:8888"),
TAG_END()));
/* Fails because url specifies both host and path */
TEST_1(!nth_site_create(NULL, site_check_all, s,
......@@ -372,7 +375,7 @@ static int test_nth_server_api(tester_t *t)
TEST_VOID(nth_site_destroy(NULL));
TEST(nth_site_magic(NULL), NULL);
TEST_VOID(nth_site_bind(NULL, nth_test_site, s));
TEST_VOID(nth_site_bind(NULL, test_site, s));
TEST_1(nth_site_set_params(NULL, TAG_END()) == -1);
TEST_1(nth_site_get_params(NULL, TAG_END()) == -1);
TEST_1(nth_site_get_stats(NULL, TAG_END()) == -1);
......@@ -385,11 +388,11 @@ static int test_nth_server_api(tester_t *t)
END();
}
static int nth_test_site(site_t *s,
nth_site_t *ns,
nth_request_t *req,
http_t const *http,
char const *path)
static int test_site(site_t *s,
nth_site_t *ns,
nth_request_t *req,
http_t const *http,
char const *path)
{
if (s == NULL || ns == NULL || req == NULL)
return 500;
......@@ -402,6 +405,7 @@ static int nth_test_site(site_t *s,
return s->s_status;
}
static int site_check_all(site_t *s,
nth_site_t *ns,
nth_request_t *req,
......@@ -431,16 +435,53 @@ static int site_check_all(site_t *s,
static int init_server(tester_t *t)
{
site_t *s = t->t_master;
site_t *m = t->t_master, *sub2;
BEGIN();
s->s_ns = nth_site_create(NULL, nth_test_site, s,
(url_string_t *)s->s_url,
NTHTAG_ROOT(t->t_root),
TAG_END());
TEST_1(t->t_master = m =
site_create(t, NULL,
su_sprintf(t->t_home, "HTTP://127.0.0.1:%u",
htons(t->t_addr->su_port)),
HTTP_200_OK,
HTTPTAG_CONTENT_TYPE_STR("text/html"),
HTTPTAG_PAYLOAD_STR("<html><body>Hello</body></html>\n"),
TPTAG_CERTIFICATE(t->t_pem),
TAG_END()));
TEST_1(site_create(t, m, "/sub/sub",
HTTP_200_OK,
HTTPTAG_CONTENT_TYPE_STR("text/html"),
HTTPTAG_PAYLOAD_STR
("<html><body>sub/sub</body></html>\n"),
TAG_END()));
TEST_1(site_create(t, m, "/sub/",
HTTP_200_OK,
HTTPTAG_CONTENT_TYPE_STR("text/html"),
HTTPTAG_PAYLOAD_STR("<html><body>sub/</body></html>\n"),
TAG_END()));
TEST_1(s->s_ns);
TEST_1(site_create(t, m, "/sub/sub/",
HTTP_200_OK,
HTTPTAG_CONTENT_TYPE_STR("text/html"),
HTTPTAG_PAYLOAD_STR
("<html><body>sub/sub/</body></html>\n"),
TAG_END()));
TEST_1(sub2 =
site_create(t, m, "/sub2/",
HTTP_200_OK,
HTTPTAG_CONTENT_TYPE_STR("text/html"),
HTTPTAG_PAYLOAD_STR("<html><body>sub2/</body></html>\n"),
TAG_END()));
TEST_1(site_create(t, sub2, "sub/",
HTTP_200_OK,
HTTPTAG_CONTENT_TYPE_STR("text/html"),
HTTPTAG_PAYLOAD_STR
("<html><body>sub2/sub/</body></html>\n"),
TAG_END()));
END();
}
......@@ -538,6 +579,66 @@ static int test_requests(tester_t *t)
TEST_S(buffer, "HTTP/1.1 200 OK");
}
{
static char const request[] =
"GET %s HTTP/1.1" CRLF
"Host: 127.0.0.1" CRLF
"User-Agent: Test-Tool" CRLF
"Connection: close" CRLF
CRLF;
char *get;
get = su_sprintf(NULL, request, "/sub");
TEST(send_request(t, get, -1, 0, buffer, sizeof(buffer), &m), 0);
m = sspace(buffer); buffer[m++] = '\0';
TEST_S(buffer, "HTTP/1.1 301");
m += strcspn(buffer + m, CRLF) + 1;
free(get);
get = su_sprintf(NULL, request, "/sub/");
TEST(send_request(t, get, -1, 0, buffer, sizeof(buffer), &m), 0);
m = strcspn(buffer, CRLF); buffer[m++] = '\0';
TEST_S(buffer, "HTTP/1.1 200 OK");
TEST_1(strstr(buffer + m, "<body>sub/</body>"));
free(get);
get = su_sprintf(NULL, request, "/sub2/");
TEST(send_request(t, get, -1, 0, buffer, sizeof(buffer), &m), 0);
m = strcspn(buffer, CRLF); buffer[m++] = '\0';
TEST_S(buffer, "HTTP/1.1 200 OK");
TEST_1(strstr(buffer + m, "<body>sub2/</body>"));
free(get);
get = su_sprintf(NULL, request, "/sub2/hub");
TEST(send_request(t, get, -1, 0, buffer, sizeof(buffer), &m), 0);
m = strcspn(buffer, CRLF); buffer[m++] = '\0';
TEST_S(buffer, "HTTP/1.1 200 OK");
TEST_1(strstr(buffer + m, "<body>sub2/</body>"));
free(get);
/* Test that absolute path for subdir site is calculated correctly */
get = su_sprintf(NULL, request, "/sub2/sub");
TEST(send_request(t, get, -1, 0, buffer, sizeof(buffer), &m), 0);
m = sspace(buffer); buffer[m++] = '\0';
TEST_S(buffer, "HTTP/1.1 301");
TEST_1(strstr(buffer + m, "/sub2/sub/" CRLF));
free(get);
get = su_sprintf(NULL, request, "/sub2/sub/");
TEST(send_request(t, get, -1, 0, buffer, sizeof(buffer), &m), 0);
m = strcspn(buffer, CRLF); buffer[m++] = '\0';
TEST_S(buffer, "HTTP/1.1 200 OK");
TEST_1(strstr(buffer + m, "<body>sub2/sub/</body>"));
free(get);
get = su_sprintf(NULL, request, "/sub/sub");
TEST(send_request(t, get, -1, 0, buffer, sizeof(buffer), &m), 0);
m = strcspn(buffer, CRLF); buffer[m++] = '\0';
TEST_S(buffer, "HTTP/1.1 200 OK");
TEST_1(strstr(buffer + m, "<body>sub/sub</body>"));
free(get);
}
{
static char const kuik[] =
"kuik" CRLF CRLF;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment