-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add tests for passwdqc pwqcheck #41
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you for the contribution. Yes, we need tests.
Makefile
Outdated
@@ -307,6 +307,17 @@ remove_lib_wrapped: | |||
remove_locales_wrapped: | |||
for f in $(LANGUAGES); do $(RM) $(DESTDIR)$(LOCALEDIR)/$$f/LC_MESSAGES/$(PACKAGE).mo; done | |||
|
|||
test: |
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 we want this target called check
, and it should exit non-zero on any test failures.
And we should run it from GitHub Actions, but that may be a separate PR or at least separate commit.
@echo "Running tests..." | ||
# Set LD_LIBRARY_PATH to include the current directory | ||
@export LDFLAGS="-Wl,-rpath,$(CURDIR)"; \ | ||
export LD_LIBRARY_PATH=$(CURDIR):$$LD_LIBRARY_PATH; \ |
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.
My thinking was to start with what I've been doing in manual testing - running pwqcheck on a large file and confirming the hash of its output isn't unexpectedly changed. This wouldn't directly test the individual checks, but it would ensure stable behavior. So if we ever make code changes that change the behavior on such large test input, we'll need to explicitly acknowledge this and update the hash. A drawback is the large input file would need to be stored somewhere in here or download from somewhere external (e.g., the
I see that you also test a few features that the above would not. |
tests/test-pwqcheck-basic.sh
Outdated
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 lenght password" |
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.
Typo: lenght
.
Also, if we do these tests, there should probably be one for a password that's just above max length, with expected fail
.
Also, shouldn't we expect specific fail
reasons?
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.
Thanks for the review !
-
I will correct the typo and add test case for a password just above the max length and ensure it fails as expected.
-
Reagarding the fail reason,Could you please clarify if you are expecting specific fail reasons for each test case?
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.
- Reagarding the fail reason,Could you please clarify if you are expecting specific fail reasons for each test case?
Yes, like you already have in another script where you check against expected output. Instead of the word fail
, you could include those reason strings.
Thanks for sharing your approach |
This PR currently fails our whitespace-errors test:
|
In general, yes. In this same PR, no.
Currently no. I'd like to hear from @ldv-alt on this. Off the top of my head, the options are:
|
The color output could be undesired when redirected to a build log file. I suggest to use color only when outputting to a tty, which I think you can test with We use 8-wide tabs for indentation in this source tree, and I think it makes sense to continue with this style for the shell scripts in here as well (not switch to 4 spaces). |
tests/test-pwqcheck-basic.sh
Outdated
exit_code=$? | ||
|
||
if [[ "$expected" == "pass" && $exit_code -eq 0 ]] || \ | ||
[[ "$expected" == "fail" && $exit_code -ne 0 ]]; then |
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.
This could be more portable (to other shells) if written as a test
expression (so in single brackets and using -a
and -o
for AND and OR) rather than as two bash
conditional expressions.
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.
should we set the default shell to sh instead of bash?
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.
We could, if we actually test these scripts with non-bash as well.
Please also add your copyright statements and references to |
This is still failing. You can run the above |
Signed-off-by: Zaiba Sanglikar <[email protected]>
Signed-off-by: Zaiba Sanglikar <[email protected]>
Currently, there are no tests implemented for the package, so this serves as an initial attempt to implement basic testing coverage.
This PR introduces an initial set of tests for the pwqcheck binary of the passwdqc package.
Any feedback or suggestions would be appreciated.