Skip to content

Commit 0c43437

Browse files
Merge pull request #229 from projectdiscovery/dependabot/go_modules/dev/github.com/projectdiscovery/mapcidr-1.1.16
2 parents e34df20 + 1ca40c5 commit 0c43437

File tree

5 files changed

+45
-36
lines changed

5 files changed

+45
-36
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/projectdiscovery/goflags v0.1.28
77
github.com/projectdiscovery/gologger v1.1.11
88
github.com/projectdiscovery/hmap v0.0.26
9-
github.com/projectdiscovery/mapcidr v1.1.15
9+
github.com/projectdiscovery/mapcidr v1.1.16
1010
github.com/projectdiscovery/retryabledns v1.0.43
1111
github.com/stretchr/testify v1.8.4
1212
golang.org/x/net v0.17.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ github.com/projectdiscovery/gologger v1.1.11 h1:8vsz9oJlDT9euw6xlj7F7dZ6RWItVIqV
136136
github.com/projectdiscovery/gologger v1.1.11/go.mod h1:UR2bgXl7zraOxYGnUwuO917hifWrwMJ0feKnVqMQkzY=
137137
github.com/projectdiscovery/hmap v0.0.26 h1:tjGViKL175CABIa5XaYvyeI0ByYaNxebZZSk8yNJw1k=
138138
github.com/projectdiscovery/hmap v0.0.26/go.mod h1:fCDaE8LWdoWDq9VjW7eW8CFCh14oLtviL6OgxI7T6r4=
139-
github.com/projectdiscovery/mapcidr v1.1.15 h1:rYAgxLvMyxPU0JunE/Y3uSK1n/TcNJHK839d6YM0ms4=
140-
github.com/projectdiscovery/mapcidr v1.1.15/go.mod h1:s9erRsoZqWcLGhJW+WT1SnbscqzhHRRnSX916xBw5ZM=
139+
github.com/projectdiscovery/mapcidr v1.1.16 h1:rjj1w5D6hbTsUQXYClLcGdfBEy9bryclgi70t0vBggo=
140+
github.com/projectdiscovery/mapcidr v1.1.16/go.mod h1:rGqpBhStdwOQ2uS62QM9qPsybwMwIhT7CTd2bxoHs8Q=
141141
github.com/projectdiscovery/retryabledns v1.0.43 h1:QQPwb1J7NvjAjyXueKS/ZmoAqofDWF3qS9zIRhFMgmg=
142142
github.com/projectdiscovery/retryabledns v1.0.43/go.mod h1:ZKe4nKyrmZhoxEOL5DLaqqNP7QN9lqeu15sfBigxmqU=
143143
github.com/projectdiscovery/utils v0.0.64 h1:umTmYC9srbLgtJcMbHK+I77oT2MjrW6SjCt7P/F9puA=

