Skip to content

Commit 85f055d

Browse files
authored
Merge pull request #1097 from CakeDC/issue/1096-bug-in-social-behavior
#1096: fixed `findExistingForSocialLogin` finder
2 parents f538426 + 325c48c commit 85f055d

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/Model/Behavior/SocialBehavior.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Cake\Core\Configure;
1717
use Cake\Datasource\EntityInterface;
1818
use Cake\Event\EventDispatcherTrait;
19+
use Cake\ORM\Query\SelectQuery;
1920
use Cake\Utility\Hash;
2021
use CakeDC\Users\Exception\AccountNotActiveException;
2122
use CakeDC\Users\Exception\MissingEmailException;
@@ -138,7 +139,6 @@ protected function _createSocialUser($data, $options = [])
138139
$useEmail = $options['use_email'] ?? null;
139140
$validateEmail = (bool)($options['validate_email'] ?? null);
140141
$tokenExpiration = $options['token_expiration'] ?? null;
141-
$existingUser = null;
142142
$email = $data['email'] ?? null;
143143
if ($useEmail && empty($email)) {
144144
throw new MissingEmailException(__d('cake_d_c/users', 'Email not present'));
@@ -276,12 +276,11 @@ public function generateUniqueUsername($username)
276276
* Prepare a query to retrieve existing entity for social login
277277
*
278278
* @param \Cake\ORM\Query\SelectQuery $query The base query.
279-
* @param array $options Find options with email key.
279+
* @param string|null $email Find options with email key.
280280
* @return \Cake\ORM\Query\SelectQuery
281281
*/
282-
public function findExistingForSocialLogin(\Cake\ORM\Query\SelectQuery $query, array $options)
282+
public function findExistingForSocialLogin(SelectQuery $query, ?string $email = null): SelectQuery
283283
{
284-
$email = $options['email'] ?? null;
285284
if (!$email) {
286285
return $query->where('1 != 1');
287286
}

tests/TestCase/Controller/Traits/Webauthn2FaTraitTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,10 @@ public function testWebauthn2faIsRegister()
108108
$this->Trait
109109
->expects($this->exactly(2))
110110
->method('set')
111-
->willReturnCallback(fn ($name, $value) =>
112-
match ([$name, $value]) {
113-
['isRegister', true] => null,
114-
['username', 'user-2'] => null
115-
});
111+
->willReturnCallback(fn ($name, $value) => match ([$name, $value]) {
112+
['isRegister', true] => null,
113+
['username', 'user-2'] => null
114+
});
116115
$this->Trait->webauthn2fa();
117116
$this->assertSame(
118117
$user,
@@ -146,11 +145,10 @@ public function testWebauthn2faDontRequireRegister()
146145
$this->Trait
147146
->expects($this->exactly(2))
148147
->method('set')
149-
->willReturnCallback(fn ($name, $value) =>
150-
match ([$name, $value]) {
151-
['isRegister', false] => null,
152-
['username', 'user-1'] => null
153-
});
148+
->willReturnCallback(fn ($name, $value) => match ([$name, $value]) {
149+
['isRegister', false] => null,
150+
['username', 'user-1'] => null
151+
});
154152
$this->Trait->webauthn2fa();
155153
$this->assertSame(
156154
$user,

0 commit comments

Comments
 (0)