-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying of DNS resolvers, endpoint IP addresses (#6)
* progress * remove test SOA work * prep work for new requester * all lookup options working * some cmd util tests * fix tests, add log lines, test cmd on CI * CSVtoIPs test cases * README updates * change pad flag to `no-pad`, since we default to padding * threadsafe dnscache * haha * endpoint parser tests * dns cache tests * LookupIP tests * improve lookup tests
- Loading branch information
Showing
11 changed files
with
742 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"strings" | ||
|
||
secop "github.com/fardog/secureoperator" | ||
) | ||
|
||
// CSVtoEndpoints takes a comma-separated string of endpoints, and parses to a | ||
// []secop.Endpoint | ||
func CSVtoEndpoints(csv string) (eps []secop.Endpoint, err error) { | ||
reps := strings.Split(csv, ",") | ||
for _, r := range reps { | ||
if r == "" { | ||
continue | ||
} | ||
|
||
ep, err := secop.ParseEndpoint(r, 53) | ||
if err != nil { | ||
return eps, err | ||
} | ||
|
||
eps = append(eps, ep) | ||
} | ||
|
||
return eps, err | ||
} | ||
|
||
// CSVtoIPs takes a comma-separated string of IPs, and parses to a []net.IP | ||
func CSVtoIPs(csv string) (ips []net.IP, err error) { | ||
rs := strings.Split(csv, ",") | ||
|
||
for _, r := range rs { | ||
if r == "" { | ||
continue | ||
} | ||
|
||
ip := net.ParseIP(r) | ||
if ip == nil { | ||
return ips, fmt.Errorf("unable to parse IP from string %s", r) | ||
} | ||
ips = append(ips, ip) | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package cmd | ||
|
||
import "testing" | ||
|
||
func TestCSVtoEndpoints(t *testing.T) { | ||
type Case struct { | ||
csv string | ||
err bool | ||
expected []string | ||
} | ||
|
||
cs := []Case{ | ||
Case{ | ||
"8.8.8.8:53,8.8.4.4:8053", | ||
false, | ||
[]string{"8.8.8.8:53", "8.8.4.4:8053"}, | ||
}, | ||
Case{ | ||
"8.8.8.8,8.8.4.4:8053", | ||
false, | ||
[]string{"8.8.8.8:53", "8.8.4.4:8053"}, | ||
}, | ||
Case{ | ||
"8.8.8.8", | ||
false, | ||
[]string{"8.8.8.8:53"}, | ||
}, | ||
Case{ | ||
"", | ||
false, | ||
[]string{}, | ||
}, | ||
Case{ | ||
"8.8.8.8:53:54", | ||
true, | ||
[]string{}, | ||
}, | ||
} | ||
|
||
for i, c := range cs { | ||
results, err := CSVtoEndpoints(c.csv) | ||
if c.err && err == nil { | ||
t.Errorf("%v: expected err, got none", i) | ||
} else if !c.err && err != nil { | ||
t.Errorf("%v: did not expect error, got: %v", i, err) | ||
} | ||
|
||
if e, r := len(c.expected), len(results); e != r { | ||
t.Errorf("%v: expected %v results, got %v", i, e, r) | ||
continue | ||
} | ||
|
||
for j, r := range results { | ||
if r.String() != c.expected[j] { | ||
t.Errorf("%v,%v: expected %v, got %v", i, j, r, c.expected[j]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestCSVtoIPs(t *testing.T) { | ||
type Case struct { | ||
csv string | ||
err bool | ||
expected []string | ||
} | ||
|
||
cs := []Case{ | ||
Case{ | ||
"8.8.8.8,8.8.4.4", | ||
false, | ||
[]string{"8.8.8.8", "8.8.4.4"}, | ||
}, | ||
Case{ | ||
"8.8.8.8,8.8.4.4", | ||
false, | ||
[]string{"8.8.8.8", "8.8.4.4"}, | ||
}, | ||
Case{ | ||
"8.8.8.8", | ||
false, | ||
[]string{"8.8.8.8"}, | ||
}, | ||
Case{ | ||
"", | ||
false, | ||
[]string{}, | ||
}, | ||
Case{ | ||
"8.8.8.8:53", | ||
true, | ||
[]string{}, | ||
}, | ||
} | ||
|
||
for i, c := range cs { | ||
results, err := CSVtoIPs(c.csv) | ||
if c.err && err == nil { | ||
t.Errorf("%v: expected err, got none", i) | ||
} else if !c.err && err != nil { | ||
t.Errorf("%v: did not expect error, got: %v", i, err) | ||
} | ||
|
||
if e, r := len(c.expected), len(results); e != r { | ||
t.Errorf("%v: expected %v results, got %v", i, e, r) | ||
continue | ||
} | ||
|
||
for j, r := range results { | ||
if r.String() != c.expected[j] { | ||
t.Errorf("%v,%v: expected %v, got %v", i, j, r, c.expected[j]) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.