Skip to content

Commit 4bb4176

Browse files
committed
temp commit
1 parent 731fc0c commit 4bb4176

File tree

5 files changed

+153
-49
lines changed

5 files changed

+153
-49
lines changed

src/Bolt/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function readTransaction(callable $tsxHandler, ?TransactionConfiguration
111111
$this->getLogger()?->log(LogLevel::INFO, 'Beginning read transaction', ['config' => $config]);
112112
$config = $this->mergeTsxConfig($config);
113113

114-
return $this->retry($tsxHandler, false, $config);
114+
return $this->retry($tsxHandler, true, $config);
115115
}
116116

117117
/**

src/Databags/Notification.php

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ public function getCodeClassification(): string
5757
return $this->splitCode()['classification'];
5858
}
5959

60-
public function getCodeCategory(): string
61-
{
62-
return $this->splitCode()['category'];
63-
}
64-
65-
public function getCodeTitle(): string
66-
{
67-
return $this->splitCode()['title'];
68-
}
69-
7060
public function getSeverity(): string
7161
{
7262
return $this->severity;
@@ -92,10 +82,6 @@ public function getTitle(): string
9282
return $this->title;
9383
}
9484

95-
public function getCategory(): string
96-
{
97-
return $this->category;
98-
}
9985

10086
/**
10187
* Matches inherited return type: array<string, string|Position>.
@@ -105,31 +91,6 @@ public function getCategory(): string
10591
* @return array<string, string|Position>
10692
*/
10793
public function toArray(): array
108-
{
109-
return [
110-
'severity' => $this->severity,
111-
'description' => $this->description,
112-
'code' => $this->code,
113-
'position' => $this->position,
114-
'title' => $this->title,
115-
'category' => $this->category,
116-
];
117-
}
118-
119-
/**
120-
* If you still want a version with the position converted to array,
121-
* use this custom method instead of overriding toArray().
122-
*
123-
* @return array{
124-
* severity: string,
125-
* description: string,
126-
* code: string,
127-
* position: array<string, float|int|null|string>,
128-
* title: string,
129-
* category: string
130-
* }
131-
*/
132-
public function toSerializedArray(): array
13394
{
13495
return [
13596
'severity' => $this->severity,
@@ -140,4 +101,5 @@ public function toSerializedArray(): array
140101
'category' => $this->category,
141102
];
142103
}
104+
143105
}

testkit-backend/src/Responses/Types/CypherObject.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,28 @@ public static function autoDetect($value): TestkitResponseInterface
130130
$elementId = (string) $value->getId();
131131
}
132132

133-
$relationshipKey = $value->getId().'_'.$value->getStartNodeId().'_'.$value->getEndNodeId();
134-
135-
$startNodeElementId = self::$relationshipElementIdMap[$relationshipKey]['startNodeElementId'] ?? (string) $value->getStartNodeId();
136-
$endNodeElementId = self::$relationshipElementIdMap[$relationshipKey]['endNodeElementId'] ?? (string) $value->getEndNodeId();
133+
// First check if the relationship has methods to get start/end node element IDs
134+
$startNodeElementId = null;
135+
$endNodeElementId = null;
136+
137+
if (method_exists($value, 'getStartNodeElementId')) {
138+
$startNodeElementId = $value->getStartNodeElementId();
139+
}
140+
if (method_exists($value, 'getEndNodeElementId')) {
141+
$endNodeElementId = $value->getEndNodeElementId();
142+
}
143+
144+
// If not available directly, check our stored mappings from paths
145+
if ($startNodeElementId === null || $endNodeElementId === null) {
146+
$relationshipKey = $value->getId().'_'.$value->getStartNodeId().'_'.$value->getEndNodeId();
147+
148+
if ($startNodeElementId === null) {
149+
$startNodeElementId = self::$relationshipElementIdMap[$relationshipKey]['startNodeElementId'] ?? (string) $value->getStartNodeId();
150+
}
151+
if ($endNodeElementId === null) {
152+
$endNodeElementId = self::$relationshipElementIdMap[$relationshipKey]['endNodeElementId'] ?? (string) $value->getEndNodeId();
153+
}
154+
}
137155

