Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ repos:
language: system
files: ^resources/.*\.php$
exclude: ^resources/lib/UnityHTTPD\.php$
- id: assert-forbidden-used
name: Assert forbidden() is used
entry: bash ./test/assert-forbidden-used.bash
language: system
files: ^webroot/admin/.*\.php$
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
This will enable strict mode and throw an exception rather than returning `false`.
- `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`.
`resources/**/*.php` should throw exceptions instead.
- all pages under `webroot/admin/` must check for `$USER->isAdmin()` and call `UnityHTTPD::forbidden()` if not admin.

This repository will automatically check PRs for linting compliance.

Expand Down
20 changes: 20 additions & 0 deletions test/assert-forbidden-used.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set -euo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
if [[ $# -lt 1 ]]; then
echo "at least one argument required"
exit 1
fi

rc=0
for file in "$@"; do
grep_rc=0; grep -q UnityHTTPD::forbidden "$file" || grep_rc=$?
case "$grep_rc" in
0)
: ;; # code is good, do nothing
1)
echo "UnityHTTPD::forbidden() was not called in file '$file'!"; rc=1 ;;
*)
echo "grep failed!"; rc=1 ;;
esac
done
exit "$rc"