Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Admin/EmailAccount): updating shared account smtp pw fails
Browse files Browse the repository at this point in the history
- always set imap = smtp password for shared accounts
- update of smtp pw did not work if imap/smtp credential_ids
 had been different

Change-Id: Icc150f7596bdf37fb47858890be86d1f1727c662
Reviewed-on: http://gerrit.tine20.com/customers/17845
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
  • Loading branch information
pschuele committed Sep 10, 2020
1 parent 3f9f921 commit 482c1ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 9 additions & 4 deletions tests/tine20/Admin/Frontend/Json/EmailAccountTest.php
Expand Up @@ -452,6 +452,8 @@ protected function _checkMasterUserTable()
public function testUpdatePasswordOfSharedAccount()
{
$sharedAccount = $this->testEmailAccountApiSharedAccount(false);
$sharedAccount->resolveCredentials(false);
self::assertEquals('123', $sharedAccount->password);

$emailUser = Felamimail_Controller_Account::getInstance()->getSharedAccountEmailUser($sharedAccount);
$emailUserBackend = Tinebase_EmailUser::getInstance(Tinebase_Config::IMAP);
Expand All @@ -461,16 +463,19 @@ public function testUpdatePasswordOfSharedAccount()
$pw = $userInBackend['password'];

$sharedAccountArray = $sharedAccount->toArray();
$sharedAccountArray['password'] = 'someupdatedPW';
// FE might send empty user
$sharedAccountArray['user'] = '';
$newPw = 'someupdatedPW';
$sharedAccountArray['password'] = $newPw;
$this->_json->saveEmailAccount($sharedAccountArray);
// test imap login
$sharedAccount = Felamimail_Controller_Account::getInstance()->get($sharedAccount);
self::assertEquals($sharedAccount->credentials_id, $sharedAccount->smtp_credentials_id);
Felamimail_Backend_ImapFactory::factory($sharedAccount->getId());
$sharedAccount->resolveCredentials();
$sharedAccount->resolveCredentials(false);
self::assertNotEmpty($sharedAccount->user, 'username should not be empty/overwritten! '
. print_r($sharedAccount->toArray(), true));
self::assertEquals($newPw, $sharedAccount->password);
$sharedAccount->resolveCredentials(false, false, true);
self::assertEquals($newPw, $sharedAccount->smtp_password);

// check if pw was changed
$userInBackend = $emailUserBackend->getRawUserById($emailUser);
Expand Down
11 changes: 7 additions & 4 deletions tine20/Felamimail/Controller/Account.php
Expand Up @@ -920,21 +920,24 @@ protected function _beforeUpdateSharedAccountCredentials($_record, $_oldRecord)
$newUsername = ($_record->user) ? $_record->user : $credentials->username;

$_record->credentials_id = $this->_createSharedCredentials($newUsername, $newPassword);
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(
__METHOD__ . '::' . __LINE__ . ' Created new credentials (id ' . $_record->credentials_id . ')');

$imapCredentialsChanged = true;
} else {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(
__METHOD__ . '::' . __LINE__ . ' Credentials did not change');
$imapCredentialsChanged = false;
}

if ($_record->smtp_user && $_record->smtp_password) {
// NOTE: this is currently not possible to set via the FE - maybe we should remove it?
// create extra smtp credentials
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(
__METHOD__ . '::' . __LINE__ . ' Update/create SMTP credentials.');
$_record->smtp_credentials_id = $this->_createSharedCredentials($_record->smtp_user, $_record->smtp_password);

} else if (
$imapCredentialsChanged
&& (! $_record->smtp_credentials_id || $_record->smtp_credentials_id == $_oldRecord->credentials_id)
) {
} else if ($imapCredentialsChanged) {
// use imap credentials for smtp auth as well
$_record->smtp_credentials_id = $_record->credentials_id;
}
Expand Down

0 comments on commit 482c1ca

Please sign in to comment.