randyk      2003/10/19 21:53:34

  Modified:    env/cgi_test cgi_test.c
               env/cgi_test/t cgi.t
  Log:
  - add large GET and POST tests to libapreq_cgi tests
  - add cookie tests to libapreq_cgi tests, but don't run them yet
  
  Revision  Changes    Path
  1.3       +64 -13    httpd-apreq-2/env/cgi_test/cgi_test.c
  
  Index: cgi_test.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/cgi_test/cgi_test.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- cgi_test.c        14 Oct 2003 04:21:58 -0000      1.2
  +++ cgi_test.c        20 Oct 2003 04:53:34 -0000      1.3
  @@ -52,7 +52,6 @@
    * <http://www.apache.org/>.
    */
   
  -
   #include "apreq.h"
   #include "apreq_env.h"
   #include "apreq_params.h"
  @@ -74,22 +73,31 @@
   static int dump_table(void *count, const char *key, const char *value)
   {
       int *c = (int *) count;
  -    *c = *c + strlen(key) + strlen(value);
  +    int value_len = strlen(value);
  +    if(value_len) *c = *c + strlen(key) + value_len;
       return 1;
   }
   
  -int main(void)
  +int main(int argc, char *argv[])
   {
       env_ctx *ctx;
       apr_pool_t *pool;
  -    const apreq_param_t *foo, *bar;
  +    const apreq_param_t *foo, *bar, *test, *key;
       apr_table_t *params;
       int count = 0;
  -
  -    if (apr_initialize() != APR_SUCCESS) {
  -        fprintf(stderr, "apr_initialize failed\n");
  +    apr_status_t s;
  +    const apreq_jar_t *jar;
  +    apreq_cookie_t *cookie;
  +    apr_ssize_t ssize;
  +    apr_size_t size;
  +    char *dest;
  +
  +    atexit(apr_terminate);
  +    if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
  +        fprintf(stderr, "apr_app_initialize failed\n");
           exit(-1);
       }
  +
       if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
           fprintf(stderr, "apr_pool_create failed\n");
           exit(-1);
  @@ -103,15 +111,58 @@
   
       printf("%s", "Content-Type: text/plain\n\n");
       apreq_log(APREQ_DEBUG 0, ctx, "%s", "Fetching the parameters");
  +
       foo = apreq_param(ctx->req, "foo");
       bar = apreq_param(ctx->req, "bar");
  +
  +    test = apreq_param(ctx->req, "test");
  +    key = apreq_param(ctx->req, "key");
  +
       if (foo || bar) {
  -      if(foo) printf("\t%s => %s\n", "foo", foo->v.data);
  -      if(bar) printf("\t%s => %s\n", "bar", bar->v.data);
  -      return 0;
  +        if(foo) {
  +            printf("\t%s => %s\n", "foo", foo->v.data);
  +            apreq_log(APREQ_DEBUG 0, ctx, "%s => %s", "foo", foo->v.data);
  +        }
  +        if(bar) {
  +            printf("\t%s => %s\n", "bar", bar->v.data);
  +            apreq_log(APREQ_DEBUG 0, ctx, "%s => %s", "bar", bar->v.data);
  +        }
  +    }
  +    
  +    else if (test && key) {
  +        jar = apreq_jar(ctx, NULL);
  +        apreq_log(APREQ_DEBUG 0, ctx, "Fetching Cookie %s", key->v.data);
  +        cookie = apreq_cookie(jar, key->v.data);
  +        if (cookie == NULL) {
  +            apreq_log(APREQ_DEBUG 0, ctx, 
  +                      "No cookie for %s found!", key->v.data);
  +            exit(-1);
  +        }
  +
  +        if (strcmp(test->v.data, "bake") == 0) {
  +            s = apreq_cookie_bake(cookie, ctx);
  +        }
  +        else if (strcmp(test->v.data, "bake2") == 0) {
  +            s = apreq_cookie_bake2(cookie, ctx);
  +        }
  +        else {
  +            size = strlen(cookie->v.data);
  +            dest = apr_palloc(ctx->pool, size + 1);
  +            ssize = apreq_decode(dest, cookie->v.data, size);
  +            printf("%s", dest);
  +        }
  +    }
  +
  +    else { 
  +        apreq_log(APREQ_DEBUG 0, ctx, "Fetching all parameters");
  +        params = apreq_params(ctx->pool, ctx->req);
  +        if (params == NULL) {
  +            apreq_log(APREQ_DEBUG 0, ctx, "No parameters found!");
  +            exit(-1);
  +        }
  +        apr_table_do(dump_table, &count, params, NULL);
  +        printf("%d", count);
       }
  -    params = apreq_params(ctx->pool, ctx->req);
  -    apr_table_do(dump_table, &count, params, NULL);
  -    printf("%d", count);
  +    
       return 0;
   }
  
  
  
  1.3       +73 -22    httpd-apreq-2/env/cgi_test/t/cgi.t
  
  Index: cgi.t
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/cgi_test/t/cgi.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- cgi.t     14 Oct 2003 04:21:58 -0000      1.2
  +++ cgi.t     20 Oct 2003 04:53:34 -0000      1.3
  @@ -4,8 +4,9 @@
   use Apache::Test;
   use Apache::TestUtil;
   use Apache::TestConfig;
  -use Apache::TestRequest qw(GET_BODY UPLOAD_BODY POST_BODY GET_RC);
  +use Apache::TestRequest qw(GET_BODY UPLOAD_BODY POST_BODY GET_RC GET_HEAD);
   use constant WIN32 => Apache::TestConfig::WIN32;
  +use HTTP::Cookies;
   
   my @key_len = (5, 100, 305);
   my @key_num = (5, 15, 26);
  @@ -19,28 +20,8 @@
   
   my $script = WIN32 ? '/cgi-bin/cgi_test.exe' : '/cgi-bin/cgi_test';
   my $line_end = WIN32 ? "\r\n" : "\n";
  -
  -ok t_cmp("\tfoo => 1$line_end", 
  -         POST_BODY("$script?foo=1"), "simple get");
  -ok t_cmp("\tfoo => ?$line_end\tbar => hello world$line_end", 
  -         GET_BODY("$script?foo=%3F&bar=hello+world"), "simple get");
  -
   my $filler = "0123456789" x 5; # < 64K
   
  -my $body = POST_BODY("/$script", content => 
  -                     "aaa=$filler;foo=1;bar=2;filler=$filler");
  -ok t_cmp("\tfoo => 1$line_end\tbar => 2$line_end", 
  -         $body, "simple post");
  -
  -$body = POST_BODY("/$script?foo=1", content => 
  -                  "intro=$filler&bar=2&conclusion=$filler");
  -ok t_cmp("\tfoo => 1$line_end\tbar => 2$line_end", 
  -         $body, "simple post");
  -
  -$body = UPLOAD_BODY("/$script?foo=0", content => $filler);
  -ok t_cmp("\tfoo => 0$line_end", 
  -         $body, "simple upload");
  -
   # GET
   for my $key_len (@key_len) {
       for my $key_num (@key_num) {
  @@ -77,10 +58,80 @@
           my $query = join ";", @query;
   
           t_debug "# of keys : $big_key_num, big_key_len $big_key_len";
  -        $body = POST_BODY($script, content => "$query;$filler");
  +        my $body = POST_BODY($script, content => "$query;$filler");
           ok t_cmp($len,
                    $body,
                    "POST big data");
       }
   
  +}
  +
  +ok t_cmp("\tfoo => 1$line_end", 
  +         GET_BODY("$script?foo=1", Cookie => "simple=get", Content => 
'assa'));
  +
  +ok t_cmp("\tfoo => ?$line_end\tbar => hello world$line_end", 
  +         GET_BODY("$script?foo=%3F&bar=hello+world"), "simple get");
  +
  +my $body = POST_BODY("/$script", content => 
  +                     "aaa=$filler;foo=1;bar=2;filler=$filler");
  +ok t_cmp("\tfoo => 1$line_end\tbar => 2$line_end", 
  +         $body, "simple post");
  +
  +$body = POST_BODY("/$script?foo=1", content => 
  +                  "intro=$filler&bar=2&conclusion=$filler");
  +ok t_cmp("\tfoo => 1$line_end\tbar => 2$line_end", 
  +         $body, "simple post");
  +
  +$body = UPLOAD_BODY("/$script?foo=0", content => $filler);
  +ok t_cmp("\tfoo => 0$line_end", 
  +         $body, "simple upload");
  +
  +exit;
  +
  +{
  +    my $test  = 'netscape';
  +    my $key   = 'apache';
  +    my $value = 'ok';
  +    my $cookie = qq{$key=$value};
  +    ok t_cmp($value,
  +             GET_BODY("$script?test=$test&key=$key", Cookie => $cookie),
  +             $test);
  +}
  +{
  +    my $test  = 'rfc';
  +    my $key   = 'apache';
  +    my $value = 'ok';
  +    my $cookie = qq{\$Version="1"; $key="$value"; \$Path="$script"};
  +    ok t_cmp(qq{"$value"},
  +             GET_BODY("$script?test=$test&key=$key", Cookie => $cookie),
  +             $test);
  +}
  +{
  +    my $test  = 'encoded value with space';
  +    my $key   = 'apache';
  +    my $value = 'okie dokie';
  +    my $cookie = "$key=" . join '',
  +        map {/ / ? '+' : sprintf '%%%.2X', ord} split //, $value;
  +    ok t_cmp($value,
  +             GET_BODY("$script?test=$test&key=$key", Cookie => $cookie),
  +             $test);
  +}
  +{
  +    my $test  = 'bake';
  +    my $key   = 'apache';
  +    my $value = 'ok';
  +    my $cookie = "$key=$value";
  +    my ($header) = GET_HEAD("$script?test=$test&key=$key", 
  +                            Cookie => $cookie) =~ /^#Set-Cookie:\s+(.+)/m;
  +
  +    ok t_cmp($cookie, $header, $test);
  +}
  +{
  +    my $test  = 'bake2';
  +    my $key   = 'apache';
  +    my $value = 'ok';
  +    my $cookie = qq{\$Version="1"; $key="$value"; \$Path="$script"};
  +    my ($header) = GET_HEAD("$script?test=$test&key=$key", 
  +                            Cookie => $cookie) =~ /^#Set-Cookie2:\s+(.+)/m;
  +    ok t_cmp(qq{$key="$value"; Version=1; path="$script"}, $header, $test);
   }
  
  
  

Reply via email to