Skip to content

Commit

Permalink
add simple test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoweibin committed Oct 18, 2010
1 parent 33f0ea3 commit d83fcfa
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 0 deletions.
112 changes: 112 additions & 0 deletions test/t/simple_get.t
@@ -0,0 +1,112 @@
#
#===============================================================================
#
# DESCRIPTION: test
#
# FILES: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Weibin Yao (http://yaoweibin.cn/), yaoweibin@gmail.com
# COMPANY:
# VERSION: 1.0
# CREATED: 03/02/2010 03:18:28 PM
# REVISION: ---
#===============================================================================


# vi:filetype=perl

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

plan tests => repeat_each() * 2 * blocks();

#no_diff;

run_tests();

__DATA__
=== TEST 1: the simple_get test
--- config
resolver 192.168.203.2;
server {
listen 1982;
server_name localhost;
oauth_consumer_key key;
oauth_consumer_secret secret;
oauth_realm "http://example.org";
oauth_variables $oauth_token $oauth_token_secret $proxy_uri;
session_zone $user_id zone=test:10m;
#two step oauth
location /{
set $user_id yaoweibin;
if ($user_id = "") {
rewrite (.*) /session last;
}
rewrite (.*) /get_local_session last;
return 404;
}
location /get_local_session {
session_get zone=test $oauth_token $oauth_token_secret;
if ($oauth_token = "") {
rewrite (.*) /session last;
}
if ($oauth_token_secret = "") {
rewrite (.*) /session last;
}
rewrite (.*) /oauth_proxy last;
}
location /oauth_proxy {
if ($oauth_token = "") {
return 403;
}
if ($oauth_token_secret = "") {
return 403;
}
set $proxy_uri "http://term.ie/oauth/example/echo_api.php?method=foo&bar=baz";
proxy_pass $oauth_signed_authenticated_call_uri;
}
location /session {
eval_override_content_type application/x-www-form-urlencoded;
eval $oauth_token $oauth_token_secret {
set $proxy_uri "http://term.ie/oauth/example/request_token.php";
proxy_pass $oauth_signed_request_token_uri;
}
eval $oauth_token $oauth_token_secret {
set $proxy_uri "http://term.ie/oauth/example/access_token.php";
proxy_pass $oauth_signed_access_token_uri;
}
if ($oauth_token = "") {
return 403;
}
if ($oauth_token_secret = "") {
return 403;
}
session_store zone=test $oauth_token $oauth_token_secret expire=1d;
add_header Location http://127.0.0.1:1982/;
return 302;
}
}
--- request
GET /
--- response_body_like: ^bar=baz&method=foo$
115 changes: 115 additions & 0 deletions test/t/simple_header.t
@@ -0,0 +1,115 @@
#
#===============================================================================
#
# DESCRIPTION: test
#
# FILES: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Weibin Yao (http://yaoweibin.cn/), yaoweibin@gmail.com
# COMPANY:
# VERSION: 1.0
# CREATED: 03/02/2010 03:18:28 PM
# REVISION: ---
#===============================================================================


# vi:filetype=perl

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

plan tests => repeat_each() * 2 * blocks();

#no_diff;

run_tests();

