'Security token is missing on tests with Symfony/Codeception
I'm trying to test my API interface in Symfony with Codeception (Rest and Symfony module). This API uses JWT-Authentication. So far retrieving the token and calling the controller works.
Unfortunately the token is not stored in the token storage and so my voters dont get the right user (they get a Null-Token instead).
I already figured out, that there aere two dependency injection containers - one with the token and one without.
Has anybody else experiencing this and found a proper solution?
Here is a code example:
$I->amBearerAuthenticated($token);
$I->sendGet('/api/resource');
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->seeResponseIsJson();
Details
- Codeception version: 4.1.29
- PHP Version: 7.4
- Operating System: Windows/Debian
- Installation type: Composer
- Suite configuration:
actor: ApiTester
modules:
enabled:
- \App\Tests\Helper\Api
- Symfony:
app_path: 'src'
environment: 'test'
headers:
Content-Type: application/json
- Doctrine2:
depends: Symfony
cleanup: true
- REST:
url: https://localhost
depends: Symfony
- Asserts
- Db:
dsn: 'mysql:host=%DATABASE_HOST%:%DATABASE_PORT%;dbname=%META_DATABASE_NAME%'
user: '%DATABASE_USER%'
password: '%DATABASE_PASSWORD%'
dump:
- tests/_data/meta_dump.sql
- tests/_data/meta_security_dump.sql
cleanup: true # reload dump between tests
populate: true # load dump before all tests
databases:
DATA:
dsn: 'mysql:host=%DATABASE_HOST%:%DATABASE_PORT%;dbname=%DATA_DATABASE_NAME%'
user: '%DATABASE_USER%'
password: '%DATABASE_PASSWORD%'
dump: tests/_data/data_dump.sql
cleanup: false
populate: true # load dump before all tests
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
