Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Model/Behavior/SocialAccountBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function validateAccount($provider, $reference, $token)
->where(['provider' => $provider, 'reference' => $reference])
->first();

if (!empty($socialAccount) && $socialAccount->token === $token) {
if (!empty($socialAccount) && hash_equals((string)$socialAccount->token, (string)$token)) {
if ($socialAccount->active) {
throw new AccountAlreadyActiveException(__d('cake_d_c/users', 'Account already validated'));
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Fixture/UsersFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
*/
class UsersFixture extends TestFixture
{
/**
* Explicit table alias so _schemaFromReflection resolves to
* CakeDC\Users\Model\Table\UsersTable (which overrides additional_data to json type).
* Without this, the fixture namespace plugin-detection fails because
* Plugin::isLoaded() uses forward-slash names while the namespace uses backslashes.
*
* @var string
*/
public string $tableAlias = 'CakeDC/Users.Users';

/**
* Init method
*
Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/Model/Behavior/SocialAccountBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ public function testValidateEmailInvalidToken()
$this->Behavior->validateAccount(1, 'reference-1234', 'invalid-token');
}

/**
* Partial token (prefix of the real token) must be rejected — exercises timing-safe comparison
*/
public function testValidateAccountPartialTokenIsRejected()
{
$this->expectException(RecordNotFoundException::class);
// 'token-123' is a prefix of the valid 'token-1234' — must still fail
$this->Behavior->validateAccount(SocialAccountsTable::PROVIDER_FACEBOOK, 'reference-1-1234', 'token-123');
}

/**
* Empty string token must be rejected — exercises timing-safe comparison with empty input
*/
public function testValidateAccountEmptyTokenIsRejected()
{
$this->expectException(RecordNotFoundException::class);
$this->Behavior->validateAccount(SocialAccountsTable::PROVIDER_FACEBOOK, 'reference-1-1234', '');
}

/**
* Test validateEmail method
*/
Expand Down
12 changes: 6 additions & 6 deletions tests/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
'provider' => ['type' => 'string', 'length' => 255, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'username' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'reference' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'avatar' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'avatar' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'description' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'link' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'link' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'token' => ['type' => 'string', 'length' => 500, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'token_secret' => ['type' => 'string', 'length' => 500, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'token_expires' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
Expand Down Expand Up @@ -62,15 +62,15 @@
'token_expires' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'api_token' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'activation_date' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'secret' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'secret_verified' => ['type' => 'boolean', 'length' => null, 'null' => true, 'default' => false, 'comment' => '', 'precision' => null],
'secret' => ['type' => 'string', 'length' => 32, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
'secret_verified' => ['type' => 'boolean', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'tos_date' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'active' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => true, 'comment' => '', 'precision' => null],
'active' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => false, 'comment' => '', 'precision' => null],
'is_superuser' => ['type' => 'boolean', 'length' => null, 'unsigned' => false, 'null' => false, 'default' => false, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'role' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => 'user', 'comment' => '', 'precision' => null, 'fixed' => null],
'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'modified' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'additional_data' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'additional_data' => ['type' => 'json', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'last_login' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'lockout_time' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'login_token' => ['type' => 'string', 'length' => 32, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
Expand Down
Loading