Skip to content
Snippets Groups Projects
Commit db50dc5b authored by Chris Leppanen's avatar Chris Leppanen
Browse files

Issue #1567508 by kruser, beansboxchrispang: Fixed User import is incorrectly changing passwords.

parent 7bac6180
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,10 @@ class FeedsUserProcessor extends FeedsProcessor { ...@@ -40,7 +40,10 @@ class FeedsUserProcessor extends FeedsProcessor {
* Loads an existing user. * Loads an existing user.
*/ */
protected function entityLoad(FeedsSource $source, $uid) { protected function entityLoad(FeedsSource $source, $uid) {
return user_load($uid); // Copy the password so that we can compare it again at save.
$user = user_load($uid);
$user->feeds_original_pass = $user->pass;
return $user;
} }
/** /**
...@@ -59,7 +62,15 @@ class FeedsUserProcessor extends FeedsProcessor { ...@@ -59,7 +62,15 @@ class FeedsUserProcessor extends FeedsProcessor {
if ($this->config['defuse_mail']) { if ($this->config['defuse_mail']) {
$account->mail = $account->mail . '_test'; $account->mail = $account->mail . '_test';
} }
user_save($account, (array) $account);
$edit = (array) $account;
// Remove pass from $edit if the password is unchanged.
if (isset($account->feeds_original_pass) && $account->pass == $account->feeds_original_pass) {
unset($edit['pass']);
}
user_save($account, $edit);
if ($account->uid && !empty($account->openid)) { if ($account->uid && !empty($account->openid)) {
$authmap = array( $authmap = array(
'uid' => $account->uid, 'uid' => $account->uid,
......
...@@ -34,12 +34,12 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase { ...@@ -34,12 +34,12 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase {
0 => array( 0 => array(
'source' => 'name', 'source' => 'name',
'target' => 'name', 'target' => 'name',
'unique' => 0, 'unique' => FALSE,
), ),
1 => array( 1 => array(
'source' => 'mail', 'source' => 'mail',
'target' => 'mail', 'target' => 'mail',
'unique' => 1, 'unique' => TRUE,
), ),
2 => array( 2 => array(
'source' => 'since', 'source' => 'since',
...@@ -74,7 +74,7 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase { ...@@ -74,7 +74,7 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase {
$this->assertText('Created 3 users'); $this->assertText('Created 3 users');
// 1 user has an invalid email address, all users should be assigned // 1 user has an invalid email address, all users should be assigned
// the manager role. // the manager role.
$this->assertText('Failed importing 2 user'); $this->assertText('Failed importing 2 users.');
$this->drupalGet('admin/people'); $this->drupalGet('admin/people');
$this->assertText('Morticia'); $this->assertText('Morticia');
$this->assertText('Fester'); $this->assertText('Fester');
...@@ -84,12 +84,39 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase { ...@@ -84,12 +84,39 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase {
$count = db_query("SELECT count(*) FROM {users_roles} WHERE rid = :rid", array(':rid' => $admin_rid))->fetchField(); $count = db_query("SELECT count(*) FROM {users_roles} WHERE rid = :rid", array(':rid' => $admin_rid))->fetchField();
$this->assertEqual($count, 0, t('No imported user was assigned the administrator role.')); $this->assertEqual($count, 0, t('No imported user was assigned the administrator role.'));
// @todo Test status setting, update existing and role settings. // Run import again, verify no new users.
$this->importFile('user_import', $this->absolutePath() . '/tests/feeds/users.csv');
$this->assertText('Failed importing 2 users.');
// Attempt to log in as one of the imported users. // Attempt to log in as one of the imported users.
$account = user_load_by_name('Morticia'); $account = user_load_by_name('Morticia');
$this->assertTrue($account, 'Imported user account loaded.'); $this->assertTrue($account, 'Imported user account loaded.');
$account->pass_raw = 'mort'; $account->pass_raw = 'mort';
$this->drupalLogin($account); $this->drupalLogin($account);
// Login as admin.
$this->drupalLogin($this->admin_user);
// Removing a mapping forces updating without needing a different file.
// We are also testing that if we don't map anything to the user's password
// that it will keep its existing one.
$mappings = array(
3 => array(
'source' => 'password',
'target' => 'pass',
),
);
$this->removeMappings('user_import', $mappings);
$this->setSettings('user_import', 'FeedsUserProcessor', array('update_existing' => 2));
$this->importFile('user_import', $this->absolutePath() . '/tests/feeds/users.csv');
// Assert result.
$this->assertText('Updated 3 users');
$this->assertText('Failed importing 2 user');
// Attempt to log in as one of the imported users.
$account = user_load_by_name('Fester');
$this->assertTrue($account, 'Imported user account loaded.');
$account->pass_raw = 'fest';
$this->drupalLogin($account);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment