Skip to content

Commit 1fc5a40

Browse files
committed
Add tests for cluster auth
1 parent b0f219c commit 1fc5a40

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

tests/ValkeyGlideClusterFeaturesTest.php

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,40 +96,34 @@ public function testConstructorWithNullCredentials()
9696
public function testConstructorWithPasswordCredentials()
9797
{
9898
// Test with password-only credentials
99-
if ($this->getAuth()) {
100-
$valkey_glide = new ValkeyGlideCluster(
101-
[['host' => '127.0.0.1', 'port' => 7001]],
102-
false,
103-
$this->getAuth() // password credentials
104-
);
99+
$valkey_glide = new ValkeyGlideCluster(
100+
[['host' => '127.0.0.1', 'port' => 5001]],
101+
false,
102+
['username' => '', 'password' => 'dummy_password'] // password credentials
103+
);
105104

106-
$this->assertTrue($valkey_glide->ping(['type' => 'primarySlotKey', 'key' => 'test']));
107-
$valkey_glide->close();
108-
} else {
109-
$this->markTestSkipped('No authentication configured');
110-
}
105+
$this->assertTrue($valkey_glide->ping(['type' => 'primarySlotKey', 'key' => 'test']));
106+
$valkey_glide->close();
111107
}
112108

113109
public function testConstructorInvalidAuth()
114110
{
115-
if ($this->getAuth()) {
116-
// Test constructor with credentials (if auth is configured)
117-
$addresses = [
118-
[['host' => '127.0.0.1', 'port' => 7001]],
119-
];
120-
121-
// Try to connect with incorrect auth
122-
$valkey_glide = null;
123-
try {
124-
$credentials = ['username' => 'invalid_user', 'password' => 'invalid_password'];
125-
$valkey_glide = new ValkeyGlideCluster($addresses, false, $credentials);
126-
$this->fail("Should throw an exception when running commands with invalid authentication");
127-
} catch (Exception $e) {
128-
$this->assertStringContains("WRONGPASS", $e->getMessage(), "Exception should indicate authentication failure");
129-
} finally {
130-
// Clean up
131-
$valkey_glide?->close();
132-
}
111+
// Test constructor with credentials (if auth is configured)
112+
$addresses = [
113+
[['host' => '127.0.0.1', 'port' => 5001]],
114+
];
115+
116+
// Try to connect with incorrect auth
117+
$valkey_glide = null;
118+
try {
119+
$credentials = ['username' => 'invalid_user', 'password' => 'invalid_password'];
120+
$valkey_glide = new ValkeyGlideCluster($addresses, false, $credentials);
121+
$this->fail("Should throw an exception when running commands with invalid authentication");
122+
} catch (Exception $e) {
123+
$this->assertStringContains("WRONGPASS", $e->getMessage(), "Exception should indicate authentication failure");
124+
} finally {
125+
// Clean up
126+
$valkey_glide?->close();
133127
}
134128
}
135129

tests/create-valkey-cluster.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ echo "Creating cluster..."
5252

5353
# 5. Use cluster_manager.py to create the TLS cluster
5454
../valkey-glide/utils/cluster_manager.py --tls start --prefix tls-cluster --cluster-mode -p 8001 8002 8003 8004 8005 8006
55+
56+
# 6. Use cluster_manager.py to create cluster with auth
57+
../valkey-glide/utils/cluster_manager.py --auth dummy_password start --prefix auth-cluster --cluster-mode -p 5001 5002 5003 5004 5005 5006

0 commit comments

Comments
 (0)