-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changing fuzzer tests and making it simpler, adding TLS
- Loading branch information
1 parent
59c8235
commit 329248e
Showing
1 changed file
with
20 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,38 @@ | ||
package fuzzer_test | ||
|
||
import ( | ||
"log" | ||
"net" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/CyberRoute/bruter/pkg/fuzzer" | ||
) | ||
|
||
func TestGet(t *testing.T) { | ||
// create a listener with the desired port. | ||
l, err := net.Listen("tcp", "127.0.0.1:8080") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
// Create a mock HTTP server | ||
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
// Respond with a mock JSON response | ||
response := map[string]interface{}{ | ||
"key": "value", | ||
} | ||
err := json.NewEncoder(w).Encode(response) | ||
if err != nil { | ||
t.Fatalf("Error encoding JSON response: %v", err) | ||
} | ||
})) | ||
defer server.Close() | ||
|
||
ts.Listener.Close() | ||
ts.Listener = l | ||
|
||
// Start the server. | ||
ts.Start() | ||
|
||
// Test 1 - valid URL | ||
// Set up test input parameters | ||
Mu := &sync.Mutex{} | ||
path := "/test" | ||
progress := float32(0.5) | ||
verbose := true | ||
|
||
// Create a test server that returns a 200 status code | ||
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
})) | ||
defer testServer.Close() | ||
|
||
domain := testServer.URL[7:] // Remove the "http://" prefix | ||
path := "/" | ||
|
||
go fuzzer.Get(&sync.Mutex{}, domain, path, progress, true) | ||
|
||
// Test 3 - 403 status code | ||
progress = float32(0.5) | ||
|
||
// Create a test server that returns a 403 status code | ||
testServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusForbidden) | ||
})) | ||
defer testServer.Close() | ||
|
||
domain = testServer.URL[7:] // Remove the "http://" prefix | ||
path = "/" | ||
|
||
go fuzzer.Get(&sync.Mutex{}, domain, path, progress, true) | ||
|
||
// Test 4 - non-200, non-403 status code | ||
progress = float32(0.5) | ||
|
||
// Create a test server that returns a 500 status code | ||
testServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
})) | ||
defer testServer.Close() | ||
|
||
domain = testServer.URL[7:] // Remove the "http://" prefix | ||
path = "/" | ||
|
||
go fuzzer.Get(&sync.Mutex{}, domain, path, progress, true) | ||
domain := strings.TrimPrefix(server.URL, "https://") | ||
|
||
ts.Close() | ||
// Call the Get function with the mock server URL | ||
fuzzer.Get(Mu, domain, path, progress, verbose) | ||
} |