I am trying to use Codeception to function test my app's RESTful API. I am using HttpBasicAuth with a custom auth function that validates username and password.
The endpoint I am trying to test is a simple GET /users. The functional.suite.yml looks like this:
class_name: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
- REST:
depends: PhpBrowser
- tests\codeception\_support\FixtureHelper
config:
Yii2:
configFile: 'codeception/config/functional.php'
REST:
url: 'http://localhost:8888/v1/'
My UserApiCept.php starts this way:
<?php
$I = new FunctionalTester($scenario);
$I->wantTo('test the user REST API');
$I->amHttpAuthenticated('goodname', 'goodpassword');
$I->sendGET('users/1');
When I run the suite I get a 401 (Unauthorized HTTP Exception). In --debug, request headers are empty. However, when I run the GET in Postman (providing the username and password), the GET returns the JSON response I expect. So I know the API works.
It appears that there is an issue with amHttpAuthenticated, which I assume is supposed to provide the authorization header, right?
Any advice on how I can troubleshoot this?
Mahalo, Joe