From 898430b6b10c1430cc9df8b1aecd8c1e5baea555 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 26 Jul 2019 10:48:34 +0200 Subject: [PATCH] supresses disclosing the userid for LDAP users in the welcome mail The userid is not relevant here, and by default cannot be used to login with. Typically, there is a common type of login names in organizations (LDAP username or email most often) that does not need to be disclosed. Signed-off-by: Arthur Schiwon --- settings/Mailer/NewUserMailHelper.php | 4 +- .../Settings/Mailer/NewUserMailHelperTest.php | 224 ++++++++++++++++++ 2 files changed, 227 insertions(+), 1 deletion(-) diff --git a/settings/Mailer/NewUserMailHelper.php b/settings/Mailer/NewUserMailHelper.php index d88f7300f84..fd447c48f01 100644 --- a/settings/Mailer/NewUserMailHelper.php +++ b/settings/Mailer/NewUserMailHelper.php @@ -136,7 +136,9 @@ class NewUserMailHelper { $emailTemplate->addHeading($l10n->t('Welcome aboard %s', [$displayName])); } $emailTemplate->addBodyText($l10n->t('Welcome to your %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); - $emailTemplate->addBodyText($l10n->t('Your username is: %s', [$userId])); + if($user->getBackendClassName() !== 'LDAP') { + $emailTemplate->addBodyText($l10n->t('Your username is: %s', [$userId])); + } if ($generatePasswordResetToken) { $leftButtonText = $l10n->t('Set your password'); } else { diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php index 5eccc5bc9f4..f29da7fbfde 100644 --- a/tests/Settings/Mailer/NewUserMailHelperTest.php +++ b/tests/Settings/Mailer/NewUserMailHelperTest.php @@ -599,6 +599,230 @@ Go to TestCloud: https://example.com/ Install Client: https://nextcloud.com/install/#install-clients +-- +TestCloud - +This is an automatically sent email, please do not reply. +EOF; + + $result = $this->newUserMailHelper->generateTemplate($user, false); + $this->assertEquals($expectedHtmlBody, $result->renderHtml()); + $this->assertEquals($expectedTextBody, $result->renderText()); + $this->assertSame('OC\Mail\EMailTemplate', get_class($result)); + } + + public function testGenerateTemplateWithoutUserId() { + $this->urlGenerator + ->expects($this->at(0)) + ->method('getAbsoluteURL') + ->with('/') + ->willReturn('https://example.com/'); + + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ + $user = $this->createMock(IUser::class); + $user + ->expects($this->any()) + ->method('getDisplayName') + ->willReturn('John Doe'); + $user + ->expects($this->any()) + ->method('getUID') + ->willReturn('john'); + $user + ->expects($this->atLeastOnce()) + ->method('getBackendClassName') + ->willReturn('LDAP'); + $this->defaults + ->expects($this->any()) + ->method('getName') + ->willReturn('TestCloud'); + $this->defaults + ->expects($this->any()) + ->method('getTextColorPrimary') + ->willReturn('#ffffff'); + + $expectedHtmlBody = << + + + + + + + + + + + + + +
+
+ + + +
+ + + + + + +
+ + + +
+ +
+ + +
+
+
+ + + + + + +
 
+ + + + + +
+

Welcome aboard John Doe

+
+ + + + + + +
 
+ + + +
+ + + + + + +
+ + + + + + +
 
+ + + + + +
+ + + + + +
+

Welcome to your TestCloud account, you can add, protect, and share your data.

+
+
+ + + + + +
 
+ + + + + + +
+ + + + + +
+
+ + + + +
+ + + + +
+ Go to TestCloud +
+
+ + + + +
+ + + + +
+ Install Client +
+
+
+
+
+
+
+ + + + + +
 
+ + + + +
+
+ +
                                                           
+ + +EOF; + $expectedTextBody = <<