Skip to content

Commit 5079e2c

Browse files
committed
fix psalm authentication
1 parent fd20fac commit 5079e2c

File tree

15 files changed

+174
-274
lines changed

15 files changed

+174
-274
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 181 deletions
This file was deleted.

psalm.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
xmlns="https://getpsalm.org/schema/config"
99
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
1010
hoistConstants="true"
11-
errorBaseline="psalm-baseline.xml"
11+
findUnusedBaselineEntry="true"
12+
findUnusedCode="false"
1213
>
1314
<projectFiles>
1415
<directory name="src"/>

src/Authentication/Authenticate.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public static function fromUrl(UriInterface $uri): AuthenticateInterface
8282
$userInfo = $uri->getUserInfo();
8383

8484
if (substr_count($userInfo, ':') === 1) {
85-
[$user, $pass] = explode(':', $userInfo);
85+
/** @var array{0: string, 1: string} $explode */
86+
$explode = explode(':', $userInfo);
87+
[$user, $pass] = $explode;
8688

8789
return self::basic($user, $pass);
8890
}

src/Authentication/BasicAuth.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16+
use Laudis\Neo4j\Common\ResponseHelper;
1617
use function base64_encode;
1718

1819
use Bolt\enum\Signature;
@@ -63,31 +64,25 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
6364
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
6465
{
6566
if (method_exists($protocol, 'logon')) {
66-
$response = $protocol->hello(['user_agent' => $userAgent])->getResponse();
67-
if ($response->signature === Signature::FAILURE) {
68-
throw Neo4jException::fromBoltResponse($response);
69-
}
67+
$protocol->hello(['user_agent' => $userAgent]);
68+
ResponseHelper::getResponse($protocol);
7069

71-
$response = $protocol->logon([
70+
$protocol->logon([
7271
'scheme' => 'basic',
7372
'principal' => $this->username,
7473
'credentials' => $this->password,
75-
])->getResponse();
74+
]);
7675
} else {
77-
$response = $protocol->hello([
76+
$protocol->hello([
7877
'user_agent' => $userAgent,
7978
'scheme' => 'basic',
8079
'principal' => $this->username,
8180
'credentials' => $this->password,
82-
])->getResponse();
83-
}
84-
85-
if ($response->signature === Signature::FAILURE) {
86-
throw Neo4jException::fromBoltResponse($response);
81+
]);
8782
}
8883

8984
/** @var array{server: string, connection_id: string, hints: list} */
90-
return $response->content;
85+
return ResponseHelper::getResponse($protocol)->content;
9186
}
9287

9388
public function toString(UriInterface $uri): string

src/Authentication/KerberosAuth.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16-
use Bolt\helpers\Auth;
17-
use Bolt\protocol\Response;
1816
use Bolt\protocol\V4_4;
1917
use Bolt\protocol\V5;
18+
use Bolt\protocol\V5_1;
19+
use Bolt\protocol\V5_2;
20+
use Bolt\protocol\V5_3;
21+
use Bolt\protocol\V5_4;
22+
use Laudis\Neo4j\Common\ResponseHelper;
2023
use Laudis\Neo4j\Contracts\AuthenticateInterface;
21-
use Laudis\Neo4j\Exception\Neo4jException;
2224
use Psr\Http\Message\RequestInterface;
2325
use Psr\Http\Message\UriInterface;
2426

@@ -50,15 +52,28 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
5052
->withHeader('User-Agent', $userAgent);
5153
}
5254

