Skip to content

Instantly share code, notes, and snippets.

@lusis lusis/cache_test.t
Created Nov 3, 2016

Embed
What would you like to do?
Test::Nginx to validate cache behaviour
use Test::Nginx::Socket 'no_plan';
no warnings;
no_diff;
#repeat_each(5);
run_tests();
__DATA__
=== TEST 3: test_proxy_cache
--- http_config
proxy_cache_path /tmp/cache levels=1:2 use_temp_path=on keys_zone=auth_cache:10m;
upstream cluster {
server 127.0.0.1:9999;
# the following will only work if you're using the upstream health check module
# comment the next three lines out if not
check interval=3000 rise=1 fall=1 timeout=1000 type=http default_down=false;
check_http_send "GET /up HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 127.0.0.1:9999;
location /up {
echo up;
}
location / {
auth_basic "Restricted";
auth_basic_user_file /t/htpasswd;
echo $remote_user;
}
}
--- config
location /auth {
proxy_cache_key "$http_authorization:$scheme:$proxy_host:$request_uri";
proxy_cache auth_cache;
proxy_cache_valid any 15s;
add_header X-Cache-Status $upstream_cache_status;
proxy_cache_methods GET;
proxy_pass http://cluster;
}
--- more_headers eval
["Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjI6dXNlcjJwYXNz"]
--- request eval
["GET /auth",
"GET /auth",
"GET /auth",
"GET /auth",
"GET /auth"]
--- response_headers eval
["X-Cache-Status: MISS",
"X-Cache-Status: HIT",
"X-Cache-Status: HIT",
"X-Cache-Status: HIT",
"X-Cache-Status: MISS"]
--- response_body eval
["user1\n",
"user1\n",
"user1\n",
"user1\n",
"user2\n"]
--- error_code eval
["200", "200","200","200", "200"]
user1:$apr1$Qvwr0dJh$1BUVspwNFbDtlQ1jzf9Ft.
user2:$apr1$O061IwuG$4NUV0xoQmiMGv6ua5mx1a/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.