libs/client_test.go

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,43 @@ func TestGetASNFromOrg(t *testing.T) {
100100
require.Nil(t, err)
101101

102102
tt := []struct {
103-
name string
104-
org string
105-
result []*Response
103+
name string
104+
org string
105+
err bool
106+
expected []*Response
106107
}{
107-
{"not found", "RANDOM_TEXT", []*Response{}},
108-
{"regex match", "PPLINKNET*", []*Response{
109-
{
110-
FirstIp: "45.239.52.0",
111-
LastIp: "45.239.55.255",
112-
Input: "PPLINKNET",
113-
ASN: 268353,
114-
Country: "BR",
115-
Org: "PPLINKNET SERVICOS DE COMUNICACAO LTDA - ME"},
116-
{
117-
FirstIp: "2804:4fd8::",
118-
LastIp: "2804:4fd8:ffff:ffff:ffff:ffff:ffff:ffff",
119-
Input: "PPLINKNET",
120-
ASN: 268353,
121-
Country: "BR",
122-
Org: "PPLINKNET SERVICOS DE COMUNICACAO LTDA - ME"},
123-
}},
124-
{"exact match", "PPLINKNET", []*Response{}},
108+
{"not found", "RANDOM_TEXT", true, []*Response{}},
109+
// Todo: excluding - ref: https://github.com/projectdiscovery/asnmap-server/issues/43
110+
// {"regex match", "PPLINKNET*", false, []*Response{
111+
// {
112+
// FirstIp: "45.239.52.0",
113+
// LastIp: "45.239.55.255",
114+
// Input: "PPLINKNET",
115+
// ASN: 268353,
116+
// Country: "BR",
117+
// Org: "PPLINKNET SERVICOS DE COMUNICACAO LTDA - ME"},
118+
// {
119+
// FirstIp: "2804:4fd8::",
120+
// LastIp: "2804:4fd8:ffff:ffff:ffff:ffff:ffff:ffff",
121+
// Input: "PPLINKNET",
122+
// ASN: 268353,
123+
// Country: "BR",
124+
// Org: "PPLINKNET SERVICOS DE COMUNICACAO LTDA - ME"},
125+
// }},
126+
{"exact match", "PPLINKNET", false, []*Response{}},
125127
}
126128

127129
for _, tc := range tt {
128130
t.Run(tc.name, func(t *testing.T) {
129131
i, err := client.GetData(tc.org)
130-
require.Nil(t, err)
132+
if tc.err {
133+
require.NotNil(t, err)
134+
return
135+
} else {
136+
require.Nil(t, err)
137+
}
131138
// // Expecting true from comparision
132-
for _, result := range tc.result {
139+
for _, result := range tc.expected {
133140
x := compareResponse(i, result)
134141
require.True(t, x)
135142
}
@@ -140,12 +147,10 @@ func TestGetASNFromOrg(t *testing.T) {
140147
// compareResponse compares ASN & ORG against given domain with expected output's ASN & ORG
141148
// Have excluded IPs for now as they might change in future.
142149
func compareResponse(respA []*Response, respB *Response) bool {
143-
compareResult := false
144-
145-
for ind := range respA {
146-
if respA[ind].ASN == respB.ASN && respA[ind].Org == respB.Org {
147-
compareResult = true
150+
for _, r := range respA {
151+
if r.Equal(*respB) {
152+
return true
148153
}
149154
}
150-
return compareResult
155+
return false
151156
}

libs/formatter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type Response struct {
2828
Org string `json:"org,omitempty"`
2929
}
3030

31+
func (r Response) Equal(r2 Response) bool {
32+
return r.ASN == r2.ASN && strings.EqualFold(r.Org, r2.Org)
33+
}
34+
3135
// attachPrefix func attaches 'AS' prefix to ASN numbers
3236
func attachPrefix(input string) string {
3337
inp := input

runner/runner_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestRunner(t *testing.T) {
2727
Input: "104.16.99.52",
2828
ASN: 13335,
2929
Country: "US",
30-
Org: "CLOUDFLARENET"},
30+
Org: "cloudflarenet"},
3131
},
3232
},
3333
{
@@ -42,7 +42,7 @@ func TestRunner(t *testing.T) {
4242
Input: "14421",
4343
ASN: 14421,
4444
Country: "US",
45-
Org: "THERAVANCE"},
45+
Org: "theravance"},
4646
},
4747
},
4848
{
@@ -141,8 +141,8 @@ func TestProcessForDomainInput(t *testing.T) {
141141
// compareResponse compares ASN & ORG against given domain with expected output's ASN & ORG
142142
// Have excluded IPs for now as they might change in future.
143143
func compareResponse(respA []*asnmap.Response, respB *asnmap.Response) bool {
144-
for ind := range respA {
145-
if respA[ind].ASN == respB.ASN && respA[ind].Org == respB.Org {
144+
for _, r := range respA {
145+
if r.Equal(*respB) {
146146
return true
147147
}
148148
}

0 commit comments

Comments
 (0)