53-
public function authenticateBolt(V4_4|V5 $protocol, string $userAgent): array
55+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
5456
{
55-
$response = $protocol->hello(Auth::kerberos($this->token, $userAgent));
56-
if ($response->getSignature() === Response::SIGNATURE_FAILURE) {
57-
throw Neo4jException::fromBoltResponse($response);
57+
if (method_exists($protocol, 'logon')) {
58+
$protocol->hello(['user_agent' => $userAgent]);
59+
ResponseHelper::getResponse($protocol);
60+
61+
$protocol->logon([
62+
'scheme' => 'kerberos',
63+
'principal' => '',
64+
'credentials' => $this->token,
65+
]);
66+
} else {
67+
$protocol->hello([
68+
'user_agent' => $userAgent,
69+
'scheme' => 'kerberos',
70+
'principal' => '',
71+
'credentials' => $this->token,
72+
]);
5873
}
5974

6075
/** @var array{server: string, connection_id: string, hints: list} */
61-
return $response->getContent();
76+
return ResponseHelper::getResponse($protocol);
6277
}
6378

6479
public function toString(UriInterface $uri): string

src/Authentication/NoAuth.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16-
use Bolt\helpers\Auth;
17-
use Bolt\protocol\Response;
16+
use Bolt\enum\Signature;
1817
use Bolt\protocol\V4_4;
1918
use Bolt\protocol\V5;
19+
use Bolt\protocol\V5_1;
20+
use Bolt\protocol\V5_2;
21+
use Bolt\protocol\V5_3;
22+
use Bolt\protocol\V5_4;
23+
use Laudis\Neo4j\Common\ResponseHelper;
2024
use Laudis\Neo4j\Contracts\AuthenticateInterface;
2125
use Laudis\Neo4j\Exception\Neo4jException;
2226
use Psr\Http\Message\RequestInterface;
@@ -42,15 +46,24 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
4246
return $request->withHeader('User-Agent', $userAgent);
4347
}
4448

45-
public function authenticateBolt(V4_4|V5 $protocol, string $userAgent): array
49+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
4650
{
47-
$response = $protocol->hello(Auth::none($userAgent));
48-
if ($response->getSignature() === Response::SIGNATURE_FAILURE) {
49-
throw Neo4jException::fromBoltResponse($response);
51+
if (method_exists($protocol, 'logon')) {
52+
$protocol->hello(['user_agent' => $userAgent]);
53+
ResponseHelper::getResponse($protocol);
54+
55+
$protocol->logon([
56+
'scheme' => 'none',
57+
]);
58+
} else {
59+
$protocol->hello([
60+
'user_agent' => $userAgent,
61+
'scheme' => 'none',
62+
]);
5063
}
5164

5265
/** @var array{server: string, connection_id: string, hints: list} */
53-
return $response->getContent();
66+
return ResponseHelper::getResponse($protocol)->content;
5467
}
5568

5669
public function toString(UriInterface $uri): string

src/Authentication/OpenIDConnectAuth.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16-
use Bolt\helpers\Auth;
17-
use Bolt\protocol\Response;
16+
use Bolt\enum\Signature;
1817
use Bolt\protocol\V4_4;
1918
use Bolt\protocol\V5;
19+
use Bolt\protocol\V5_1;
20+
use Bolt\protocol\V5_2;
21+
use Bolt\protocol\V5_3;
22+
use Bolt\protocol\V5_4;
23+
use Laudis\Neo4j\Common\ResponseHelper;
2024
use Laudis\Neo4j\Contracts\AuthenticateInterface;
2125
use Laudis\Neo4j\Exception\Neo4jException;
2226
use Psr\Http\Message\RequestInterface;
@@ -47,15 +51,26 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
4751
->withHeader('User-Agent', $userAgent);
4852
}
4953

50-
public function authenticateBolt(V4_4|V5 $protocol, string $userAgent): array
54+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
5155
{
52-
$response = $protocol->hello(Auth::bearer($this->token, $userAgent));
53-
if ($response->getSignature() === Response::SIGNATURE_FAILURE) {
54-
throw Neo4jException::fromBoltResponse($response);
56+
if (method_exists($protocol, 'logon')) {
57+
$protocol->hello(['user_agent' => $userAgent]);
58+
ResponseHelper::getResponse($protocol);
59+
60+
$protocol->logon([
61+
'scheme' => 'bearer',
62+
'credentials' => $this->token,
63+
]);
64+
} else {
65+
$protocol->hello([
66+
'user_agent' => $userAgent,
67+
'scheme' => 'bearer',
68+
'credentials' => $this->token,
69+
]);
5570
}
5671

5772
/** @var array{server: string, connection_id: string, hints: list} */
58-
return $response->getContent();
73+
return ResponseHelper::getResponse($protocol)->content;
5974
}
6075

6176
public function toString(UriInterface $uri): string

0 commit comments

Comments
 (0)