restic / rest-server

Rest Server is a high performance HTTP server that implements restic's REST backend API.
BSD 2-Clause "Simplified" License
922 stars 138 forks source link

What is the purpose of the for-loop in `TestValidate` of `htpasswd_test.go`? #220

Closed m0 closed 1 year ago

m0 commented 1 year ago

This is not a feature request/enhancement, but I did not find any other apropriate way to ask questions about the codebase (the forum seems to be targeted towards end-users):

I am debugging an issue with failing authentication and started looking at the code. While looking through the tests of htpasswd.go by @MichaelEischer and @rawtaz I stumbled upon the for-loop in TestValidate whose purpose is not clear to me. I have some guesses (ranging from forgotten debugging code to testing internal state of htpass) so it would be nice if the authors could shade some light on this. :bow: :slightly_smiling_face: Thanks!

MichaelEischer commented 1 year ago

htpass.Validate caches successful authentications. That is, we need at least a second iteration to test that the caching works as expected (or rather that the password is still checked correctly). The additional iterations are just there make sure that continued password validations still behave as expected. Three iterations would probably be enough to achieve the same effect. But the test is fast enough anyways, so it doesn't hurt.