Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$ |