Skip to content

Commit

Permalink
more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Jan 4, 2021
1 parent dfa52bd commit 02fc16d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 14 deletions.
6 changes: 4 additions & 2 deletions cli/cmd/dns.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"log"
"runtime"
Expand All @@ -26,8 +27,9 @@ func runDNS(cmd *cobra.Command, args []string) error {
}

if err := cli.Gobuster(mainContext, globalopts, plugin); err != nil {
if goberr, ok := err.(*gobusterdns.ErrWildcard); ok {
return fmt.Errorf("%s. To force processing of Wildcard DNS, specify the '--wildcard' switch", goberr.Error())
var wErr *gobusterdns.ErrWildcard
if errors.As(err, &wErr) {
return fmt.Errorf("%w. To force processing of Wildcard DNS, specify the '--wildcard' switch", wErr)
}
return fmt.Errorf("error on running gobuster: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions cli/cmd/fuzz.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"log"

Expand All @@ -25,8 +26,9 @@ func runFuzz(cmd *cobra.Command, args []string) error {
}

if err := cli.Gobuster(mainContext, globalopts, plugin); err != nil {
if goberr, ok := err.(*gobusterfuzz.ErrWildcard); ok {
return fmt.Errorf("%s. To force processing of Wildcard responses, specify the '--wildcard' switch", goberr.Error())
var wErr *gobusterfuzz.ErrWildcard
if errors.As(err, &wErr) {
return fmt.Errorf("%w. To force processing of Wildcard responses, specify the '--wildcard' switch", wErr)
}
return fmt.Errorf("error on running gobuster: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/OJ/gobuster/v3/helper"
"github.com/OJ/gobuster/v3/libgobuster"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

func addBasicHTTPOptions(cmd *cobra.Command) {
Expand Down Expand Up @@ -161,7 +161,7 @@ func parseCommonHTTPOptions(cmd *cobra.Command) (libgobuster.HTTPOptions, error)
if options.Username != "" && options.Password == "" {
fmt.Printf("[?] Auth Password: ")
// please don't remove the int cast here as it is sadly needed on windows :/
passBytes, err := terminal.ReadPassword(int(syscall.Stdin)) //nolint:unconvert
passBytes, err := term.ReadPassword(int(syscall.Stdin)) //nolint:unconvert
// print a newline to simulate the newline that was entered
// this means that formatting/printing after doesn't look bad.
fmt.Println("")
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/OJ/gobuster/v3
require (
github.com/google/uuid v1.1.4
github.com/spf13/cobra v1.1.1
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
)

go 1.15
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -234,12 +232,9 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad h1:MCsdmFSdEd4UEa5TKS5JztCRHK/WtvNei1edOj5RSRo=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down
6 changes: 6 additions & 0 deletions helper/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func TestParseExtensions(t *testing.T) {
}

for _, x := range tt {
x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
t.Run(x.testName, func(t *testing.T) {
t.Parallel()
ret, err := ParseExtensions(x.extensions)
if x.expectedError != "" {
if err != nil && err.Error() != x.expectedError {
Expand Down Expand Up @@ -55,7 +57,9 @@ func TestParseCommaSeparatedInt(t *testing.T) {
}

for _, x := range tt {
x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
t.Run(x.testName, func(t *testing.T) {
t.Parallel()
ret, err := ParseCommaSeparatedInt(x.stringCodes)
if x.expectedError != "" {
if err != nil && err.Error() != x.expectedError {
Expand Down Expand Up @@ -83,6 +87,7 @@ func BenchmarkParseExtensions(b *testing.B) {
}

for _, x := range tt {
x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
b.Run(x.testName, func(b2 *testing.B) {
for y := 0; y < b2.N; y++ {
_, _ = ParseExtensions(x.extensions)
Expand All @@ -107,6 +112,7 @@ func BenchmarkParseCommaSeparatedInt(b *testing.B) {
}

for _, x := range tt {
x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
b.Run(x.testName, func(b2 *testing.B) {
for y := 0; y < b2.N; y++ {
_, _ = ParseCommaSeparatedInt(x.stringCodes)
Expand Down
15 changes: 15 additions & 0 deletions libgobuster/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import (
)

func TestNewStringSet(t *testing.T) {
t.Parallel()
if NewStringSet().Set == nil {
t.Fatal("newStringSet returned nil Set")
}
}

func TestNewIntSet(t *testing.T) {
t.Parallel()
if NewIntSet().Set == nil {
t.Fatal("newIntSet returned nil Set")
}
}

func TestStringSetAdd(t *testing.T) {
t.Parallel()
x := NewStringSet()
x.Add("test")
if len(x.Set) != 1 {
Expand All @@ -28,6 +31,7 @@ func TestStringSetAdd(t *testing.T) {
}

func TestStringSetAddDouble(t *testing.T) {
t.Parallel()
x := NewStringSet()
x.Add("test")
x.Add("test")
Expand All @@ -37,6 +41,7 @@ func TestStringSetAddDouble(t *testing.T) {
}

func TestStringSetAddRange(t *testing.T) {
t.Parallel()
x := NewStringSet()
x.AddRange([]string{"string1", "string2"})
if len(x.Set) != 2 {
Expand All @@ -45,6 +50,7 @@ func TestStringSetAddRange(t *testing.T) {
}

func TestStringSetAddRangeDouble(t *testing.T) {
t.Parallel()
x := NewStringSet()
x.AddRange([]string{"string1", "string2", "string1", "string2"})
if len(x.Set) != 2 {
Expand All @@ -53,6 +59,7 @@ func TestStringSetAddRangeDouble(t *testing.T) {
}

func TestStringSetContains(t *testing.T) {
t.Parallel()
x := NewStringSet()
v := []string{"string1", "string2", "1234", "5678"}
x.AddRange(v)
Expand All @@ -64,6 +71,7 @@ func TestStringSetContains(t *testing.T) {
}

func TestStringSetContainsAny(t *testing.T) {
t.Parallel()
x := NewStringSet()
v := []string{"string1", "string2", "1234", "5678"}
x.AddRange(v)
Expand All @@ -78,6 +86,7 @@ func TestStringSetContainsAny(t *testing.T) {
}

func TestStringSetStringify(t *testing.T) {
t.Parallel()
x := NewStringSet()
v := []string{"string1", "string2", "1234", "5678"}
x.AddRange(v)
Expand All @@ -91,6 +100,7 @@ func TestStringSetStringify(t *testing.T) {
}

func TestIntSetAdd(t *testing.T) {
t.Parallel()
x := NewIntSet()
x.Add(1)
if len(x.Set) != 1 {
Expand All @@ -99,6 +109,7 @@ func TestIntSetAdd(t *testing.T) {
}

func TestIntSetAddDouble(t *testing.T) {
t.Parallel()
x := NewIntSet()
x.Add(1)
x.Add(1)
Expand All @@ -108,6 +119,7 @@ func TestIntSetAddDouble(t *testing.T) {
}

func TestIntSetContains(t *testing.T) {
t.Parallel()
x := NewIntSet()
v := []int{1, 2, 3, 4}
for _, y := range v {
Expand All @@ -121,6 +133,7 @@ func TestIntSetContains(t *testing.T) {
}

func TestIntSetStringify(t *testing.T) {
t.Parallel()
x := NewIntSet()
v := []int{1, 3, 2, 4}
expected := "1,2,3,4"
Expand All @@ -135,6 +148,7 @@ func TestIntSetStringify(t *testing.T) {
}

func TestLineCounter(t *testing.T) {
t.Parallel()
var tt = []struct {
testName string
s string
Expand All @@ -161,6 +175,7 @@ func TestLineCounter(t *testing.T) {
}

func TestLineCounterError(t *testing.T) {
t.Parallel()
r := iotest.TimeoutReader(strings.NewReader("test"))
_, err := lineCounter(r)
if !errors.Is(err, iotest.ErrTimeout) {
Expand Down
3 changes: 2 additions & 1 deletion libgobuster/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (client *HTTPClient) makeRequest(fullURL, host string, data io.Reader) (*ht

resp, err := client.client.Do(req)
if err != nil {
if ue, ok := err.(*url.Error); ok {
var ue *url.Error
if errors.As(err, &ue) {
if strings.HasPrefix(ue.Err.Error(), "x509") {
return nil, fmt.Errorf("invalid certificate: %w", ue.Err)
}
Expand Down
1 change: 1 addition & 0 deletions libgobuster/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func randomString(length int) (string, error) {
}

func TestRequest(t *testing.T) {
t.Parallel()
ret, err := randomString(100)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 02fc16d

Please sign in to comment.