yellow.git


yellow

~ opinionated web scanning pipeline for pentesters in a hurry
git clone https://github.com/djnnvx/yellow.git
log | files | refs | archive | README | LICENSE

urls_test.go (1218B)

      1 package scan
      2 
      3 import (
      4 	"reflect"
      5 	"testing"
      6 )
      7 
      8 func TestDirRoots(t *testing.T) {
      9 	got := dirRoots([]string{
     10 		"https://x.tld/app/login",
     11 		"https://x.tld/app/logout",
     12 		"https://x.tld/app/",
     13 		"https://x.tld/",
     14 		"https://x.tld/api/v1/users?id=1",
     15 		"https://other.tld/a/b/c",
     16 		"::::not a url",
     17 		"/relative/only",
     18 	})
     19 
     20 	want := []string{
     21 		"https://other.tld/a/b/",
     22 		"https://x.tld/",
     23 		"https://x.tld/api/v1/",
     24 		"https://x.tld/app/",
     25 	}
     26 	if !reflect.DeepEqual(got, want) {
     27 		t.Errorf("got %v, want %v", got, want)
     28 	}
     29 }
     30 
     31 func TestDirRootsDedupes(t *testing.T) {
     32 	got := dirRoots([]string{
     33 		"https://x.tld/a/1", "https://x.tld/a/2", "https://x.tld/a/3",
     34 	})
     35 	if len(got) != 1 || got[0] != "https://x.tld/a/" {
     36 		t.Errorf("got %v, want one root https://x.tld/a/", got)
     37 	}
     38 }
     39 
     40 func TestCapURLs(t *testing.T) {
     41 	five := []string{"a", "b", "c", "d", "e"}
     42 
     43 	if got := capURLs(five, 3, "test"); len(got) != 3 {
     44 		t.Errorf("cap 3: got %d entries, want 3", len(got))
     45 	}
     46 	if got := capURLs(five, 10, "test"); len(got) != 5 {
     47 		t.Errorf("cap above length must not truncate: got %d, want 5", len(got))
     48 	}
     49 	if got := capURLs(five, 0, "test"); len(got) != 5 {
     50 		t.Errorf("cap 0 means unlimited: got %d, want 5", len(got))
     51 	}
     52 }