Пример #1
0
static void netscape_cookie(dAT)
{
    char expires[APR_RFC822_DATE_LEN];
    char *val;
    apreq_cookie_t *c;

    *(const char **)&val = apr_table_get(jar, "foo");
    AT_not_null(val);

    c = apreq_value_to_cookie(val);

    AT_str_eq(c->v.data, "bar");
    AT_int_eq(apreq_cookie_version(c), 0);
    AT_str_eq(apreq_cookie_as_string(c, p), "foo=bar");

    c->domain = apr_pstrdup(p, "example.com");
    AT_str_eq(apreq_cookie_as_string(c, p), "foo=bar; domain=example.com");

    c->path = apr_pstrdup(p, "/quux");
    AT_str_eq(apreq_cookie_as_string(c, p),
              "foo=bar; path=/quux; domain=example.com");

    apreq_cookie_expires(c, "+1y");
    apr_rfc822_date(expires, apr_time_now()
                             + apr_time_from_sec(apreq_atoi64t("+1y")));
    expires[7] = '-';
    expires[11] = '-';
    val = apr_pstrcat(p, "foo=bar; path=/quux; domain=example.com; expires=",
                      expires, NULL);

    AT_str_eq(apreq_cookie_as_string(c, p), val);
}
Пример #2
0
static void make_param(dAT)
{
    apreq_param_t *param, *decode;
    apr_status_t s;
    apr_size_t nlen = 3, vlen = 11;
    char *name = apr_palloc(p,nlen+1);
    char *val = apr_palloc(p,vlen+1);
    char *encode;
    strcpy(name, "foo");
    strcpy(val, "bar > alpha");

    param = apreq_param_make(p, name, nlen, val, vlen);
    AT_str_eq(param->v.name, name);
    AT_int_eq(param->v.dlen, vlen);
    AT_str_eq(param->v.data, val);

    encode = apreq_param_encode(p, param);
    AT_str_eq(encode, "foo=bar+%3E+alpha");

    s = apreq_param_decode(&decode, p, encode, nlen, vlen+2);
    AT_int_eq(s, APR_SUCCESS);
    AT_str_eq(decode->v.name, name);
    AT_int_eq(decode->v.dlen, vlen);
    AT_str_eq(decode->v.data, val);
}
Пример #3
0
static void jar_get_rfc(dAT)
{
    const char *val;
    AT_not_null(val = apr_table_get(jar2, "first"));
    AT_str_eq(val, "a");
    AT_not_null(val = apr_table_get(jar2, "second"));
    AT_str_eq(val, "be");
    AT_not_null(val = apr_table_get(jar2, "third"));
    AT_str_eq(val, "cie");
}
Пример #4
0
static void params_as(dAT)
{
    const char *val;
    apr_array_header_t *arr;
    arr = apreq_params_as_array(p,args,"a");
    AT_int_eq(arr->nelts, 2);
    val = apreq_params_as_string(p,args,"a",APREQ_JOIN_AS_IS);
    AT_str_eq(val, "1, 2");
    val = apreq_params_as_string(p,args,"does_not_exist",APREQ_JOIN_AS_IS);
    AT_str_eq(val, "");
}
Пример #5
0
static void string_decoding_in_place(dAT)
{
    char *s1 = apr_palloc(p,4096);
    char *s2 = apr_palloc(p,4096);
    char *s3;

    strcpy(s1, "bend it like beckham");
    strcpy(s2, "dandy %3Edons");

    AT_str_eq(s1,"bend it like beckham");
    apreq_unescape(s1);
    AT_str_eq(s1, "bend it like beckham");
    s3 = apreq_escape(p, s1, 20);
    AT_str_eq(s3, "bend+it+like+beckham");
    apreq_unescape(s3);
    AT_str_eq(s3,"bend it like beckham");

    AT_str_eq(s2,"dandy %3Edons");
    apreq_unescape(s2);
    AT_str_eq(s2,"dandy >dons");
    s3 = apreq_escape(p, s2, 11);
    AT_str_eq(s3,"dandy+%3Edons");
    apreq_unescape(s3);
    AT_str_eq(s3,"dandy >dons");
}
Пример #6
0
static void test_quote(dAT)
{
    size_t len;
    char dst[64];

    len = apreq_quote(dst, "foo", 3);
    AT_int_eq(len, 5);
    AT_str_eq(dst, "\"foo\"");

    len = apreq_quote(dst, "\"foo", 4);
    AT_int_eq(len, 7);
    AT_str_eq(dst, "\"\\\"foo\"");

    len = apreq_quote(dst, "foo\\bar", 7);
    AT_int_eq(len, 10);
    AT_str_eq(dst, "\"foo\\\\bar\"");

    len = apreq_quote(dst, "foo\0bar", 7);
    AT_int_eq(len, 10);
    AT_str_eq(dst, "\"foo\\0bar\"");
}
Пример #7
0
static void rfc_cookie(dAT)
{
    apreq_cookie_t *c = apreq_cookie_make(p,"rfc",3,"out",3);
    const char *expected;
    long expires;

    AT_str_eq(c->v.data, "out");

    apreq_cookie_version_set(c, 1);
    AT_int_eq(apreq_cookie_version(c), 1);
    AT_str_eq(apreq_cookie_as_string(c,p),"rfc=out; Version=1");

    c->domain = apr_pstrdup(p, "example.com");

#ifndef WIN32

    AT_str_eq(apreq_cookie_as_string(c,p),
              "rfc=out; Version=1; domain=\"example.com\"");
    c->path = apr_pstrdup(p, "/quux");
    AT_str_eq(apreq_cookie_as_string(c,p),
              "rfc=out; Version=1; path=\"/quux\"; domain=\"example.com\"");

    apreq_cookie_expires(c, "+3m");
    expires = apreq_atoi64t("+3m");
    expected = apr_psprintf(p, "rfc=out; Version=1; path=\"/quux\"; "
                       "domain=\"example.com\"; max-age=%ld",
                       expires);
    AT_str_eq(apreq_cookie_as_string(c,p), expected);

#else

    expected = "rfc=out; Version=1; domain=\"example.com\"";
    AT_str_eq(apreq_cookie_as_string(c,p), expected);

    c->path = apr_pstrdup(p, "/quux");
    expected = "rfc=out; Version=1; path=\"/quux\"; domain=\"example.com\"";
    AT_str_eq(apreq_cookie_as_string(c,p), expected);

    apreq_cookie_expires(c, "+3m");
    expires = apreq_atoi64t("+3m");
    expected = apr_psprintf(p, "rfc=out; Version=1; path=\"/quux\"; "
                           "domain=\"example.com\"; max-age=%ld",
                           expires);
    AT_str_eq(apreq_cookie_as_string(c,p), expected);

#endif

}
Пример #8
0
static void test_quote_once(dAT)
{
    size_t len;
    char dst[64];

    len = apreq_quote_once(dst, "foo", 3);
    AT_int_eq(len, 5);
    AT_str_eq(dst, "\"foo\"");

    len = apreq_quote_once(dst, "\"foo", 4);
    AT_int_eq(len, 7);
    AT_str_eq(dst, "\"\\\"foo\"");

    len = apreq_quote_once(dst, "foo\"", 4);
    AT_int_eq(len, 7);
    AT_str_eq(dst, "\"foo\\\"\"");

    len = apreq_quote_once(dst, "foo\0bar", 7);
    AT_int_eq(len, 10);
    AT_str_eq(dst, "\"foo\\0bar\"");

    /* null byte must be escaped, even when there are already double
       quotes */
    len = apreq_quote_once(dst, "\"foo\0bar\"", 9);
    AT_int_eq(len, 14);
    AT_str_eq(dst, "\"\\\"foo\\0bar\\\"\"");

    len = apreq_quote_once(dst, "\"foo\"", 5);
    AT_int_eq(len, 5);
    AT_str_eq(dst, "\"foo\"");

    len = apreq_quote_once(dst, "'foo'", 5);
    AT_int_eq(len, 7);
    AT_str_eq(dst, "\"'foo'\"");

    len = apreq_quote_once(dst, "\"fo\\o\"", 6);
    AT_int_eq(len, 6);
    AT_str_eq(dst, "\"fo\\o\"");

    len = apreq_quote_once(dst, "\"foo\"bar\"", 9);
    AT_int_eq(len, 14);
    AT_str_eq(dst, "\"\\\"foo\\\"bar\\\"\"");
}
Пример #9
0
static void jar_get_ns(dAT)
{

    AT_str_eq(apr_table_get(jar, "a"), "1");

    /* ignore wacky cookies that don't have an '=' sign */
    AT_is_null(apr_table_get(jar, "bad"));

    /* accept wacky cookies that contain multiple '=' */
    AT_str_eq(apr_table_get(jar, "ns"), "foo=1&bar=2");

    AT_str_eq(apr_table_get(jar,"foo"), "bar");
    AT_str_eq(apr_table_get(jar,"fl"),  "left");
    AT_str_eq(apr_table_get(jar,"fr"),  "right");
    AT_str_eq(apr_table_get(jar,"frl"), "right-left");
    AT_str_eq(apr_table_get(jar,"flr"), "left-right");
    AT_str_eq(apr_table_get(jar,"fll"), "left-left");
    AT_is_null(apr_table_get(jar,""));
}
Пример #10
0
static void request_args_get(dAT)
{
    const char *val;
    const apreq_param_t *param;

    AT_str_eq(apr_table_get(args,"a"), "1");

    val = apr_table_get(args,"quux");
    AT_str_eq(val, "foo bar");
    param = apreq_value_to_param(val);
    AT_int_eq(param->v.dlen, 7);

    AT_str_eq(apr_table_get(args,"plus"), "+");
    AT_str_eq(apr_table_get(args,"uplus"), "+");
    AT_str_eq(apr_table_get(args,"okie"), "dokie");
    AT_str_eq(apr_table_get(args,"novalue1"), "");
    AT_str_eq(apr_table_get(args,"novalue2"),"");
}
Пример #11
0
static void version_string(dAT)
{
    const char *vstring = apreq_version_string();
    AT_not_null(vstring);
    AT_str_eq(vstring, APREQ_VERSION_STRING);
}