yellow~ opinionated web scanning pipeline for pentesters in a hurry |
| git clone https://github.com/djnnvx/yellow.git |
| log | files | refs | archive | README | LICENSE |
portscan_test.go (1777B)
1 package scan 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestMergePortResultsKeepsUnfingerprintedPorts(t *testing.T) { 9 open := []int{22, 80, 443} 10 enriched := map[int]PortResult{ 11 22: {Port: 22, Proto: "tcp", Service: "ssh"}, 12 80: {Port: 80, Proto: "tcp", Service: "http", Version: "OpenBSD httpd"}, 13 } 14 15 got := mergePortResults(open, enriched) 16 17 if len(got) != len(open) { 18 t.Fatalf("dropped open ports: got %d results, want %d (%v)", len(got), len(open), got) 19 } 20 want := []PortResult{ 21 {Port: 22, Proto: "tcp", Service: "ssh"}, 22 {Port: 80, Proto: "tcp", Service: "http", Version: "OpenBSD httpd"}, 23 {Port: 443, Proto: "tcp"}, 24 } 25 if !reflect.DeepEqual(got, want) { 26 t.Errorf("got %+v, want %+v", got, want) 27 } 28 } 29 30 func TestMergePortResultsNoFingerprints(t *testing.T) { 31 got := mergePortResults([]int{8080}, map[int]PortResult{}) 32 want := []PortResult{{Port: 8080, Proto: "tcp"}} 33 if !reflect.DeepEqual(got, want) { 34 t.Errorf("got %+v, want %+v", got, want) 35 } 36 } 37 38 func TestParsePorts(t *testing.T) { 39 tests := []struct { 40 spec string 41 want []int 42 wantErr bool 43 }{ 44 {spec: "22,80,443", want: []int{22, 80, 443}}, 45 {spec: "80-83", want: []int{80, 81, 82, 83}}, 46 {spec: "22, 100-102", want: []int{22, 100, 101, 102}}, 47 {spec: "443-443", want: []int{443}}, 48 {spec: "100-80", wantErr: true}, 49 {spec: "http", wantErr: true}, 50 {spec: "1-x", wantErr: true}, 51 } 52 53 for _, tt := range tests { 54 got, err := parsePorts(tt.spec) 55 if tt.wantErr { 56 if err == nil { 57 t.Errorf("parsePorts(%q): want error, got %v", tt.spec, got) 58 } 59 continue 60 } 61 if err != nil { 62 t.Errorf("parsePorts(%q): unexpected error %v", tt.spec, err) 63 continue 64 } 65 if !reflect.DeepEqual(got, tt.want) { 66 t.Errorf("parsePorts(%q) = %v, want %v", tt.spec, got, tt.want) 67 } 68 } 69 }