138156
$tbr = new CypherRelationship(
139157
new CypherObject('CypherInt', $value->getId()),
@@ -180,11 +198,6 @@ public static function autoDetect($value): TestkitResponseInterface
180198
'startNodeElementId' => $startNodeElementId,
181199
'endNodeElementId' => $endNodeElementId,
182200
];
183-
184-
error_log('DEBUG PATH: Stored mapping for key: '.$relationshipKey);
185-
error_log('DEBUG PATH: Stored startNodeElementId: '.$startNodeElementId);
186-
error_log('DEBUG PATH: Stored endNodeElementId: '.$endNodeElementId);
187-
188201
$rels[] = self::autoDetect($boundRel);
189202
}
190203
} else {

tests/Unit/KerberosAuthTest.php

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

1414
namespace Laudis\Neo4j\Tests\Unit;
1515

16+
use Bolt\enum\Message;
17+
use Bolt\enum\Signature;
18+
use Bolt\protocol\Response;
19+
use Bolt\protocol\V4_4;
20+
use Bolt\protocol\V5;
1621
use Laudis\Neo4j\Authentication\KerberosAuth;
22+
use Laudis\Neo4j\Bolt\BoltConnection;
1723
use Laudis\Neo4j\Common\Neo4jLogger;
24+
use Laudis\Neo4j\Databags\Neo4jError;
25+
use Laudis\Neo4j\Exception\Neo4jException;
1826
use PHPUnit\Framework\TestCase;
1927
use Psr\Http\Message\UriInterface;
2028

@@ -28,6 +36,50 @@ protected function setUp(): void
2836
$this->auth = new KerberosAuth('test-token', $logger);
2937
}
3038

