Skip to content

Commit dbafdb7

Browse files
committed
test: re-enable the OAuth2 protocol suite excluded by its *TestCase.php filename
tests/OAuth2ProtocolTestCase.php (23 tests covering the auth-code, PKCE, implicit, client-credentials, refresh and revocation flows) never ran in the Application Test Suite: PHPUnit's directory discovery only picks up *Test.php, and the file has carried the *TestCase.php suffix since the Laravel 11 upgrade (ae24738). Renamed file + class to OAuth2ProtocolTest so the suite discovers it again. Two latent problems surfaced by re-enabling it, both fixed: - OAUTH2_VALIDATE_RESOURCE_SERVER_IP was unset in the testing env, so the resource-server IP allow-list check (ValidateBearerTokenResourceServerStrategy) silently no-oped and testResourceServerIntrospectionNotValidIP got 200 where it asserts 400. Enabled via phpunit.xml <env>. - With the gate on, the caller IP came from $_SERVER['REMOTE_ADDR'], which is unset under the PHPUnit CLI unless an earlier test happened to assign it and leak it (OAuth2LoginStrategyTest::setUp does) - the same tests passed or failed depending on suite order. tests/bootstrap.php now pins REMOTE_ADDR=127.0.0.1 for the whole run. Full Application suite: 196 tests / 1004 assertions, 0 failures (was 173 - the 23 protocol tests now run).
1 parent fc403be commit dbafdb7

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

phpunit.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@
2525
</testsuites>
2626
<php>
2727
<env name="APP_ENV" value="testing"/>
28+
<!-- the resource-server IP allow-list check (ValidateBearerTokenResourceServerStrategy) no-ops
29+
when this is off, silently passing introspection calls that must be rejected (see
30+
OAuth2ProtocolTest::testResourceServerIntrospectionNotValidIP). Deterministic caller IP
31+
comes from tests/bootstrap.php (REMOTE_ADDR=127.0.0.1). -->
32+
<env name="OAUTH2_VALIDATE_RESOURCE_SERVER_IP" value="true"/>
2833
</php>
2934
</phpunit>

tests/OAuth2EndSessionTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
/**
1919
* Class OAuth2EndSessionTest
20-
* NOTE: deliberately NOT placed in OAuth2ProtocolTestCase.php - that file's *TestCase.php suffix
21-
* keeps it OUT of the Application Test Suite (PHPUnit only auto-discovers *Test.php), so a test
22-
* added there would never run in CI.
2320
* @package Tests
2421
*/
2522
final class OAuth2EndSessionTest extends OpenStackIDBaseTestCase
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Class OAuth2ProtocolTest
2424
* Test Suite for OAuth2 Protocol
2525
*/
26-
final class OAuth2ProtocolTestCase extends OpenStackIDBaseTestCase
26+
final class OAuth2ProtocolTest extends OpenStackIDBaseTestCase
2727
{
2828

2929
private $current_realm;

tests/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
require dirname(__DIR__).'/bootstrap/autoload.php';
55

6+
// PHPUnit runs from the CLI, where REMOTE_ADDR is unset. Code under test reads it directly
7+
// (UserIPHelperProvider), so without a deterministic value here the resource-server IP checks
8+
// depended on whichever earlier test happened to set $_SERVER['REMOTE_ADDR'] and leak it -
9+
// the same suite passed or failed depending on test order.
10+
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
11+
612

713
use Symfony\Component\ErrorHandler\ErrorHandler;
814

0 commit comments

Comments
 (0)