|
3 | 3 | package integTest
|
4 | 4 |
|
5 | 5 | import (
|
| 6 | + "math/rand" |
6 | 7 | "strings"
|
7 | 8 |
|
8 | 9 | "github.com/google/uuid"
|
@@ -971,3 +972,130 @@ func (suite *GlideTestSuite) TestFlushDBWithOptions_AsyncMode() {
|
971 | 972 | assert.NoError(suite.T(), err)
|
972 | 973 | assert.Empty(suite.T(), val.Value())
|
973 | 974 | }
|
| 975 | + |
| 976 | +func (suite *GlideTestSuite) TestUpdateConnectionPasswordCluster() { |
| 977 | + suite.T().Skip("Skipping update connection password cluster test") |
| 978 | + // Create admin client |
| 979 | + adminClient := suite.defaultClusterClient() |
| 980 | + defer adminClient.Close() |
| 981 | + |
| 982 | + // Create test client |
| 983 | + testClient := suite.defaultClusterClient() |
| 984 | + defer testClient.Close() |
| 985 | + |
| 986 | + // Generate random password |
| 987 | + pwd := uuid.NewString() |
| 988 | + |
| 989 | + // Validate that we can use the test client |
| 990 | + _, err := testClient.Info() |
| 991 | + assert.NoError(suite.T(), err) |
| 992 | + |
| 993 | + // Update password without re-authentication |
| 994 | + _, err = testClient.UpdateConnectionPassword(pwd, false) |
| 995 | + assert.NoError(suite.T(), err) |
| 996 | + |
| 997 | + // Verify client still works with old auth |
| 998 | + _, err = testClient.Info() |
| 999 | + assert.NoError(suite.T(), err) |
| 1000 | + |
| 1001 | + // Update server password and kill all other clients to force reconnection |
| 1002 | + _, err = adminClient.CustomCommand([]string{"CONFIG", "SET", "requirepass", pwd}) |
| 1003 | + assert.NoError(suite.T(), err) |
| 1004 | + |
| 1005 | + _, err = adminClient.CustomCommand([]string{"CLIENT", "KILL", "TYPE", "NORMAL"}) |
| 1006 | + assert.NoError(suite.T(), err) |
| 1007 | + |
| 1008 | + // Verify client auto-reconnects with new password |
| 1009 | + _, err = testClient.Info() |
| 1010 | + assert.NoError(suite.T(), err) |
| 1011 | + |
| 1012 | + // test reset connection password |
| 1013 | + _, err = testClient.ResetConnectionPassword() |
| 1014 | + assert.NoError(suite.T(), err) |
| 1015 | + |
| 1016 | + // Cleanup: config set reset password |
| 1017 | + _, err = adminClient.CustomCommand([]string{"CONFIG", "SET", "requirepass", ""}) |
| 1018 | + assert.NoError(suite.T(), err) |
| 1019 | +} |
| 1020 | + |
| 1021 | +func (suite *GlideTestSuite) TestUpdateConnectionPasswordCluster_InvalidParameters() { |
| 1022 | + // Create test client |
| 1023 | + testClient := suite.defaultClusterClient() |
| 1024 | + defer testClient.Close() |
| 1025 | + |
| 1026 | + // Test empty password |
| 1027 | + _, err := testClient.UpdateConnectionPassword("", true) |
| 1028 | + assert.NotNil(suite.T(), err) |
| 1029 | + assert.IsType(suite.T(), &errors.RequestError{}, err) |
| 1030 | +} |
| 1031 | + |
| 1032 | +func (suite *GlideTestSuite) TestUpdateConnectionPasswordCluster_NoServerAuth() { |
| 1033 | + // Create test client |
| 1034 | + testClient := suite.defaultClusterClient() |
| 1035 | + defer testClient.Close() |
| 1036 | + |
| 1037 | + // Validate that we can use the client |
| 1038 | + _, err := testClient.Info() |
| 1039 | + assert.NoError(suite.T(), err) |
| 1040 | + |
| 1041 | + // Test immediate re-authentication fails when no server password is set |
| 1042 | + pwd := uuid.NewString() |
| 1043 | + _, err = testClient.UpdateConnectionPassword(pwd, true) |
| 1044 | + assert.NotNil(suite.T(), err) |
| 1045 | + assert.IsType(suite.T(), &errors.RequestError{}, err) |
| 1046 | +} |
| 1047 | + |
| 1048 | +func (suite *GlideTestSuite) TestUpdateConnectionPasswordCluster_LongPassword() { |
| 1049 | + // Create test client |
| 1050 | + testClient := suite.defaultClusterClient() |
| 1051 | + defer testClient.Close() |
| 1052 | + |
| 1053 | + // Generate long random password (1000 chars) |
| 1054 | + const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 1055 | + pwd := make([]byte, 1000) |
| 1056 | + for i := range pwd { |
| 1057 | + pwd[i] = letters[rand.Intn(len(letters))] |
| 1058 | + } |
| 1059 | + |
| 1060 | + // Validate that we can use the client |
| 1061 | + _, err := testClient.Info() |
| 1062 | + assert.NoError(suite.T(), err) |
| 1063 | + |
| 1064 | + // Test replacing connection password with a long password string |
| 1065 | + _, err = testClient.UpdateConnectionPassword(string(pwd), false) |
| 1066 | + assert.NoError(suite.T(), err) |
| 1067 | +} |
| 1068 | + |
| 1069 | +func (suite *GlideTestSuite) TestUpdateConnectionPasswordCluster_ImmediateAuthWrongPassword() { |
| 1070 | + // Create admin client |
| 1071 | + adminClient := suite.defaultClusterClient() |
| 1072 | + defer adminClient.Close() |
| 1073 | + |
| 1074 | + // Create test client |
| 1075 | + testClient := suite.defaultClusterClient() |
| 1076 | + defer testClient.Close() |
| 1077 | + |
| 1078 | + pwd := uuid.NewString() |
| 1079 | + notThePwd := uuid.NewString() |
| 1080 | + |
| 1081 | + // Validate that we can use the client |
| 1082 | + _, err := testClient.Info() |
| 1083 | + assert.NoError(suite.T(), err) |
| 1084 | + |
| 1085 | + // Set the password to something else |
| 1086 | + _, err = adminClient.CustomCommand([]string{"CONFIG", "SET", "requirepass", notThePwd}) |
| 1087 | + assert.NoError(suite.T(), err) |
| 1088 | + |
| 1089 | + // Test that re-authentication fails when using wrong password |
| 1090 | + _, err = testClient.UpdateConnectionPassword(pwd, true) |
| 1091 | + assert.NotNil(suite.T(), err) |
| 1092 | + assert.IsType(suite.T(), &errors.RequestError{}, err) |
| 1093 | + |
| 1094 | + // But using correct password returns OK |
| 1095 | + _, err = testClient.UpdateConnectionPassword(notThePwd, true) |
| 1096 | + assert.NoError(suite.T(), err) |
| 1097 | + |
| 1098 | + // Cleanup: Reset password |
| 1099 | + _, err = adminClient.CustomCommand([]string{"CONFIG", "SET", "requirepass", ""}) |
| 1100 | + assert.NoError(suite.T(), err) |
| 1101 | +} |
0 commit comments