-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathunicode-testscript
More file actions
executable file
·157 lines (125 loc) · 5.32 KB
/
unicode-testscript
File metadata and controls
executable file
·157 lines (125 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.
#set -x
set -e
set -o nounset
set -o pipefail
set -o errtrace
if [ "$(id -u)" = 0 ] && [ -z "${GITHUB_WORKSPACE:-}" ]; then
printf "%s\n" "$0: ERROR: No need to run as root!" >&2
exit 1
fi
## XXX: Unrelated unit test. Non-ideal location but OK.
source /usr/libexec/helper-scripts/use_sudo.sh
source /usr/libexec/helper-scripts/use_pkexec.sh
source /usr/libexec/helper-scripts/boot-session-detection.bsh
source /usr/libexec/helper-scripts/wc-test.sh
folder_list="Assembly Bash C C# C++ Go Java JavaScript Python RegEx Rust Solidity"
total_file_counter=0
process_file() {
local file_name file_content
file_name="$1"
test -r "$file_name"
base_name="$(basename "$file_name")"
if [ "$base_name" = "README.md" ] || \
[ "$base_name" = "omnisharp.json" ] || \
[ "$base_name" = "java.regex" ] || \
[ "$base_name" = "pcre2.regex" ]; then
return 0
fi
total_file_counter=$(( total_file_counter + 1))
printf "%s\n" "$file_name" >/dev/null
## grep-find-unicode-wrapper is similar like grep.
## - Exit code 0: if found.
## - Non-zero exit code: if not found.
if ! grep-find-unicode-wrapper "$file_name" >/dev/null ; then
printf "%s\n" "$0: ERROR: Failed to find unicode using 'grep-find-unicode-wrapper' in file '$file_name'." >&2
exit 1
fi
## unicode-show will exit 1 if unicode was found.
## So if unicode-show was to exit 0, then it would have failed to find unicode.
if unicode-show "$file_name" >/dev/null ; then
## unicode-show exit code 0.
printf "%s\n" "$0: ERROR: Failed to find unicode using 'unicode-show' (file check) in file '$file_name'." >&2
exit 1
fi
if cat -- "$file_name" | unicode-show >/dev/null ; then
## unicode-show exit code non-zero.
printf "%s\n" "$0: ERROR: Failed to find unicode using 'unicode-show' (stdin check) in file '$file_name'." >&2
exit 1
fi
## unicode-show exit code 0.
## 'stcatn' should sanitize. Therefore 'unicode-show' should not find any unicode and exit 0.
## Check if there is a non-zero exit code in this pipe, because if so, that's a bug.
if ! stcatn "$file_name" | unicode-show >/dev/null ; then
## unicode-show exit code 0.
printf "%s\n" "$0: ERROR: Failed to sanitize string using 'stcatn' in file '$file_name'." >&2
exit 1
fi
## unicode-show non-zero exit code.
if ! cat -- "$file_name" | sanitize-string nolimit >/dev/null ; then
## unicode-show exit code 0.
printf "%s\n" "$0: ERROR: Failed to sanitize string using 'sanitize-string' (stdin check) in file '$file_name'." >&2
exit 1
fi
## > ./unicode-testscript: line 83: warning: command substitution: ignored null byte in input
file_content="$(cat -- "$file_name")"
if ! sanitize-string nolimit "$file_content" >/dev/null ; then
## unicode-show exit code 0.
printf "%s\n" "$0: ERROR: Failed to sanitize string using 'sanitize-string' (command check) in file '$file_name'." >&2
exit 1
fi
return 0
}
if ! test -d "$HOME/trojan-source" ; then
printf "%s\n" "
$0: ERROR: Folder '$HOME/trojan-source' missing. To get it:
cd ~
git clone git@github.com:nickboucher/trojan-source.git" >&2
fi
## Creates files:
## /tmp/user/1000/suspicious-unicode-test/1.txt
## etc.
/usr/libexec/helper-scripts/write-suspicious-unicode "$HOME/suspicious-unicode-tests-temp-folder/suspicious-unicode-test" >/dev/null
## Create files:
## /tmp/user/1000/suspicious-ascii-test
## etc.
/usr/libexec/helper-scripts/write-suspicious-ascii "$HOME/suspicious-unicode-tests-temp-folder/suspicious-ascii-test" >/dev/null
for folder_name in $folder_list ; do
while IFS= read -r -d '' file_name; do
## Must be outside of process substitution to be able to exit script.
process_file "$file_name"
done < <(find "$HOME/trojan-source/$folder_name" -maxdepth 1 -type f -not -iwholename '*.git*' -print0 )
done
while IFS= read -r -d '' file_name; do
## Must be outside of process substitution to be able to exit script.
process_file "$file_name"
done < <(find "$HOME/suspicious-unicode-tests-temp-folder/suspicious-unicode-test" -maxdepth 1 -type f -not -iwholename '*.git*' -print0 )
while IFS= read -r -d '' file_name; do
## Must be outside of process substitution to be able to exit script.
process_file "$file_name"
done < <(find "$HOME/suspicious-unicode-tests-temp-folder/suspicious-ascii-test" -maxdepth 1 -type f -not -iwholename '*.git*' -print0 )
if [ ! "$(printf "%s" "test" | stcatn | wc -l)" = "1" ]; then
printf "%s\n" "$0: ERROR: 1" >&2
exit 1
fi
if [ ! "$(printf "%s\n" "test" | stcatn | wc -l)" = "1" ]; then
printf "%s\n" "$0: ERROR: 2" >&2
exit 1
fi
if [ ! "$(printf "%s\n\n" "test" | stcatn | wc -l)" = "2" ]; then
printf "%s\n" "$0: ERROR: 3" >&2
exit 1
fi
mkdir --parents -- "$HOME/suspicious-unicode-tests-temp-folder/suspicious-whitespace-test"
printf "\n \n " | sponge -- "$HOME/suspicious-unicode-tests-temp-folder/suspicious-whitespace-test/1.txt"
if ! stcatn "$HOME/suspicious-unicode-tests-temp-folder/suspicious-whitespace-test/1.txt" | unicode-show ; then
printf "%s\n" "$0: ERROR: 4" >&2
exit 1
fi
if [ ! "$(stcatn "$HOME/suspicious-unicode-tests-temp-folder/suspicious-whitespace-test/1.txt" | wc -l)" = "3" ]; then
printf "%s\n" "$0: ERROR: 5" >&2
exit 1
fi
printf "%s\n" "$0: INFO: OK"