Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.4 Compatibility #183

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
php-versions: ['8.2', '8.3']
php-versions: ['8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v4
Expand Down
28 changes: 14 additions & 14 deletions tests/Feature/Auth/OAuthAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ final class OAuthAuthenticationTest extends TestCase

public function test_redirects_to_oauth_provider(): void
{
$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
return $this->mock_controller()->oauthRedirect($request);
});

$response = $this->get(__METHOD__);
$response = $this->get(__FUNCTION__);
$response->assertRedirect(self::OAUTH_DUMMY_PROVIDER_URL);
}

public function test_callback_success(): void
{
$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
$oauthUser = $this->createStub(User::class);
$oauthUser->token = 'a';
$oauthUser->method('getRaw')->willReturn([
Expand All @@ -47,7 +47,7 @@ public function test_callback_success(): void
return $this->mock_controller($driver)->oauthCallback($request);
});

$response = $this->get(__METHOD__);
$response = $this->get(__FUNCTION__);
$response->assertRedirect('/logged-in');
$this->assertAuthenticated();
}
Expand All @@ -59,14 +59,14 @@ public function test_exceptions_restart_flow_for_invalid_state(): void
//
})->name('login-oauth-redirect');

$this->app['router']->get(__METHOD__, function (Request $request) use ($exception) {
$this->app['router']->get(__FUNCTION__, function (Request $request) use ($exception) {
$driver = $this->createStub(AzureDriver::class);
$driver->method('user')->willThrowException($exception);

return $this->mock_controller($driver)->oauthCallback($request);
});

$response = $this->get(__METHOD__);
$response = $this->get(__FUNCTION__);
$response->assertRedirect('/login-oauth-redirect');
}

Expand All @@ -85,56 +85,56 @@ public function test_exceptions_restart_flow_for_guzzle_400_code(): void
//
})->name('login-oauth-redirect');

$this->app['router']->get(__METHOD__, function (Request $request) use ($exception) {
$this->app['router']->get(__FUNCTION__, function (Request $request) use ($exception) {
$driver = $this->createStub(AzureDriver::class);
$driver->method('user')->willThrowException($exception);

return $this->mock_controller($driver)->oauthCallback($request);
});

$response = $this->get(__METHOD__);
$response = $this->get(__FUNCTION__);
$response->assertRedirect('/login-oauth-redirect');
}

public function test_unhandled_exceptions_are_rethrown(): void
{
$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
$driver = $this->createStub(AzureDriver::class);
$driver->method('user')->willThrowException(new \Exception('Unhandled, yay!'));

return $this->mock_controller($driver)->oauthCallback($request);
});

$response = $this->get(__METHOD__);
$response = $this->get(__FUNCTION__);
$this->assertEquals('Unhandled, yay!', $response->exception->getMessage());
}

public function test_logout(): void
{
$this->app['router']->post(__METHOD__, function (Request $request) {
$this->app['router']->post(__FUNCTION__, function (Request $request) {
$driver = $this->createStub(AzureDriver::class);
$driver->method('getLogoutUrl')->willReturn('/oauth2/v2.0/logout');

return $this->mock_controller($driver)->oauthLogout();
});

Auth::shouldReceive('logout')->once();
$response = $this->post(__METHOD__);
$response = $this->post(__FUNCTION__);
$response->assertRedirect();
$this->assertStringContainsString('/oauth2/v2.0/logout', $response->headers->get('Location'));
}

public function test_logout_with_redirect(): void
{
$this->app['router']->post(__METHOD__, function (Request $request) {
$this->app['router']->post(__FUNCTION__, function (Request $request) {
$driver = $this->createStub(AzureDriver::class);
$driver->method('getLogoutUrl')->willReturn('/oauth2/v2.0/logout');

return $this->mock_controller($driver)->oauthLogout('https://google.com?foo=1&bar=2');
});

Auth::shouldReceive('logout')->once();
$response = $this->post(__METHOD__);
$response = $this->post(__FUNCTION__);
$response->assertRedirect();
$this->assertStringContainsString('/oauth2/v2.0/logout', $response->headers->get('Location'));
$this->assertStringContainsString('?post_logout_redirect_uri=https%3A%2F%2Fgoogle.com%3Ffoo%3D1%26bar%3D2', $response->headers->get('Location'));
Expand Down
24 changes: 12 additions & 12 deletions tests/Feature/Auth/OpenAM11AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function getEnvironmentSetUp($app)

public function test_successful_login_no_mfa(): void
{
$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
// Doing withCookie() on the get won't work cuz that only injects into the Request,
// but the controller must access this via the $_COOKIE array to avoid Laravel "decrypting"
// the value and exploding.
Expand All @@ -63,48 +63,48 @@ public function test_successful_login_no_mfa(): void
return $this->mock_controller()->login($request, $this->strategy);
})->name('login');

$response = $this->get(__METHOD__);
$response = $this->get(__FUNCTION__);
$response->assertRedirect('/logged-in');
$this->assertAuthenticated();
}

public function test_redirects_when_no_cookie(): void
{
$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
unset($_COOKIE['nusso']);

return $this->mock_controller()->login($request, $this->strategy);
})->name('login');

$response = $this->get(__METHOD__)->assertRedirect();
$response = $this->get(__FUNCTION__)->assertRedirect();
$this->assertSsoRedirect($response);
}

public function test_redirects_when_cookie_is_invalid(): void
{
$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
$_COOKIE['nusso'] = 'dummy-token';

$this->api->setHttpClient($this->mockedResponse(407, ''));

return $this->mock_controller()->login($request, $this->strategy);
})->name('login');

