Skip to content

Commit cc40020

Browse files
committed
Add integration tests for user_status API
Signed-off-by: Jonas Meurer <jonas@freesources.org>
1 parent 7c64e5c commit cc40020

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Feature: user_status
2+
Background:
3+
Given using api version "2"
4+
And user "user0" exists
5+
And user "user0" has status "dnd"
6+
7+
Scenario: listing recent user statuses with default settings
8+
Then user statuses for "admin" list "user0" with status "dnd"
9+
10+
Scenario: empty recent user statuses with disabled user enumeration
11+
Given As an "admin"
12+
When parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no"
13+
Then user statuses for "admin" are empty
14+
15+
Scenario: empty recent user statuses with user enumeration limited to common groups
16+
Given As an "admin"
17+
When parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "yes"
18+
And parameter "shareapi_restrict_user_enumeration_to_group" of app "core" is set to "yes"
19+
Then user statuses for "admin" are empty
20+
21+
Scenario: empty recent user statuses with user enumeration limited to phone matches
22+
Given As an "admin"
23+
When parameter "shareapi_restrict_user_enumeration_to_group" of app "core" is set to "no"
24+
And parameter "shareapi_restrict_user_enumeration_to_phone" of app "core" is set to "yes"
25+
Then user statuses for "admin" are empty

build/integration/features/bootstrap/CollaborationContext.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
use Behat\Behat\Context\Context;
2727
use Behat\Gherkin\Node\TableNode;
28+
use GuzzleHttp\Client;
2829
use PHPUnit\Framework\Assert;
2930

3031
require __DIR__ . '/../../vendor/autoload.php';
@@ -70,4 +71,85 @@ protected function resetAppConfigs(): void {
7071
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match');
7172
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
7273
}
74+
75+
/**
76+
* @Given /^user "([^"]*)" has status "([^"]*)"$/
77+
* @param string $user
78+
* @param string $status
79+
*/
80+
public function assureUserHasStatus($user, $status) {
81+
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/user_status/api/v1/user_status/status";
82+
$client = new Client();
83+
$options = [
84+
'headers' => [
85+
'OCS-APIREQUEST' => 'true',
86+
],
87+
];
88+
if ($user === 'admin') {
89+
$options['auth'] = $this->adminUser;
90+
} else {
91+
$options['auth'] = [$user, $this->regularUser];
92+
}
93+
94+
$options['form_params'] = [
95+
'statusType' => $status
96+
];
97+
98+
$this->response = $client->put($fullUrl, $options);
99+
$this->theHTTPStatusCodeShouldBe(200);
100+
101+
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/user_status/api/v1/user_status";
102+
unset($options['form_params']);
103+
$this->response = $client->get($fullUrl, $options);
104+
$this->theHTTPStatusCodeShouldBe(200);
105+
106+
$returnedStatus = json_decode(json_encode(simplexml_load_string($this->response->getBody()->getContents())->data), true)['status'];
107+
Assert::assertEquals($status, $returnedStatus);
108+
}
109+
110+
/**
111+
* @param string $user
112+
* @return null|array
113+
*/
114+
public function getStatusList(string $user): ?array {
115+
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/user_status/api/v1/statuses";
116+
$client = new Client();
117+
$options = [
118+
'headers' => [
119+
'OCS-APIREQUEST' => 'true',
120+
],
121+
];
122+
if ($user === 'admin') {
123+
$options['auth'] = $this->adminUser;
124+
} else {
125+
$options['auth'] = [$user, $this->regularUser];
126+
}
127+
128+
$this->response = $client->get($fullUrl, $options);
129+
$this->theHTTPStatusCodeShouldBe(200);
130+
131+
$contents = $this->response->getBody()->getContents();
132+
return json_decode(json_encode(simplexml_load_string($contents)->data), true);
133+
}
134+
135+
/**
136+
* @Given /^user statuses for "([^"]*)" list "([^"]*)" with status "([^"]*)"$/
137+
* @param string $user
138+
* @param string $statusUser
139+
* @param string $status
140+
*/
141+
public function assertStatusesList(string $user, string $statusUser, string $status): void {
142+
$statusList = $this->getStatusList($user);
143+
Assert::assertArrayHasKey('element', $statusList);
144+
Assert::assertEquals($status, array_column($statusList['element'], 'status', 'userId')[$statusUser]);
145+
}
146+
147+
/**
148+
* @Given /^user statuses for "([^"]*)" are empty$/
149+
* @param string $user
150+
*/
151+
public function assertStatusesEmpty(string $user): void {
152+
$statusList = $this->getStatusList($user);
153+
Assert::assertEmpty($statusList);
154+
}
73155
}

build/integration/features/bootstrap/Provisioning.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @author Sergio Bertolín <sbertolin@solidgear.es>
1414
* @author Thomas Müller <thomas.mueller@tmit.eu>
1515
* @author Vincent Petry <vincent@nextcloud.com>
16+
* @author Jonas Meurer <jonas@freesources.org>
1617
*
1718
* @license GNU AGPL version 3 or any later version
1819
*

0 commit comments

Comments
 (0)