Skip to content

Commit 35a0ee2

Browse files
committed
fix(ProvisioningApi): only return verified additional mails per user
It would not per se be bad to return all of them, however the meta data about the verified state is missing. Since the information may go out to connected clients, those may have wrong trust the returned email addresses. Email verification still works with this change. Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent ff92ab1 commit 35a0ee2

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

apps/provisioning_api/lib/Controller/AUserData.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ protected function getUserData(string $userId, bool $includeScopes = false): ?ar
149149
$additionalEmails = $additionalEmailScopes = [];
150150
$emailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
151151
foreach ($emailCollection->getProperties() as $property) {
152+
if ($property->getLocallyVerified() !== IAccountManager::VERIFIED) {
153+
continue;
154+
}
152155
$additionalEmails[] = $property->getValue();
153156
if ($includeScopes) {
154157
$additionalEmailScopes[] = $property->getScope();

apps/testing/appinfo/routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,10 @@
6363
'type' => null
6464
]
6565
],
66+
[
67+
'name' => 'MailVerificationTest',
68+
'url' => '/api/v1/mailverification',
69+
'verb' => 'POST',
70+
]
6671
],
6772
];
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace OCA\Testing\Controller;
4+
5+
use InvalidArgumentException;
6+
use OCP\Accounts\IAccountManager;
7+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
8+
use OCP\AppFramework\Http\DataResponse;
9+
use OCP\AppFramework\OCSController;
10+
use OCP\IRequest;
11+
use OCP\IUser;
12+
use OCP\IUserManager;
13+
14+
class MailVerificationTestController extends OCSController {
15+
public function __construct(
16+
$appName,
17+
IRequest $request,
18+
protected IAccountManager $accountManager,
19+
protected IUserManager $userManager,
20+
) {
21+
parent::__construct($appName, $request);
22+
}
23+
24+
public function verify(string $userId, string $email): DataResponse {
25+
$user = $this->userManager->get($userId);
26+
$userAccount = $this->accountManager->getAccount($user);
27+
$emailProperty = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)
28+
->getPropertyByValue($email);
29+
if ($emailProperty === null) {
30+
throw new InvalidArgumentException('Email not available in account.');
31+
}
32+
$emailProperty->setLocallyVerified(IAccountManager::VERIFIED);
33+
return new DataResponse();
34+
}
35+
}

build/integration/features/bootstrap/Provisioning.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,4 +980,28 @@ public function userHasNotSetting($user, \Behat\Gherkin\Node\TableNode $settings
980980
}
981981
}
982982
}
983+
984+
/**
985+
* @Then user :user verifies email :email
986+
*/
987+
public function userVerifiesEmail(string $userId, string $email): void {
988+
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/testing/api/v1/mailverification";
989+
$client = new Client();
990+
$options = [];
991+
if ($this->currentUser === 'admin') {
992+
$options['auth'] = $this->adminUser;
993+
}
994+
995+
$options['form_params'] = [
996+
'userid' => $userId,
997+
'email' => $email,
998+
];
999+
1000+
$options['headers'] = [
1001+
'OCS-APIREQUEST' => 'true',
1002+
];
1003+
1004+
$this->response = $client->post($fullUrl, $options);
1005+
}
9831006
}
1007+

build/integration/features/provisioning-v1.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ Feature: provisioning
129129
| value | no.reply@nextcloud.com |
130130
And the OCS status code should be "100"
131131
And the HTTP status code should be "200"
132+
And user "brand-new-user" verifies email "no.reply@nextcloud.com"
132133
And sending "PUT" to "/cloud/users/brand-new-user" with
133134
| key | additional_mail |
134135
| value | noreply@nextcloud.com |
135136
And the OCS status code should be "100"
136137
And the HTTP status code should be "200"
138+
And user "brand-new-user" verifies email "noreply@nextcloud.com"
137139
And sending "PUT" to "/cloud/users/brand-new-user" with
138140
| key | phone |
139141
| value | +49 711 / 25 24 28-90 |
@@ -302,11 +304,13 @@ Feature: provisioning
302304
| value | no.reply6@nextcloud.com |
303305
And the OCS status code should be "100"
304306
And the HTTP status code should be "200"
307+
And user "brand-new-user" verifies email "no.reply6@nextcloud.com"
305308
And sending "PUT" to "/cloud/users/brand-new-user" with
306309
| key | additional_mail |
307310
| value | noreply7@nextcloud.com |
308311
And the OCS status code should be "100"
309312
And the HTTP status code should be "200"
313+
And user "brand-new-user" verifies email "no.reply7@nextcloud.com"
310314
When sending "PUT" to "/cloud/users/brand-new-user/additional_mail" with
311315
| key | no.reply6@nextcloud.com |
312316
| value | |

0 commit comments

Comments
 (0)