Skip to content
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
21 changes: 21 additions & 0 deletions lib/Cleantalk/Antispam/Integrations/NextendSocialLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function getDataForChecking($argument)
)
);
}
return null;
}

public function doBlock($message)
Expand All @@ -25,4 +26,24 @@ public function doBlock($message)
$ct_comment = $message;
ct_die(null, null);
}

/**
* Checks if the OAuth provider is enabled by verifying the saved configuration.
*
* @param string $provider_id The ID of the OAuth provider.
* @return bool Returns true if the OAuth provider is enabled and properly configured; otherwise, returns false.
*/
public static function isOAuthProviderEnabled($provider_id)
{
if ( ! $provider_id || ! is_string($provider_id) ) {
return false;
}
try {
$option = get_option($provider_id);
$object = maybe_unserialize($option);
return is_array($object) && !empty($object['client_secret']);
} catch (\Throwable $e) {
return false;
}
Comment thread
Copilot marked this conversation as resolved.
}
}
8 changes: 8 additions & 0 deletions lib/Cleantalk/ApbctWP/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AllowDynamicProperties;
use ArrayObject;
use Cleantalk\Antispam\Integrations\NextendSocialLogin;
use Cleantalk\ApbctWP\FindSpam\LoginIPKeeper;
use Cleantalk\ApbctWP\Firewall\SFWUpdateSentinel;
use Cleantalk\ApbctWP\ServiceConstants;
Expand Down Expand Up @@ -1017,6 +1018,13 @@ public function isAltSessionsRequired($get_reason = false)
$result = 'plugin_active__moosend-email-marketing';
}

//nextend social login requires alt sessions https://app.doboard.com/1/task/53787
if (apbct_is_plugin_active('nextend-facebook-connect/nextend-facebook-connect.php')) {
if (NextendSocialLogin::isOAuthProviderEnabled('nsl_google')) {
$result = 'plugin_active__nextend-facebook-connect';
}
}
Comment thread
alexandergull marked this conversation as resolved.

return $get_reason ? $result : $result !== false;
}

Expand Down
108 changes: 108 additions & 0 deletions tests/Antispam/Integrations/TestNextendSocialLogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace {
if ( ! class_exists('NextendSocialProviderDummy', false) ) {
class NextendSocialProviderDummy
{
private $auth_user_data = array();

public function __construct(array $auth_user_data = array())
{
$this->auth_user_data = $auth_user_data;
}

public function getAuthUserData($key)
{
return $this->auth_user_data[$key] ?? null;
}
}
}
}

namespace Cleantalk\Antispam\Integrations {

if ( ! function_exists(__NAMESPACE__ . '\\ct_die') ) {
function ct_die($message = null, $code = null)
{
$GLOBALS['nextend_social_login_test_ct_die'] = array(
'message' => $message,
'code' => $code,
);
}
}

class TestNextendSocialLogin extends \ApbctTestCase
{
protected function setUp(): void
{
parent::setUp();
$GLOBALS['nextend_social_login_test_ct_die'] = null;
$GLOBALS['ct_comment'] = null;
}

protected function tearDown(): void
{
unset($GLOBALS['nextend_social_login_test_ct_die']);
$GLOBALS['ct_comment'] = null;
parent::tearDown();
}

public function testGetDataForCheckingReturnsEmailAndNicknameForNextendProvider()
{
$integration = new NextendSocialLogin();
$provider = new \NextendSocialProviderDummy(array(
'email' => 'user@example.com',
'name' => 'User Name',
));

$this->assertSame(
array(
'email' => 'user@example.com',
'nickname' => 'User Name',
),
$integration->getDataForChecking($provider)
);
}

public function testGetDataForCheckingReturnsNullForUnsupportedArgument()
{
$integration = new NextendSocialLogin();

$this->assertNull($integration->getDataForChecking(new \stdClass()));
}

public function testDoBlockSetsGlobalCommentAndInvokesCtDie()
{
$integration = new NextendSocialLogin();

$integration->doBlock('blocked message');

$this->assertSame('blocked message', $GLOBALS['ct_comment']);
$this->assertSame(
array(
'message' => null,
'code' => null,
),
$GLOBALS['nextend_social_login_test_ct_die']
);
}

public function testIsOAuthProviderEnabledReturnsFalseForInvalidProviderId()
{
$this->assertFalse(NextendSocialLogin::isOAuthProviderEnabled(''));
$this->assertFalse(NextendSocialLogin::isOAuthProviderEnabled(123));
$this->assertFalse(NextendSocialLogin::isOAuthProviderEnabled(null));
}

public function testIsOAuthProviderEnabledReturnsTrueWhenClientSecretExists()
{

update_option('nextend_social_login_provider', serialize(array(
'client_secret' => 'secret-value',
)));

$this->assertTrue(NextendSocialLogin::isOAuthProviderEnabled('nextend_social_login_provider'));
}
}

}
2 changes: 1 addition & 1 deletion tests/ApbctTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class ApbctTestCase extends TestCase
{
/**
* @var \CleantalkSP\SpbctWP\State
* @var State
*/
protected static $state_storage;

Expand Down
Loading