Skip to content

Commit 39ad545

Browse files
committed
more changes to test code and smaller fixes found by tests
1 parent 56e3f19 commit 39ad545

6 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎.gitignore‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.env
22
bin/*
33
*.exe
4-
testing/perftest/perftest
5-
testing/functest/functest
4+
testing/bin/*
5+
!testing/bin/README.md
6+
testing/perftest/bin/
7+
testing/functest/bin/

‎src/main.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func handleLookup(w http.ResponseWriter, r *http.Request) {
298298

299299
ip := r.PathValue("ip")
300300

301-
if ip == "" {
301+
if ip == "" || !IsValidIP(ip) {
302302
w.Header().Set("X-Blocklist-Status", "error")
303303
w.WriteHeader(http.StatusBadRequest)
304304
logHttpReq(r, start, ReqType, "Error")
@@ -390,6 +390,12 @@ func handleAuth(w http.ResponseWriter, r *http.Request) {
390390

391391
ip := r.PathValue("ip")
392392

393+
if ip == "" || !IsValidIP(ip) {
394+
w.WriteHeader(http.StatusBadRequest)
395+
logHttpReq(r, start, ReqType, "Error")
396+
return
397+
}
398+
393399
_, blocked := ipTableLookup(ip)
394400

395401
if blocked {
@@ -399,7 +405,7 @@ func handleAuth(w http.ResponseWriter, r *http.Request) {
399405
}
400406

401407
logHttpReq(r, start, ReqType, "NotBlocked")
402-
w.WriteHeader(http.StatusNoContent)
408+
w.WriteHeader(http.StatusOK)
403409
}
404410

405411
func handlePut(w http.ResponseWriter, r *http.Request) {

‎testing/bin/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Compiled test binaries are written here — this directory is intentionally tracked in git to ensure it exists after a fresh clone.
2+
3+
Binaries are excluded via .gitignore.

‎testing/functest/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func lookupIP(lookupBase, ip string) (LookupResponse, int, error) {
8787
}
8888
defer resp.Body.Close()
8989

90-
if resp.StatusCode == http.StatusNoContent {
90+
if resp.StatusCode != http.StatusOK {
9191
return LookupResponse{Blocked: false}, resp.StatusCode, nil
9292
}
9393

‎testing/functest/test,sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go build -buildvcs=false -o ../bin/functest
2+
../bin/functest

‎testing/perftest/test,sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go build -buildvcs=false -o ../bin/perftest
2+
../bin/perftest

0 commit comments

Comments
 (0)