39+
public function testAuthenticateBoltFailureV5(): void
40+
{
41+
$this->expectException(Neo4jException::class);
42+
43+
$mockProtocol = $this->createMock(V5::class);
44+
$mockProtocol->method('hello');
45+
$mockProtocol->method('getResponse')->willReturn(new Response(
46+
Message::HELLO,
47+
Signature::FAILURE,
48+
['code' => 'Neo.ClientError.Security.Unauthorized', 'message' => 'Invalid credentials']
49+
));
50+
51+
$mockConnection = $this->createMock(BoltConnection::class);
52+
$mockConnection->method('protocol')->willReturn($mockProtocol);
53+
54+
$error = Neo4jError::fromMessageAndCode('Neo.ClientError.Security.Unauthorized', 'Invalid credentials');
55+
$exception = new Neo4jException([$error]);
56+
$mockConnection->method('assertNoFailure')->will($this->throwException($exception));
57+
58+
$this->auth->authenticateBolt($mockConnection, 'neo4j-client/1.0');
59+
}
60+
61+
public function testAuthenticateBoltFailureV4(): void
62+
{
63+
$this->expectException(Neo4jException::class);
64+
65+
$mockProtocol = $this->createMock(V4_4::class);
66+
$mockProtocol->method('hello');
67+
$mockProtocol->method('getResponse')->willReturn(new Response(
68+
Message::HELLO,
69+
Signature::FAILURE,
70+
['code' => 'Neo.ClientError.Security.Unauthorized', 'message' => 'Invalid credentials']
71+
));
72+
73+
$mockConnection = $this->createMock(BoltConnection::class);
74+
$mockConnection->method('protocol')->willReturn($mockProtocol);
75+
76+
$error = Neo4jError::fromMessageAndCode('Neo.ClientError.Security.Unauthorized', 'Invalid credentials');
77+
$exception = new Neo4jException([$error]);
78+
$mockConnection->method('assertNoFailure')->will($this->throwException($exception));
79+
80+
$this->auth->authenticateBolt($mockConnection, 'neo4j-client/1.0');
81+
}
82+
3183
public function testToString(): void
3284
{
3385
$uri = $this->createMock(UriInterface::class);

tests/Unit/NoAuthTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@
1313

1414
namespace Laudis\Neo4j\Tests\Unit;
1515

16+
use Bolt\enum\Message;
17+
use Bolt\enum\Signature;
18+
use Bolt\protocol\Response;
19+
use Bolt\protocol\V4_4;
20+
use Bolt\protocol\V5_1;
1621
use Laudis\Neo4j\Authentication\NoAuth;
22+
use Laudis\Neo4j\Bolt\BoltConnection;
1723
use Laudis\Neo4j\Common\Neo4jLogger;
24+
use Laudis\Neo4j\Databags\Neo4jError;
25+
use Laudis\Neo4j\Enum\ConnectionProtocol;
26+
use Laudis\Neo4j\Exception\Neo4jException;
1827
use PHPUnit\Framework\TestCase;
1928
use Psr\Http\Message\UriInterface;
2029

@@ -27,6 +36,74 @@ protected function setUp(): void
2736
$logger = $this->createMock(Neo4jLogger::class);
2837
$this->auth = new NoAuth($logger);
2938
}
39+
public function testAuthenticateBoltSuccessV5(): void
40+
{
41+
$userAgent = 'neo4j-client/1.0';
42+
43+
$mockProtocol = $this->createMock(V5_1::class);
44+
$mockProtocol->method('hello');
45+
$mockProtocol->method('logon');
46+
$mockProtocol->method('getResponse')->willReturn(new Response(
47+
Message::HELLO,
48+
Signature::SUCCESS,
49+
['server' => 'neo4j-server', 'connection_id' => '12345', 'hints' => []]
50+
));
51+
52+
$mockConnection = $this->createMock(BoltConnection::class);
53+
$mockConnection->method('protocol')->willReturn($mockProtocol);
54+
$mockConnection->method('getProtocol')->willReturn(ConnectionProtocol::BOLT_V5_1());
55+
56+
$result = $this->auth->authenticateBolt($mockConnection, $userAgent);
57+
$this->assertArrayHasKey('server', $result);
58+
$this->assertSame('neo4j-server', $result['server']);
59+
$this->assertSame('12345', $result['connection_id']);
60+
}
61+
62+
public function testAuthenticateBoltFailureV5(): void
63+
{
64+
$this->expectException(Neo4jException::class);
65+
66+
$mockProtocol = $this->createMock(V5_1::class);
67+
$mockProtocol->method('hello');
68+
$mockProtocol->method('logon');
69+
$mockProtocol->method('getResponse')->willReturn(new Response(
70+
Message::HELLO,
71+
Signature::FAILURE,
72+
['code' => 'Neo.ClientError.Security.Unauthorized', 'message' => 'Invalid credentials']
73+
));
74+
75+
$mockConnection = $this->createMock(BoltConnection::class);
76+
$mockConnection->method('protocol')->willReturn($mockProtocol);
77+
$mockConnection->method('getProtocol')->willReturn(ConnectionProtocol::BOLT_V5_1());
78+
79+
$error = Neo4jError::fromMessageAndCode('Neo.ClientError.Security.Unauthorized', 'Invalid credentials');
80+
$exception = new Neo4jException([$error]);
81+
$mockConnection->method('assertNoFailure')->will($this->throwException($exception));
82+
83+
$this->auth->authenticateBolt($mockConnection, 'neo4j-client/1.0');
84+
}
85+
86+
public function testAuthenticateBoltSuccessV4(): void
87+
{
88+
$userAgent = 'neo4j-client/1.0';
89+
90+
$mockProtocol = $this->createMock(V4_4::class);
91+
$mockProtocol->method('hello');
92+
$mockProtocol->method('getResponse')->willReturn(new Response(
93+
Message::HELLO,
94+
Signature::SUCCESS,
95+
['server' => 'neo4j-server', 'connection_id' => '12345', 'hints' => []]
96+
));
97+
98+
$mockConnection = $this->createMock(BoltConnection::class);
99+
$mockConnection->method('protocol')->willReturn($mockProtocol);
100+
$mockConnection->method('getProtocol')->willReturn(ConnectionProtocol::BOLT_V44());
101+
102+
$result = $this->auth->authenticateBolt($mockConnection, $userAgent);
103+
$this->assertArrayHasKey('server', $result);
104+
$this->assertSame('neo4j-server', $result['server']);
105+
$this->assertSame('12345', $result['connection_id']);
106+
}
30107

31108
public function testToString(): void
32109
{

0 commit comments

Comments
 (0)