Skip to content

Commit 615d0c0

Browse files
authored
[MATRIX-1102] use server returned statement text in history (#3164)
1 parent 3054559 commit 615d0c0

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

pkg/flink/app/application.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ func (a *Application) readEvalPrint() {
205205
return
206206
}
207207
if !executedStatement.IsSensitiveStatement {
208-
a.history.Append(userInput)
208+
// Append executedStatement text since sensitive information such as password can be masked in server side
209+
if executedStatement.Statement != "" {
210+
a.history.Append(executedStatement.Statement)
211+
}
209212
}
210213

211214
if !executedStatement.IsDryRunStatement() {

pkg/flink/app/application_test.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ func (s *ApplicationTestSuite) TestReplExitsAppWhenUserInitiatedExit() {
108108
cupaloy.SnapshotT(s.T(), actual)
109109
}
110110

111-
func (s *ApplicationTestSuite) TestReplAppendsStatementToHistoryIfNoErrorAndNotSensistiveStatement() {
111+
func (s *ApplicationTestSuite) TestReplAppendsStatementToHistoryIfNoErrorAndNotSensitiveStatement() {
112112
userInput := "test-input"
113-
statement := types.ProcessedStatement{PageToken: "not-empty"}
113+
statement := types.ProcessedStatement{PageToken: "not-empty", Statement: userInput}
114114
s.inputController.EXPECT().GetUserInput().Return(userInput)
115115
s.inputController.EXPECT().HasUserEnabledReverseSearch().Return(false)
116116
s.inputController.EXPECT().HasUserInitiatedExit(userInput).Return(false)
@@ -124,6 +124,40 @@ func (s *ApplicationTestSuite) TestReplAppendsStatementToHistoryIfNoErrorAndNotS
124124
require.Equal(s.T(), []string{userInput}, s.history.Data)
125125
}
126126

127+
func (s *ApplicationTestSuite) TestReplAppendsStatementToHistoryWithMaskedInput() {
128+
userInput := "test-input"
129+
maskedInput := "test-input-masked"
130+
statement := types.ProcessedStatement{PageToken: "not-empty", Statement: maskedInput}
131+
s.inputController.EXPECT().GetUserInput().Return(userInput)
132+
s.inputController.EXPECT().HasUserEnabledReverseSearch().Return(false)
133+
s.inputController.EXPECT().HasUserInitiatedExit(userInput).Return(false)
134+
s.statementController.EXPECT().ExecuteStatement(userInput).Return(&statement, nil)
135+
s.resultFetcher.EXPECT().Init(statement)
136+
s.interactiveOutputController.EXPECT().VisualizeResults()
137+
138+
actual := test.RunAndCaptureSTDOUT(s.T(), s.app.readEvalPrint)
139+
140+
require.Empty(s.T(), actual)
141+
require.Equal(s.T(), []string{maskedInput}, s.history.Data)
142+
}
143+
144+
func (s *ApplicationTestSuite) TestReplAppendsStatementToHistoryWithEmptyText() {
145+
userInput := "test-input"
146+
maskedInput := ""
147+
statement := types.ProcessedStatement{PageToken: "not-empty", Statement: maskedInput}
148+
s.inputController.EXPECT().GetUserInput().Return(userInput)
149+
s.inputController.EXPECT().HasUserEnabledReverseSearch().Return(false)
150+
s.inputController.EXPECT().HasUserInitiatedExit(userInput).Return(false)
151+
s.statementController.EXPECT().ExecuteStatement(userInput).Return(&statement, nil)
152+
s.resultFetcher.EXPECT().Init(statement)
153+
s.interactiveOutputController.EXPECT().VisualizeResults()
154+
155+
actual := test.RunAndCaptureSTDOUT(s.T(), s.app.readEvalPrint)
156+
157+
require.Empty(s.T(), actual)
158+
require.Equal(s.T(), []string{}, s.history.Data)
159+
}
160+
127161
func (s *ApplicationTestSuite) TestReplDoesntAppendStatementToHistoryIfError() {
128162
userInput := "test-input"
129163

@@ -138,7 +172,7 @@ func (s *ApplicationTestSuite) TestReplDoesntAppendStatementToHistoryIfError() {
138172
require.Equal(s.T(), []string{}, s.history.Data)
139173
}
140174

141-
func (s *ApplicationTestSuite) TestReplDoesntAppendStatementToHistoryIfSensistiveStatement() {
175+
func (s *ApplicationTestSuite) TestReplDoesntAppendStatementToHistoryIfSensitiveStatement() {
142176
userInput := "test-input"
143177
statement := types.ProcessedStatement{PageToken: "not-empty", IsSensitiveStatement: true}
144178
s.inputController.EXPECT().GetUserInput().Return(userInput)

pkg/flink/internal/store/store_utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func processSetStatement(properties types.UserPropertiesInterface, statement str
5454
return &types.ProcessedStatement{
5555
Kind: config.OpSet,
5656
Status: types.COMPLETED,
57+
Statement: statement,
5758
StatementResults: createStatementResults([]string{"Key", "Value"}, properties.ToSortedSlice(true)),
5859
IsLocalStatement: true,
5960
}, nil
@@ -86,6 +87,7 @@ func processSetStatement(properties types.UserPropertiesInterface, statement str
8687
Kind: config.OpSet,
8788
StatusDetail: "configuration updated successfully",
8889
Status: types.COMPLETED,
90+
Statement: statement,
8991
StatementResults: createStatementResults([]string{"Key", "Value"}, [][]string{{configKey, configVal}}),
9092
IsLocalStatement: true,
9193
IsSensitiveStatement: hasSensitiveKey(configKey),
@@ -103,6 +105,7 @@ func processResetStatement(properties types.UserPropertiesInterface, statement s
103105
Kind: config.OpReset,
104106
StatusDetail: "configuration has been reset successfully",
105107
Status: types.COMPLETED,
108+
Statement: statement,
106109
StatementResults: createStatementResults([]string{"Key", "Value"}, properties.ToSortedSlice(true)),
107110
IsLocalStatement: true,
108111
}, nil
@@ -120,6 +123,7 @@ func processResetStatement(properties types.UserPropertiesInterface, statement s
120123
Kind: config.OpReset,
121124
StatusDetail: fmt.Sprintf(`configuration key "%s" has been reset successfully`, configKey),
122125
Status: types.COMPLETED,
126+
Statement: statement,
123127
StatementResults: createStatementResults([]string{"Key", "Value"}, properties.ToSortedSlice(true)),
124128
IsLocalStatement: true,
125129
}, nil
@@ -167,6 +171,7 @@ func processUseStatement(properties types.UserPropertiesInterface, statement str
167171
Kind: config.OpUse,
168172
StatusDetail: "configuration updated successfully",
169173
Status: types.COMPLETED,
174+
Statement: statement,
170175
StatementResults: createStatementResults([]string{"Key", "Value"}, addedConfig),
171176
IsLocalStatement: true,
172177
}, nil

pkg/flink/internal/store/store_utils_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestProcessSetStatement(t *testing.T) {
5959
assert.EqualValues(t, types.COMPLETED, result.Status)
6060

6161
assert.Equal(t, 2, len(result.StatementResults.Headers))
62+
assert.Equal(t, "set", result.Statement)
6263
assert.Equal(t, len(s.Properties.GetProperties()), len(result.StatementResults.Rows))
6364
cupaloy.SnapshotT(t, result.StatementResults)
6465
})
@@ -67,6 +68,7 @@ func TestProcessSetStatement(t *testing.T) {
6768
result, err := processSetStatement(s.Properties, "set 'location'='USA'")
6869
assert.Nil(t, err)
6970
assert.EqualValues(t, types.COMPLETED, result.Status)
71+
assert.Equal(t, "set 'location'='USA'", result.Statement)
7072
assert.Equal(t, "configuration updated successfully", result.StatusDetail)
7173
cupaloy.SnapshotT(t, result.StatementResults)
7274
})
@@ -77,6 +79,7 @@ func TestProcessSetStatement(t *testing.T) {
7779
assert.EqualValues(t, types.COMPLETED, result.Status)
7880

7981
assert.Equal(t, 2, len(result.StatementResults.Headers))
82+
assert.Equal(t, "set", result.Statement)
8083
assert.Equal(t, len(s.Properties.GetProperties()), len(result.StatementResults.Rows))
8184
cupaloy.SnapshotT(t, result.StatementResults)
8285
})
@@ -155,6 +158,7 @@ func TestProcessResetStatement(t *testing.T) {
155158
assert.EqualValues(t, types.COMPLETED, result.Status)
156159

157160
assert.Equal(t, 2, len(result.StatementResults.Headers))
161+
assert.Equal(t, "set", result.Statement)
158162
assert.Equal(t, len(s.Properties.GetProperties()), len(result.StatementResults.Rows))
159163
cupaloy.SnapshotT(t, result.StatementResults)
160164
})
@@ -170,6 +174,7 @@ func TestProcessResetStatement(t *testing.T) {
170174
result, _ := processResetStatement(s.Properties, "reset")
171175
assert.EqualValues(t, types.COMPLETED, result.Status)
172176
assert.Equal(t, "configuration has been reset successfully", result.StatusDetail)
177+
assert.Equal(t, "reset", result.Statement)
173178
assert.ElementsMatch(t, defaultSetOutput.GetHeaders(), result.StatementResults.GetHeaders())
174179
assert.ElementsMatch(t, defaultSetOutput.GetRows(), result.StatementResults.GetRows())
175180
})
@@ -186,6 +191,7 @@ func TestProcessResetStatement(t *testing.T) {
186191
result, _ := processResetStatement(s.Properties, "reset 'catalog'")
187192
assert.EqualValues(t, types.COMPLETED, result.Status)
188193
assert.Equal(t, `configuration key "catalog" has been reset successfully`, result.StatusDetail)
194+
assert.Equal(t, "reset 'catalog'", result.Statement)
189195
assert.ElementsMatch(t, defaultSetOutput.GetHeaders(), result.StatementResults.GetHeaders())
190196
assert.ElementsMatch(t, defaultSetOutput.GetRows(), result.StatementResults.GetRows())
191197
})
@@ -194,8 +200,9 @@ func TestProcessResetStatement(t *testing.T) {
194200
s.Properties.Set(config.KeyCatalog, "catalog")
195201
s.Properties.Set(config.KeyDatabase, "db")
196202
statement := fmt.Sprintf("reset '%s'", config.KeyCatalog)
197-
_, err := processResetStatement(s.Properties, statement)
203+
result, err := processResetStatement(s.Properties, statement)
198204
assert.Nil(t, err)
205+
assert.Equal(t, statement, result.Statement)
199206
assert.False(t, s.Properties.HasKey(config.KeyCatalog))
200207
assert.False(t, s.Properties.HasKey(config.KeyDatabase))
201208
})
@@ -221,6 +228,7 @@ func TestProcessUseStatement(t *testing.T) {
221228
result, err := processUseStatement(s.Properties, "use db1")
222229
require.Nil(t, err)
223230
require.Equal(t, config.OpUse, result.Kind)
231+
require.Equal(t, "use db1", result.Statement)
224232
require.EqualValues(t, types.COMPLETED, result.Status)
225233
require.Equal(t, "configuration updated successfully", result.StatusDetail)
226234
expectedResult := createStatementResults([]string{"Key", "Value"}, [][]string{{config.KeyDatabase, "db1"}})
@@ -237,6 +245,7 @@ func TestProcessUseStatement(t *testing.T) {
237245
result, err := processUseStatement(s.Properties, "use catalog metadata")
238246
require.Nil(t, err)
239247
require.Equal(t, config.OpUse, result.Kind)
248+
require.Equal(t, "use catalog metadata", result.Statement)
240249
require.EqualValues(t, types.COMPLETED, result.Status)
241250
require.Equal(t, "configuration updated successfully", result.StatusDetail)
242251
expectedResult := createStatementResults([]string{"Key", "Value"}, [][]string{{config.KeyCatalog, "metadata"}})
@@ -248,6 +257,7 @@ func TestProcessUseStatement(t *testing.T) {
248257
result, err := processUseStatement(s.Properties, "USE `my catalog`.`my database`")
249258
require.Nil(t, err)
250259
require.Equal(t, config.OpUse, result.Kind)
260+
require.Equal(t, "USE `my catalog`.`my database`", result.Statement)
251261
require.EqualValues(t, types.COMPLETED, result.Status)
252262
require.Equal(t, "configuration updated successfully", result.StatusDetail)
253263
expectedResult := createStatementResults([]string{"Key", "Value"}, [][]string{

0 commit comments

Comments
 (0)