Skip to content

Commit a782f5d

Browse files
authored
PHP 8.4 Compatibility (#183)
1 parent 0c4b455 commit a782f5d

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
php-versions: ['8.2', '8.3']
16+
php-versions: ['8.2', '8.3', '8.4']
1717

1818
steps:
1919
- uses: actions/checkout@v4

tests/Feature/Auth/OAuthAuthenticationTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ final class OAuthAuthenticationTest extends TestCase
2424

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

31-
$response = $this->get(__METHOD__);
31+
$response = $this->get(__FUNCTION__);
3232
$response->assertRedirect(self::OAUTH_DUMMY_PROVIDER_URL);
3333
}
3434

3535
public function test_callback_success(): void
3636
{
37-
$this->app['router']->get(__METHOD__, function (Request $request) {
37+
$this->app['router']->get(__FUNCTION__, function (Request $request) {
3838
$oauthUser = $this->createStub(User::class);
3939
$oauthUser->token = 'a';
4040
$oauthUser->method('getRaw')->willReturn([
@@ -47,7 +47,7 @@ public function test_callback_success(): void
4747
return $this->mock_controller($driver)->oauthCallback($request);
4848
});
4949

50-
$response = $this->get(__METHOD__);
50+
$response = $this->get(__FUNCTION__);
5151
$response->assertRedirect('/logged-in');
5252
$this->assertAuthenticated();
5353
}
@@ -59,14 +59,14 @@ public function test_exceptions_restart_flow_for_invalid_state(): void
5959
//
6060
})->name('login-oauth-redirect');
6161

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

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

69-
$response = $this->get(__METHOD__);
69+
$response = $this->get(__FUNCTION__);
7070
$response->assertRedirect('/login-oauth-redirect');
7171
}
7272

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

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

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

95-
$response = $this->get(__METHOD__);
95+
$response = $this->get(__FUNCTION__);
9696
$response->assertRedirect('/login-oauth-redirect');
9797
}
9898

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

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

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

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

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

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

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

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

136136
Auth::shouldReceive('logout')->once();
137-
$response = $this->post(__METHOD__);
137+
$response = $this->post(__FUNCTION__);
138138
$response->assertRedirect();
139139
$this->assertStringContainsString('/oauth2/v2.0/logout', $response->headers->get('Location'));
140140
$this->assertStringContainsString('?post_logout_redirect_uri=https%3A%2F%2Fgoogle.com%3Ffoo%3D1%26bar%3D2', $response->headers->get('Location'));

tests/Feature/Auth/OpenAM11AuthenticationTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function getEnvironmentSetUp($app)
5151

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

66-
$response = $this->get(__METHOD__);
66+
$response = $this->get(__FUNCTION__);
6767
$response->assertRedirect('/logged-in');
6868
$this->assertAuthenticated();
6969
}
7070

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

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

79-
$response = $this->get(__METHOD__)->assertRedirect();
79+
$response = $this->get(__FUNCTION__)->assertRedirect();
8080
$this->assertSsoRedirect($response);
8181
}
8282

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

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

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

93-
$response = $this->get(__METHOD__)->assertRedirect();
93+
$response = $this->get(__FUNCTION__)->assertRedirect();
9494
$this->assertSsoRedirect($response);
9595
}
9696

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

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

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

107-
$this->get(__METHOD__)->assertStatus(500);
107+
$this->get(__FUNCTION__)->assertStatus(500);
108108
}
109109

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

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

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

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

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

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

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

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

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

tests/Feature/VerifyEventHubHMACTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,33 @@ protected function getEnvironmentSetUp($app)
2929
public function test_valid_signature_pass_through(): void
3030
{
3131
$success_msg = 'hmac is ok';
32-
$this->app['router']->post(__METHOD__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () use ($success_msg) {
32+
$this->app['router']->post(__FUNCTION__, ['middleware' => self::HMAC_VERIFICATION_MIDDLEWARE, 'uses' => function () use ($success_msg) {
3333
return $success_msg;
3434
}]);
3535

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

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

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

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

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

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

71-
$response = $this->postJson(__METHOD__, ['application_id' => 12345], [$this->header_name => '8ZTNZ1zD67n4v2A5ajcoYOTvy3xXi463bes8IiuskCs=']);
71+
$response = $this->postJson(__FUNCTION__, ['application_id' => 12345], [$this->header_name => '8ZTNZ1zD67n4v2A5ajcoYOTvy3xXi463bes8IiuskCs=']);
7272
$response->assertStatus(500);
7373
$response->assertSeeText('Invalid hash algorithm');
7474
} // end test_bad_hmac_algorithm

0 commit comments

Comments
 (0)