Skip to content

Commit 06d08fc

Browse files
authored
Merge pull request #401 from nbycomp/feature/reject-invalid-filter-format
Feature/reject invalid filter format
2 parents 0a2b7d7 + 139f4ad commit 06d08fc

4 files changed

Lines changed: 46 additions & 13 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ ADD test/ /tests
191191
RUN /tests/all.sh
192192

193193
FROM resource AS integrationtests
194-
RUN apt update && apt install -y squid
194+
RUN apt update && apt install -y iproute2 squid
195195
ADD test/ /tests/test
196196
ADD integration-tests /tests/integration-tests
197197
RUN /tests/integration-tests/integration.sh

assets/check

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ tag_regex=$(jq -r '.source.tag_regex // ""' <<< "$payload")
2727
git_config_payload=$(jq -r '.source.git_config // []' <<< "$payload")
2828
ref=$(jq -r '.version.ref // ""' <<< "$payload")
2929
skip_ci_disabled=$(jq -r '.source.disable_ci_skip // false' <<< "$payload")
30-
filter_whitelist=$(jq -r '.source.commit_filter.include // []' <<< "$payload")
31-
filter_blacklist=$(jq -r '.source.commit_filter.exclude // []' <<< "$payload")
30+
filter_include=$(jq '.source.commit_filter.include // []' <<< "$payload")
31+
filter_exclude=$(jq '.source.commit_filter.exclude // []' <<< "$payload")
3232
version_depth=$(jq -r '.source.version_depth // 1' <<< "$payload")
3333
reverse=false
3434

@@ -43,6 +43,16 @@ else
4343
tagflag="--no-tags"
4444
fi
4545

46+
for filter in "$filter_include" "$filter_exclude"
47+
do
48+
if jq -e 'type != "array"' <<<"$filter"
49+
then
50+
echo 'invalid commit filter (expected array of strings)'
51+
echo "$filter"
52+
exit 1
53+
fi
54+
done
55+
4656
# We're just checking for commits; we don't ever need to fetch LFS files here!
4757
export GIT_LFS_SKIP_SMUDGE=1
4858

@@ -81,20 +91,20 @@ else
8191
fi
8292

8393
list_command="git rev-list --all --first-parent $log_range $paths_search"
84-
if [ `echo $filter_whitelist | jq -r '. | length'` -gt 0 ]
94+
if jq -e 'length > 0' <<<"$filter_include"
8595
then
8696
list_command+=" | git rev-list --stdin --date-order --first-parent --no-walk=unsorted "
87-
whitelist_items=$(echo $filter_whitelist | jq -r -c '.[]')
97+
whitelist_items=$(echo $filter_include | jq -r -c '.[]')
8898
for wli in "$whitelist_items"
8999
do
90100
list_command+=" --grep=\"$wli\""
91101
done
92102
fi
93103

94-
if [ `echo $filter_blacklist | jq -r '. | length'` -gt 0 ]
104+
if jq -e 'length > 0' <<<"$filter_exclude"
95105
then
96106
list_command+=" | git rev-list --stdin --date-order --invert-grep --first-parent --no-walk=unsorted "
97-
blacklist_items=$(echo $filter_blacklist | jq -r -c '.[]')
107+
blacklist_items=$(echo $filter_exclude | jq -r -c '.[]')
98108
for bli in "$blacklist_items"
99109
do
100110
list_command+=" --grep=\"$bli\""

integration-tests/helpers.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ __run() {
139139
set +e
140140
attempts=10
141141
while (( attempts )); do
142-
( netstat -an | grep LISTEN | grep 3128 ) >/dev/null 2>&1
143-
rc=$?
144-
145-
if [[ $rc == 0 ]]; then
142+
if ss -ltn | grep -q 3128; then
146143
break
147144
else
148145
echo "Waiting for proxy to finish reconfiguring..."

test/check.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ it_skips_excluded_commits_conventional() {
532532
}
533533

534534
it_skips_non_included_and_excluded_commits() {
535-
local repo=$(init_repo)
535+
local repo=$(init_repo)
536536
local ref1=$(make_commit $repo)
537537
local ref2=$(make_commit $repo "not skipped commit")
538538
local ref3=$(make_commit $repo "not skipped sometimes")
@@ -545,6 +545,32 @@ local repo=$(init_repo)
545545
"
546546
}
547547

548+
it_rejects_filter_with_incorrect_format() {
549+
local repo=$(init_repo)
550+
local ref1=$(make_commit $repo)
551+
552+
set +e
553+
output=$(
554+
jq --arg uri "$(init_repo)" \
555+
--arg ref "$(make_commit "$repo")" \
556+
-n '{
557+
source: {
558+
$uri,
559+
commit_filter: {
560+
include: "a string, not an array",
561+
}
562+
},
563+
version: {
564+
$ref
565+
}
566+
}' | ${resource_dir}/check | tee /dev/stderr
567+
)
568+
exit_code=$?
569+
set -e
570+
571+
test $exit_code -ne 0
572+
}
573+
548574
it_does_not_skip_marked_commits_when_disable_skip_configured() {
549575
local repo=$(init_repo)
550576
local ref1=$(make_commit_to_future $repo)
@@ -968,6 +994,7 @@ run it_skips_excluded_commits
968994
run it_skips_excluded_commits_conventional
969995
run it_skips_non_included_commits
970996
run it_skips_non_included_and_excluded_commits
997+
run it_rejects_filter_with_incorrect_format
971998
run it_does_not_skip_marked_commits_when_disable_skip_configured
972999
run it_fails_if_key_has_password_not_provided
9731000
run it_can_unlock_key_with_password
@@ -999,4 +1026,3 @@ run it_checks_lastest_commit
9991026
run it_can_check_a_repo_having_multiple_root_commits
10001027
run it_checks_with_version_depth
10011028
run it_checks_uri_with_tag_filter_and_version_depth
1002-

0 commit comments

Comments
 (0)