-
Notifications
You must be signed in to change notification settings - Fork 18
Add tests for passwdqc pwqcheck #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zaiba-S
wants to merge
2
commits into
openwall:main
Choose a base branch
from
Zaiba-S:add-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2025 by Zaiba Sanglikar. See LICENSE. | ||
# | ||
# | ||
|
||
if [ -t 1 ]; then | ||
# Colors for better visibility | ||
GREEN='\033[0;32m' | ||
RED='\033[0;31m' | ||
NC='\033[0m' | ||
else | ||
GREEN='' | ||
RED='' | ||
NC='' | ||
fi | ||
|
||
# Test function for basic password checks | ||
test_basic_password() { | ||
local password="$1" | ||
local expected="$2" | ||
local description="$3" | ||
|
||
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck" | ||
|
||
echo -n "Testing $description: " | ||
result=$(echo "$password" | "$PWQCHECK_BIN" -1 2>&1) | ||
exit_code=$? | ||
|
||
if [ "$expected" = "pass" -a "$exit_code" -eq 0 ] || \ | ||
[ "$expected" = "fail" -a "$exit_code" -ne 0 ]; then | ||
echo -e "${GREEN}PASS${NC}" | ||
echo " Password tested: '$password'" | ||
echo " Result: $result" | ||
echo | ||
return 0 | ||
else | ||
echo -e "${RED}FAIL${NC}" | ||
echo "Password tested: $password" | ||
echo "Expected: $expected" | ||
echo "Got: $result" | ||
echo | ||
return 1 | ||
fi | ||
} | ||
|
||
echo "Running Basic Password Validation Tests..." | ||
|
||
# Test Suite 1: Strong Passwords | ||
echo -e "\nTesting Strong Passwords:" | ||
test_basic_password "P@ssw0rd123!" "pass" "Standard strong password" | ||
test_basic_password "Tr0ub4dor&3" "pass" "Complex password" | ||
test_basic_password "iStayInloreAtHomeb7&street111" "pass" "Long passphrase" | ||
test_basic_password "H3llo@W0rld2024" "pass" "Strong password with year" | ||
|
||
# Test Suite 2: Common Weak Patterns | ||
echo -e "\nTesting Weak Patterns:" | ||
test_basic_password "password123" "fail" "Common password with numbers" | ||
test_basic_password "qwerty" "fail" "Keyboard pattern" | ||
test_basic_password "admin123" "fail" "Common admin password" | ||
test_basic_password "letmein" "fail" "Common weak password" | ||
|
||
# Test Suite 3: Mixed Complexity | ||
echo -e "\nTesting Mixed Complexity:" | ||
test_basic_password "MyP@ssw0rd" "pass" "Mixed case with symbols and numbers" | ||
test_basic_password "Str0ng!P@ssphrase" "pass" "Strong with multiple special chars" | ||
test_basic_password "C0mpl3x1ty!" "pass" "Complex but reasonable length" | ||
|
||
# Test Suite 4: Edge Cases | ||
echo -e "\nTesting Edge Cases:" | ||
test_basic_password " " "fail" "Single space" | ||
test_basic_password "" "fail" "Empty password" | ||
test_basic_password "$(printf 'a%.0s' {1..71})" "fail" "Very long password" | ||
test_basic_password "ljy8zk9aBJ3hA3TXAAMAQe61ytFohJM4SuPFbA4L1xDqV2JDE1n8BCnLN96evcJMWyTkr9y3" "pass" "Max length password" | ||
test_basic_password "ljy8zk9aBJ3hA3TXAAMAQe61ytFohJM4SuPFbA4L1xDqV2JDE1n8BCnLN96evcJMWyTkr9y312345" "fail" "Max length exceed password" | ||
echo -e "\nAll basic password validation tests completed!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2025 by Zaiba Sanglikar. See LICENSE. | ||
# | ||
# | ||
|
||
if [ -t 1 ]; then | ||
# Colors for better visibility | ||
GREEN='\033[0;32m' | ||
RED='\033[0;31m' | ||
NC='\033[0m' | ||
else | ||
GREEN='' | ||
RED='' | ||
NC='' | ||
fi | ||
|
||
# Test helper function with improved output handling | ||
test_password() { | ||
local password="$1" | ||
local min_params="$2" | ||
local expected="$3" | ||
local test_name="$4" | ||
|
||
printf "Testing %-40s" "$test_name:" | ||
|
||
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck" | ||
|
||
output=$(echo "$password" | "$PWQCHECK_BIN" -1 "min=$min_params" 2>&1) | ||
status=$? | ||
|
||
if [ "$expected" = "pass" -a $status -eq 0 ] || \ | ||
[ "$expected" = "fail" -a $status -ne 0 ]; then | ||
echo -e "${GREEN}PASS${NC}" | ||
echo " Password tested: '$password'" | ||
echo " Result: $output" | ||
echo | ||
else | ||
echo -e "${RED}FAIL${NC}" | ||
echo " Password tested: '$password'" | ||
echo " Expected: $expected" | ||
echo " Got: $output" | ||
echo " Exit status: $status" | ||
echo | ||
return 1 | ||
fi | ||
} | ||
|
||
# Main test suite | ||
main() { | ||
echo "=== Password Length Tests ===" | ||
echo | ||
|
||
# Test 1: Default minimum lengths | ||
test_password "short" "24,12,8,7,6" "fail" "Short password" | ||
test_password "ThisIsAVeryLongPasswordThatShouldPass123!" "24,12,8,7,6" "pass" "Long complex password" | ||
|
||
# Test 2: Custom minimum lengths | ||
test_password "pass123" "6,6,6,6,6" "pass" "Password with relaxed mins" | ||
test_password "a" "6,6,6,6,6" "fail" "Single character password" | ||
|
||
# Test 3: Different complexity levels | ||
test_password "BearD&Tach" "8,8,8,8,8" "pass" "Simple but long password" | ||
test_password "P@ssw0rd!" "8,8,8,8,8" "pass" "Complex password" | ||
|
||
# Test 4: Edge cases | ||
test_password "YakMeas1" "8,8,8,8,8" "pass" "Exactly minimum length" | ||
test_password "7chars" "8,8,8,8,8" "fail" "Below minimum length" | ||
|
||
# Test 5: Different complexity classes | ||
echo "Testing complexity classes..." | ||
test_password "FigRatMatBatSatWatPatCat" "24,12,8,7,6" "pass" "N0: 24-char basic password" | ||
test_password "Complex12Pass" "24,12,8,7,6" "pass" "N1: 12-char mixed password" | ||
test_password "P@ss8chr" "24,12,8,7,6" "pass" "N2: 8-char complex password" | ||
test_password "P@s7chr" "24,12,8,7,6" "pass" "N3: 7-char complex password" | ||
test_password "B!rd5#K" "24,12,8,7,6" "pass" "N4: 6-char highly complex password" | ||
} | ||
|
||
# Run the tests | ||
main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2025 by Zaiba Sanglikar. See LICENSE. | ||
# | ||
# | ||
|
||
if [ -t 1 ]; then | ||
# Colors for better visibility | ||
GREEN='\033[0;32m' | ||
RED='\033[0;31m' | ||
NC='\033[0m' | ||
else | ||
GREEN='' | ||
RED='' | ||
NC='' | ||
fi | ||
|
||
# Function to test multiple passwords | ||
test_multiple_passwords() { | ||
local test_name="$1" | ||
local passwords="$2" | ||
local expected_results="$3" | ||
|
||
echo -e "\nRunning Test: ${test_name}" | ||
echo "------------------------" | ||
|
||
# Create a temporary file for test output | ||
local temp_output | ||
temp_output=$(mktemp) | ||
|
||
PWQCHECK_BIN="$(dirname "$0")/../pwqcheck" | ||
|
||
# Run pwqcheck with multiple passwords | ||
echo -e "$passwords" | "$PWQCHECK_BIN" --multi -1 > "$temp_output" 2>&1 | ||
|
||
# Compare results | ||
local actual_results | ||
actual_results=$(cat "$temp_output") | ||
if echo "$actual_results" | grep -q "$expected_results"; then | ||
echo -e "${GREEN}PASS${NC}" | ||
echo "Test output matches expected results" | ||
else | ||
echo -e "${RED}FAIL${NC}" | ||
echo "Expected:" | ||
echo "$expected_results" | ||
echo "Got:" | ||
cat "$temp_output" | ||
fi | ||
|
||
rm -f "$temp_output" | ||
} | ||
|
||
echo "Running Multiple Password Tests..." | ||
|
||
# Test 1: Mix of valid and invalid passwords | ||
test_multiple_passwords "Mixed Passwords" \ | ||
"StrongP@ss123! | ||
weak | ||
Tr0ub4dor&3 | ||
password123 | ||
C0mpl3x1ty!" \ | ||
"OK: StrongP@ss123! | ||
Bad passphrase | ||
OK: Tr0ub4dor&3 | ||
Bad passphrase | ||
OK: C0mpl3x1ty!" | ||
|
||
# Test 2: All valid passwords | ||
test_multiple_passwords "All Valid Passwords" \ | ||
"P@ssw0rd123! | ||
Tr0ub4dor&3 | ||
C0mpl3x1ty! | ||
H3llo@W0rld" \ | ||
"OK: P@ssw0rd123! | ||
OK: Tr0ub4dor&3 | ||
OK: C0mpl3x1ty! | ||
OK: H3llo@W0rld" | ||
|
||
# Test 3: All invalid passwords | ||
test_multiple_passwords "All Invalid Passwords" \ | ||
"password123 | ||
qwerty | ||
admin | ||
letmein" \ | ||
"Bad passphrase | ||
Bad passphrase | ||
Bad passphrase | ||
Bad passphrase" | ||
|
||
# Test 4: Empty lines and special characters | ||
test_multiple_passwords "Special Cases" \ | ||
"StrongP@ss123! | ||
P@ssw0rd! | ||
Tr0ub4dor&3" \ | ||
"OK: StrongP@ss123! | ||
Bad passphrase | ||
OK: P@ssw0rd! | ||
Bad passphrase | ||
OK: Tr0ub4dor&3" | ||
|
||
# Test 5: With custom parameters | ||
test_multiple_passwords "Custom Parameters" \ | ||
"short | ||
medium12345 | ||
VeryLongP@ssword123!" \ | ||
"Bad passphrase | ||
OK: medium12345 | ||
OK: VeryLongP@ssword123!" | ||
|
||
echo -e "\nAll multiple password tests completed!" | ||
|
||
# Test 6: Large number of passwords | ||
echo -e "\nTesting large batch of passwords..." | ||
{ | ||
for i in {1..50}; do | ||
if [ $((i % 2)) -eq 0 ]; then | ||
echo "StrongP@ss${i}!" | ||
else | ||
echo "weak${i}" | ||
fi | ||
done | ||
} | "$PWQCHECK_BIN" --multi -1 | ||
|
||
echo "Large batch test completed!" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is excessive. For my manual testing, I simply set
LD_LIBRARY_PATH=.
and it just works.The change of
LDFLAGS
wouldn't take effect at this point anyway, because the test scripts being invoked from here assume the tool has already been built.