$response = $this->get(__METHOD__)->assertRedirect();
$response = $this->get(__FUNCTION__)->assertRedirect();
$this->assertSsoRedirect($response);
}

public function test_exception_when_apigee_key_is_invalid(): void
{
$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
$_COOKIE['nusso'] = 'dummy-token';

$this->api->setHttpClient($this->mockedResponse(401, ''));

return $this->mock_controller()->login($request, $this->strategy);
})->name('login');

$this->get(__METHOD__)->assertStatus(500);
$this->get(__FUNCTION__)->assertStatus(500);
}

public function test_sends_to_mfa(): void
Expand All @@ -115,14 +115,14 @@ public function test_sends_to_mfa(): void
$this->api = new ApigeeAgentless(resolve(Client::class), config('app.url'), config('nusoa.sso'));
$this->strategy = new OpenAM11($this->api);

$this->app['router']->get(__METHOD__, ['middleware' => 'web', 'uses' => function (Request $request) {
$this->app['router']->get(__FUNCTION__, ['middleware' => 'web', 'uses' => function (Request $request) {
$_COOKIE['openAMssoToken'] = 'dummy-token';
$this->api->setHttpClient($this->mockedResponse(200, $this->ssoResponseJson('test-id', false)));

return $this->mock_controller()->login($request, $this->strategy);
}])->name('login');

$response = $this->withSession([])->get(__METHOD__)->assertRedirect();
$response = $this->withSession([])->get(__FUNCTION__)->assertRedirect();

$error = sprintf('SSO redirect URL %s should contain ldap-and-duo', $response->getTargetUrl());
$this->assertGreaterThan(-1, strpos($response->getTargetUrl(), 'authIndexValue=ldap-and-duo'), $error);
Expand All @@ -133,15 +133,15 @@ public function tests_exception_when_insecure_connection_used(): void
// Disable the "force HTTPS" thing in ::prepareUrlForRequest
$this->useSecure = false;

$this->app['router']->get(__METHOD__, function (Request $request) {
$this->app['router']->get(__FUNCTION__, function (Request $request) {
$_COOKIE['nusso'] = 'dummy-token';

$this->api->setHttpClient($this->mockedResponse(407, ''));

return $this->mock_controller()->login($request, $this->strategy);
})->name('login');

$response = $this->get(__METHOD__)->assertStatus(500);
$response = $this->get(__FUNCTION__)->assertStatus(500);
$this->assertInstanceOf(InsecureSsoError::class, $response->exception);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/Feature/VerifyEventHubHMACTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@ protected function getEnvironmentSetUp($app)
public function test_valid_signature_pass_through(): void
{
$success_msg = 'hmac is ok';
$this->app['router']->post(__METHOD__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () use ($success_msg) {
$this->app['router']->post(__FUNCTION__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () use ($success_msg) {
return $success_msg;
}]);

$response = $this->postJson(__METHOD__, ['application_id' => 12345], [$this->header_name => '8ZTNZ1zD67n4v2A5ajcoYOTvy3xXi463bes8IiuskCs=']);
$response = $this->postJson(__FUNCTION__, ['application_id' => 12345], [$this->header_name => '8ZTNZ1zD67n4v2A5ajcoYOTvy3xXi463bes8IiuskCs=']);
$response->assertOk();
$response->assertSeeText($success_msg);
} // end test_valid_signature_pass_through

public function test_invalid_signature_401_unauthorized(): void
{
$this->app['router']->post(__METHOD__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () {
$this->app['router']->post(__FUNCTION__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () {
return 'middleware passed';
}]);

$response = $this->postJson(__METHOD__, ['application_id' => 12345], [$this->header_name => 'lhG3Qp8AjwJ77P4qd5VRN9DxHCRjUCRxCRMrK8BACds=']);
$response = $this->postJson(__FUNCTION__, ['application_id' => 12345], [$this->header_name => 'lhG3Qp8AjwJ77P4qd5VRN9DxHCRjUCRxCRMrK8BACds=']);
$response->assertStatus(401);
$response->assertSeeText('HMAC Validation Failure');
} // end test_invalid_signature_401_unauthorized

public function test_no_header_401_unauthorized(): void
{
$this->app['router']->post(__METHOD__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () {
$this->app['router']->post(__FUNCTION__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () {
return 'middleware passed';
}]);

$response = $this->postJson(__METHOD__, ['application_id' => 12345]);
$response = $this->postJson(__FUNCTION__, ['application_id' => 12345]);
$response->assertStatus(401);
$response->assertSeeText('No HMAC Signature Sent');
} // end test_no_header_401_unauthorized
Expand All @@ -64,11 +64,11 @@ public function test_bad_hmac_algorithm(): void
{
$this->app['config']->set('nusoa.eventHub.hmacVerificationAlgorithmForPHPHashHmac', 'a very invalid algorithm');

$this->app['router']->post(__METHOD__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () {
$this->app['router']->post(__FUNCTION__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () {
return 'middleware passed';
}]);

$response = $this->postJson(__METHOD__, ['application_id' => 12345], [$this->header_name => '8ZTNZ1zD67n4v2A5ajcoYOTvy3xXi463bes8IiuskCs=']);
$response = $this->postJson(__FUNCTION__, ['application_id' => 12345], [$this->header_name => '8ZTNZ1zD67n4v2A5ajcoYOTvy3xXi463bes8IiuskCs=']);
$response->assertStatus(500);
$response->assertSeeText('Invalid hash algorithm');
} // end test_bad_hmac_algorithm
Expand Down
Loading