Skip to content

Commit

Permalink
Merge pull request #1840 from actiontech/fix-issue1783-6
Browse files Browse the repository at this point in the history
Fix issue1783 6
  • Loading branch information
taolx0 authored Sep 15, 2023
2 parents d374245 + 156a73d commit 4b3d581
Show file tree
Hide file tree
Showing 3 changed files with 490 additions and 9 deletions.
219 changes: 219 additions & 0 deletions sqle/driver/mysql/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6096,3 +6096,222 @@ func TestDMLCheckScanRows(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"rows", "type"}).AddRow("100000000", "range"))
runSingleRuleInspectCase(rule, t, "", inspect11, "delete from exist_tb_2 where v1=1", newTestResult())
}

func TestDMLCheckJoinFieldUseIndex(t *testing.T) {
rule := rulepkg.RuleHandlerMap[rulepkg.DMLCheckJoinFieldUseIndex].Rule

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_3 on exist_tb_2.v1=exist_tb_3.v2`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldUseIndex),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_1 left join exist_tb_2 on exist_tb_1.v1=exist_tb_2.user_id`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`select * from exist_tb_1 t1 left join exist_tb_2 t2 on t1.id = t2.id left join exist_tb_3 t3
on t3.v2 = t2.id where exist_tb_2.v2 = 'v1'`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldUseIndex),
)

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`select * from exist_tb_1 t1 left join exist_tb_2 t2 on t1.id = id`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`update exist_tb_1 t1 left join exist_tb_2 t2 on t1.id = t2.id
set t1.id = 1
where t2.id = 2;`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`update exist_tb_1 t1 left join exist_tb_2 t2 on t1.id = t2.id left join exist_tb_3 t3 on t2.id=t3.id
set t1.id = 1
where t2.id = 2;`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldUseIndex),
)

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`update exist_tb_1 t1 left join exist_tb_2 t2 on t1.id = t2.v2
set t1.id = 1
where t2.id = 2;`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldUseIndex),
)

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`delete exist_tb_1 , exist_tb_2 , exist_tb_3 from exist_tb_1 t1 left join exist_tb_2 t2 on t1.id = t2.id where t2.v2 = 'v1'`,
newTestResult())

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`delete exist_tb_1 , exist_tb_2 , exist_tb_3 from exist_tb_1 t1 left join exist_tb_2 t2 on t1.id = t2.v2 where t2.v2 = 'v1'`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldUseIndex))
}

func TestDMLCheckJoinFieldCharacterSetAndCollation(t *testing.T) {
rule := rulepkg.RuleHandlerMap[rulepkg.DMLCheckJoinFieldCharacterSetAndCollation].Rule

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_7 on exist_tb_2.v1=exist_tb_7.v3`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_7 on exist_tb_2.v1=exist_tb_7.v1`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldCharacterSetAndCollation),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_7 on exist_tb_2.v1=exist_tb_7.v2`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldCharacterSetAndCollation),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_7 on exist_tb_2.id=exist_tb_7.id`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_7 on exist_tb_2.id=exist_tb_7.v1`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_8 on exist_tb_2.v1=exist_tb_8.v3`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldCharacterSetAndCollation),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_8 on exist_tb_2.v1=exist_tb_8.v2`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`select * from exist_tb_2 left join exist_tb_8 on exist_tb_2.v1=exist_tb_8.v1`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldCharacterSetAndCollation),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`update exist_tb_2 left join exist_tb_7 on exist_tb_2.v1=exist_tb_7.v3 set exist_tb_2.id=1 where exist_tb_2.v1='1'`,
newTestResult(),
)

runSingleRuleInspectCase(
rule,
t,
"success",
DefaultMysqlInspect(),
`update exist_tb_2 left join exist_tb_7 on exist_tb_2.v1=exist_tb_7.v1 set exist_tb_2.id=1 where exist_tb_2.v1='1'`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldCharacterSetAndCollation),
)

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`delete exist_tb_1 , exist_tb_7 from exist_tb_1 t1 left join exist_tb_7 t7 on t1.id = t7.id where t1.v2 = 'v1'`,
newTestResult())

runSingleRuleInspectCase(
rule,
t,
"",
DefaultMysqlInspect(),
`delete exist_tb_1 , exist_tb_7 from exist_tb_1 t1 left join exist_tb_7 t7 on t1.v1=t7.v1 where t1.v2 = 'v1'`,
newTestResult().addResult(rulepkg.DMLCheckJoinFieldCharacterSetAndCollation))

}
Loading

0 comments on commit 4b3d581

Please sign in to comment.