public function test_process_shouldKeepSuperUserPermission_IfAccessWasManuallySet() { $this->access->setSuperUserAccess(true); $this->assertAccessReloadedAndRestored('difFenrenT'); $request = new Request(array('method' => 'API.getPiwikVersion', 'token_auth' => 'difFenrenT')); $request->process(); // make sure token auth was restored after it was loaded with difFenrenT $this->assertSameUserAsBeforeIsAuthenticated(); $this->assertTrue($this->access->hasSuperUserAccess()); }
/** * Removes all logins from the list of logins where the current user has no permission to see them. * * @param string[] $logins An array of logins / usernames. Eg array('username1', 'username2') * @return array */ public function filterLogins($logins) { if ($this->access->hasSuperUserAccess()) { return $logins; } if (!$this->access->isUserHasSomeAdminAccess()) { // keep only own user if it is in the list foreach ($logins as $login) { if ($this->isOwnLogin($login)) { return array($login); } } return array(); } foreach ($logins as $index => $login) { if (!$this->isNonSuperUserAllowedToSeeThisLogin($login)) { unset($logins[$index]); } } return array_values($logins); }
public function testHasSuperUserAccessWithEmptyAccess() { $access = new Access(); $this->assertFalse($access->hasSuperUserAccess()); }
public function testReloadAccessWithMockedAuthValid() { $mock = $this->createPiwikAuthMockInstance(); $mock->expects($this->once())->method('authenticate')->will($this->returnValue(new AuthResult(AuthResult::SUCCESS, 'login', 'token'))); $mock->expects($this->any())->method('getName')->will($this->returnValue("test name")); $access = new Access(); $this->assertTrue($access->reloadAccess($mock)); $this->assertFalse($access->hasSuperUserAccess()); }