1
- package v1_test
1
+ package auditplan
2
2
3
3
import (
4
4
"testing"
5
5
6
- v1 "github.com/actiontech/sqle/sqle/api/controller/v1"
7
6
"github.com/actiontech/sqle/sqle/model"
8
7
)
9
8
10
9
func TestIsSqlInBlackList (t * testing.T ) {
11
- filter := v1 . ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
10
+ filter := ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
12
11
{
13
12
FilterContent : "SELECT" ,
14
- FilterType : "SQL " ,
13
+ FilterType : "sql " ,
15
14
}, {
16
15
FilterContent : "table_1" ,
17
- FilterType : "SQL " ,
18
- },{
16
+ FilterType : "sql " ,
17
+ }, {
19
18
FilterContent : "ignored_service" ,
20
- FilterType : "SQL " ,
19
+ FilterType : "sql " ,
21
20
},
22
21
})
23
22
@@ -30,7 +29,7 @@ func TestIsSqlInBlackList(t *testing.T) {
30
29
`/* this is a comment, Service: ignored_service */ update * from table_ignored where id < 123;` ,
31
30
}
32
31
for _ , matchSql := range matchSqls {
33
- if ! filter .IsSqlInBlackList (matchSql ) {
32
+ if _ , isSqlInBlackList := filter .IsSqlInBlackList (matchSql ); ! isSqlInBlackList {
34
33
t .Error ("Expected SQL to match blacklist" )
35
34
}
36
35
}
@@ -42,20 +41,20 @@ func TestIsSqlInBlackList(t *testing.T) {
42
41
service */ update * from table_ignored where id < 123;` ,
43
42
}
44
43
for _ , notMatchSql := range notMatchSqls {
45
- if filter .IsSqlInBlackList (notMatchSql ) {
44
+ if _ , isSqlInBlackList := filter .IsSqlInBlackList (notMatchSql ); isSqlInBlackList {
46
45
t .Error ("Did not expect SQL to match blacklist" )
47
46
}
48
47
}
49
48
}
50
49
51
50
func TestIsIpInBlackList (t * testing.T ) {
52
- filter := v1 . ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
51
+ filter := ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
53
52
{
54
53
FilterContent : "192.168.1.23" ,
55
- FilterType : "IP " ,
54
+ FilterType : "ip " ,
56
55
}, {
57
56
FilterContent : "10.0.5.67" ,
58
- FilterType : "IP " ,
57
+ FilterType : "ip " ,
59
58
},
60
59
})
61
60
@@ -64,7 +63,7 @@ func TestIsIpInBlackList(t *testing.T) {
64
63
"192.168.1.23" ,
65
64
}
66
65
for _ , matchIp := range matchIps {
67
- if ! filter .HasEndpointInBlackList ([]string {matchIp }) {
66
+ if _ , hasEndpointInBlackList := filter .HasEndpointInBlackList ([]string {matchIp }); ! hasEndpointInBlackList {
68
67
t .Error ("Expected Ip to match blacklist" )
69
68
}
70
69
}
@@ -75,20 +74,20 @@ func TestIsIpInBlackList(t *testing.T) {
75
74
"50.67.89.12" ,
76
75
}
77
76
for _ , notMatchIp := range notMatchIps {
78
- if filter .HasEndpointInBlackList ([]string {notMatchIp }) {
77
+ if _ , hasEndpointInBlackList := filter .HasEndpointInBlackList ([]string {notMatchIp }); hasEndpointInBlackList {
79
78
t .Error ("Did not expect Ip to match blacklist" )
80
79
}
81
80
}
82
81
}
83
82
84
83
func TestIsCidrInBlackList (t * testing.T ) {
85
- filter := v1 . ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
84
+ filter := ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
86
85
{
87
86
FilterContent : "192.168.0.0/24" ,
88
- FilterType : "CIDR " ,
87
+ FilterType : "cidr " ,
89
88
}, {
90
89
FilterContent : "10.100.0.0/16" ,
91
- FilterType : "CIDR " ,
90
+ FilterType : "cidr " ,
92
91
},
93
92
})
94
93
@@ -99,7 +98,7 @@ func TestIsCidrInBlackList(t *testing.T) {
99
98
"192.168.0.45" ,
100
99
}
101
100
for _ , matchIp := range matchIps {
102
- if ! filter .HasEndpointInBlackList ([]string {matchIp }) {
101
+ if _ , hasEndpointInBlackList := filter .HasEndpointInBlackList ([]string {matchIp }); ! hasEndpointInBlackList {
103
102
t .Error ("Expected CIDR to match blacklist" )
104
103
}
105
104
}
@@ -112,20 +111,20 @@ func TestIsCidrInBlackList(t *testing.T) {
112
111
"172.30.30.45" ,
113
112
}
114
113
for _ , notMatchIp := range notMatchIps {
115
- if filter .HasEndpointInBlackList ([]string {notMatchIp }) {
114
+ if _ , hasEndpointInBlackList := filter .HasEndpointInBlackList ([]string {notMatchIp }); hasEndpointInBlackList {
116
115
t .Error ("Did not expect CIDR to match blacklist" )
117
116
}
118
117
}
119
118
}
120
119
121
120
func TestIsHostInBlackList (t * testing.T ) {
122
- filter := v1 . ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
121
+ filter := ConvertToBlackFilter ([]* model.BlackListAuditPlanSQL {
123
122
{
124
123
FilterContent : "host" ,
125
- FilterType : "HOST " ,
124
+ FilterType : "host " ,
126
125
}, {
127
126
FilterContent : "some_site" ,
128
- FilterType : "HOST " ,
127
+ FilterType : "host " ,
129
128
},
130
129
})
131
130
@@ -138,7 +137,7 @@ func TestIsHostInBlackList(t *testing.T) {
138
137
}
139
138
140
139
for _ , matchHost := range matchHosts {
141
- if ! filter .HasEndpointInBlackList ([]string {matchHost }) {
140
+ if _ , hasEndpointInBlackList := filter .HasEndpointInBlackList ([]string {matchHost }); ! hasEndpointInBlackList {
142
141
t .Error ("Expected HOST to match blacklist" )
143
142
}
144
143
}
@@ -148,7 +147,7 @@ func TestIsHostInBlackList(t *testing.T) {
148
147
"any_other_site/local" ,
149
148
}
150
149
for _ , noMatchHost := range notMatchHosts {
151
- if filter .HasEndpointInBlackList ([]string {noMatchHost }) {
150
+ if _ , hasEndpointInBlackList := filter .HasEndpointInBlackList ([]string {noMatchHost }); hasEndpointInBlackList {
152
151
t .Error ("Did not expect HOST to match blacklist" )
153
152
}
154
153
}
0 commit comments