Skip to content

Commit

Permalink
fix style and linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitris committed Jul 25, 2018
1 parent 4338856 commit 8b35a74
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions cmd/gryffin-standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func linkChannels(s *gryffin.Scan) {

}()

scan := scan // prevent capturing by goroutine below
go func() {

//
// Renderer will close all channels when a page is duplicated.
// Therefore we don't need to test whether the link is coming
Expand All @@ -89,7 +89,7 @@ func linkChannels(s *gryffin.Scan) {

go func() {
for scan := range chanFuzz {

scan := scan // prevent capture by func literal below
go func() {
f := &arachni.Fuzzer{}
f.Fuzz(scan)
Expand Down
3 changes: 1 addition & 2 deletions data/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (m *MemoryStore) Get(key string) (value interface{}, ok bool) {
default:
return value, ok
}
return value, ok
}

// IncrBy increments the value pointed by key with the delta, and return the new value.
Expand All @@ -51,7 +50,7 @@ func (m *MemoryStore) IncrBy(key string, delta int64) (newVal int64) {
}

func (m *MemoryStore) DelPrefix(prefix string) {
for k, _ := range m.heap {
for k := range m.heap {
if strings.HasPrefix(k, prefix) {
delete(m.heap, k)
}
Expand Down
2 changes: 1 addition & 1 deletion data/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func testStore(t *testing.T, s Store) {
t.Error("Incr failed.")
}
if v, ok := s.Get("foo"); v.(int64) != 110 {
t.Errorf("Incr is inconsistent %s, %s and %s", ok, v.(int64) == 110, v)
t.Errorf("Incr is inconsistent %t, %t and %s", ok, v.(int64) == 110, v)
}

}
Expand Down
10 changes: 3 additions & 7 deletions gryffin.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ type LogMessage struct {

// NewScan creates a scan.
func NewScan(method, url, post string) *Scan {

// ensure we got a memory store..
if memoryStore == nil {
memoryStore = NewGryffinStore()
Expand All @@ -107,7 +106,7 @@ func NewScan(method, url, post string) *Scan {
job.DomainsAllowed = []string{host}
}

// // Add chrome user agent
// Add chrome user agent
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36")

return &Scan{
Expand Down Expand Up @@ -348,9 +347,8 @@ func (s *Scan) IsDuplicatedPage() bool {
memoryStore.See(s.Job.ID, "oracle", f)
s.Logm("IsDuplicatedPage", "Unique Page")
return false
} else {
s.Logm("IsDuplicatedPage", "Duplicate Page")
}
s.Logm("IsDuplicatedPage", "Duplicate Page")
return true
}

Expand All @@ -368,16 +366,14 @@ func (s *Scan) Fuzz(fuzzer Fuzzer) (int, error) {

// ShouldCrawl checks if the links should be queued for next crawl.
func (s *Scan) ShouldCrawl() bool {

s.UpdateFingerprint()
f := s.Fingerprint.URL
if !memoryStore.Seen(s.Job.ID, "hash", f, 0) {
memoryStore.See(s.Job.ID, "hash", f)
s.Logm("ShouldCrawl", "Unique Link")
return true
} else {
s.Logm("ShouldCrawl", "Duplicate Link")
}
s.Logm("ShouldCrawl", "Duplicate Link")
return false
}

Expand Down
8 changes: 4 additions & 4 deletions gryffin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ func TestNewScanFromJson(t *testing.T) {

// Test arbritary url.
s := NewScan("GET", ts.URL, "")
_ = s.Poke(&http.Client{})
if err := s.Poke(&http.Client{}); err != nil {
t.Fatalf("error in s.Poke: %v", err)
}
j := s.Json()

if j == nil {
t.Error("scan.Json should return a json string.")
t.Fatalf("scan.Json: got %v, want a json string", j)
}

s2 := NewScanFromJson(j)
if s2 == nil {
t.Error("NewScanFromJson should return a scan.")
}
t.Log(s2)

}

func TestGetOrigin(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions html-distance/bktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package html-distance is a go library for computing the proximity of the HTML pages. The implementation similiarity fingerprint is Charikar's simhash.
// Package distance is a go library for computing the proximity of the HTML pages.
// The implementation similiarity fingerprint is Charikar's simhash.
//
// Distance is the hamming distance of the fingerprints. Since fingerprint is of size 64 (inherited from hash/fnv), Similiarity is defined as 1 - d / 64.
// Distance is the hamming distance of the fingerprints. Since fingerprint is
// of size 64 (inherited from hash/fnv), Similiarity is defined as 1 - d / 64.
//
// In normal scenario, similarity > 95% (i.e. d>3) could be considered as duplicated html pages.
package distance
Expand Down Expand Up @@ -64,7 +66,7 @@ func (n *Oracle) Seen(f uint64, r uint8) bool {
break
}
if c := n.nodes[k]; c != nil {
if c.Seen(f, r) == true {
if c.Seen(f, r) {
return true
}
}
Expand Down
10 changes: 8 additions & 2 deletions html-distance/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ func BenchmarkFingerprint(b *testing.B) {
func BenchmarkFingerprintWithExternalHTML(b *testing.B) {

b.Skip("Skip external dependent tests.")
resp, _ := http.Get("https://www.yahoo.com/")
resp, err := http.Get("https://www.yahoo.com/")
if err != nil {
b.Fatal(err)
}
defer resp.Body.Close()
input, _ := ioutil.ReadAll(resp.Body)
input, err := ioutil.ReadAll(resp.Body)
if err != nil {
b.Fatal(err)
}

b.ResetTimer()

Expand Down
2 changes: 0 additions & 2 deletions renderer/noscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,4 @@ func (r *NoScriptRenderer) Do(s *gryffin.Scan) {
}

go crawl()

return
}
22 changes: 10 additions & 12 deletions renderer/phantomjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func (l *link) toScan(parent *gryffin.Scan) *gryffin.Scan {
}

func (r *PhantomJSRenderer) extract(stdout io.ReadCloser, s *gryffin.Scan) {

defer close(r.done)

dec := json.NewDecoder(stdout)
Expand All @@ -166,19 +165,18 @@ func (r *PhantomJSRenderer) extract(stdout io.ReadCloser, s *gryffin.Scan) {
err := dec.Decode(&m)
if err == io.EOF {
return
} else {
if m.responseMessage != nil {
m.Response.fill(s)
if s.IsDuplicatedPage() {
return
}
r.chanResponse <- s
r.parseDetails(&m.Response.Details, s)
}
if m.responseMessage != nil {
m.Response.fill(s)
if s.IsDuplicatedPage() {
return
}
r.chanResponse <- s
r.parseDetails(&m.Response.Details, s)
}

if m.details != nil {
r.parseDetails(m.details, s)
}
if m.details != nil {
r.parseDetails(m.details, s)
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ func NewScanFromJson(b []byte) *Scan {
return &scan
}

func (s *Scan) Json() []byte {
ss := &SerializableScan{
s,
&SerializableRequest{s.Request, ""},
&SerializableResponse{
s.Response,
&SerializableRequest{s.Request, ""},
},
}
b, err := json.Marshal(ss)
if err != nil {
s.Error("Json", err)
}
return b

}
// func (s *Scan) Json() []byte {
// ss := &SerializableScan{
// s,
// &SerializableRequest{s.Request, ""},
// &SerializableResponse{
// s.Response,
// &SerializableRequest{s.Request, ""},
// },
// }
// log.Printf("DMDEBUG ss=%#v", ss)
// b, err := json.Marshal(ss)
// if err != nil {
// log.Printf("DMDEBUG error in json.Marshal: %v", err)
// s.Error("Json", err)
// }
// return b

// }

type SerializableScan struct {
*Scan
Expand Down
3 changes: 1 addition & 2 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func TestNewGryffinStore(t *testing.T) {

go func() {
store1.See("foo", "oracle", uint64(0x1234))
var b []byte
b = <-store1.GetSndChan()
var b []byte = <-store1.GetSndChan()
t.Log("Store1 got ", string(b))
store2.GetRcvChan() <- b

Expand Down

0 comments on commit 8b35a74

Please sign in to comment.