Skip to content
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

#1096: fixed findExistingForSocialLogin finder #1097

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Model/Behavior/SocialBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventDispatcherTrait;
use Cake\ORM\Query\SelectQuery;
use Cake\Utility\Hash;
use CakeDC\Users\Exception\AccountNotActiveException;
use CakeDC\Users\Exception\MissingEmailException;
Expand Down Expand Up @@ -138,7 +139,6 @@ protected function _createSocialUser($data, $options = [])
$useEmail = $options['use_email'] ?? null;
$validateEmail = (bool)($options['validate_email'] ?? null);
$tokenExpiration = $options['token_expiration'] ?? null;
$existingUser = null;
$email = $data['email'] ?? null;
if ($useEmail && empty($email)) {
throw new MissingEmailException(__d('cake_d_c/users', 'Email not present'));
Expand Down Expand Up @@ -276,12 +276,11 @@ public function generateUniqueUsername($username)
* Prepare a query to retrieve existing entity for social login
*
* @param \Cake\ORM\Query\SelectQuery $query The base query.
* @param array $options Find options with email key.
* @param string|null $email Find options with email key.
* @return \Cake\ORM\Query\SelectQuery
*/
public function findExistingForSocialLogin(\Cake\ORM\Query\SelectQuery $query, array $options)
public function findExistingForSocialLogin(SelectQuery $query, ?string $email = null): SelectQuery
{
$email = $options['email'] ?? null;
if (!$email) {
return $query->where('1 != 1');
}
Expand Down
18 changes: 8 additions & 10 deletions tests/TestCase/Controller/Traits/Webauthn2FaTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ public function testWebauthn2faIsRegister()
$this->Trait
->expects($this->exactly(2))
->method('set')
->willReturnCallback(fn ($name, $value) =>
match ([$name, $value]) {
['isRegister', true] => null,
['username', 'user-2'] => null
});
->willReturnCallback(fn ($name, $value) => match ([$name, $value]) {
['isRegister', true] => null,
['username', 'user-2'] => null
});
$this->Trait->webauthn2fa();
$this->assertSame(
$user,
Expand Down Expand Up @@ -146,11 +145,10 @@ public function testWebauthn2faDontRequireRegister()
$this->Trait
->expects($this->exactly(2))
->method('set')
->willReturnCallback(fn ($name, $value) =>
match ([$name, $value]) {
['isRegister', false] => null,
['username', 'user-1'] => null
});
->willReturnCallback(fn ($name, $value) => match ([$name, $value]) {
['isRegister', false] => null,
['username', 'user-1'] => null
});
$this->Trait->webauthn2fa();
$this->assertSame(
$user,
Expand Down
Loading