-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use Query.Get when fetching QueryParameter (#1106)
- Loading branch information
Showing
10 changed files
with
233 additions
and
14 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
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
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 @@ | ||
*.log |
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,27 @@ | ||
serve: | ||
api: | ||
port: 6061 | ||
proxy: | ||
port: 6060 | ||
|
||
access_rules: | ||
repositories: | ||
- file://./rules.1.json | ||
|
||
authenticators: | ||
noop: | ||
enabled: true | ||
bearer_token: | ||
enabled: true | ||
config: | ||
check_session_url: http://localhost:6662/session | ||
|
||
authorizers: | ||
allow: | ||
enabled: true | ||
deny: | ||
enabled: true | ||
|
||
mutators: | ||
noop: | ||
enabled: true |
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,52 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/julienschmidt/httprouter" | ||
) | ||
|
||
func main() { | ||
router := httprouter.New() | ||
|
||
router.POST("/test", test) | ||
router.GET("/session", session) | ||
|
||
port := os.Getenv("PORT") | ||
if port == "" { | ||
port = "6662" | ||
} | ||
|
||
server := http.Server{ | ||
Addr: fmt.Sprintf(":%s", port), | ||
Handler: router, | ||
} | ||
|
||
if err := server.ListenAndServe(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func test(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
b, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
|
||
if len(b) == 0 { | ||
w.WriteHeader(http.StatusBadRequest) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
} | ||
|
||
func session(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
w.WriteHeader(http.StatusOK) | ||
} |
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,34 @@ | ||
[ | ||
{ | ||
"id": "test", | ||
"upstream": { | ||
"url": "http://127.0.0.1:6662" | ||
}, | ||
"match": { | ||
"url": "http://127.0.0.1:6060/test", | ||
"methods": ["POST"] | ||
}, | ||
"authenticators": [ | ||
{ | ||
"handler": "bearer_token", | ||
"config": { | ||
"check_session_url": "http://127.0.0.1:6662/session", | ||
"preserve_path": true, | ||
"preserve_query": false, | ||
"force_method": "GET", | ||
"token_from": { | ||
"query_parameter": "token" | ||
} | ||
} | ||
} | ||
], | ||
"authorizer": { | ||
"handler": "allow" | ||
}, | ||
"mutators": [ | ||
{ | ||
"handler": "noop" | ||
} | ||
] | ||
} | ||
] |
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,77 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
waitport() { | ||
i=0 | ||
while ! nc -z localhost "$1" ; do | ||
sleep 1 | ||
if [ $i -gt 10 ]; then | ||
cat ./config.yaml | ||
cat ./oathkeeper.log | ||
exit 1 | ||
fi | ||
i=$((i+1)) | ||
done | ||
} | ||
|
||
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
|
||
run_oathkekeper() { | ||
killall oathkeeper || true | ||
|
||
export OATHKEEPER_PROXY=http://127.0.0.1:6060 | ||
export OATHKEEPER_API=http://127.0.0.1:6061 | ||
|
||
go build -o . ../.. | ||
LOG_LEVEL=debug ./oathkeeper --config ./config.yaml serve > ./oathkeeper.log 2>&1 & | ||
|
||
waitport 6060 | ||
waitport 6061 | ||
} | ||
|
||
run_api(){ | ||
killall okapi || true | ||
|
||
PORT=6662 go run ./okapi > ./api.log 2>&1 & | ||
|
||
waitport 6662 | ||
} | ||
|
||
SUCCESS_TEST=() | ||
FAILED_TEST=() | ||
|
||
run_test() { | ||
label=$1 | ||
shift 1 | ||
|
||
result="0" | ||
"$@" || result="1" | ||
|
||
if [[ "$result" -eq "0" ]]; then | ||
SUCCESS_TEST+=("$label") | ||
else | ||
FAILED_TEST+=("$label") | ||
fi | ||
} | ||
|
||
function finish { | ||
echo ::group::Config | ||
cat ./config.yaml | ||
cat ./rules.1.json | ||
echo ::endgroup:: | ||
echo ::group::Log | ||
cat ./oathkeeper.log | ||
echo ::endgroup:: | ||
} | ||
trap finish EXIT | ||
|
||
run_oathkekeper | ||
run_api | ||
|
||
curl -X POST -f http://127.0.0.1:6060/test?token=token -F fk=fv -H "Content-Type: application/x-www-form-urlencoded" -i | ||
|
||
kill %1 || true | ||
|
||
trap - EXIT |