1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Correct user_xup changed value in Steam social login provider

Info:
https://github.com/e107inc/e107/pull/4099#issuecomment-590579521
This commit is contained in:
Nick Liu
2020-02-25 12:46:44 +01:00
parent be84cf7c08
commit 639943e7ed
2 changed files with 88 additions and 1 deletions

View File

@@ -13,10 +13,19 @@ require_once("SocialLoginConfigManager.php");
class social_setup
{
public function upgrade_required()
{
return (
$this->upgrade_required_provider_name_normalization() ||
$this->upgrade_required_steam_xup_bug()
);
}
private function upgrade_required_provider_name_normalization()
{
$coreConfig = e107::getConfig();
$manager = new SocialLoginConfigManager($coreConfig);
$providerConfig = $coreConfig->getPref(SocialLoginConfigManager::SOCIAL_LOGIN_PREF);
if (!is_array($providerConfig)) $providerConfig = [];
$normalizedProviderNames = array_keys($providerConfig);
foreach ($normalizedProviderNames as $normalizedProviderName)
{
@@ -27,13 +36,30 @@ class social_setup
return false;
}
/**
* @see https://github.com/e107inc/e107/pull/4099#issuecomment-590579521
*/
private function upgrade_required_steam_xup_bug()
{
$db = e107::getDb();
$count = $db->count('user', '(*)', "user_xup LIKE 'Steam_https://steamcommunity.com/openid/id/%'");
return $count >= 1;
}
public function upgrade_pre()
{
$this->upgrade_pre_provider_name_normalization();
$this->upgrade_pre_steam_xup_bug();
}
private function upgrade_pre_provider_name_normalization()
{
$coreConfig = e107::getConfig();
$logger = e107::getMessage();
$manager = new SocialLoginConfigManager($coreConfig);
$providerConfig = $coreConfig->getPref(SocialLoginConfigManager::SOCIAL_LOGIN_PREF);
if (!is_array($providerConfig)) $providerConfig = [];
foreach ($providerConfig as $oldNormalizedProviderName => $oldOptions)
{
@@ -86,4 +112,39 @@ class social_setup
}
return $denormalizedProviderName;
}
/**
* @see https://github.com/e107inc/e107/pull/4099#issuecomment-590579521
*/
private function upgrade_pre_steam_xup_bug()
{
$logger = e107::getMessage();
$db = e107::getDb();
$db->select('user', '*', "user_xup LIKE 'Steam_https://steamcommunity.com/openid/id/%'");
$rows = $db->rows();
foreach ($rows as $row)
{
$old_user_xup = $row['user_xup'];
$new_user_xup = str_ireplace(
['http://steamcommunity.com/openid/id/', 'https://steamcommunity.com/openid/id/'],
'',
$old_user_xup
);
$status = $db->update(
'user',
"user_xup = '".$db->escape($new_user_xup)."' WHERE user_id = ".$db->escape($row['user_id'])
);
if ($status !== 1)
{
$logger->addError(
"Unexpected error while correcting user_xup of user_id = ".$row['user_id']." from \"".$old_user_xup."\" to \"".$new_user_xup."\": ".
$db->getLastErrorText()
);
}
else
{
$logger->addSuccess("Corrected user_xup of user_id = ".$row['user_id']." from \"".$old_user_xup."\" to \"".$new_user_xup."\"");
}
}
}
}

View File

@@ -10,11 +10,14 @@
class social_setupTest extends \Codeception\Test\Unit
{
public function testUpgrade()
public function _before()
{
include_once(e_PLUGIN . "social/SocialLoginConfigManager.php");
include_once(e_PLUGIN . "social/social_setup.php");
}
public function testUpgradeProviderNameNormalization()
{
e107::getConfig()->set(SocialLoginConfigManager::SOCIAL_LOGIN_PREF, SOCIAL_LOGIN_LEGACY_DATA);
$social_setup = new social_setup();
$this->assertTrue($social_setup->upgrade_required());
@@ -26,6 +29,29 @@ class social_setupTest extends \Codeception\Test\Unit
$this->assertIsNotArray(e107::getConfig()->getPref(SocialLoginConfigManager::SOCIAL_LOGIN_PREF . "/AOL"));
$this->assertIsArray(e107::getConfig()->getPref(SocialLoginConfigManager::SOCIAL_LOGIN_PREF . "/AOL-OpenID"));
}
/**
* @see https://github.com/e107inc/e107/pull/4099#issuecomment-590579521
*/
public function testUpgradeFixSteamXupBug()
{
$db = e107::getDb();
$db->insert('user', [
'user_loginname' => 'SteambB8047',
'user_password' => '$2y$10$.u22u/U392cUhvJm2DJ57.wsKtxKKj3WsZ.x6LsXoUVHVuprZGgUu',
'user_email' => '',
'user_xup' => 'Steam_https://steamcommunity.com/openid/id/76561198006790310',
]);
$insertId = $db->lastInsertId();
$social_setup = new social_setup();
$this->assertTrue($social_setup->upgrade_required());
$social_setup->upgrade_pre();
$result = $db->retrieve('user', '*', 'user_id=' . $insertId);
$this->assertEquals('Steam_76561198006790310', $result['user_xup']);
$this->assertFalse($social_setup->upgrade_required());
}
}
const SOCIAL_LOGIN_LEGACY_DATA =
array(