mirror of
https://github.com/OJ/gobuster.git
synced 2024-05-04 22:46:07 +02:00
6a2b40ff86
This was cherry-picked from the gomod branch instead of being merged as a PR for two reasons: 1) The vhost plugin addition isn't yet ready for merging, as there's a lot of code duplication. 2) This code can technically be merged as is without the mods to the vhost plugin. When/If we're ready to merge the vhost plugin we'll fix that side up.
74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
package gobusterdir
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/OJ/gobuster/v3/libgobuster"
|
|
)
|
|
|
|
func TestParseExtensions(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var tt = []struct {
|
|
testName string
|
|
Extensions string
|
|
expectedExtensions libgobuster.StringSet
|
|
expectedError string
|
|
}{
|
|
{"Valid extensions", "php,asp,txt", libgobuster.StringSet{Set: map[string]bool{"php": true, "asp": true, "txt": true}}, ""},
|
|
{"Spaces", "php, asp , txt", libgobuster.StringSet{Set: map[string]bool{"php": true, "asp": true, "txt": true}}, ""},
|
|
{"Double extensions", "php,asp,txt,php,asp,txt", libgobuster.StringSet{Set: map[string]bool{"php": true, "asp": true, "txt": true}}, ""},
|
|
{"Leading dot", ".php,asp,.txt", libgobuster.StringSet{Set: map[string]bool{"php": true, "asp": true, "txt": true}}, ""},
|
|
{"Empty string", "", libgobuster.NewStringSet(), "invalid extension string provided"},
|
|
}
|
|
|
|
for _, x := range tt {
|
|
t.Run(x.testName, func(t *testing.T) {
|
|
o := NewOptionsDir()
|
|
o.Extensions = x.Extensions
|
|
err := o.ParseExtensions()
|
|
if x.expectedError != "" {
|
|
if err.Error() != x.expectedError {
|
|
t.Fatalf("Expected error %q but got %q", x.expectedError, err.Error())
|
|
}
|
|
} else if !reflect.DeepEqual(x.expectedExtensions, o.ExtensionsParsed) {
|
|
t.Fatalf("Expected %v but got %v", x.expectedExtensions, o.ExtensionsParsed)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseStatusCodes(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var tt = []struct {
|
|
testName string
|
|
stringCodes string
|
|
expectedCodes libgobuster.IntSet
|
|
expectedError string
|
|
}{
|
|
{"Valid codes", "200,100,202", libgobuster.IntSet{Set: map[int]bool{100: true, 200: true, 202: true}}, ""},
|
|
{"Spaces", "200, 100 , 202", libgobuster.IntSet{Set: map[int]bool{100: true, 200: true, 202: true}}, ""},
|
|
{"Double codes", "200, 100, 202, 100", libgobuster.IntSet{Set: map[int]bool{100: true, 200: true, 202: true}}, ""},
|
|
{"Invalid code", "200,AAA", libgobuster.NewIntSet(), "invalid status code given: AAA"},
|
|
{"Invalid integer", "2000000000000000000000000000000", libgobuster.NewIntSet(), "invalid status code given: 2000000000000000000000000000000"},
|
|
{"Empty string", "", libgobuster.NewIntSet(), "invalid status code string provided"},
|
|
}
|
|
|
|
for _, x := range tt {
|
|
t.Run(x.testName, func(t *testing.T) {
|
|
o := NewOptionsDir()
|
|
o.StatusCodes = x.stringCodes
|
|
err := o.ParseStatusCodes()
|
|
if x.expectedError != "" {
|
|
if err.Error() != x.expectedError {
|
|
t.Fatalf("Expected error %q but got %q", x.expectedError, err.Error())
|
|
}
|
|
} else if !reflect.DeepEqual(x.expectedCodes, o.StatusCodesParsed) {
|
|
t.Fatalf("Expected %v but got %v", x.expectedCodes, o.StatusCodesParsed)
|
|
}
|
|
})
|
|
}
|
|
}
|