Skip to content

Commit

Permalink
Merge pull request #2163 from actiontech/issue1272-ci
Browse files Browse the repository at this point in the history
ci: modify bad words
  • Loading branch information
taolx0 authored Dec 18, 2023
2 parents 56859d3 + 08cf85c commit b725499
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
5 changes: 3 additions & 2 deletions sqle/api/controller/v1/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func filterSQLsByBlackList(sqls []*AuditPlanSQLReqV1, blackList []*model.BlackLi
filteredSQLs := []*AuditPlanSQLReqV1{}
filter := ConvertToBlackFilter(blackList)
for _, sql := range sqls {
if filter.IsEndpointInBlackList([]string{sql.Endpoint}) || filter.IsSqlInBlackList(sql.LastReceiveText) {
if filter.HasEndpointInBlackList([]string{sql.Endpoint}) || filter.IsSqlInBlackList(sql.LastReceiveText) {
continue
}
filteredSQLs = append(filteredSQLs, sql)
Expand Down Expand Up @@ -852,7 +852,8 @@ func (f BlackFilter) IsSqlInBlackList(checkSql string) bool {
return false
}

func (f BlackFilter) IsEndpointInBlackList(checkIps []string) bool {
// 输入一组ip若其中有一个ip在黑名单中则返回true
func (f BlackFilter) HasEndpointInBlackList(checkIps []string) bool {
var checkNetIp net.IP
for _, checkIp := range checkIps {
checkNetIp = net.ParseIP(checkIp)
Expand Down
54 changes: 33 additions & 21 deletions sqle/api/controller/v1/audit_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,21 @@ func TestIsIpInBlackList(t *testing.T) {
"10.0.5.67",
"192.168.1.23",
}

if !filter.IsEndpointInBlackList(matchIps) {
t.Error("Expected Ip to match blacklist")
for _, matchIp := range matchIps {
if !filter.HasEndpointInBlackList([]string{matchIp}) {
t.Error("Expected Ip to match blacklist")
}
}

notMatchIps := []string{
"172.16.254.89",
"134.12.45.78",
"50.67.89.12",
}
if filter.IsEndpointInBlackList(notMatchIps) {
t.Error("Did not expect Ip to match blacklist")
for _, notMatchIp := range notMatchIps {
if filter.HasEndpointInBlackList([]string{notMatchIp}) {
t.Error("Did not expect Ip to match blacklist")
}
}
}

Expand All @@ -84,28 +87,33 @@ func TestIsCidrInBlackList(t *testing.T) {
matchIps := []string{
"10.100.1.2",
"10.100.25.45",
"172.30.1.2",
"172.30.30.45",
"192.168.0.2",
"192.168.0.45",
}

if !filter.IsEndpointInBlackList(matchIps) {
t.Error("Expected CIDR to match blacklist")
for _, matchIp := range matchIps {
if !filter.HasEndpointInBlackList([]string{matchIp}) {
t.Error("Expected CIDR to match blacklist")
}
}

notMatchIps := []string{
"172.16.254.89",
"134.12.45.78",
"50.67.89.12",
"172.30.1.2",
"172.30.30.45",
}
if filter.IsEndpointInBlackList(notMatchIps) {
t.Error("Did not expect CIDR to match blacklist")
for _, notMatchIp := range notMatchIps {
if filter.HasEndpointInBlackList([]string{notMatchIp}) {
t.Error("Did not expect CIDR to match blacklist")
}
}
}

func TestIsHostInBlackList(t *testing.T) {
filter := v1.ConvertToBlackFilter([]*model.BlackListAuditPlanSQL{
{
FilterContent: "test",
FilterContent: "host",
FilterType: "HOST",
}, {
FilterContent: "some_site",
Expand All @@ -114,22 +122,26 @@ func TestIsHostInBlackList(t *testing.T) {
})

matchHosts := []string{
"localtest",
"localtest.com",
"anyTest.io",
"some-Site.org/home/",
"local_host",
"local_Host.com",
"any_Host.io",
"some_Site.org/home/",
"Some_site.cn/mysql",
}

if !filter.IsEndpointInBlackList(matchHosts) {
t.Error("Expected HOST to match blacklist")
for _, matchHost := range matchHosts {
if !filter.HasEndpointInBlackList([]string{matchHost}) {
t.Error("Expected HOST to match blacklist")
}
}

notMatchHosts := []string{
"other_site/home",
"any_other_site/local",
}
if filter.IsEndpointInBlackList(notMatchHosts) {
t.Error("Did not expect HOST to match blacklist")
for _, noMatchHost := range notMatchHosts {
if filter.HasEndpointInBlackList([]string{noMatchHost}) {
t.Error("Did not expect HOST to match blacklist")
}
}
}
2 changes: 1 addition & 1 deletion sqle/api/controller/v2/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func filterSQLsByBlackList(sqls []*AuditPlanSQLReqV2, blackList []*model.BlackLi
filteredSQLs := []*AuditPlanSQLReqV2{}
filter := v1.ConvertToBlackFilter(blackList)
for _, sql := range sqls {
if filter.IsEndpointInBlackList(sql.Endpoints) || filter.IsSqlInBlackList(sql.LastReceiveText) {
if filter.HasEndpointInBlackList(sql.Endpoints) || filter.IsSqlInBlackList(sql.LastReceiveText) {
continue
}
filteredSQLs = append(filteredSQLs, sql)
Expand Down

0 comments on commit b725499

Please sign in to comment.