Skip to content

Commit

Permalink
Merge pull request #129 from neo4j-php/118_server_states_update
Browse files Browse the repository at this point in the history
Fixed name of one and added new one.
  • Loading branch information
stefanak-michal committed Dec 14, 2023
2 parents a256e7f + 1b54b6a commit 0af4754
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
11 changes: 9 additions & 2 deletions src/protocol/ServerState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class ServerState
public const CONNECTED = 'CONNECTED';

/**
* CONNECTED state has been renamed to NEGOTIATION
* @see CONNECTED
*/
public const NEGOTIATION = self::CONNECTED;

/**
* This is not strictly a connection state, but is instead a logical state that exists after a connection has been closed. When DEFUNCT, a connection is permanently not usable.
* This may arise due to a graceful shutdown or can occur after an unrecoverable error or protocol violation.
* Clients and servers should clear up any resources associated with a connection on entering this state, including closing any open sockets.
Expand Down Expand Up @@ -67,7 +73,7 @@ class ServerState
/**
* Connection has been established and metadata has been sent back from the HELLO message or a LOGOFF message was received whilst in ready state. Ready to accept a LOGON message with authentication information.
*/
public const UNAUTHENTICATED = 'UNAUTHENTICATED';
public const AUTHENTICATION = 'AUTHENTICATION';

/**
* Internal pointer for current server state
Expand All @@ -93,7 +99,8 @@ class ServerState
self::TX_STREAMING,
self::FAILED,
self::INTERRUPTED,
self::UNAUTHENTICATED
self::AUTHENTICATION,
self::NEGOTIATION
];

/**
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v5_1/HelloMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait HelloMessage
*/
public function hello(array $extra = []): Response
{
$this->serverState->is(ServerState::CONNECTED);
$this->serverState->is(ServerState::NEGOTIATION);

if (empty($extra['user_agent']))
$extra['user_agent'] = \Bolt\helpers\Auth::$defaultUserAgent;
Expand All @@ -27,7 +27,7 @@ public function hello(array $extra = []): Response
$content = $this->read($signature);

if ($signature == Response::SIGNATURE_SUCCESS) {
$this->serverState->set(ServerState::UNAUTHENTICATED);
$this->serverState->set(ServerState::AUTHENTICATION);
} elseif ($signature == Response::SIGNATURE_FAILURE) {
$this->connection->disconnect();
$this->serverState->set(ServerState::DEFUNCT);
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/v5_1/LogoffMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function logoff(): Response
$this->write($this->packer->pack(0x6B));
$content = $this->read($signature);
if ($signature == Response::SIGNATURE_SUCCESS) {
$this->serverState->set(ServerState::UNAUTHENTICATED);
$this->serverState->set(ServerState::AUTHENTICATION);
} else {
$this->connection->disconnect();
$this->serverState->set(ServerState::DEFUNCT);
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/v5_1/LogonMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait LogonMessage
*/
public function logon(array $auth): Response
{
$this->serverState->is(ServerState::UNAUTHENTICATED);
$this->serverState->is(ServerState::AUTHENTICATION);
$this->write($this->packer->pack(0x6A, (object)$auth));
$content = $this->read($signature);
if ($signature == Response::SIGNATURE_SUCCESS) {
Expand Down
8 changes: 4 additions & 4 deletions tests/protocol/V5_1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testHello(V5_1 $cls): void

$cls->serverState->set(ServerState::CONNECTED);
$this->assertEquals(Response::SIGNATURE_SUCCESS, $cls->hello()->getSignature());
$this->assertEquals(ServerState::UNAUTHENTICATED, $cls->serverState->get());
$this->assertEquals(ServerState::AUTHENTICATION, $cls->serverState->get());

$cls->serverState->set(ServerState::CONNECTED);
$response = $cls->hello();
Expand Down Expand Up @@ -71,15 +71,15 @@ public function testLogon(V5_1 $cls): void
'00098870617373776f7264',
];

$cls->serverState->set(ServerState::UNAUTHENTICATED);
$cls->serverState->set(ServerState::AUTHENTICATION);
$this->assertEquals(Response::SIGNATURE_SUCCESS, $cls->logon([
'scheme' => 'basic',
'principal' => 'user',
'credentials' => 'password'
])->getSignature());
$this->assertEquals(ServerState::READY, $cls->serverState->get());

$cls->serverState->set(ServerState::UNAUTHENTICATED);
$cls->serverState->set(ServerState::AUTHENTICATION);
$response = $cls->logon([
'scheme' => 'basic',
'principal' => 'user',
Expand All @@ -105,7 +105,7 @@ public function testLogoff(V5_1 $cls): void

$cls->serverState->set(ServerState::READY);
$this->assertEquals(Response::SIGNATURE_SUCCESS, $cls->logoff()->getSignature());
$this->assertEquals(ServerState::UNAUTHENTICATED, $cls->serverState->get());
$this->assertEquals(ServerState::AUTHENTICATION, $cls->serverState->get());

$cls->serverState->set(ServerState::READY);
$response = $cls->logoff();
Expand Down
2 changes: 1 addition & 1 deletion tests/protocol/V5_3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testHello(V5_3 $cls): void

$cls->serverState->set(ServerState::CONNECTED);
$this->assertEquals(Response::SIGNATURE_SUCCESS, $cls->hello()->getSignature());
$this->assertEquals(ServerState::UNAUTHENTICATED, $cls->serverState->get());
$this->assertEquals(ServerState::AUTHENTICATION, $cls->serverState->get());

$cls->serverState->set(ServerState::CONNECTED);
$response = $cls->hello();
Expand Down

0 comments on commit 0af4754

Please sign in to comment.