Skip to content

Commit 4e6d009

Browse files
committed
fixed testkit tests for test_tx_func_run class
1 parent 1d62ec1 commit 4e6d009

40 files changed

+389
-365
lines changed

src/Authentication/BasicAuth.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16-
use Bolt\protocol\V4_4;
17-
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;
2216
use Exception;
17+
use Laudis\Neo4j\Bolt\BoltConnection;
2318
use Laudis\Neo4j\Bolt\BoltMessageFactory;
2419
use Laudis\Neo4j\Common\Neo4jLogger;
25-
use Laudis\Neo4j\Common\ResponseHelper;
2620
use Laudis\Neo4j\Contracts\AuthenticateInterface;
2721
use Psr\Http\Message\UriInterface;
2822

@@ -43,27 +37,26 @@ public function __construct(
4337
*
4438
* @return array{server: string, connection_id: string, hints: list}
4539
*/
46-
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
40+
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
4741
{
48-
$factory = $this->createMessageFactory($protocol);
42+
$factory = $this->createMessageFactory($connection);
4943

44+
$protocol = $connection->protocol();
5045
if (method_exists($protocol, 'logon')) {
5146
$helloMetadata = ['user_agent' => $userAgent];
5247

53-
$factory->createHelloMessage($helloMetadata)->send();
54-
$response = ResponseHelper::getResponse($protocol);
48+
$responseHello = $factory->createHelloMessage($helloMetadata)->send()->getResponse();
5549

5650
$credentials = [
5751
'scheme' => 'basic',
5852
'principal' => $this->username,
5953
'credentials' => $this->password,
6054
];
6155

62-
$factory->createLogonMessage($credentials)->send();
63-
ResponseHelper::getResponse($protocol);
56+
$response = $factory->createLogonMessage($credentials)->send()->getResponse();
6457

6558
/** @var array{server: string, connection_id: string, hints: list} */
66-
return $response->content;
59+
return array_merge($responseHello->content, $response->content);
6760
}
6861

6962
$helloMetadata = [
@@ -73,22 +66,15 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
7366
'credentials' => $this->password,
7467
];
7568

76-
$factory->createHelloMessage($helloMetadata)->send();
69+
$response = $factory->createHelloMessage($helloMetadata)->send()->getResponse();
7770

7871
/** @var array{server: string, connection_id: string, hints: list} */
79-
return ResponseHelper::getResponse($protocol)->content;
72+
return $response->content;
8073
}
8174

8275
/**
8376
* @throws Exception
8477
*/
85-
public function logoff(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): void
86-
{
87-
$factory = $this->createMessageFactory($protocol);
88-
$factory->createLogoffMessage()->send();
89-
ResponseHelper::getResponse($protocol);
90-
}
91-
9278
public function toString(UriInterface $uri): string
9379
{
9480
return sprintf('Basic %s:%s@%s:%s', $this->username, '######', $uri->getHost(), $uri->getPort() ?? '');
@@ -97,8 +83,8 @@ public function toString(UriInterface $uri): string
9783
/**
9884
* Helper to create message factory.
9985
*/
100-
private function createMessageFactory(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): BoltMessageFactory
86+
private function createMessageFactory(BoltConnection $connection): BoltMessageFactory
10187
{
102-
return new BoltMessageFactory($protocol, $this->logger);
88+
return new BoltMessageFactory($connection, $this->logger);
10389
}
10490
}

src/Authentication/KerberosAuth.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,11 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16-
use Bolt\protocol\V4_4;
17-
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;
2216
use Exception;
17+
use Laudis\Neo4j\Bolt\BoltConnection;
2318
use Laudis\Neo4j\Bolt\BoltMessageFactory;
2419
use Laudis\Neo4j\Common\Neo4jLogger;
25-
use Laudis\Neo4j\Common\ResponseHelper;
2620
use Laudis\Neo4j\Contracts\AuthenticateInterface;
27-
use Psr\Http\Message\RequestInterface;
2821
use Psr\Http\Message\UriInterface;
2922
use Psr\Log\LogLevel;
3023

@@ -41,38 +34,26 @@ public function __construct(
4134
) {
4235
}
4336

44-
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
45-
{
46-
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using KerberosAuth');
47-
48-
return $request->withHeader('Authorization', 'Kerberos '.$this->token)
49-
->withHeader('User-Agent', $userAgent);
50-
}
51-
5237
/**
5338
* @throws Exception
5439
*
5540
* @return array{server: string, connection_id: string, hints: list}
5641
*/
57-
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
42+
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
5843
{
59-
$factory = $this->createMessageFactory($protocol);
44+
$factory = $this->createMessageFactory($connection);
6045

6146
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
6247

63-
$factory->createHelloMessage(['user_agent' => $userAgent])->send();
64-
65-
$response = ResponseHelper::getResponse($protocol);
48+
$factory->createHelloMessage(['user_agent' => $userAgent])->send()->getResponse();
6649

6750
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'kerberos', 'principal' => '']);
6851

