Skip to content

Commit

Permalink
Merge pull request #1097 from CakeDC/issue/1096-bug-in-social-behavior
Browse files Browse the repository at this point in the history
#1096: fixed `findExistingForSocialLogin` finder
  • Loading branch information
arusinowski authored Sep 5, 2024
2 parents f538426 + 325c48c commit 85f055d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
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

0 comments on commit 85f055d

Please sign in to comment.