Forums › Forums › OroPlatform › OroPlatform – Programming Questions › Functional Tests 401
This topic contains 42 replies, has 4 voices, and was last updated by archy_bold 7 years, 10 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- February 4, 2015 at 9:44 am #33722
Hi,
I followed your guide about setting up the test environment and writting functional tests. I am stuck on my very first testIndex action because I get 401 (authentication failure) where I am expecting 200.
I did:
configured config_test.yml
1app/console oro:install --env test --organization-name Oro --user-name admin --user-email admin@example.com --user-firstname John --user-lastname Doe --user-password admin --sample-data n --application-url http://localhost --force1app/console doctrine:fixture:load --no-debug --append --no-interaction --env=test --fixtures ./vendor/oro/platform/src/Oro/Bundle/TestFrameworkBundle/Fixtures1app/console oro:test:schema:update --env testI see my db populated and user exists with username “admin”
and this my my test:
1234567891011121314151617181920212223242526<?phpnamespace Mekit\Bundle\AccountBundle\Tests\Functional\Controller;use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;/*** @outputBuffering enabled* @dbIsolation*/class AccountControllerTest extends WebTestCase {protected function setUp() {$this->initClient([],array_merge($this->generateBasicAuthHeader(), array('HTTP_X-CSRF-Header' => 1)));}public function testIndexAction() {$this->client->request('GET', $this->getUrl('mekit_account_index'));$result = $this->client->getResponse();$this->assertHtmlResponseStatusCodeEquals($result, 200);$this->assertContains('Account', $result->getContent());}}… and this is what i get:
123Failed asserting that 401 matches expected 200.Expected :200Actual :401:-(
I even tried without luck:
123456protected function setUp() {$this->initClient([],array_merge($this->generateBasicAuthHeader("admin", "admin"), array('HTTP_X-CSRF-Header' => 1)));}Where do you think I made a mistake out something?
oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
- CreatorTopic
- AuthorReplies
- February 5, 2015 at 2:51 am #33723
actually, looking over response codes I do not get 403(auth error) but 401(unauthorized) – so I am actually a step before it – I dumped my request and response headers:
REQUEST:
host = [“localhost”]
user-agent = [“Symfony2 BrowserKit”]
accept = [“text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8”]
accept-language = [“en-us,en;q=0.5”]
accept-charset = [“ISO-8859-1,utf-8;q=0.7,*;q=0.7”]
x-csrf-header = [1]
php-auth-user = [“admin”]
php-auth-pw = [“admin”]
authorization = [“Basic YWRtaW46YWRtaW4=”]
x-php-ob-level = [1]RESULT(401):
cache-control = [“no-cache”]
date = [“Thu, 05 Feb 2015 09:32:29 GMT”]
www-authenticate = [“Basic realm=\”Secured REST Area\””]
content-type = [“text\/html; charset=UTF-8”]any ideas?
oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
February 5, 2015 at 2:54 am #33724Hello.
Look’s like installation and code itself is fine, you can even remove ‘HTTP_X-CSRF-Header’ header because generateBasicAuthHeader will generate valid header data. Also command “oro:test:schema:update” now executing during installation in test environment, so don’t need to run it manually.
You can check your environment by running one of platform tests to verify that installation is correct.
We’ve faced this issue when test user from fixture was not downloaded. Please, check that user was uploaded:
12$ app/console doctrine:fixture:load --no-debug --append --no-interaction --env=test --fixtures src/Oro/src/Oro/Bundle/TestFrameworkBundle/Fixtures> loading [110] Oro\Bundle\TestFrameworkBundle\Fixtures\LoadUserDataAs a result where must be user with API key in your DB.
February 5, 2015 at 3:23 am #33725I have all tests failing for Oro\Bundle\UserBundle\Tests\Functional\ControllersTest
always returning 401I have loaded the fixture Oro\Bundle\TestFrameworkBundle\Fixtures\LoadUserData
I have user with api key in db (i did have it before as well though) and
still 401any other ideas?
thanks
a\oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
February 5, 2015 at 3:32 am #33726Then you should debug authentification and check which provider and why restrict access.
February 5, 2015 at 3:37 am #33727> php-auth-user = [“admin”]
It should be “admin@example.com”.February 5, 2015 at 3:58 am #33728how come? isn’t that username? i have user in db with username: admin and email:admin@example.com
now i init my client like this:
123protected function setUp() {$this->initClient([], $this->generateBasicAuthHeader());}I have removed ‘HTTP_X-CSRF-Header’ and headers are now:
REQUEST:
host = [“localhost”]
user-agent = [“Symfony2 BrowserKit”]
accept = [“text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8”]
accept-language = [“en-us,en;q=0.5”]
accept-charset = [“ISO-8859-1,utf-8;q=0.7,*;q=0.7”]
php-auth-user = [“admin@example.com”]
php-auth-pw = [“admin”]
authorization = [“Basic YWRtaW5AZXhhbXBsZS5jb206YWRtaW4=”]
x-php-ob-level = [1]RESULT(401):
cache-control = [“no-cache”]
date = [“Thu, 05 Feb 2015 10:44:30 GMT”]
www-authenticate = [“Basic realm=\”Secured REST Area\””]
content-type = [“text\/html; charset=UTF-8”]key php-auth-user is now correct but i am still getting 401
this is my config_test.yml:
123456789101112131415161718192021222324252627imports:- { resource: config_prod.yml }- { resource: parameters_test.yml }- { resource: security_test.yml }framework:test: ~session:storage_id: session.storage.mock_filecsrf_protection: trueprofiler:enabled: falseservices:twig.extension.debug:class: Twig_Extensions_Extension_Debugtags:- { name: twig.extension }swiftmailer:disable_delivery: trueoro_require_js:js_engine: ~and this is my security_test.yml:
1234567891011121314151617181920security:acl:connection: defaultcache:id: security.acl.cache.doctrineprefix: sf2_acl_firewalls:main:organization-http-basic:realm: "Secured REST Area"provider: oro_userhttp-basic: falseorganization-form-login: falselogout: falseorganization-remember-me: falseanonymous: truethey are both unmodified as they were in the platfom application.
I did a fresh install – all installs fine but still 401
when you say
Then you should debug authentification and check which provider and why restrict access.
where should i start?
oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
February 5, 2015 at 4:31 am #33729shouldn’t
http-basic: false
be
http-basic: true
in security_test.yml?
oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
February 5, 2015 at 4:53 am #33730No, your security_test.yml is fine – at least on my env it works.
> where should i start?
I’d start from UnauthorizedHttpException::__construct to get full stack trace where this exception is coming from.February 5, 2015 at 6:23 am #33731hmmm, i do NOT reach UnauthorizedHttpException class –
I inserted in the constructor:
1234debug_print_backtrace();die("KILLED!");but it never gets called!
…i’ll try to read some sf2 documentations…
oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
February 5, 2015 at 6:28 am #33732That’s odd. Symfony may return 401 from FormAuthenticationEntryPoint, DigestAuthenticationEntryPoint and FormAuthenticationEntryPoint (you can find all these files by “401” string) – maybe it’s one of these.
February 5, 2015 at 7:42 am #33733yes, odd indeed! Thanks! I found the entry point giving me 401. It is BasicAuthenticationEntryPoint.
and I have a backtrace:
There was 1 error:
12345678910111213141516171) Mekit\Bundle\AccountBundle\Tests\Functional\Controller\AccountControllerTest::testIndexActionReflectionException: Property Oro\Bundle\UserBundle\Entity\User::$avatar does not exist/home/master.mekitcrm.bradipo/oro/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php:82/home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:899/home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:537/home/master.mekitcrm.bradipo/oro/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:209/home/master.mekitcrm.bradipo/oro/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:114/home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:69/home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:47/home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:546/home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/DistributionBundle/OroKernel.php:270/home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:130/home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/DistributionBundle/OroKernel.php:239/home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:47/home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/TestFrameworkBundle/Test/WebTestCase.php:122/home/master.mekitcrm.bradipo/oro/src/Mekit/Bundle/AccountBundle/Tests/Functional/Controller/AccountControllerTest.php:12it is complaining about Oro\Bundle\UserBundle\Entity\User::$avatar
does this make sense to you?oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
February 5, 2015 at 7:45 am #33734Could you drop your test DB, remove cache and do install on clear DB? Probably you have outdated metadata somewhere.
February 5, 2015 at 8:24 am #33735ok, here we go:
123456rm -rf app/cache/[prod,dev,test,session]app/console doctrine:schema:drop --env=test --forceapp/console oro:install --env test --organization-name Oro --user-name admin --user-email admin@example.com --user-firstname John --user-lastname Doe --user-password admin --sample-data n --application-url http://localhost --forceapp/console doctrine:fixture:load --no-debug --append --no-interaction --env=test --fixtures ./vendor/oro/platform/src/Oro/Bundle/TestFrameworkBundle/Fixturesat this point I should be all set, however if I do:
1app/console doctrine:schema:update --env=test --dump-sqlI get:
12345ALTER TABLE test_search_item ADD CONSTRAINT FK_1B7F8BC932C8A3DE FOREIGN KEY (organization_id) REFERENCES oro_organization (id) ON DELETE SET NULL;ALTER TABLE test_workflow_aware_entity ADD CONSTRAINT FK_F824A8531023C4EE FOREIGN KEY (workflow_item_id) REFERENCES oro_workflow_item (id) ON DELETE SET NULL;ALTER TABLE test_workflow_aware_entity ADD CONSTRAINT FK_F824A85371FE882C FOREIGN KEY (workflow_step_id) REFERENCES oro_workflow_step (id) ON DELETE SET NULL;I don’t think it has anything to do with my problem but it is strange these were not created during install.
for now I do not force it.
so, let’s phpunit…..(fingers crossed)…
NOPE: here is backtrace:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546PHP Fatal error: Call to a member function setValue() on a non-object in /home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 2632PHP Stack trace:PHP 1. {main}() /usr/bin/phpunit:0PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:176PHP 5. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/TextUI/TestRunner.php:349PHP 6. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:705PHP 7. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:705PHP 8. PHPUnit_Framework_TestSuite->runTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:745PHP 9. PHPUnit_Framework_TestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:775PHP 10. PHPUnit_Framework_TestResult->run() /usr/share/php/PHPUnit/Framework/TestCase.php:783PHP 11. PHPUnit_Framework_TestCase->runBare() /usr/share/php/PHPUnit/Framework/TestResult.php:648PHP 12. PHPUnit_Framework_TestCase->runTest() /usr/share/php/PHPUnit/Framework/TestCase.php:838PHP 13. ReflectionMethod->invokeArgs() /usr/share/php/PHPUnit/Framework/TestCase.php:983PHP 14. Mekit\Bundle\AccountBundle\Tests\Functional\Controller\AccountControllerTest->testIndexAction() /usr/share/php/PHPUnit/Framework/TestCase.php:983PHP 15. Oro\Bundle\TestFrameworkBundle\Test\Client->request() /home/master.mekitcrm.bradipo/oro/src/Mekit/Bundle/AccountBundle/Tests/Functional/Controller/AccountControllerTest.php:17PHP 16. Symfony\Component\BrowserKit\Client->request() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/TestFrameworkBundle/Test/Client.php:58PHP 17. Oro\Bundle\TestFrameworkBundle\Test\Client->doRequest() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:334PHP 18. Symfony\Component\HttpKernel\Kernel->handle() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/TestFrameworkBundle/Test/Client.php:117PHP 19. Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:188PHP 20. Symfony\Component\HttpKernel\HttpKernel->handle() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php:62PHP 21. Symfony\Component\HttpKernel\HttpKernel->handleRaw() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:61PHP 22. Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:98PHP 23. Symfony\Component\EventDispatcher\EventDispatcher->dispatch() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php:170PHP 24. Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:53PHP 25. call_user_func() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:164PHP 26. Symfony\Component\Security\Http\Firewall->onKernelRequest() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:164PHP 27. Symfony\Component\Security\Http\Firewall\BasicAuthenticationListener->handle() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall.php:66PHP 28. Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager->authenticate() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php:74PHP 29. Oro\Bundle\SecurityBundle\Authentication\Provider\UsernamePasswordOrganizationAuthenticationProvider->authenticate() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php:74PHP 30. Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider->authenticate() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/SecurityBundle/Authentication/Provider/UsernamePasswordOrganizationAuthenticationProvider.php:22PHP 31. Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider->retrieveUser() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php:70PHP 32. Oro\Bundle\UserBundle\Security\UserProvider->loadUserByUsername() /home/master.mekitcrm.bradipo/oro/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php:83PHP 33. Oro\Bundle\UserBundle\Security\UserProvider->findUser() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/UserBundle/Security/UserProvider.php:35PHP 34. Oro\Bundle\UserBundle\Entity\UserManager->findUserByUsernameOrEmail() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/UserBundle/Security/UserProvider.php:81PHP 35. Oro\Bundle\UserBundle\Entity\UserManager->findUserByEmail() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/UserBundle/Entity/UserManager.php:168PHP 36. Oro\Bundle\UserBundle\Entity\UserManager->findUserBy() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/UserBundle/Entity/UserManager.php:145PHP 37. Doctrine\ORM\EntityRepository->findOneBy() /home/master.mekitcrm.bradipo/oro/vendor/oro/platform/src/Oro/Bundle/UserBundle/Entity/UserManager.php:124PHP 38. Doctrine\ORM\Persisters\BasicEntityPersister->load() /home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:196PHP 39. Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() /home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:756PHP 40. Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator->hydrateAllData() /home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:140PHP 41. Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator->hydrateRowData() /home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php:48PHP 42. Doctrine\ORM\UnitOfWork->createEntity() /home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php:138oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
February 5, 2015 at 8:44 am #33736> I don’t think it has anything to do with my problem but it is strange these were not created during install.
Thank you, it’s known issue.Look’s like some either DB, or cache issue, because error happens during UserManager->findUserByEmail.
Could you do install in test env on clear DB (without any dirty data)? I.e. “DROP DATABASE” and “CREATE DATABASE” instead of “doctrine:schema:drop”.
Also it would be great if you’ll be able to find out where null object come from error “Call to a member function setValue() on a non-object”.
February 5, 2015 at 8:44 am #33737i have also tested that “app/cache/test/oro_entities/Extend/Entity/EX_OroUserBundle_User.php” gets loaded and it does and it has:
123456789101112131415161718192021222324252627282930313233<?phpnamespace Extend\Entity;abstract class EX_OroUserBundle_User implements \Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface{protected $title;protected $avatar;public function setTitle($value){$this->title = $value; return $this;}public function setAvatar($value){$this->avatar = $value; return $this;}public function getTitle(){return $this->title;}public function getAvatar(){return $this->avatar;}public function __construct(){}}which seems correct to me
I am not sure why the corresponding does not mention the avatar property in “app/cache/test/oro_entities/Extend/Entity/EX_OroUserBundle_User.orm.yml”
123456789101112Extend\Entity\EX_OroUserBundle_User:type: mappedSuperclassfields:title:column: titletype: stringnullable: truelength: 255precision: nullscale: nulloro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
- AuthorReplies
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.