Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ public function testCreateShareLinkPublicUpload(array $appConfig, int $permissio
public function testEnforceLinkPassword(): void {
$password = md5(time());
$config = Server::get(IConfig::class);
$appConfig = Server::get(IAppConfig::class);
$appConfig->setValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT, true);
$config->setAppValue('core', 'shareapi_enforce_links_password', 'yes');

$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
Expand Down Expand Up @@ -320,6 +322,7 @@ public function testEnforceLinkPassword(): void {
$ocs->cleanup();

$config->setAppValue('core', 'shareapi_enforce_links_password', 'no');
$appConfig->setValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT, false);
$this->addToAssertionCount(1);
}

Expand Down
17 changes: 17 additions & 0 deletions apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function testLinkPassword(): void {
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$typedMap = [
['core', 'shareapi_enable_link_password_by_default', true],
['core', 'shareapi_enforce_links_password', true],
];
$result = $this->getResults($map, $typedMap);
Expand All @@ -159,6 +160,22 @@ public function testLinkPassword(): void {
$this->assertTrue($result['public']['password']['enforced']);
}

public function testLinkPasswordEnforcedWithoutDefaultPrompt(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$typedMap = [
['core', 'shareapi_enable_link_password_by_default', false],
['core', 'shareapi_enforce_links_password', true],
];
$result = $this->getResults($map, $typedMap);
$this->assertArrayHasKey('password', $result['public']);
$this->assertArrayHasKey('enforced', $result['public']['password']);
$this->assertFalse($result['public']['password']['enforced']);
}

public function testLinkNoPassword(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/lib/Settings/Admin/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getForm() {
'restrictUserEnumerationFullMatchDisplayname' => $this->shareManager->matchDisplayName(),
'restrictUserEnumerationFullMatchEmail' => $this->shareManager->matchEmail(),
'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->shareManager->ignoreSecondDisplayName(),
'enforceLinksPassword' => $this->shareManager->shareApiLinkEnforcePassword(false),
'enforceLinksPassword' => $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_ENFORCED),
'enforceLinksPasswordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [],
'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
Expand Down
11 changes: 8 additions & 3 deletions apps/settings/src/components/AdminSettingsSharingForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@
<NcCheckboxRadioSwitch v-model="settings.enableLinkPasswordByDefault">
{{ t('settings', 'Always ask for a password') }}
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch v-model="settings.enforceLinksPassword" :disabled="!settings.enableLinkPasswordByDefault">
<NcCheckboxRadioSwitch
v-show="settings.enableLinkPasswordByDefault"
v-model="settings.enforceLinksPassword">
{{ t('settings', 'Enforce password protection') }}
</NcCheckboxRadioSwitch>
<label v-if="settings.enforceLinksPasswordExcludedGroupsEnabled" class="sharing__labeled-entry sharing__input">
<label
v-if="settings.enforceLinksPasswordExcludedGroupsEnabled"
v-show="settings.enableLinkPasswordByDefault"
class="sharing__labeled-entry sharing__input">
<span>{{ t('settings', 'Exclude groups from password requirements') }}</span>
<NcSettingsSelectGroup
v-model="settings.enforceLinksPasswordExcludedGroups"
style="width: 100%"
:disabled="!settings.enforceLinksPassword || !settings.enableLinkPasswordByDefault" />
:disabled="!settings.enforceLinksPassword" />
</label>
<label class="sharing__labeled-entry sharing__input">
<span>{{ t('settings', 'Exclude groups from creating link shares') }}</span>
Expand Down
11 changes: 11 additions & 0 deletions apps/settings/tests/Settings/Admin/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testGetFormWithoutExcludedGroups(): void {
->willReturnMap([
['core', 'shareapi_allow_federation_on_public_shares', true],
['core', 'shareapi_enable_link_password_by_default', true],
['core', 'shareapi_enforce_links_password', false],
['core', 'shareapi_default_expire_date', false],
['core', 'shareapi_enforce_expire_date', false],
]);
Expand Down Expand Up @@ -163,6 +164,16 @@ public function testGetFormWithoutExcludedGroups(): void {
}

public function testGetFormWithExcludedGroups(): void {
$this->appConfig
->method('getValueBool')
->willReturnMap([
['core', 'shareapi_allow_federation_on_public_shares', true],
['core', 'shareapi_enable_link_password_by_default', true],
['core', 'shareapi_enforce_links_password', false],
['core', 'shareapi_default_expire_date', false],
['core', 'shareapi_enforce_expire_date', false],
]);

$this->config
->method('getAppValue')
->willReturnMap([
Expand Down
5 changes: 5 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,11 @@ protected function userCanCreateLinkShares(IUser $user): bool {

#[Override]
public function shareApiLinkEnforcePassword(bool $checkGroupMembership = true): bool {
// Password enforcement requires the default password prompt to be enabled.
if (!$this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT)) {
return false;
}

$excludedGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
if ($excludedGroups !== '' && $checkGroupMembership) {
$excludedGroups = json_decode($excludedGroups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ public function testGetDefaultValue(): void {
);

$appConfig = Server::get(IAppConfig::class);
$appConfig->deleteKey(Application::APP_ID, ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT);
$appConfig->deleteKey(Application::APP_ID, ConfigLexicon::SHARE_LINK_PASSWORD_ENFORCED);

$this->assertNull($this->propertyType->getDefaultValue($share));

$appConfig->setValueBool(Application::APP_ID, ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT, true);
$appConfig->setValueBool(Application::APP_ID, ConfigLexicon::SHARE_LINK_PASSWORD_ENFORCED, true);

$value = $this->propertyType->getDefaultValue($share);
Expand All @@ -100,6 +102,7 @@ public function testGetDefaultValue(): void {
$this->assertGreaterThan(1, strlen((string)$value));
$this->assertTrue($this->propertyType->validateValue(Server::get(IFactory::class), $share, $value));

$appConfig->deleteKey(Application::APP_ID, ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT);
$appConfig->deleteKey(Application::APP_ID, ConfigLexicon::SHARE_LINK_PASSWORD_ENFORCED);
}

Expand Down
25 changes: 25 additions & 0 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,18 +849,38 @@ public function testVerifyPasswordNullButEnforced(): void {
]);

$this->appConfig->method('getValueBool')->willReturnMap([
['core', 'shareapi_enable_link_password_by_default', true],
['core', 'shareapi_enforce_links_password', true],
]);

self::invokePrivate($this->manager, 'verifyPassword', [null]);
}

public function testVerifyPasswordEnforcedWithoutDefaultPrompt(): void {
$this->config->method('getAppValue')->willReturnMap([
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
]);

$this->appConfig->method('getValueBool')->willReturnMap([
['core', 'shareapi_enable_link_password_by_default', false],
['core', 'shareapi_enforce_links_password', true],
]);

$result = self::invokePrivate($this->manager, 'verifyPassword', [null]);
$this->assertNull($result);
}

public function testVerifyPasswordNotEnforcedGroup(): void {
$this->config->method('getAppValue')->willReturnMap([
['core', 'shareapi_enforce_links_password_excluded_groups', '', '["admin"]'],
['core', 'shareapi_enforce_links_password', 'no', 'yes'],
]);

$this->appConfig->method('getValueBool')->willReturnMap([
['core', 'shareapi_enable_link_password_by_default', true],
['core', 'shareapi_enforce_links_password', true],
]);

// Create admin user
$user = $this->createMock(IUser::class);
$this->userSession->method('getUser')->willReturn($user);
Expand All @@ -876,6 +896,11 @@ public function testVerifyPasswordNotEnforcedMultipleGroups(): void {
['core', 'shareapi_enforce_links_password', 'no', 'yes'],
]);

$this->appConfig->method('getValueBool')->willReturnMap([
['core', 'shareapi_enable_link_password_by_default', true],
['core', 'shareapi_enforce_links_password', true],
]);

// Create admin user
$user = $this->createMock(IUser::class);
$this->userSession->method('getUser')->willReturn($user);
Expand Down
Loading