-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from projectdiscovery/dev
v1.1.2 Release preparation
- Loading branch information
Showing
21 changed files
with
637 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
|
||
cmd/httpx/httpx | ||
integration_tests/httpx | ||
integration_tests/integration-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
|
||
"github.com/julienschmidt/httprouter" | ||
"github.com/projectdiscovery/httpx/internal/testutils" | ||
) | ||
|
||
var httpTestcases = map[string]testutils.TestCase{ | ||
"Standard HTTP GET Request": &standardHttpGet{}, | ||
"Standard HTTPS GET Request": &standardHttpGet{tls: true}, | ||
"Raw HTTP GET Request": &standardHttpGet{unsafe: true}, | ||
"Raw request with non standard rfc path via stdin": &standardHttpGet{unsafe: true, stdinPath: "/%invalid"}, | ||
"Raw request with non standard rfc path via cli flag": &standardHttpGet{unsafe: true, path: "/%invalid"}, | ||
"Regression test for: https://github.com/projectdiscovery/httpx/issues/363": &issue363{}, // infinite redirect | ||
"Regression test for: https://github.com/projectdiscovery/httpx/issues/276": &issue276{}, // full path with port in output | ||
"Regression test for: https://github.com/projectdiscovery/httpx/issues/277": &issue277{}, // scheme://host:port via stdin | ||
"Regression test for: https://github.com/projectdiscovery/httpx/issues/303": &issue303{}, // misconfigured gzip header with uncompressed body | ||
} | ||
|
||
type standardHttpGet struct { | ||
tls bool | ||
unsafe bool | ||
stdinPath string | ||
path string | ||
expectedOutput string | ||
} | ||
|
||
func (h *standardHttpGet) Execute() error { | ||
router := httprouter.New() | ||
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
fmt.Fprintf(w, "This is a test") | ||
r.Close = true | ||
})) | ||
var ts *httptest.Server | ||
if h.tls { | ||
ts = httptest.NewTLSServer(router) | ||
} else { | ||
ts = httptest.NewServer(router) | ||
} | ||
defer ts.Close() | ||
var extra []string | ||
if h.unsafe { | ||
extra = append(extra, "-unsafe") | ||
} | ||
if h.path != "" { | ||
extra = append(extra, "-path", "\""+h.path+"\"") | ||
} | ||
|
||
URL := ts.URL | ||
if h.stdinPath != "" { | ||
URL += h.stdinPath | ||
} | ||
|
||
results, err := testutils.RunHttpxAndGetResults(URL, debug, extra...) | ||
if err != nil { | ||
return err | ||
} | ||
if len(results) != 1 { | ||
return errIncorrectResultsCount(results) | ||
} | ||
|
||
if h.expectedOutput != "" && !strings.EqualFold(results[0], h.expectedOutput) { | ||
return errIncorrectResult(results[0], h.expectedOutput) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type issue276 struct{} | ||
|
||
func (h *issue276) Execute() error { | ||
var ts *httptest.Server | ||
router := httprouter.New() | ||
router.GET("/redirect", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
w.Header().Add("Location", ts.URL+"/redirect") | ||
w.WriteHeader(302) | ||
fmt.Fprintf(w, "<html><body><title>Object moved</title></body></html>") | ||
})) | ||
ts = httptest.NewServer(router) | ||
defer ts.Close() | ||
|
||
results, err := testutils.RunHttpxAndGetResults(ts.URL+"/redirect", debug, "-status-code", "-title", "-no-color") | ||
if err != nil { | ||
return err | ||
} | ||
if len(results) != 1 { | ||
return errIncorrectResultsCount(results) | ||
} | ||
// check if we have all the items on the cli | ||
// full url with port | ||
// status code | ||
// title | ||
expected := ts.URL + "/redirect" + " [302] [Object moved]" | ||
if !strings.EqualFold(results[0], expected) { | ||
return errIncorrectResult(results[0], expected) | ||
} | ||
return nil | ||
} | ||
|
||
type issue277 struct{} | ||
|
||
func (h *issue277) Execute() error { | ||
var ts *httptest.Server | ||
router := httprouter.New() | ||
router.GET("/hpp", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | ||
if p.ByName("pp") == `%22%3E%3Ch1%3Easdasd%3C%2Fh1%3E` { | ||
w.WriteHeader(http.StatusOK) | ||
} | ||
})) | ||
ts = httptest.NewServer(router) | ||
defer ts.Close() | ||
uripath := "/hpp/?pp=%22%3E%3Ch1%3Easdasd%3C%2Fh1%3E" | ||
results, err := testutils.RunHttpxAndGetResults(ts.URL+uripath, debug) | ||
if err != nil { | ||
return err | ||
} | ||
if len(results) != 1 { | ||
return errIncorrectResultsCount(results) | ||
} | ||
// check if we have all the items on the cli | ||
// full url with port | ||
// status code | ||
// title | ||
expected := ts.URL + uripath | ||
if !strings.EqualFold(results[0], expected) { | ||
return errIncorrectResult(results[0], expected) | ||
} | ||
return nil | ||
} | ||
|
||
type issue303 struct{} | ||
|
||
func (h *issue303) Execute() error { | ||
var ts *httptest.Server | ||
router := httprouter.New() | ||
router.GET("/hpp", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | ||
// mimic a misconfigured web server behavior declaring gzip body | ||
w.Header().Add("Content-Encoding", "gzip") | ||
// but sending it uncompressed | ||
fmt.Fprint(w, "<html><body>This is a test</body></html>") | ||
})) | ||
ts = httptest.NewServer(router) | ||
defer ts.Close() | ||
results, err := testutils.RunHttpxAndGetResults(ts.URL, debug) | ||
if err != nil { | ||
return err | ||
} | ||
if len(results) != 1 { | ||
return errIncorrectResultsCount(results) | ||
} | ||
// check if we have all the items on the cli | ||
// full url with port | ||
expected := ts.URL | ||
if !strings.EqualFold(results[0], expected) { | ||
return errIncorrectResult(results[0], expected) | ||
} | ||
return nil | ||
} | ||
|
||
type issue363 struct{} | ||
|
||
func (h *issue363) Execute() error { | ||
var ts *httptest.Server | ||
router := httprouter.New() | ||
router.GET("/redirect", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
w.Header().Add("Location", ts.URL+"/redirect") | ||
w.WriteHeader(302) | ||
fmt.Fprintf(w, "<html><body><title>Object moved</title></body></html>") | ||
})) | ||
ts = httptest.NewServer(router) | ||
defer ts.Close() | ||
|
||
results, err := testutils.RunHttpxAndGetResults(ts.URL+"/redirect", debug, "-no-color", "-follow-redirects") | ||
if err != nil { | ||
return err | ||
} | ||
if len(results) != 1 { | ||
return errIncorrectResultsCount(results) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/logrusorgru/aurora" | ||
"github.com/projectdiscovery/httpx/internal/testutils" | ||
) | ||
|
||
var ( | ||
debug = os.Getenv("DEBUG") == "true" | ||
customTest = os.Getenv("TEST") | ||
protocol = os.Getenv("PROTO") | ||
|
||
errored = false | ||
) | ||
|
||
func main() { | ||
success := aurora.Green("[✓]").String() | ||
failed := aurora.Red("[✘]").String() | ||
|
||
tests := map[string]map[string]testutils.TestCase{ | ||
"http": httpTestcases, | ||
} | ||
for proto, tests := range tests { | ||
if protocol == "" || protocol == proto { | ||
fmt.Printf("Running test cases for \"%s\"\n", aurora.Blue(proto)) | ||
|
||
for name, test := range tests { | ||
if customTest != "" && !strings.Contains(name, customTest) { | ||
continue // only run tests user asked | ||
} | ||
err := test.Execute() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, name, err) | ||
errored = true | ||
} else { | ||
fmt.Printf("%s Test \"%s\" passed!\n", success, name) | ||
} | ||
} | ||
} | ||
} | ||
if errored { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func errIncorrectResultsCount(results []string) error { | ||
return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t")) | ||
} | ||
|
||
func errIncorrectResult(expected, got string) error { | ||
return fmt.Errorf("incorrect result: expected \"%s\" got \"%s\"", expected, got) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.