69-
$factory->createLogonMessage([
52+
$response = $factory->createLogonMessage([
7053
'scheme' => 'kerberos',
7154
'principal' => '',
7255
'credentials' => $this->token,
73-
])->send();
74-
75-
ResponseHelper::getResponse($protocol);
56+
])->send()->getResponse();
7657

7758
/**
7859
* @var array{server: string, connection_id: string, hints: list}
@@ -88,8 +69,8 @@ public function toString(UriInterface $uri): string
8869
/**
8970
* Helper to create the message factory.
9071
*/
91-
private function createMessageFactory(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): BoltMessageFactory
72+
private function createMessageFactory(BoltConnection $connection): BoltMessageFactory
9273
{
93-
return new BoltMessageFactory($protocol, $this->logger);
74+
return new BoltMessageFactory($connection, $this->logger);
9475
}
9576
}

src/Authentication/NoAuth.php

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

1414
namespace Laudis\Neo4j\Authentication;
1515

16-
use Bolt\protocol\V4_4;
17-
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;
2216
use Exception;
17+
use Laudis\Neo4j\Bolt\BoltConnection;
2318
use Laudis\Neo4j\Bolt\BoltMessageFactory;
2419
use Laudis\Neo4j\Common\Neo4jLogger;
25-
use Laudis\Neo4j\Common\ResponseHelper;
2620
use Laudis\Neo4j\Contracts\AuthenticateInterface;
27-
use Psr\Http\Message\RequestInterface;
2821
use Psr\Http\Message\UriInterface;
29-
use Psr\Log\LogLevel;
3022

3123
use function sprintf;
3224

@@ -37,30 +29,21 @@ public function __construct(
3729
) {
3830
}
3931

40-
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
41-
{
42-
$this->logger?->log(LogLevel::DEBUG, 'Authentication disabled');
43-
44-
return $request->withHeader('User-Agent', $userAgent);
45-
}
46-
4732
/**
4833
* @throws Exception
4934
*
5035
* @return array{server: string, connection_id: string, hints: list}
5136
*/
52-
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
37+
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
5338
{
54-
$factory = $this->createMessageFactory($protocol);
39+
$factory = $this->createMessageFactory($connection);
5540

56-
if (method_exists($protocol, 'logon')) {
41+
if (method_exists($connection, 'logon')) {
5742
$helloMetadata = ['user_agent' => $userAgent];
5843

59-
$factory->createHelloMessage($helloMetadata)->send();
60-
$response = ResponseHelper::getResponse($protocol);
44+
$factory->createHelloMessage($helloMetadata)->send()->getResponse();
6145

62-
$factory->createLogonMessage(['scheme' => 'none'])->send();
63-
ResponseHelper::getResponse($protocol);
46+
$response = $factory->createLogonMessage(['scheme' => 'none'])->send()->getResponse();
6447

6548
/** @var array{server: string, connection_id: string, hints: list} */
6649
return $response->content;
@@ -71,26 +54,19 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
7154
'scheme' => 'none',
7255
];
7356

74-
$factory->createHelloMessage($helloMetadata)->send();
57+
$response = $factory->createHelloMessage($helloMetadata)->send()->getResponse();
7558

7659
/** @var array{server: string, connection_id: string, hints: list} */
77-
return ResponseHelper::getResponse($protocol)->content;
78-
}
79-
80-
public function logoff(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): void
81-
{
82-
$factory = $this->createMessageFactory($protocol);
83-
$factory->createLogoffMessage()->send();
84-
ResponseHelper::getResponse($protocol);
60+
return $response->content;
8561
}
8662

8763
public function toString(UriInterface $uri): string
8864
{
8965
return sprintf('No Auth %s:%s', $uri->getHost(), $uri->getPort() ?? '');
9066
}
9167

92-
private function createMessageFactory(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): BoltMessageFactory
68+
private function createMessageFactory(BoltConnection $connection): BoltMessageFactory
9369
{
94-
return new BoltMessageFactory($protocol, $this->logger);
70+
return new BoltMessageFactory($connection, $this->logger);
9571
}
9672
}

