kenpompy icon indicating copy to clipboard operation
kenpompy copied to clipboard

Add login failure detection

Open esqew opened this issue 1 year ago • 1 comments

Logging into KenPom with MechanicalSoup is a bit wonky in that the service seems to always return 200 OK status code even on a credential-related failure. This leads to confusion like in #15 where one might assume a login was successful as no exception was thrown, but downstream encounters issues trying to pull data requiring a valid session.

On further inspection, it seems the difference the response for a successful login and an unsuccessful one (due to incorrect credentials) is that the Set-Cookie response header returns a PHPSESSID for successful logins, and cookie invalidation information otherwise. As such, I've updated utils.py to look for the string "PHPSESSID=" in the response header value for Set-Cookie and, in its absence, throw the Logging in to kenpom.com failed Exception. I've also added logic into tests/conftest.py to ensure that pytest aborts when the login fails (as most tests will begin failing without a successful login anyway).

If you can, I could use some help testing this in verifying that everyone does indeed get a Set-Cookie: "PHPSESSID=..." header on successful login before this gets merged in.

esqew avatar Aug 05 '22 02:08 esqew

Missed this, thanks for the PR. I'll take try to test soon.

j-andrews7 avatar Oct 10 '22 14:10 j-andrews7