8 namespace Fossology\Lib\Dao;
15 require_once __DIR__.
'/../../Plugin/FO_Plugin.php';
24 private $uploadPermissionDao;
26 protected function setUp() :
void
29 $this->
dbManager = &$this->testDb->getDbManager();
31 $this->testDb->createPlainTables(array(
'upload',
'uploadtree'));
33 $this->
dbManager->prepare($stmt =
'insert.upload',
34 "INSERT INTO upload (upload_pk, uploadtree_tablename) VALUES ($1, $2)");
35 $uploadArray = array(array(1,
'uploadtree'), array(2,
'uploadtree_a'));
36 foreach ($uploadArray as $uploadEntry) {
39 $logger = M::mock(
'Monolog\Logger');
40 $logger->shouldReceive(
'debug');
43 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
46 protected function tearDown() :
void
48 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
53 public function testmakeAccessibleToGroup()
55 $this->testDb->createPlainTables(array(
'perm_upload',
'group_user_member'));
58 $groupIdAlternative = 602;
59 $this->
dbManager->insertTableRow(
'group_user_member', array(
'group_fk'=>$groupId,
'user_fk'=>$userId,
'group_perm'=>
Auth::PERM_READ));
60 $this->
dbManager->insertTableRow(
'group_user_member', array(
'group_fk'=>$groupIdAlternative,
'user_fk'=>$userId,
'group_perm'=>
Auth::PERM_READ));
62 $unaccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId=1, $groupId);
63 assertThat($unaccessibleIsAccessible,equalTo(
false));
65 $this->uploadPermissionDao->makeAccessibleToGroup($uploadId, $groupId,
Auth::PERM_WRITE);
66 $accessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
67 assertThat($accessibleIsAccessible,equalTo(
true));
68 $stillUnaccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupIdAlternative);
69 assertThat($stillUnaccessibleIsAccessible,equalTo(
false));
71 $this->uploadPermissionDao->makeAccessibleToAllGroupsOf($uploadId, $userId);
72 $nowAccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupIdAlternative);
73 assertThat($nowAccessibleIsAccessible,equalTo(
true));
76 public function testDeletePermissionId()
78 $this->testDb->createPlainTables(array(
'perm_upload'));
79 $this->testDb->insertData(array(
'perm_upload'));
80 $accessibleBefore = $this->uploadPermissionDao->isAccessible($uploadId=1, $groupId=2);
81 assertThat($accessibleBefore,equalTo(
true));
82 $this->uploadPermissionDao->updatePermissionId(1,0);
83 $accessibleAfter = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
84 assertThat($accessibleAfter,equalTo(
false));
87 public function testUpdatePermissionId()
89 $this->testDb->createPlainTables(array(
'perm_upload'));
90 $this->testDb->insertData(array(
'perm_upload'));
92 $adminBefore = $this->uploadPermissionDao->isEditable($uploadId=1, $groupId=2);
93 assertThat($adminBefore,equalTo(
true));
95 $adminNomore = $this->uploadPermissionDao->isEditable($uploadId, $groupId);
96 assertThat($adminNomore,equalTo(
false));
98 $adminAgain = $this->uploadPermissionDao->isEditable($uploadId, $groupId);
99 assertThat($adminAgain,equalTo(
true));
102 public function testInsertPermission()
104 $this->testDb->createPlainTables(array(
'perm_upload'));
105 $accessibleBefore = $this->uploadPermissionDao->isAccessible($uploadId=1, $groupId=2);
106 assertThat($accessibleBefore,equalTo(
false));
107 $this->uploadPermissionDao->insertPermission($uploadId, $groupId,
Auth::PERM_READ);
108 $accessibleAfter = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
109 assertThat($accessibleAfter,equalTo(
true));
110 $this->uploadPermissionDao->insertPermission($uploadId, $groupId,
Auth::PERM_NONE);
111 $accessibleNomore = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
112 assertThat($accessibleNomore,equalTo(
false));
115 public function testGetPublicPermission()
117 $this->testDb->insertData(array(
'upload'));
118 $perm = $this->uploadPermissionDao->getPublicPermission(3);
119 assertThat($perm,equalTo(0));
122 public function testGetPermissionGroups()
124 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
125 $this->testDb->insertData(array(
'perm_upload',
'groups'));
126 $permissionGroups = $this->uploadPermissionDao->getPermissionGroups(1);
127 assertThat($permissionGroups,is(array(2=>array(
'perm_upload_pk'=>1,
'perm'=>10,
'group_pk'=>2,
'group_name'=>
'fossy'))));
130 public function testAccessibilityViaNone()
132 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
133 $this->testDb->insertData(array(
'groups'));
135 $accessibilityWithBadGroup = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
136 assertThat($accessibilityWithBadGroup, equalTo(
false));
139 public function testAccessibilityViaGroup()
141 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
142 $this->testDb->insertData(array(
'groups',
'perm_upload'));
144 $accessibilityByGroup = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
145 assertThat($accessibilityByGroup, equalTo(
true));
149 public function testAccessibilityViaPublicForUnqualifiedUser()
151 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
152 $this->testDb->insertData(array(
'groups'));
154 $accessibilityByNone = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
155 assertThat($accessibilityByNone, equalTo(
false));
157 $this->uploadPermissionDao->setPublicPermission($uploadId,
Auth::PERM_READ);
158 $accessibilityByPublic = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
159 assertThat($accessibilityByPublic, equalTo(
false));
162 public function testAccessibilityViaPublicForQualifiedUser()
164 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
165 $this->testDb->insertData(array(
'groups'));
167 $accessibilityByNone = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
168 assertThat($accessibilityByNone, equalTo(
false));
170 $this->uploadPermissionDao->setPublicPermission($uploadId,
Auth::PERM_READ);
171 $accessibilityByPublic = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
172 assertThat($accessibilityByPublic, equalTo(
true));
184 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
185 $this->testDb->insertData(array(
'groups',
'perm_upload'));
187 $result = $this->uploadPermissionDao->isEditable(2, 3);
188 $this->assertNotNull($result);
189 $this->assertTrue($result);
200 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
201 $this->testDb->insertData(array(
'groups',
'perm_upload'));
203 $result = $this->uploadPermissionDao->isAccessible(2, 3);
204 $this->assertNotNull($result);
205 $this->assertTrue($result);
215 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
216 $this->testDb->insertData(array(
'groups',
'perm_upload'));
218 $result = $this->uploadPermissionDao->isAccessible(2, 3);
219 $this->assertNotNull($result);
220 $this->assertFalse($result);
Contains the constants and helpers for authentication of user.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
fo_dbManager * dbManager
fo_dbManager object