__DATA__
=== TEST 1: the simple_get test
--- config
resolver 192.168.203.2;
server {
listen 1982;
server_name localhost;
oauth_consumer_key key;
oauth_consumer_secret secret;
oauth_realm "http://example.org";
oauth_variables $oauth_token $oauth_token_secret $proxy_uri;
session_zone $user_id zone=test:10m;
#two step oauth
location /{
set $user_id yaoweibin;
if ($user_id = "") {
rewrite (.*) /session last;
}
rewrite (.*) /get_local_session last;
return 404;
}
location /get_local_session {
session_get zone=test $oauth_token $oauth_token_secret;
if ($oauth_token = "") {
rewrite (.*) /session last;
}
if ($oauth_token_secret = "") {
rewrite (.*) /session last;
}
rewrite (.*) /oauth_proxy last;
}
location /oauth_proxy {
if ($oauth_token = "") {
return 403;
}
if ($oauth_token_secret = "") {
return 403;
}
set $proxy_uri "http://term.ie/oauth/example/echo_api.php?method=foo&bar=baz";
proxy_set_header Authorization $oauth_signed_authenticated_call_header;
proxy_pass $proxy_uri;
}
location /session {
eval_override_content_type application/x-www-form-urlencoded;
eval $oauth_token $oauth_token_secret {
set $proxy_uri "http://term.ie/oauth/example/request_token.php";
proxy_set_header Authorization $oauth_signed_request_token_header;
proxy_pass $proxy_uri;
}
eval $oauth_token $oauth_token_secret {
set $proxy_uri "http://term.ie/oauth/example/access_token.php";
proxy_set_header Authorization $oauth_signed_access_token_header;
proxy_pass $proxy_uri;
}
if ($oauth_token = "") {
return 403;
}
if ($oauth_token_secret = "") {
return 403;
}
session_store zone=test $oauth_token $oauth_token_secret expire=1d;
add_header Location http://localhost:1982/;
return 302;
}
}
--- request
GET /
--- response_body_like: ^method=foo&bar=baz$
125 changes: 125 additions & 0 deletions test/t/simple_post.t
@@ -0,0 +1,125 @@
#
#===============================================================================
#
# DESCRIPTION: test
#
# FILES: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Weibin Yao (http://yaoweibin.cn/), yaoweibin@gmail.com
# COMPANY:
# VERSION: 1.0
# CREATED: 03/02/2010 03:18:28 PM
# REVISION: ---
#===============================================================================


# vi:filetype=perl

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

plan tests => repeat_each() * 2 * blocks();

#no_diff;

run_tests();

__DATA__
=== TEST 1: the simple_get test
--- config
resolver 192.168.203.2;
server {
listen 1982;
server_name localhost;
oauth_consumer_key key;
oauth_consumer_secret secret;
oauth_realm "http://example.org";
oauth_variables $oauth_token $oauth_token_secret $proxy_uri;
session_zone $user_id zone=test:10m;
#two step oauth
location /{
set $user_id yaoweibin;
if ($user_id = "") {
rewrite (.*) /session last;
}
rewrite (.*) /get_local_session last;
return 404;
}
location /get_local_session {
session_get zone=test $oauth_token $oauth_token_secret;
if ($oauth_token = "") {
rewrite (.*) /session last;
}
if ($oauth_token_secret = "") {
rewrite (.*) /session last;
}
rewrite (.*) /oauth_proxy last;
}
location /oauth_proxy {
if ($oauth_token = "") {
return 403;
}
if ($oauth_token_secret = "") {
return 403;
}
set $proxy_uri "http://term.ie/oauth/example/echo_api.php?method=foo&bar=baz";
proxy_set_body $oauth_signed_authenticated_call_postargs;
proxy_method POST;
proxy_set_header Content-Type application/x-www-form-urlencoded;
proxy_pass http://term.ie/oauth/example/echo_api.php;
}
location /session {
eval_override_content_type application/x-www-form-urlencoded;
eval $oauth_token $oauth_token_secret {
proxy_method POST;
set $proxy_uri "http://term.ie/oauth/example/request_token.php";
proxy_set_body $oauth_signed_request_token_postargs;
proxy_set_header Content-Type application/x-www-form-urlencoded;
proxy_pass "http://term.ie/oauth/example/request_token.php";
}
eval $oauth_token $oauth_token_secret {
proxy_method POST;
set $proxy_uri "http://term.ie/oauth/example/access_token.php";
proxy_set_body $oauth_signed_access_token_postargs;
proxy_set_header Content-Type application/x-www-form-urlencoded;
proxy_pass "http://term.ie/oauth/example/access_token.php";
}
if ($oauth_token = "") {
return 403;
}
if ($oauth_token_secret = "") {
return 403;
}
session_store zone=test $oauth_token $oauth_token_secret expire=1d;
add_header Location http://localhost:1982/;
return 302;
}
}
--- request
GET /
--- response_body_like: ^bar=baz&method=foo$

0 comments on commit d83fcfa

Please sign in to comment.