-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic authorization test case. (#96)
- Loading branch information
Showing
3 changed files
with
236 additions
and
4 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
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,169 @@ | ||
{ | ||
"Configs": { | ||
"EnableDebug": true | ||
}, | ||
"Consumers": [ | ||
{ | ||
"userid": "test", | ||
"password": "123456", | ||
"Headers-Authorization": { | ||
"authorization": "Basic dGVzdDoxMjM0NTY=" | ||
} | ||
} | ||
], | ||
"Listeners": [ | ||
{ | ||
"Protocol": "HTTP", | ||
"Port": 8080 | ||
}, | ||
{ | ||
"Protocol": "HTTP", | ||
"Port": 8081 | ||
}, | ||
{ | ||
"Protocol": "HTTP", | ||
"Port": 8082 | ||
} | ||
], | ||
"RouteRules": { | ||
"8080": { | ||
"*": { | ||
"RouteType": "HTTP", | ||
"Matches": [ | ||
{ | ||
"Path": { | ||
"Type": "Prefix", | ||
"Path": "/" | ||
}, | ||
"EnableHeadersAuthorization": true, | ||
"HeadersAuthorizationType": "Basic", | ||
"BackendService": { | ||
"backendService1": { | ||
"Weight": 100 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"8081": { | ||
"*": { | ||
"Matches": [ | ||
{ | ||
"ServerRoot": "www1", | ||
"Index": [ | ||
"index.html", | ||
"index.htm" | ||
], | ||
"TryFiles": [ | ||
"$uri", | ||
"$uri/default/", | ||
"=404" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"8082": { | ||
"*": { | ||
"Matches": [ | ||
{ | ||
"ServerRoot": "www2", | ||
"Index": [ | ||
"default.html", | ||
"index.html" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"Services": { | ||
"backendService1": { | ||
"StickyCookieName": "_srv_id", | ||
"StickyCookieExpires": 3600, | ||
"HealthCheck": { | ||
"Interval": 10, | ||
"MaxFails": 3, | ||
"FailTimeout": 30, | ||
"Path": "/", | ||
"Matches": [ | ||
{ | ||
"StatusCodes": [ | ||
200 | ||
] | ||
} | ||
] | ||
}, | ||
"Endpoints": { | ||
"127.0.0.1:8081": { | ||
"Weight": 50 | ||
}, | ||
"127.0.0.1:8082": { | ||
"Weight": 50 | ||
} | ||
} | ||
} | ||
}, | ||
"Chains": { | ||
"HTTPRoute": [ | ||
"common/access-control.js", | ||
"common/ratelimit.js", | ||
"common/consumer.js", | ||
"http/codec.js", | ||
"http/auth.js", | ||
"http/route.js", | ||
"http/service.js", | ||
"http/metrics.js", | ||
"http/tracing.js", | ||
"http/logging.js", | ||
"http/circuit-breaker.js", | ||
"http/throttle-domain.js", | ||
"http/throttle-route.js", | ||
"filter/request-redirect.js", | ||
"filter/header-modifier.js", | ||
"filter/url-rewrite.js", | ||
"http/forward.js", | ||
"http/default.js" | ||
], | ||
"HTTPSRoute": [ | ||
"common/access-control.js", | ||
"common/ratelimit.js", | ||
"common/tls-termination.js", | ||
"common/consumer.js", | ||
"http/codec.js", | ||
"http/auth.js", | ||
"http/route.js", | ||
"http/service.js", | ||
"http/metrics.js", | ||
"http/tracing.js", | ||
"http/logging.js", | ||
"http/circuit-breaker.js", | ||
"http/throttle-domain.js", | ||
"http/throttle-route.js", | ||
"filter/request-redirect.js", | ||
"filter/header-modifier.js", | ||
"filter/url-rewrite.js", | ||
"http/forward.js", | ||
"http/default.js" | ||
], | ||
"TLSPassthrough": [ | ||
"common/access-control.js", | ||
"common/ratelimit.js", | ||
"tls/passthrough.js", | ||
"common/consumer.js" | ||
], | ||
"TLSTerminate": [ | ||
"common/access-control.js", | ||
"common/ratelimit.js", | ||
"common/tls-termination.js", | ||
"common/consumer.js", | ||
"tls/forward.js" | ||
], | ||
"TCPRoute": [ | ||
"common/access-control.js", | ||
"common/ratelimit.js", | ||
"tcp/forward.js" | ||
] | ||
} | ||
} |
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,64 @@ | ||
|
||
### header ### | ||
export main=`ps aux | grep pipy | grep " --admin-port=12300" | grep -v grep | awk '{print $2}'` | ||
if ! [ "x$main" = "x" ]; then | ||
kill -9 "$main" > /dev/null | ||
fi | ||
# kill -SIGINT $pipypid | ||
export pipy=`ps aux | grep pipy | grep " --admin-port=12301" | grep -v grep | awk '{print $2}'` | ||
if ! [ "x$pipy" = "x" ]; then | ||
kill -9 "$pipy" > /dev/null | ||
fi | ||
|
||
export name=`echo "$BASH_SOURCE" | awk -F "[./]" '{print $4}'` | ||
|
||
if test -f "config/$name/main.js"; then | ||
(pipy "config/$name/main.js" --admin-port=12300 >/dev/null 2>&1 &) | ||
fi | ||
|
||
cp -f "config/$name/config.json" pjs/ | ||
(pipy pjs/main.js --admin-port=12301 >tmp/pipy.log 2>&1 &) | ||
for i in {1..10} | ||
do | ||
cat tmp/pipy.log 2>&1 | grep "Thread 0 started" >/dev/null | ||
if ! [ $? -eq 0 ]; then | ||
sleep 0.5 | ||
else | ||
break | ||
fi | ||
done | ||
|
||
### shell ### | ||
|
||
describe "SHPEC basic authorization Test" | ||
|
||
start="$(date +%s%3N)" | ||
curl -s -i http://127.0.0.1:8080/ > tmp/1.log | ||
curl -si http://127.0.0.1:8080/ -H "authorization: Basic dGVzdDoxMjM0NTY=" > tmp/2.log | ||
output_1="$(cat tmp/1.log)" | ||
output_2="$(cat tmp/2.log)" | ||
end="$(date +%s%3N)" | ||
runtime=$((end-start)) | ||
|
||
it "1: 401 Unauthorized" | ||
assert grep "$output_1" "401 Unauthorized" | ||
end | ||
|
||
it "2: 200 OK" | ||
assert grep "$output_2" "200 OK" | ||
end | ||
|
||
end | ||
|
||
### footer ### | ||
|
||
export main=`ps aux | grep pipy | grep " --admin-port=12300" | grep -v grep | awk '{print $2}'` | ||
if ! [ "x$main" = "x" ]; then | ||
kill -9 "$main" > /dev/null | ||
fi | ||
# kill -SIGINT $pipypid | ||
export pipy=`ps aux | grep pipy | grep " --admin-port=12301" | grep -v grep | awk '{print $2}'` | ||
if ! [ "x$pipy" = "x" ]; then | ||
kill -9 "$pipy" > /dev/null | ||
fi | ||
|