Skip to content

Commit

Permalink
Clean up tests and fix hidden AuthHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
marshyski committed Nov 10, 2024
1 parent 197f9f5 commit 8861c12
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pal-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ jobs:
make docker
rm -f ./localhost.*
- name: Run Tests Using pal Docker Container
- name: Run Tests Twice Using pal Docker Container
run: |
make test
make test && make test
- name: Run Vulnerability Scanner On Filesystem
uses: aquasecurity/[email protected]
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ deploy:
tags:
- deploy
# Command or script (use $PAL_INPUT for variables)
cmd: echo "hello $PAL_INPUT"
cmd: echo "GROUP=$PAL_GROUP ACTION=$PAL_ACTION INPUT=$PAL_INPUT REQUEST=$PAL_REQUEST UPLOAD_DIR=$PAL_UPLOAD_DIR"
```
**Example Request**
Expand Down Expand Up @@ -240,7 +240,11 @@ POST [BASIC AUTH] /v1/pal/ui/files/upload (Multiform Upload)
**cURL Upload Example**

```bash
curl -vsk -F files='@{{ filename }}' -u 'admin:p@LLy5' 'https://127.0.0.1:8443/v1/pal/upload'
# Get Cookie
curl -sSk -XPOST -d 'username=admin' -d 'password=p@LLy5' --cookie-jar ./pal.cookie 'https://127.0.0.1:8443/v1/pal/ui/login'

