Skip to content

Commit

Permalink
build(ci): also check for code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
developStorm committed May 22, 2024
1 parent 2b0f0d9 commit 3993fe7
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 66 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ jobs:
with:
go-version: 1.18
- name: Run go fmt
run: go fmt ./...
run: |
NON_COMPLIANT_FILES=$(gofmt -s -l $(find . -type f -name '*.go'| grep -v "/.template/"))
if [ -n "$NON_COMPLIANT_FILES" ]; then
echo "The following files are not formatted correctly:"
echo "$NON_COMPLIANT_FILES"
exit 1
fi
22 changes: 11 additions & 11 deletions input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ example.com
`
port := uint(443)
expected := []ScanTarget{
ScanTarget{IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag"},
ScanTarget{IP: net.ParseIP("10.0.0.1"), Domain: "example.com"},
ScanTarget{IP: net.ParseIP("10.0.0.1")},
ScanTarget{Domain: "example.com"},
ScanTarget{Domain: "example.com"},
ScanTarget{IP: net.ParseIP("2.2.2.0"), Tag: "tag"},
ScanTarget{IP: net.ParseIP("2.2.2.1"), Tag: "tag"},
ScanTarget{IP: net.ParseIP("2.2.2.2"), Tag: "tag"},
ScanTarget{IP: net.ParseIP("2.2.2.3"), Tag: "tag"},
ScanTarget{IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag", Port: &port},
ScanTarget{IP: net.ParseIP("10.0.0.1"), Port: &port},
{IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag"},
{IP: net.ParseIP("10.0.0.1"), Domain: "example.com"},
{IP: net.ParseIP("10.0.0.1")},
{Domain: "example.com"},
{Domain: "example.com"},
{IP: net.ParseIP("2.2.2.0"), Tag: "tag"},
{IP: net.ParseIP("2.2.2.1"), Tag: "tag"},
{IP: net.ParseIP("2.2.2.2"), Tag: "tag"},
{IP: net.ParseIP("2.2.2.3"), Tag: "tag"},
{IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag", Port: &port},
{IP: net.ParseIP("10.0.0.1"), Port: &port},
}

ch := make(chan ScanTarget, 0)
Expand Down
4 changes: 2 additions & 2 deletions lib/output/test/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,14 +1050,14 @@ func TestMySQL(t *testing.T) {
SerialNumber: big.NewInt(2),
Issuer: pkix.Name{
CommonName: "MySQL_Server_8.0.3-rc_Auto_Generated_CA_Certificate",
Names: []pkix.AttributeTypeAndValue{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3},
Names: []pkix.AttributeTypeAndValue{{Type: asn1.ObjectIdentifier{2, 5, 4, 3},
Value: "MySQL_Server_8.0.3-rc_Auto_Generated_CA_Certificate"}},
ExtraNames: []pkix.AttributeTypeAndValue(nil),
OriginalRDNS: pkix.RDNSequence{pkix.RelativeDistinguishedNameSET{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3},
Value: "MySQL_Server_8.0.3-rc_Auto_Generated_CA_Certificate"}}}},
Subject: pkix.Name{
CommonName: "MySQL_Server_8.0.3-rc_Auto_Generated_Server_Certificate",
Names: []pkix.AttributeTypeAndValue{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3},
Names: []pkix.AttributeTypeAndValue{{Type: asn1.ObjectIdentifier{2, 5, 4, 3},
Value: "MySQL_Server_8.0.3-rc_Auto_Generated_Server_Certificate"}},
ExtraNames: []pkix.AttributeTypeAndValue(nil),
OriginalRDNS: pkix.RDNSequence{pkix.RelativeDistinguishedNameSET{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3},
Expand Down
2 changes: 1 addition & 1 deletion lib/smb/smb/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (s *Session) TreeDisconnect(name string) error {

func (s *Session) Close() {
s.Debug("Closing session", nil)
for k, _ := range s.trees {
for k := range s.trees {
s.TreeDisconnect(k)
}
s.Debug("Closing TCP connection", nil)
Expand Down
8 changes: 4 additions & 4 deletions modules/oracle/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (conn *Connection) Connect(connectDescriptor string) (*HandshakeLog, error)
Version: encodeReleaseVersion(conn.scanner.config.ReleaseVersion),
Options: NSNOptions(0),
Services: []NSNService{
NSNService{
{
Type: NSNServiceSupervisor,
Values: []NSNValue{
*NSNValueVersion(conn.scanner.config.ReleaseVersion),
Expand All @@ -259,7 +259,7 @@ func (conn *Connection) Connect(connectDescriptor string) (*HandshakeLog, error)
},
Marker: 0,
},
NSNService{
{
Type: NSNServiceAuthentication,
Values: []NSNValue{
*NSNValueVersion(conn.scanner.config.ReleaseVersion),
Expand All @@ -270,15 +270,15 @@ func (conn *Connection) Connect(connectDescriptor string) (*HandshakeLog, error)
},
Marker: 0,
},
NSNService{
{
Type: NSNServiceEncryption,
Values: []NSNValue{
*NSNValueVersion(conn.scanner.config.ReleaseVersion),
*NSNValueBytes(encryptionBytes),
},
Marker: 0,
},
NSNService{
{
Type: NSNServiceDataIntegrity,
Values: []NSNValue{
*NSNValueVersion(conn.scanner.config.ReleaseVersion),
Expand Down
82 changes: 41 additions & 41 deletions modules/oracle/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func fromHex(h string) []byte {
}

var validHeaders = map[string]TNSHeader{
"00 08 00 01 02 03 00 45": TNSHeader{
"00 08 00 01 02 03 00 45": {
Length: 8,
PacketChecksum: 1,
Type: 2,
Flags: 3,
HeaderChecksum: 0x45,
},
"f2 1e 01 00 07 06 76 54": TNSHeader{
"f2 1e 01 00 07 06 76 54": {
Length: 0xF21E,
PacketChecksum: 0x0100,
Type: 0x07,
Expand All @@ -95,7 +95,7 @@ func orPanic(ret []byte, err error) []byte {
}

var validTNSData = map[string]TestCase{
"00.empty": TestCase{
"00.empty": {
Encoding: "00 0A 00 00 06 00 00 00 80 00",
Value: &TNSPacket{
Header: &TNSHeader{
Expand All @@ -111,7 +111,7 @@ var validTNSData = map[string]TestCase{
},
},
},
"00.trivial": TestCase{
"00.trivial": {
Encoding: "00 10 00 00 06 00 00 00 00 01 31 32 33 34 35 36",
Value: &TNSPacket{
Header: &TNSHeader{
Expand All @@ -127,7 +127,7 @@ var validTNSData = map[string]TestCase{
},
},
},
"01.NSN.Request": TestCase{
"01.NSN.Request": {
Encoding: "00 a8 00 00 06 00 00 00 00 00 de ad be ef 00 9e " + /* ................ */
"0a 20 03 00 00 04 00 00 04 00 03 00 00 00 00 00 " + /* . .............. */
"04 00 05 0a 20 03 00 00 08 00 01 00 00 04 ec 19 " + /* .... ........... */
Expand All @@ -154,7 +154,7 @@ var validTNSData = map[string]TestCase{
Version: encodeReleaseVersion("10.2.0.3.0"),
Options: NSNOptions(0),
Services: []NSNService{
NSNService{
{
Type: 4,
Values: []NSNValue{
*NSNValueVersion("10.2.0.3.0"),
Expand All @@ -163,45 +163,45 @@ var validTNSData = map[string]TestCase{
},
Marker: 0,
},
NSNService{
{
Type: 1,
Values: []NSNValue{
*NSNValueVersion("10.2.0.3.0"),
NSNValue{
{
Type: 3,
Value: fromHex("e0 e1"),
},
NSNValue{
{
Type: 6,
Value: fromHex("fc ff"),
},
NSNValue{
{
Type: 2,
Value: fromHex("01"),
},
NSNValue{
{
Type: 0,
Value: []byte("NTS"),
},
},
Marker: 0,
},
NSNService{
{
Type: 2,
Values: []NSNValue{
*NSNValueVersion("10.2.0.3.0"),
NSNValue{
{
Type: 1,
Value: fromHex("00 11 06 10 0c 0f 0a 0b 08 02 01 03"),
},
},
Marker: 0,
},
NSNService{
{
Type: 3,
Values: []NSNValue{
*NSNValueVersion("10.2.0.3.0"),
NSNValue{
{
Type: 1,
Value: fromHex("00 03 01"),
},
Expand All @@ -215,7 +215,7 @@ var validTNSData = map[string]TestCase{
}

var validTNSConnect = map[string]TestCase{
"01. 013A-0139": TestCase{
"01. 013A-0139": {
Encoding: "00 ca 00 00 01 00 00 00 01 3a 01 2c 0c 41 20 00 " + /* .........:.,.A . */
"ff ff 7f 08 00 00 01 00 00 90 00 3a 00 00 08 00 " + /* ...........:.... */
"41 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + /* AA.............. */
Expand Down Expand Up @@ -254,7 +254,7 @@ var validTNSConnect = map[string]TestCase{
},
},
},
"02. 138-138": TestCase{
"02. 138-138": {
Encoding: "01 00 00 00 01 04 00 00 01 38 01 2c 00 00 08 00 " + /* .........8.,.... */
"7f ff 86 0e 00 00 01 00 00 c6 00 3a 00 00 02 00 " + /* ...........:.... */
"61 61 00 00 00 00 00 00 00 00 00 00 04 10 00 00 " + /* aa.............. */
Expand Down Expand Up @@ -296,7 +296,7 @@ var validTNSConnect = map[string]TestCase{
},
},
},
"03. 138-138": TestCase{
"03. 138-138": {
Encoding: "00 ec 00 00 01 04 00 00 01 38 01 2c 00 00 08 00 " + /* .........8.,.... */
"7f ff 86 0e 00 00 01 00 00 b2 00 3a 00 00 02 00 " + /* ...........:.... */
"61 61 00 00 00 00 00 00 00 00 00 00 10 ec 00 00 " + /* aa.............. */
Expand Down Expand Up @@ -337,7 +337,7 @@ var validTNSConnect = map[string]TestCase{
},
},
},
"unknown": TestCase{
"unknown": {
Encoding: "00 d7 00 00 01 00 00 00 01 3b 01 2c 0c 41 20 00 " + /* .........;.,.A . */
"ff ff 7f 08 00 00 01 00 00 91 00 46 00 00 08 00 " + /* ...........F.... */
"41 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + /* AA.............. */
Expand Down Expand Up @@ -377,7 +377,7 @@ var validTNSConnect = map[string]TestCase{
},
},
},
"unknown3a": TestCase{
"unknown3a": {
Encoding: "00 d7 00 00 01 00 00 00 01 3b 01 2c 0c 41 20 00 " + /* .........;.,.A . */
"ff ff 7f 08 00 00 01 00 00 91 00 46 00 00 08 00 " + /* ...........F.... */
"41 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + /* AA.............. */
Expand Down Expand Up @@ -420,7 +420,7 @@ var validTNSConnect = map[string]TestCase{
}

var validTNSAccept = map[string]TestCase{
"01. 013A-0139": TestCase{
"01. 013A-0139": {
Encoding: "00 20 00 00 02 00 00 00 01 39 00 00 08 00 7f ff " + /* . .......9...... */
"01 00 00 00 00 20 61 61 00 00 00 00 00 00 00 00 ", /* ..... aa........ */
Value: &TNSPacket{
Expand Down Expand Up @@ -587,7 +587,7 @@ func TestTNSData(t *testing.T) {

var descriptorValues = map[string]Descriptor{
//"()": Descriptor{},
"(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))(ERROR=(CODE=303)(EMFI=1))))": Descriptor{
"(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))(ERROR=(CODE=303)(EMFI=1))))": {
DescriptorEntry{"DESCRIPTION.ERR", "1153"},
DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"},
Expand All @@ -596,7 +596,7 @@ var descriptorValues = map[string]Descriptor{
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "303"},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"},
},
"(DESCRIPTION=\n\t(ERR=1153)\n\t(VSNNUM=186647040)\n\t(ERROR_STACK=\n\t\t(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\n\t\t(ERROR=(CODE=303)(EMFI=1))\n\t)\n)\n": Descriptor{
"(DESCRIPTION=\n\t(ERR=1153)\n\t(VSNNUM=186647040)\n\t(ERROR_STACK=\n\t\t(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\n\t\t(ERROR=(CODE=303)(EMFI=1))\n\t)\n)\n": {
DescriptorEntry{"DESCRIPTION.ERR", "1153"},
DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"},
Expand All @@ -605,7 +605,7 @@ var descriptorValues = map[string]Descriptor{
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "303"},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"},
},
" (DESCRIPTION=\r\n (ERR=1153)\r\n (VSNNUM=186647040)\r\n (ERROR_STACK=\r\n (ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\r\n (ERROR=(CODE=303)(EMFI=1))\r\n )\r\n) ": Descriptor{
" (DESCRIPTION=\r\n (ERR=1153)\r\n (VSNNUM=186647040)\r\n (ERROR_STACK=\r\n (ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\r\n (ERROR=(CODE=303)(EMFI=1))\r\n )\r\n) ": {
DescriptorEntry{"DESCRIPTION.ERR", "1153"},
DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"},
Expand All @@ -614,7 +614,7 @@ var descriptorValues = map[string]Descriptor{
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "303"},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"},
},
"(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='(embedded \\'quotes\\')'))(ERROR=(CODE= \" (23) \" )(EMFI=1))))": Descriptor{
"(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='(embedded \\'quotes\\')'))(ERROR=(CODE= \" (23) \" )(EMFI=1))))": {
DescriptorEntry{"DESCRIPTION.ERR", "1153"},
DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"},
Expand All @@ -623,7 +623,7 @@ var descriptorValues = map[string]Descriptor{
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "\" (23) \""},
DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"},
},
"(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=)(CID=(PROGRAM=C:\\Users\\localadmin\\work\\oracle\\instantclient_11_2\\sqlplus.exe)(HOST=win10pc)(USER=localadmin)))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))": Descriptor{
"(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=)(CID=(PROGRAM=C:\\Users\\localadmin\\work\\oracle\\instantclient_11_2\\sqlplus.exe)(HOST=win10pc)(USER=localadmin)))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))": {
DescriptorEntry{"DESCRIPTION.CONNECT_DATA.SERVICE_NAME", ""},
DescriptorEntry{"DESCRIPTION.CONNECT_DATA.CID.PROGRAM", "C:\\Users\\localadmin\\work\\oracle\\instantclient_11_2\\sqlplus.exe"},
DescriptorEntry{"DESCRIPTION.CONNECT_DATA.CID.HOST", "win10pc"},
Expand All @@ -635,20 +635,20 @@ var descriptorValues = map[string]Descriptor{
}

var descriptorGetValuesTests = map[string]map[string][]string{
"(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": map[string][]string{
"A.B.C": []string{"ABC1", "ABC2"},
"A.B.D": []string{"ABD"},
"A.E": []string{"AE"},
"does.not.exist": []string{},
"A.F": []string{""},
"(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": {
"A.B.C": {"ABC1", "ABC2"},
"A.B.D": {"ABD"},
"A.E": {"AE"},
"does.not.exist": {},
"A.F": {""},
},
"(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=iii)(I=)(I=))": map[string][]string{
"A.B.C": []string{"ABC1", "ABC2"},
"A.B.D": []string{"ABD1", "ABD2", "ABD3"},
"A.B.E": []string{"ABE"},
"A.F.G.H": []string{"AFGH"},
"does.not.exist": []string{},
"A.I": []string{"", "iii", "", ""},
"(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=iii)(I=)(I=))": {
"A.B.C": {"ABC1", "ABC2"},
"A.B.D": {"ABD1", "ABD2", "ABD3"},
"A.B.E": {"ABE"},
"A.F.G.H": {"AFGH"},
"does.not.exist": {},
"A.I": {"", "iii", "", ""},
},
}

Expand All @@ -673,14 +673,14 @@ type GetValueTestResult struct {
}

var descriptorGetValueTests = map[string]map[string]GetValueTestResult{
"(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": map[string]GetValueTestResult{
"(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": {
"A.B.C": {Value: "", Error: ErrUnexpectedResponse},
"A.B.D": {Value: "ABD", Error: nil},
"A.E": {Value: "AE", Error: nil},
"does.not.exist": {Value: "", Error: ErrUnexpectedResponse},
"A.F": {Value: "", Error: nil},
},
"(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=))": map[string]GetValueTestResult{
"(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=))": {
"A.B.C": {Value: "", Error: ErrUnexpectedResponse},
"A.B.D": {Value: "", Error: ErrUnexpectedResponse},
"A.B.E": {Value: "ABE", Error: nil},
Expand Down
4 changes: 2 additions & 2 deletions modules/postgres/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ func (m *connectionManager) closeConnection(c io.Closer) {
func (m *connectionManager) cleanUp() {
// first in, last out: empty out the map
defer func() {
for conn, _ := range m.connections {
for conn := range m.connections {
delete(m.connections, conn)
}
}()
for connection, _ := range m.connections {
for connection := range m.connections {
// Close them all even if there is a panic with one
defer func(c io.Closer) {
m.closeConnection(c)
Expand Down
8 changes: 4 additions & 4 deletions modules/redis/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ var redisErrorMessages = map[string]string{

// redisArrays maps encoded array values to the corresponding array (Note: reverse key/value order from other maps)
var redisArrays = map[string]RedisArray{
"*0\r\n": RedisArray{},
"*1\r\n+\r\n": RedisArray{SimpleString("")},
"*2\r\n*1\r\n*0\r\n*1\r\n$5\r\n12345\r\n": RedisArray{RedisArray{RedisArray{}}, RedisArray{BulkString("12345")}},
"*0\r\n": {},
"*1\r\n+\r\n": {SimpleString("")},
"*2\r\n*1\r\n*0\r\n*1\r\n$5\r\n12345\r\n": {RedisArray{RedisArray{}}, RedisArray{BulkString("12345")}},
"*5\r\n" +
"+simpleString\r\n" +
"-ERR error message\r\n" +
":12345\r\n" +
"$47\r\n*5\r\n+simpleString\r\n-ERR error message\r\n:12345\r\n\r\n" +
"*0\r\n": RedisArray{
"*0\r\n": {
SimpleString("simpleString"),
ErrorMessage("ERR error message"),
Integer(12345),
Expand Down

0 comments on commit 3993fe7

Please sign in to comment.