Skip to content

Commit

Permalink
add test cases for the new built-in variable
Browse files Browse the repository at this point in the history
  • Loading branch information
flygoast committed Sep 24, 2013
1 parent bd01c4a commit e7a8d44
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/nginx-tests/nginx-tests/http_raw_uri_variable.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/perl

# (C) Maxim Dounin
# (C) flygoast

# Tests for 'raw_uri' built-in variable.

###############################################################################

use warnings;
use strict;

use Test::More;

BEGIN { use FindBin; chdir($FindBin::Bin); }

use lib 'lib';
use Test::Nginx;

###############################################################################

select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(6)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
daemon off;
events {
}
http {
%%TEST_GLOBALS_HTTP%%
server {
listen 127.0.0.1:8080;
server_name localhost;
location / {
add_header X-RAW-URI $raw_uri;
return 200;
}
}
}
EOF

$t->run();

###############################################################################

raw_uri('/rawuri', '/rawuri', 'uri');
raw_uri('/rawuri%3F', '/rawuri%3F', 'escaped uri');
raw_uri('/rawuri?arg=foo', '/rawuri', 'uri with arguments');
raw_uri('/rawuri?arg=%2F', '/rawuri', 'uri with escaped arguments');
raw_uri('/rawuri%3F?arg=foo', '/rawuri%3F', 'escaped uri with arguments');
raw_uri('/rawuri%3F?arg=%2F', '/rawuri%3F',
'escaped uri with escaped arguments');

###############################################################################

sub raw_uri {
my ($url, $value, $name) = @_;
my $data = http_get($url);
if ($data !~ qr!^X-RAW-URI: (.*?)\x0d?$!ms) {
fail($name);
return;
}
my $raw_uri = $1;
is($raw_uri, $value, $name);
}

###############################################################################

0 comments on commit e7a8d44

Please sign in to comment.