# Use Cookie to Upload File
curl -sSk -XPOST -F files='@{{ filename }}' -b ./pal.cookie 'https://127.0.0.1:8443/v1/pal/ui/files/upload'
```

### Notifications
Expand Down
9 changes: 0 additions & 9 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ func (s *DB) GetGroups() map[string][]data.ActionData {
log.Println(err.Error())
}

// Hide auth_header from response but make not empty for indicators
for k, v := range data {
for i, e := range v {
if e.AuthHeader != "" {
e.AuthHeader = "hidden"
data[k][i] = e
}
}
}
return data
}

Expand Down
3 changes: 2 additions & 1 deletion routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func GetDBGet(c echo.Context) error {

val, err := db.DBC.Get(key)
if err != nil {
return c.String(http.StatusNotFound, "error vlaue not found with key: "+key)
return c.String(http.StatusNotFound, "error value not found with key: "+key)
}

return c.String(http.StatusOK, val)
Expand Down Expand Up @@ -835,6 +835,7 @@ func GetAction(c echo.Context) error {

for _, e := range resMap[group] {
if e.Action == action {
e.AuthHeader = "hidden"
return c.JSONPretty(http.StatusOK, e, " ")
}
}
Expand Down
1 change: 1 addition & 0 deletions test/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build:
- action: go-pal
desc: Lint & Build Pal
auth_header: X-Pal-Auth PaLLy!@#890-
output: true
on_error:
notification: "$PAL_GROUP/$PAL_ACTION lint or build failed: $PAL_OUTPUT"
Expand Down
1 change: 1 addition & 0 deletions test/html.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ html:
# curl -sk -o /dev/null -w '%{content_type}' 'https://127.0.0.1:8443/v1/pal/run/html/index_cache'
- action: index_cache
desc: Sets Max-Age Cache Control & Renders HTML Content-Type
auth_header: X-Pal-Auth PaLLy!@#890-
output: true
concurrent: true
headers:
Expand Down
2 changes: 2 additions & 0 deletions test/json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ json:
# curl -sk 'https://127.0.0.1:8443/v1/pal/run/json/parse?input=%7B%22hello%22%3A%22world%22%7D'
- action: parse
desc: Run jq On Input JSON
auth_header: X-Pal-Auth PaLLy!@#890-
output: true
concurrent: true
headers:
Expand All @@ -17,6 +18,7 @@ json:
# curl -sk -XPOST -H 'X-PAL-TEST: true' -d 'test_body' 'https://127.0.0.1:8443/v1/pal/run/json/parse_pal_request?test=true'
- action: parse_pal_request
desc: Run jq On PAL_REQUEST JSON
auth_header: X-Pal-Auth PaLLy!@#890-
output: true
concurrent: true
headers:
Expand Down
152 changes: 132 additions & 20 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -1,102 +1,214 @@
#!/bin/bash

URL='https://127.0.0.1:8443/v1/pal/run'
HOST='127.0.0.1'
PORT='8443'
HEADER='X-Pal-Auth: PaLLy!@#890-'

while [[ $# -gt 0 ]]; do
case "$1" in
-p)
PORT="$2"
shift 2
;;
-h)
HOST="$2"
shift 2
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done

URL="https://$HOST:$PORT"
HEALTHCHECK="$URL/v1/pal/health"

echo "URL=$URL"
echo "HEALTHCHECK=$HEALTHCHECK"

# health_check
OUT=$(curl -sSk "$HEALTHCHECK")

if [ "$(echo "$OUT" | grep -c "ok")" = 1 ]; then
echo "[pass] health_check"
else
echo "$OUT"
echo "[fail] health_check" && exit 1
fi

# save cookie
curl -sSk -XPOST -d 'username=admin' -d 'password=p@LLy5' --cookie-jar ./pal.cookie "$URL/v1/pal/ui/login" 1>/dev/null

# file_upload
echo 'test' >./test.txt
OUT=$(curl -sSk -XPOST -F files='@./test.txt' -b ./pal.cookie "$URL/v1/pal/ui/files/upload")
if [ "$(echo "$OUT" | grep -c "uploaded 1 file")" = 1 ]; then
echo "[pass] file_upload"
else
echo "$OUT"
rm -f ./pal.cookie ./test.txt
echo "[fail] file_upload" && exit 1
fi
rm -f ./test.txt

# file_download
OUT=$(curl -sSk -b ./pal.cookie "$URL/v1/pal/ui/files/download/test.txt")
if [ "$(echo "$OUT" | grep -c "test")" = 1 ]; then
echo "[pass] file_download"
else
echo "$OUT"
rm -f ./pal.cookie
echo "[fail] file_download" && exit 1
fi

# file_delete
OUT=$(curl -sSk -b ./pal.cookie "$URL/v1/pal/ui/files/delete/test.txt")
if [ "$OUT" = "" ]; then
echo "[pass] file_delete"
else
echo "$OUT"
rm -f ./pal.cookie
echo "[fail] file_delete" && exit 1
fi
rm -f ./pal.cookie

# auth
OUT=$(curl -sk -H 'X-Pal-Auth: PaLLy!@#890-' "$URL/test/auth?input=helloworld")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/auth?input=helloworld")

if [ "$(echo "$OUT" | grep -c "helloworld")" = 1 ]; then
echo "[pass] auth"
else
echo "$OUT"
echo "[fail] auth" && exit 1
fi

# no_auth
OUT=$(curl -sk -H 'X-Pal-Auth: PaLLy!@#890-' "$URL/test/no_auth")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/no_auth")

if [ "$(echo "$OUT" | grep -c "no_auth")" = 1 ]; then
echo "[pass] no_auth"
else
echo "$OUT"
echo "[fail] no_auth" && exit 1
fi

# fail
OUT=$(curl -sk "$URL/test/fail")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/fail")

if [ "$(echo "$OUT" | grep -c "exit")" = 1 ]; then
echo "[pass] fail"
else
echo "$OUT"
echo "[fail] fail" && exit 1
fi

# fail_timeout
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/fail_timeout")

if [ "$(echo "$OUT" | grep -c "killed")" = 1 ]; then
echo "[pass] fail_timeout"
else
echo "$OUT"
echo "[fail] fail_timeout" && exit 1
fi

# block
curl -sk $URL/test/block 1>/dev/null &
curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/block" 1>/dev/null &
sleep 1
OUT=$(curl -sk "$URL/test/block?input=1")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/block?input=1")

if [ "$(echo "$OUT" | grep -c "block")" = 1 ]; then
echo "[pass] block"
else
echo "$OUT"
echo "[fail] block" && exit 1
fi

# no_block
curl -sk $URL/test/no_block 1>/dev/null &
curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/no_block" 1>/dev/null &
sleep 1
OUT=$(curl -sk "$URL/test/no_block")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/no_block")

if [ "$(echo "$OUT" | grep -c "no_block")" = 1 ]; then
echo "[pass] no_block"
else
echo "$OUT"
echo "[fail] no_block" && exit 1
fi

# no_output
OUT=$(curl -sk "$URL/test/no_output")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/no_output")

if [ "$(echo "$OUT" | grep -c "done")" = 1 ]; then
echo "[pass] no_output"
else
echo "$OUT"
echo "[fail] no_output" && exit 1
fi

# input_validate
OUT=$(curl -sk "$URL/test/input_validate?input=123")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/input_validate?input=123")

if [ "$(echo "$OUT" | grep -c "input_validate")" = 1 ]; then
echo "[pass] input_validate"
else
echo "$OUT"
echo "[fail] input_validate" && exit 1
fi

# retry_fail
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/retry_fail?input=123")

if [ "$(echo "$OUT" | grep -c "2 retries")" = 1 ]; then
echo "[pass] retry_fail"
else
echo "$OUT"
echo "[fail] retry_fail" && exit 1
fi

# json/parse
OUT=$(curl -sk "$URL/json/parse?input=%7B%22hello%22%3A%22world%22%7D")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/json/parse?input=%7B%22hello%22%3A%22world%22%7D")
if [ "$(echo "$OUT" | grep -c "hello")" = 1 ]; then
echo "[pass] json/parse"
else
echo "$OUT"
echo "[fail] json/parse" && exit 1
fi

# invalid
OUT=$(curl -sk "$URL/test/invalid")
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/run/test/invalid")
if [ "$(echo "$OUT" | grep -c "invalid")" = 1 ]; then
echo "[pass] invalid"
else
echo "$OUT"
echo "[fail] invalid" && exit 1
fi

# html/index_cache
OUT=$(curl -sk -o /dev/null -w '%{content_type}' "$URL/html/index_cache")
OUT=$(curl -sSk -H "$HEADER" -o /dev/null -w '%{content_type}' "$URL/v1/pal/run/html/index_cache")
if [ "$(echo "$OUT" | grep -c 'text/html')" = 1 ]; then
echo "[pass] html/index_cache"
else
echo "$OUT"
echo "[fail] html/index_cache" && exit 1
fi

# test/container_run
# OUT=$(curl -sk "$URL/test/container_run")
# if [ "$(echo "$OUT" | grep -c 'container_run')" = 1 ]; then
# echo "[pass] test/container_run"
# else
# echo "[fail] test/container_run" && exit 1
# fi
# DB PUT/GET
curl -sSk -XPUT -H "$HEADER" -d 'UniqString123' "$URL/v1/pal/db/put?key=test" 1>/dev/null
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/db/get?key=test")
if [ "$(echo "$OUT" | grep -c "UniqString123")" = 1 ]; then
echo "[pass] db/put/get"
else
echo "$OUT"
echo "[fail] db/put/get"
fi

curl -sfk -XDELETE -H "$HEADER" "$URL/v1/pal/db/delete?key=test" 1>/dev/null
OUT=$(curl -sSk -H "$HEADER" "$URL/v1/pal/db/get?key=test")
if [ "$(echo "$OUT" | grep -c "value not found")" = 1 ]; then
echo "[pass] db/delete"
else
echo "$OUT"
echo "[fail] db/delete"
fi
Loading

0 comments on commit 8861c12

Please sign in to comment.