update unit tests
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
parent
676a4c781a
commit
3323d01db1
|
@ -384,6 +384,7 @@ class RequestHandlerControllerTest extends TestCase {
|
||||||
'parent' => null,
|
'parent' => null,
|
||||||
'accepted' => '0',
|
'accepted' => '0',
|
||||||
'expiration' => null,
|
'expiration' => null,
|
||||||
|
'password' => null,
|
||||||
'mail_send' => '0'
|
'mail_send' => '0'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -669,13 +669,14 @@ class ShareAPIController extends OCSController {
|
||||||
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
|
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
|
||||||
|
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* expirationdate, password and publicUpload only make sense for link shares
|
* expirationdate, password and publicUpload only make sense for link shares
|
||||||
*/
|
*/
|
||||||
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
|
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
|
||||||
if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
|
|
||||||
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$newPermissions = null;
|
$newPermissions = null;
|
||||||
if ($publicUpload === 'true') {
|
if ($publicUpload === 'true') {
|
||||||
|
|
|
@ -936,36 +936,6 @@ class ApiTest extends TestCase {
|
||||||
$this->shareManager->deleteShare($share2);
|
$this->shareManager->deleteShare($share2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @medium
|
|
||||||
* @depends testCreateShareUserFile
|
|
||||||
*/
|
|
||||||
public function testUpdateShareInvalidPermissions() {
|
|
||||||
$node1 = $this->userFolder->get($this->filename);
|
|
||||||
$share1 = $this->shareManager->newShare();
|
|
||||||
$share1->setNode($node1)
|
|
||||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
|
||||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
|
||||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
||||||
->setPermissions(19);
|
|
||||||
$share1 = $this->shareManager->createShare($share1);
|
|
||||||
|
|
||||||
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
|
|
||||||
try {
|
|
||||||
$ocs->updateShare($share1->getId());
|
|
||||||
$this->fail();
|
|
||||||
} catch (OCSBadRequestException $e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
$ocs->cleanup();
|
|
||||||
|
|
||||||
//Permissions should not have changed!
|
|
||||||
$share1 = $this->shareManager->getShareById('ocinternal:' . $share1->getId());
|
|
||||||
$this->assertEquals(19, $share1->getPermissions());
|
|
||||||
|
|
||||||
$this->shareManager->deleteShare($share1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @medium
|
* @medium
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -429,11 +429,11 @@ class MigrationTest extends TestCase {
|
||||||
|
|
||||||
foreach ($allShares as $share) {
|
foreach ($allShares as $share) {
|
||||||
if ((int)$share['share_type'] === Share::SHARE_TYPE_LINK) {
|
if ((int)$share['share_type'] === Share::SHARE_TYPE_LINK) {
|
||||||
$this->assertSame(null, $share['share_with']);
|
$this->assertNull( $share['share_with']);
|
||||||
$this->assertSame('shareWith', $share['password']);
|
$this->assertSame('shareWith', $share['password']);
|
||||||
} else {
|
} else {
|
||||||
$this->assertSame('shareWith', $share['share_with']);
|
$this->assertSame('shareWith', $share['share_with']);
|
||||||
$this->assertSame(null, $share['password']);
|
$this->assertNull($share['password']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
namespace OCA\ShareByMail\Tests;
|
namespace OCA\ShareByMail\Tests;
|
||||||
|
|
||||||
|
|
||||||
use OC\HintException;
|
|
||||||
use OCA\ShareByMail\Settings\SettingsManager;
|
use OCA\ShareByMail\Settings\SettingsManager;
|
||||||
use OCA\ShareByMail\ShareByMailProvider;
|
use OCA\ShareByMail\ShareByMailProvider;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
@ -33,9 +32,7 @@ use OCP\ILogger;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\Security\IHasher;
|
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
use OCP\Share\Exceptions\ShareNotFound;
|
|
||||||
use OCP\Share\IManager;
|
use OCP\Share\IManager;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
@ -127,7 +124,8 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
$this->logger,
|
$this->logger,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->urlGenerator,
|
$this->urlGenerator,
|
||||||
$this->activityManager
|
$this->activityManager,
|
||||||
|
$this->settingsManager
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -318,7 +316,7 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
$this->share->expects($this->once())->method('getPermissions')->willReturn($permissions + 1);
|
$this->share->expects($this->once())->method('getPermissions')->willReturn($permissions + 1);
|
||||||
$this->share->expects($this->once())->method('getShareOwner')->willReturn($uidOwner);
|
$this->share->expects($this->once())->method('getShareOwner')->willReturn($uidOwner);
|
||||||
$this->share->expects($this->once())->method('getSharedBy')->willReturn($sharedBy);
|
$this->share->expects($this->once())->method('getSharedBy')->willReturn($sharedBy);
|
||||||
$this->share->expects($this->once())->method('getId')->willReturn($id);
|
$this->share->expects($this->atLeastOnce())->method('getId')->willReturn($id);
|
||||||
|
|
||||||
$this->assertSame($this->share,
|
$this->assertSame($this->share,
|
||||||
$instance->update($this->share)
|
$instance->update($this->share)
|
||||||
|
|
|
@ -510,7 +510,7 @@
|
||||||
passwordField.attr('value', '');
|
passwordField.attr('value', '');
|
||||||
passwordField.attr('placeholder', PASSWORD_PLACEHOLDER_MESSAGE);
|
passwordField.attr('placeholder', PASSWORD_PLACEHOLDER_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
var passwordField = '#passwordField-' + this.cid + '-' + shareId;
|
passwordField = '#passwordField-' + this.cid + '-' + shareId;
|
||||||
this.$(passwordField).focus();
|
this.$(passwordField).focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -623,10 +623,9 @@
|
||||||
var $li = $element.closest('li[data-share-id]');
|
var $li = $element.closest('li[data-share-id]');
|
||||||
var shareId = $li.data('share-id');
|
var shareId = $li.data('share-id');
|
||||||
|
|
||||||
if ($element.is(':checked')) {
|
|
||||||
var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE;
|
|
||||||
} else {
|
|
||||||
var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE | OC.PERMISSION_READ;
|
var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE | OC.PERMISSION_READ;
|
||||||
|
if ($element.is(':checked')) {
|
||||||
|
permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** disable checkboxes during save operation to avoid race conditions **/
|
/** disable checkboxes during save operation to avoid race conditions **/
|
||||||
|
|
|
@ -116,7 +116,7 @@ class DefaultShareProvider implements IShareProvider {
|
||||||
|
|
||||||
//If a password is set store it
|
//If a password is set store it
|
||||||
if ($share->getPassword() !== null) {
|
if ($share->getPassword() !== null) {
|
||||||
$qb->setValue('share_with', $qb->createNamedParameter($share->getPassword()));
|
$qb->setValue('password', $qb->createNamedParameter($share->getPassword()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//If an expiration date is set store it
|
//If an expiration date is set store it
|
||||||
|
|
|
@ -266,8 +266,8 @@ class Manager implements IManager {
|
||||||
|
|
||||||
// Check that read permissions are always set
|
// Check that read permissions are always set
|
||||||
// Link shares are allowed to have no read permissions to allow upload to hidden folders
|
// Link shares are allowed to have no read permissions to allow upload to hidden folders
|
||||||
$noReadPermissionRequired = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK
|
$noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK
|
||||||
|| $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL;
|
|| $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL;
|
||||||
if (!$noReadPermissionRequired &&
|
if (!$noReadPermissionRequired &&
|
||||||
($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
|
($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
|
||||||
throw new \InvalidArgumentException('Shares need at least read permissions');
|
throw new \InvalidArgumentException('Shares need at least read permissions');
|
||||||
|
@ -936,13 +936,20 @@ class Manager implements IManager {
|
||||||
* Work around so we don't return expired shares but still follow
|
* Work around so we don't return expired shares but still follow
|
||||||
* proper pagination.
|
* proper pagination.
|
||||||
*/
|
*/
|
||||||
if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
|
|
||||||
$shares2 = [];
|
$shares2 = [];
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
$added = 0;
|
$added = 0;
|
||||||
foreach ($shares as $share) {
|
foreach ($shares as $share) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->checkExpireDate($share);
|
||||||
|
} catch (ShareNotFound $e) {
|
||||||
|
//Ignore since this basically means the share is deleted
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$added++;
|
$added++;
|
||||||
$shares2[] = $share;
|
$shares2[] = $share;
|
||||||
|
|
||||||
|
@ -972,23 +979,6 @@ class Manager implements IManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
$shares = $shares2;
|
$shares = $shares2;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// remove all shares which are already expired
|
|
||||||
foreach ($shares as $key => $share) {
|
|
||||||
try {
|
|
||||||
$this->checkExpireDate($share);
|
|
||||||
} catch (ShareNotFound $e) {
|
|
||||||
unset($shares[$key]);
|
|
||||||
try {
|
|
||||||
$this->deleteShare($share);
|
|
||||||
} catch (NotFoundException $e) {
|
|
||||||
//Ignore since this basically means the share is deleted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $shares;
|
return $shares;
|
||||||
}
|
}
|
||||||
|
@ -1011,11 +1001,6 @@ class Manager implements IManager {
|
||||||
$this->checkExpireDate($share);
|
$this->checkExpireDate($share);
|
||||||
} catch (ShareNotFound $e) {
|
} catch (ShareNotFound $e) {
|
||||||
unset($shares[$key]);
|
unset($shares[$key]);
|
||||||
try {
|
|
||||||
$this->deleteShare($share);
|
|
||||||
} catch (NotFoundException $e) {
|
|
||||||
//Ignore since this basically means the share is deleted
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@ interface IShare {
|
||||||
/**
|
/**
|
||||||
* Set the expiration date
|
* Set the expiration date
|
||||||
*
|
*
|
||||||
* @param \DateTime $expireDate
|
* @param null|\DateTime $expireDate
|
||||||
* @return \OCP\Share\IShare The modified object
|
* @return \OCP\Share\IShare The modified object
|
||||||
* @since 9.0.0
|
* @since 9.0.0
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -338,7 +338,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$qb->insert('share')
|
$qb->insert('share')
|
||||||
->values([
|
->values([
|
||||||
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
|
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
|
||||||
'share_with' => $qb->expr()->literal('sharedWith'),
|
'password' => $qb->expr()->literal('password'),
|
||||||
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
||||||
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
||||||
'item_type' => $qb->expr()->literal('file'),
|
'item_type' => $qb->expr()->literal('file'),
|
||||||
|
@ -366,7 +366,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->assertEquals($id, $share->getId());
|
$this->assertEquals($id, $share->getId());
|
||||||
$this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType());
|
$this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType());
|
||||||
$this->assertEquals('sharedWith', $share->getPassword());
|
$this->assertNull($share->getSharedWith());
|
||||||
|
$this->assertEquals('password', $share->getPassword());
|
||||||
$this->assertEquals('sharedBy', $share->getSharedBy());
|
$this->assertEquals('sharedBy', $share->getSharedBy());
|
||||||
$this->assertEquals('shareOwner', $share->getShareOwner());
|
$this->assertEquals('shareOwner', $share->getShareOwner());
|
||||||
$this->assertEquals($ownerPath, $share->getNode());
|
$this->assertEquals($ownerPath, $share->getNode());
|
||||||
|
@ -752,7 +753,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$qb->insert('share')
|
$qb->insert('share')
|
||||||
->values([
|
->values([
|
||||||
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
|
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
|
||||||
'share_with' => $qb->expr()->literal('password'),
|
'password' => $qb->expr()->literal('password'),
|
||||||
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
||||||
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
||||||
'item_type' => $qb->expr()->literal('file'),
|
'item_type' => $qb->expr()->literal('file'),
|
||||||
|
@ -2353,9 +2354,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$rootFolder
|
$rootFolder
|
||||||
);
|
);
|
||||||
|
|
||||||
$u1 = $userManager->createUser('testShare1', 'test');
|
$password = md5(time());
|
||||||
$u2 = $userManager->createUser('testShare2', 'test');
|
|
||||||
$u3 = $userManager->createUser('testShare3', 'test');
|
$u1 = $userManager->createUser('testShare1', $password);
|
||||||
|
$u2 = $userManager->createUser('testShare2', $password);
|
||||||
|
$u3 = $userManager->createUser('testShare3', $password);
|
||||||
|
|
||||||
$g1 = $groupManager->createGroup('group1');
|
$g1 = $groupManager->createGroup('group1');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue