Skip to content

Commit 696ffc2

Browse files
committed
fix: correct t.Assert call in Test_Model_Fields_Empty
Replace t.Assert(len(result) <= 1) with t.AssertLE(len(result), 1). t.Assert requires two arguments (actual, expected) but was given a boolean expression.
1 parent 03e53e2 commit 696ffc2

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

contrib/drivers/mysql/mysql_z_unit_feature_error_handling_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func Test_Model_Fields_Empty(t *testing.T) {
184184
gtest.C(t, func(t *gtest.T) {
185185
result, err := db.Model(table).Fields("").Limit(1).All()
186186
t.AssertNil(err)
187-
t.Assert(len(result) <= 1)
187+
t.AssertLE(len(result), 1)
188188
})
189189
}
190190

@@ -200,8 +200,8 @@ func Test_Model_Order_InvalidSyntax(t *testing.T) {
200200
})
201201
}
202202

203-
// Test_Model_Group_InvalidSyntax tests Group with invalid syntax
204-
func Test_Model_Group_InvalidSyntax(t *testing.T) {
203+
// Test_Model_Group_UnknownColumn tests Group with non-existent column
204+
func Test_Model_Group_UnknownColumn(t *testing.T) {
205205
table := createInitTable()
206206
defer dropTable(table)
207207

@@ -234,9 +234,11 @@ func Test_Model_SQLInjection_Where(t *testing.T) {
234234
defer dropTable(table)
235235

236236
gtest.C(t, func(t *gtest.T) {
237-
// Attempt SQL injection through parameter
237+
// Attempt SQL injection through string column parameter.
238+
// Using string column `nickname` instead of int column `id`,
239+
// because MySQL coerces "1 OR 1=1" to 1 for int columns.
238240
maliciousInput := "1 OR 1=1"
239-
result, err := db.Model(table).Where("id = ?", maliciousInput).All()
241+
result, err := db.Model(table).Where("nickname = ?", maliciousInput).All()
240242
t.AssertNil(err)
241243
t.Assert(len(result), 0) // Should not return all records
242244
})

0 commit comments

Comments
 (0)