|
42 | 42 | use OCP\Security\IHasher; |
43 | 43 | use OCP\Security\ISecureRandom; |
44 | 44 | use OCP\Share\Exceptions\ShareNotFound; |
| 45 | +use OCP\Share\IAttributes; |
45 | 46 | use OCP\Share\IProviderFactory; |
46 | 47 | use OCP\Share\IShare; |
47 | 48 | use OCP\Share\IShareProvider; |
@@ -3494,6 +3495,70 @@ public function testGetAllSharedWith() { |
3494 | 3495 | $this->assertSame($shares, [$share1, $share2]); |
3495 | 3496 | } |
3496 | 3497 |
|
| 3498 | + /** |
| 3499 | + * @dataProvider strictSubsetOfAttributesDataProvider |
| 3500 | + * |
| 3501 | + * @param IAttributes $allowedAttributes |
| 3502 | + * @param IAttributes $newAttributes |
| 3503 | + * @param boolean $expected |
| 3504 | + */ |
| 3505 | + public function testStrictSubsetOfAttributes($allowedAttributes, $newAttributes, $expected) { |
| 3506 | + $this->assertEquals( |
| 3507 | + $expected, |
| 3508 | + $this->invokePrivate( |
| 3509 | + $this->manager, |
| 3510 | + 'strictSubsetOfAttributes', |
| 3511 | + [$allowedAttributes, $newAttributes] |
| 3512 | + ) |
| 3513 | + ); |
| 3514 | + } |
| 3515 | + |
| 3516 | + public function strictSubsetOfAttributesDataProvider() { |
| 3517 | + $providedValues = []; |
| 3518 | + |
| 3519 | + // removal of attributes should result in false |
| 3520 | + $allowedAttributes = $this->createMock(IAttributes::class); |
| 3521 | + $newAttributes = $this->createMock(IAttributes::class); |
| 3522 | + $allowedAttributes->method('toArray')->willReturn([ |
| 3523 | + ['scope' => 'app1', 'key' => 'perm1', 'enabled' => false] |
| 3524 | + ]); |
| 3525 | + $newAttributes->expects($this->at(0)) |
| 3526 | + ->method('getAttribute')->with('app1', 'perm1')->will($this->returnValue(null)); |
| 3527 | + $providedValues[] = [$allowedAttributes, $newAttributes, false]; |
| 3528 | + |
| 3529 | + // increase of attributes should result in false |
| 3530 | + $allowedAttributes = $this->createMock(IAttributes::class); |
| 3531 | + $newAttributes = $this->createMock(IAttributes::class); |
| 3532 | + $allowedAttributes->method('toArray')->willReturn([ |
| 3533 | + ['scope' => 'app1', 'key' => 'perm1', 'enabled' => false] |
| 3534 | + ]); |
| 3535 | + $newAttributes->expects($this->at(0)) |
| 3536 | + ->method('getAttribute')->with('app1', 'perm1')->will($this->returnValue(true)); |
| 3537 | + $providedValues[] = [$allowedAttributes, $newAttributes, false]; |
| 3538 | + |
| 3539 | + // no change of attributes should result in true |
| 3540 | + $allowedAttributes = $this->createMock(IAttributes::class); |
| 3541 | + $newAttributes = $this->createMock(IAttributes::class); |
| 3542 | + $allowedAttributes->method('toArray')->willReturn([ |
| 3543 | + ['scope' => 'app1', 'key' => 'perm1', 'enabled' => true] |
| 3544 | + ]); |
| 3545 | + $newAttributes->expects($this->at(0)) |
| 3546 | + ->method('getAttribute')->with('app1', 'perm1')->will($this->returnValue(true)); |
| 3547 | + $providedValues[] = [$allowedAttributes, $newAttributes, true]; |
| 3548 | + |
| 3549 | + // decrease of attributes should result in true |
| 3550 | + $allowedAttributes = $this->createMock(IAttributes::class); |
| 3551 | + $newAttributes = $this->createMock(IAttributes::class); |
| 3552 | + $allowedAttributes->method('toArray')->willReturn([ |
| 3553 | + ['scope' => 'app1', 'key' => 'perm1', 'enabled' => true] |
| 3554 | + ]); |
| 3555 | + $newAttributes->expects($this->at(0)) |
| 3556 | + ->method('getAttribute')->with('app1', 'perm1')->will($this->returnValue(false)); |
| 3557 | + $providedValues[] = [$allowedAttributes, $newAttributes, true]; |
| 3558 | + |
| 3559 | + return $providedValues; |
| 3560 | + } |
| 3561 | + |
3497 | 3562 | /** |
3498 | 3563 | * @dataProvider strictSubsetOfPermissionsDataProvider |
3499 | 3564 | * |
|
0 commit comments