2013-07-17 23 views
5

我有一個自定義用戶提供程序和用戶實體,我已經在Symfony 2.2中成功使用過。但是現在我升級到了2.3,並且我意識到「記住我」功能已經失效。所以我創建了一個新的sf2應用程序和一個功能測試。當我使用Acme \ DemoBundle默認值時,測試通過。但是當我添加我的提供商時,它又開始失敗。下面是測試:使用自定義用戶提供程序,用戶實體等時「記住我」測試失敗

<?php 

namespace Acme\DemoBundle\Tests\Controller; 

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 
use Symfony\Component\BrowserKit\Cookie; 

class DemoControllerTest extends WebTestCase 
{ 
    public function testRemember() 
    { 
     $client = static::createClient(); 

     $securedPageUri = '/user/settings/account'; 
     $securedPageFilter = 'html:contains("New Password")'; 
     $loginPageFilter = 'html:contains("Login")'; 
     $username = '[email protected]'; 
     $password = 'test'; 
     /* 
     $securedPageUri = '/demo/secured/hello/World'; 
     $securedPageFilter = 'html:contains("Hello resource secured for admin only.")'; 
     $loginPageFilter = 'html:contains("Login")'; 
     $username = 'admin'; 
     $password = 'adminpass'; 
     */ 

     // Go to Secured page, and be redirected to Login page 
     $client->request('GET', $securedPageUri); 
     $crawler = $client->followRedirect(); 
     $this->assertGreaterThan(0, $crawler->filter($loginPageFilter)->count()); 

     // Try to log in, and be redirected to Secured page 
     $form = $crawler->selectButton('Login')->form(); 
     $form['_username'] = $username; 
     $form['_password'] = $password; 
     $form['_remember_me'] = 1; 
     $client->submit($form); 
     $crawler = $client->followRedirect(); 
     $this->assertGreaterThan(0, $crawler->filter($securedPageFilter)->count()); 

     // Remove all the cookies, but keep the "remember me" cookie 
     $remembermeCookie = $client->getCookieJar()->get('REMEMBERME'); 
     $client->restart(); 
     $client->getCookieJar()->set($remembermeCookie); 

     // Go to Secured page, this time we should be allowed in 
     $client->followRedirects(); 
     $crawler = $client->request('GET', $securedPageUri); 
     //$this->assertTrue($client->getResponse()->isSuccessful()); 
     $this->assertEquals(0, $crawler->filter($loginPageFilter)->count(), "Redirected to Login page"); // THIS IS WHERE THE TEST FAILS 
     $this->assertGreaterThan(0, $crawler->filter($securedPageFilter)->count()); 
    } 
} 

測試工作得很好,我已經嘗試測試它太手動:我登錄,刪除會話cookie,並嘗試用記得我的cookie訪問受保護的頁面。記住我的cookie會被刪除,並被重定向到登錄頁面:S

任何想法爲什麼會發生這種情況?我的提供者不會做任何奇怪的事情,它只是像往常一樣從數據庫中抓取用戶。爲什麼地球上這會影響「記住我」的功能?有沒有我不知道的變化?我沒有使用自定義身份驗證提供程序,只是用戶提供程序。

哦,這裏是日誌,使用grep安全

[2013-07-17 15:18:49] security.DEBUG: Username "[email protected]" was reloaded from user provider. [] [] 
[2013-07-17 15:18:49] security.DEBUG: Write SecurityContext in the session [] [] 
[2013-07-17 15:18:49] security.DEBUG: Remember-me cookie detected. [] [] 
[2013-07-17 15:18:49] security.WARNING: User class for remember-me cookie not supported. [] [] 
[2013-07-17 15:18:49] security.DEBUG: Clearing remember-me cookie "REMEMBERME" [] [] 
[2013-07-17 15:18:49] security.INFO: Populated SecurityContext with an anonymous Token [] [] 
[2013-07-17 15:18:49] security.DEBUG: Access is denied (user is not fully authenticated) by "/srv/www/dev/public/remember/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php" at line 73; redirecting to authentication entry point [] [] 
[2013-07-17 15:18:49] security.DEBUG: Calling Authentication entry point [] [] 
[2013-07-17 15:18:49] security.DEBUG: Write SecurityContext in the session [] [] 
[2013-07-17 15:18:49] security.INFO: Populated SecurityContext with an anonymous Token [] [] 
[2013-07-17 15:18:49] security.DEBUG: Write SecurityContext in the session [] [] 

UPDATE:而且只有當我粘貼的日誌我注意到警告。無論如何,你知道如何解決這個問題嗎?

更新2:如果我使用默認的用戶提供程序,但仍然是我自己的用戶類,它工作正常。該錯誤消息非常具有誤導性。

+0

你有沒有解決這個問題? –

回答

相關問題