Skip to content

Commit b1a27d6

Browse files
committed
CI: Correct the tests and run them on GitHub Actions
1 parent 0410d11 commit b1a27d6

File tree

8 files changed

+173
-153
lines changed

8 files changed

+173
-153
lines changed

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,13 @@ remove_lib_wrapped:
307307
remove_locales_wrapped:
308308
for f in $(LANGUAGES); do $(RM) $(DESTDIR)$(LOCALEDIR)/$$f/LC_MESSAGES/$(PACKAGE).mo; done
309309

310-
check:
310+
check: default
311311
@echo "Running tests..."
312-
# Set LD_LIBRARY_PATH to include the current directory
313-
@export LDFLAGS="-Wl,-rpath,$(CURDIR)"; \
314-
export LD_LIBRARY_PATH=$(CURDIR):$$LD_LIBRARY_PATH; \
312+
@export LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH; \
313+
set -e; \
315314
for test in tests/*.sh; do \
316315
echo "Executing $$test..."; \
317-
bash $$test || echo "$$test failed"; \
316+
$$test; \
318317
done
319318
@echo "Tests completed!"
320319

ci/run-build-and-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ make -k $j \
3636
CFLAGS_lib='-Wall -W -Werror -fPIC' \
3737
all locales
3838

39+
make check
40+
3941
if git status --porcelain |grep ^.; then
4042
echo >&2 'git status reported uncleanness'
4143
exit 1

tests/test-pwqcheck-basic.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
#
66

7+
set -o pipefail
8+
9+
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
10+
711
if [ -t 1 ]; then
812
# Colors for better visibility
913
GREEN='\033[0;32m'
@@ -21,26 +25,25 @@ test_basic_password() {
2125
local expected="$2"
2226
local description="$3"
2327

24-
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
28+
printf "%-40s" "$description"
2529

26-
echo -n "Testing $description: "
2730
result=$(echo "$password" | "$PWQCHECK_BIN" -1 2>&1)
2831
exit_code=$?
2932

3033
if [ "$expected" = "pass" -a "$exit_code" -eq 0 ] || \
3134
[ "$expected" = "fail" -a "$exit_code" -ne 0 ]; then
3235
echo -e "${GREEN}PASS${NC}"
33-
echo " Password tested: '$password'"
34-
echo " Result: $result"
35-
echo
36+
# echo " Password tested: '$password'"
37+
# echo " Result: $result"
38+
# echo
3639
return 0
3740
else
3841
echo -e "${RED}FAIL${NC}"
3942
echo "Password tested: $password"
4043
echo "Expected: $expected"
4144
echo "Got: $result"
4245
echo
43-
return 1
46+
exit 1
4447
fi
4548
}
4649

@@ -73,4 +76,5 @@ test_basic_password "" "fail" "Empty password"
7376
test_basic_password "$(printf 'a%.0s' {1..71})" "fail" "Very long password"
7477
test_basic_password "ljy8zk9aBJ3hA3TXAAMAQe61ytFohJM4SuPFbA4L1xDqV2JDE1n8BCnLN96evcJMWyTkr9y3" "pass" "Max length password"
7578
test_basic_password "ljy8zk9aBJ3hA3TXAAMAQe61ytFohJM4SuPFbA4L1xDqV2JDE1n8BCnLN96evcJMWyTkr9y312345" "fail" "Max length exceed password"
76-
echo -e "\nAll basic password validation tests completed!"
79+
80+
echo -e "\nBasic password validation tests completed\n"

tests/test-pwqcheck-length.sh

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
#
66

7+
set -o pipefail
8+
9+
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
10+
711
if [ -t 1 ]; then
812
# Colors for better visibility
913
GREEN='\033[0;32m'
@@ -22,59 +26,53 @@ test_password() {
2226
local expected="$3"
2327
local test_name="$4"
2428

25-
printf "Testing %-40s" "$test_name:"
26-
27-
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
29+
printf "%-40s" "$test_name"
2830

2931
output=$(echo "$password" | "$PWQCHECK_BIN" -1 "min=$min_params" 2>&1)
3032
status=$?
3133

3234
if [ "$expected" = "pass" -a $status -eq 0 ] || \
3335
[ "$expected" = "fail" -a $status -ne 0 ]; then
3436
echo -e "${GREEN}PASS${NC}"
35-
echo " Password tested: '$password'"
36-
echo " Result: $output"
37-
echo
37+
# echo " Password tested: '$password'"
38+
# echo " Result: $output"
39+
# echo
3840
else
3941
echo -e "${RED}FAIL${NC}"
4042
echo " Password tested: '$password'"
4143
echo " Expected: $expected"
4244
echo " Got: $output"
4345
echo " Exit status: $status"
4446
echo
45-
return 1
47+
exit 1
4648
fi
4749
}
4850

49-
# Main test suite
50-
main() {
51-
echo "=== Password Length Tests ==="
52-
echo
51+
echo "Password Length Tests"
52+
echo
5353

54-
# Test 1: Default minimum lengths
55-
test_password "short" "24,12,8,7,6" "fail" "Short password"
56-
test_password "ThisIsAVeryLongPasswordThatShouldPass123!" "24,12,8,7,6" "pass" "Long complex password"
54+
# Test 1: Default minimum lengths
55+
test_password "short" "24,12,8,7,6" "fail" "Short password"
56+
test_password "ThisIsAVeryLongPasswordThatShouldPass123!" "24,12,8,7,6" "pass" "Long complex password"
5757

58-
# Test 2: Custom minimum lengths
59-
test_password "pass123" "6,6,6,6,6" "pass" "Password with relaxed mins"
60-
test_password "a" "6,6,6,6,6" "fail" "Single character password"
58+
# Test 2: Custom minimum lengths
59+
test_password "pass123" "6,6,6,6,6" "pass" "Password with relaxed mins"
60+
test_password "a" "6,6,6,6,6" "fail" "Single character password"
6161

62-
# Test 3: Different complexity levels
63-
test_password "BearD&Tach" "8,8,8,8,8" "pass" "Simple but long password"
64-
test_password "P@ssw0rd!" "8,8,8,8,8" "pass" "Complex password"
62+
# Test 3: Different complexity levels
63+
test_password "BearD&Tach" "8,8,8,8,8" "pass" "Simple but long password"
64+
test_password "P@ssw0rd!" "8,8,8,8,8" "pass" "Complex password"
6565

66-
# Test 4: Edge cases
67-
test_password "YakMeas1" "8,8,8,8,8" "pass" "Exactly minimum length"
68-
test_password "7chars" "8,8,8,8,8" "fail" "Below minimum length"
66+
# Test 4: Edge cases
67+
test_password "YakMeas1" "8,8,8,8,8" "pass" "Exactly minimum length"
68+
test_password "7chars" "8,8,8,8,8" "fail" "Below minimum length"
6969

70-
# Test 5: Different complexity classes
71-
echo "Testing complexity classes..."
72-
test_password "FigRatMatBatSatWatPatCat" "24,12,8,7,6" "pass" "N0: 24-char basic password"
73-
test_password "Complex12Pass" "24,12,8,7,6" "pass" "N1: 12-char mixed password"
74-
test_password "P@ss8chr" "24,12,8,7,6" "pass" "N2: 8-char complex password"
75-
test_password "P@s7chr" "24,12,8,7,6" "pass" "N3: 7-char complex password"
76-
test_password "B!rd5#K" "24,12,8,7,6" "pass" "N4: 6-char highly complex password"
77-
}
70+
# Test 5: Different complexity classes
71+
echo "Testing complexity classes..."
72+
test_password "FigRatMatBatSatWatPatCat" "24,12,8,7,6" "pass" "N0: 24-char basic password"
73+
test_password "Complex12Pass" "24,12,8,7,6" "pass" "N1: 12-char mixed password"
74+
test_password "P@ss8chr" "24,12,8,7,6" "pass" "N2: 8-char complex password"
75+
test_password "P@s7chr" "24,12,8,7,6" "pass" "N3: 7-char complex password"
76+
test_password "B!rd5#K" "24,12,8,7,6" "pass" "N4: 6-char highly complex password"
7877

79-
# Run the tests
80-
main
78+
echo -e "\nPassword length tests completed\n"

tests/test-pwqcheck-multi.sh

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
#
66

7+
set -o pipefail
8+
9+
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
10+
711
if [ -t 1 ]; then
812
# Colors for better visibility
913
GREEN='\033[0;32m'
@@ -21,14 +25,11 @@ test_multiple_passwords() {
2125
local passwords="$2"
2226
local expected_results="$3"
2327

24-
echo -e "\nRunning Test: ${test_name}"
25-
echo "------------------------"
28+
printf "%-40s" "$test_name"
2629

2730
# Create a temporary file for test output
2831
local temp_output
29-
temp_output=$(mktemp)
30-
31-
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
32+
temp_output=$(mktemp) || exit
3233

3334
# Run pwqcheck with multiple passwords
3435
echo -e "$passwords" | "$PWQCHECK_BIN" --multi -1 > "$temp_output" 2>&1
@@ -38,13 +39,15 @@ test_multiple_passwords() {
3839
actual_results=$(cat "$temp_output")
3940
if echo "$actual_results" | grep -q "$expected_results"; then
4041
echo -e "${GREEN}PASS${NC}"
41-
echo "Test output matches expected results"
42+
# echo "Test output matches expected results"
4243
else
4344
echo -e "${RED}FAIL${NC}"
4445
echo "Expected:"
4546
echo "$expected_results"
4647
echo "Got:"
4748
cat "$temp_output"
49+
rm -f "$temp_output"
50+
exit 1
4851
fi
4952

5053
rm -f "$temp_output"
@@ -107,18 +110,20 @@ VeryLongP@ssword123!" \
107110
OK: medium12345
108111
OK: VeryLongP@ssword123!"
109112

110-
echo -e "\nAll multiple password tests completed!"
113+
echo -e "\nMultiple password tests completed\n"
114+
115+
exit 0
111116

112117
# Test 6: Large number of passwords
113118
echo -e "\nTesting large batch of passwords..."
114119
{
115-
for i in {1..50}; do
116-
if [ $((i % 2)) -eq 0 ]; then
117-
echo "StrongP@ss${i}!"
118-
else
119-
echo "weak${i}"
120-
fi
121-
done
122-
} | "$PWQCHECK_BIN" --multi -1
120+
for i in {1..50}; do
121+
if [ $((i % 2)) -eq 0 ]; then
122+
echo "StrongP@ss${i}!"
123+
else
124+
echo "weak${i}"
125+
fi
126+
done
127+
} | "$PWQCHECK_BIN" --multi -1
123128

124129
echo "Large batch test completed!"

tests/test-pwqcheck-similarity.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
#
66

7+
set -o pipefail
8+
9+
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
10+
711
if [ -t 1 ]; then
812
# Colors for better visibility
913
GREEN='\033[0;32m'
@@ -15,25 +19,24 @@ else
1519
NC=''
1620
fi
1721

18-
1922
# Function to run pwqcheck with two passwords
2023
test_passwords() {
2124
local new_pass="$1"
2225
local old_pass="$2"
2326
local expected_result="$3"
2427
local test_name="$4"
2528

26-
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck"
29+
printf "%-40s" "$test_name"
2730

2831
# Run pwqcheck with both passwords and --similar=deny option
2932
result=$(printf "%s\n%s" "$new_pass" "$old_pass" | "$PWQCHECK_BIN" -2 similar=deny 2>&1)
3033
exit_code=$?
3134

3235
# Check if the result matches expected
3336
if [ $exit_code -eq "$expected_result" ]; then
34-
echo -e "${GREEN}PASS:${NC} $test_name"
37+
echo -e "${GREEN}PASS${NC}"
3538
else
36-
echo -e "${RED}FAIL:${NC} $test_name"
39+
echo -e "${RED}FAIL${NC}"
3740
echo " Expected exit code: $expected_result, Got: $exit_code"
3841
echo " Output: $result"
3942
fi
@@ -42,63 +45,63 @@ test_passwords() {
4245

4346
#add a function to test when similar passwords are permitted
4447
test_passwords_permit() {
45-
4648
local new_pass="$1"
4749
local old_pass="$2"
4850
local expected_result="$3"
4951
local test_name="$4"
5052

53+
printf "%-40s" "$test_name"
54+
5155
# Run pwqcheck with both passwords and --similar=permit option
52-
result=$(printf "%s\n%s" "$new_pass" "$old_pass" | "$PWQCHECK_BIN" -2 similar=permit 2>&1)
56+
result=$(printf "%s\n%s" "$new_pass" "$old_pass" | "$PWQCHECK_BIN" -2 similar=permit 2>&1)
5357
exit_code=$?
5458

5559
# Check if the result matches expected
5660
if [ $exit_code -eq "$expected_result" ]; then
57-
echo -e "${GREEN}✓ PASS:${NC} $test_name"
58-
((TESTS_PASSED++))
61+
echo -e "${GREEN}PASS${NC}"
5962
else
60-
echo -e "${RED}FAIL:${NC} $test_name"
63+
echo -e "${RED}FAIL${NC}"
6164
echo " Expected exit code: $expected_result, Got: $exit_code"
6265
echo " Output: $result"
6366
fi
6467
}
6568

6669
# Main testing section
6770
echo "Running pwqcheck similarity tests with --similar=deny..."
68-
echo "===================================================="
6971

7072
# Test 1: Identical passwords (should fail with deny)
7173
test_passwords "ComplexPass123!" "ComplexPass123!" 1 \
72-
"Identical passwords should be rejected when similarity is denied"
74+
"Identical passwords rejected"
7375

7476
# Test 2: Case variation (should fail with deny)
7577
test_passwords "ComplexPass123!" "complexpass123!" 1 \
76-
"Case variations should be rejected when similarity is denied"
78+
"Case variations rejected"
7779

7880
# Test 3: Number substitution (should fail with deny)
7981
test_passwords "P@ssw0rd123!" "Password123!" 1 \
80-
"Common number substitutions should be rejected when similarity is denied"
82+
"Common number substitutions rejected"
8183

8284
# Test 4: Different passwords (should pass even with deny)
8385
test_passwords "ComplexPass123!" "TotallyDifferent456@" 0 \
84-
"Different passwords should be accepted even when similarity is denied"
86+
"Different passwords accepted"
8587

8688
echo
8789
echo "Running pwqcheck similarity tests with --similar=permit..."
88-
echo "====================================================="
8990

9091
# Test 5: Identical passwords (should pass with permit)
9192
test_passwords_permit "VeryComplexPass#789" "VeryComplexPass#789!" 0 \
92-
"Identical passwords should be accepted when similarity is permitted"
93+
"Identical passwords accepted"
9394

9495
# Test 6: Case variation (should pass with permit)
9596
test_passwords_permit "ComplexPass123!" "complexpass123!" 0 \
96-
"Case variations should be accepted when similarity is permitted"
97+
"Case variations accepted"
9798

9899
# Test 7: Number substitution (should pass with permit)
99100
test_passwords_permit "P@ssw0rd123!" "Password123!" 0 \
100-
"Common number substitutions should be accepted when similarity is permitted"
101+
"Common number substitutions accepted"
101102

102103
# Test 8: Different passwords (should pass with permit)
103104
test_passwords_permit "ComplexPass123!" "TotallyDifferent456@" 0 \
104-
"Different passwords should be accepted when similarity is permitted"
105+
"Different passwords accepted"
106+
107+
echo -e "\npwqcheck similarity tests completed\n"

0 commit comments

Comments
 (0)