/** * @dataProvider dataProvider * * @param UserInterface $user * @param bool $expected */ public function testOnSuccessLogin(UserInterface $user, $expected) { $this->token->expects($this->once())->method('getUser')->willReturn($user); $this->event->expects($this->once())->method('getAuthenticationToken')->willReturn($this->token); $this->event->expects($expected ? $this->once() : $this->never())->method('getRequest')->willReturn($this->request); $this->assertNull($this->request->attributes->get('_fullRedirect')); $this->listener->onSecurityInteractiveLogin($this->event); $this->assertEquals($expected, $this->request->attributes->get('_fullRedirect')); }
/** * @test */ public function taskUserTracker() { $user = new User(); $task = new Task(); $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($this->token)); $this->token->expects($this->once())->method('getUser')->will($this->returnValue($user)); $tracker = new Tracker($user, $task, new \DateTime('now')); $this->trackerRepository->expects($this->once())->method('retrieveUserTracker')->with($user)->will($this->returnValue($tracker)); $result = $this->twigExtension->userTracker(); $this->assertEquals($tracker, $result); }
/** * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclNativeHelper::apply */ public function testApplyAnonymous() { $queryBuilder = new QueryBuilder($this->conn); $queryBuilder->add('from', array(array('table' => 'myTable', 'alias' => 'n'))); $roles = array(); $this->token->expects($this->once())->method('getRoles')->will($this->returnValue($roles)); $this->rh->expects($this->once())->method('getReachableRoles')->with($roles)->will($this->returnValue($roles)); $this->token->expects($this->any())->method('getUser')->will($this->returnValue('anon.')); $permissionDef = new PermissionDefinition(array('view'), 'Kunstmaan\\NodeBundle\\Entity\\Node', 'n'); /* @var $qb QueryBuilder */ $qb = $this->object->apply($queryBuilder, $permissionDef); $query = $qb->getSQL(); $this->assertContains('"IS_AUTHENTICATED_ANONYMOUSLY"', $query); }
/** * @test */ public function handleReturnToken() { $token = new WsseToken(); $token->setUser('admin'); $token->setAttribute('digest', 'admin'); $token->setAttribute('nonce', 'admin'); $token->setAttribute('created', '2010-12-12 20:00:00'); $this->tokenMock->expects($this->atLeastOnce())->method('getUser')->will($this->returnValue($this->userMock)); $this->userMock->expects($this->once())->method('isActive')->will($this->returnValue(true)); $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->will($this->returnValue($this->tokenMock)); /** @noinspection PhpUndefinedMethodInspection */ $this->securityContext->expects($this->once())->method('setToken')->with($this->tokenMock); $this->request->headers->add(array('X-WSSE' => 'UsernameToken Username="******", PasswordDigest="admin", Nonce="admin", Created="2010-12-12 20:00:00"')); $this->wsseListener->handle($this->responseEvent); }
/** * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getAllowedEntityIds * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getPermittedAclIdsSQLForUser */ public function testGetAllowedEntityIds() { $roles = array(new Role('ROLE_KING')); $allRoles = array($roles[0], new Role('ROLE_SUBJECT')); $this->token->expects($this->once())->method('getRoles')->will($this->returnValue($roles)); $this->rh->expects($this->once())->method('getReachableRoles')->with($roles)->will($this->returnValue($allRoles)); $user = $this->getMockBuilder('FOS\\UserBundle\\Model\\UserInterface')->getMock(); $user->expects($this->any())->method('getUsername')->will($this->returnValue('MyUser')); $this->token->expects($this->any())->method('getUser')->will($this->returnValue($user)); $hydrator = $this->getMockBuilder('Doctrine\\ORM\\Internal\\Hydration\\ScalarHydrator')->disableOriginalConstructor()->getMock(); $rows = array(array('id' => 1), array('id' => 9)); $hydrator->expects($this->once())->method('hydrateAll')->will($this->returnValue($rows)); $this->em->expects($this->any())->method('newHydrator')->will($this->returnValue($hydrator)); /* @var $query NativeQuery */ $query = new NativeQuery($this->em); $this->em->expects($this->once())->method('createNativeQuery')->will($this->returnValue($query)); $permissionDef = new PermissionDefinition(array('view'), 'Kunstmaan\\NodeBundle\\Entity\\Node', 'n'); /* @var $result array */ $result = $this->object->getAllowedEntityIds($permissionDef); $this->assertEquals(array(1, 9), $result); }