src/Authentication/OpenIDConnectAuth.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16-
use Bolt\protocol\V4_4;
17-
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;
2216
use Exception;
17+
use Laudis\Neo4j\Bolt\BoltConnection;
2318
use Laudis\Neo4j\Bolt\BoltMessageFactory;
2419
use Laudis\Neo4j\Common\Neo4jLogger;
25-
use Laudis\Neo4j\Common\ResponseHelper;
2620
use Laudis\Neo4j\Contracts\AuthenticateInterface;
2721
use Psr\Http\Message\RequestInterface;
2822
use Psr\Http\Message\UriInterface;
@@ -51,24 +45,20 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
5145
*
5246
* @return array{server: string, connection_id: string, hints: list}
5347
*/
54-
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
48+
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
5549
{
56-
$factory = $this->createMessageFactory($protocol);
50+
$factory = $this->createMessageFactory($connection);
5751

5852
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
5953

60-
$factory->createHelloMessage(['user_agent' => $userAgent])->send();
61-
62-
$response = ResponseHelper::getResponse($protocol);
54+
$factory->createHelloMessage(['user_agent' => $userAgent])->send()->getResponse();
6355

6456
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'bearer']);
6557

66-
$factory->createLogonMessage([
58+
$response = $factory->createLogonMessage([
6759
'scheme' => 'bearer',
6860
'credentials' => $this->token,
69-
])->send();
70-
71-
ResponseHelper::getResponse($protocol);
61+
])->send()->getResponse();
7262

7363
/**
7464
* @var array{server: string, connection_id: string, hints: list}
@@ -84,8 +74,8 @@ public function toString(UriInterface $uri): string
8474
/**
8575
* Helper to create the message factory.
8676
*/
87-
public function createMessageFactory(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): BoltMessageFactory
77+
public function createMessageFactory(BoltConnection $connection): BoltMessageFactory
8878
{
89-
return new BoltMessageFactory($protocol, $this->logger);
79+
return new BoltMessageFactory($connection, $this->logger);
9080
}
9181
}

src/Bolt/BoltConnection.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function __construct(
8585
private readonly ConnectionConfiguration $config,
8686
private readonly ?Neo4jLogger $logger,
8787
) {
88-
$this->messageFactory = new BoltMessageFactory($this->protocol(), $this->logger);
88+
$this->messageFactory = new BoltMessageFactory($this, $this->logger);
8989
}
9090

9191
public function getEncryptionLevel(): string
@@ -109,14 +109,6 @@ public function getServerAddress(): UriInterface
109109
return $this->config->getServerAddress();
110110
}
111111

112-
/**
113-
* @psalm-mutation-free
114-
*/
115-
public function getServerVersion(): string
116-
{
117-
return $this->config->getServerVersion();
118-
}
119-
120112
/**
121113
* @psalm-mutation-free
122114
*/
@@ -392,16 +384,12 @@ public function getUserAgent(): string
392384
return $this->userAgent;
393385
}
394386

395-
private function assertNoFailure(Response $response): void
387+
public function assertNoFailure(Response $response): void
396388
{
397389
if ($response->signature === Signature::FAILURE) {
398390
$this->logger?->log(LogLevel::ERROR, 'FAILURE');
399-
$message = $this->messageFactory->createResetMessage();
400-
$resetResponse = $message->send()->getResponse();
401391
$this->subscribedResults = [];
402-
if ($resetResponse->signature === Signature::FAILURE) {
403-
throw new Neo4jException([Neo4jError::fromBoltResponse($resetResponse), Neo4jError::fromBoltResponse($response)]);
404-
}
392+
405393
throw Neo4jException::fromBoltResponse($response);
406394
}
407395
}

0 commit comments

Comments
 (0)