nicumicle / simple-jwt-login

This plugin allows you to log in, register, authenticate, delete and change the user password to a WordPress website using a JWT.
http://wordpress.org/plugins/simple-jwt-login/
GNU General Public License v3.0
83 stars 23 forks source link

True2thepen patch 3 #67

Open true2thepen opened 1 year ago

true2thepen commented 1 year ago

Issue Link

19

Types of changes

Description

Added check for username/email in username field on /auth endpoint. This allows user to login in with either username or email in username field as they normally would in WordPress.

How has this been tested?

Tested on dev server running WP 6.1.1 and PHP 8.1

Screenshots (optional)

Checklist:

true2thepen commented 1 year ago

This is failing 2 tests. I have yet to discover why. It works on the dev server. I did find during all these failed test that I inadvertently allowed the email field to contain either the username or email. I have since fixed this. Any ideas on why these two tests are failing let me know.

true2thepen commented 1 year ago

@nicumicle Help please. Are the following two test possibly incorrect. Both mock a password of 1234 and send a password of 123. It's the only reason I can see that my changes are failing the tests. If not, any suggestions - cause I'm befuddled at the moment. Code works with testing on my dev server.

Use Postman to test. Pass username field with username or email and correct password returns true. Pass incorrect credentials returns false. Pass email field with email and correct password returns true. Pass email field with username and correct password returns false. Pass incorrect credentials returns false.

Error output: There were 2 errors:

1) SimpleJWTLoginTests\Services\AuthenticateServiceTest::testSuccessFlowWithFullPayload Exception: Wrong user credentials.

/app/simple-jwt-login/src/Services/AuthenticateService.php:119 /app/simple-jwt-login/src/Services/AuthenticateService.php:79 /app/tests/Services/AuthenticateServiceTest.php:293

This test mocks the password to 1234 yet sends a password of 123. Test is supposed to be a successful test.

2) SimpleJWTLoginTests\Services\AuthenticateServiceTest::testSuccessFlowWithFullPayloadAndPasshash Exception: Wrong user credentials.

/app/simple-jwt-login/src/Services/AuthenticateService.php:119 /app/simple-jwt-login/src/Services/AuthenticateService.php:79 /app/tests/Services/AuthenticateServiceTest.php:346

This test mocks a password of 1234, yet sends a password of 123. Test is supposed to be a successful test.

ERRORS! Tests: 270, Assertions: 602, Errors: 2.

true2thepen commented 1 year ago

Found the problem in the tests. When you change the authentication to allow username to contain either the username or the email, you need to account for this in the tests. Which they weren't. Tests are now fixed.