forked from webcompas/acme-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly parse r.RemoteAddr (joohoi#50)
* Properly parse r.RemoteAddr * Add tests, and fix net.ParseCIDR issues with IPv6 addresses enclosed in brackets
- Loading branch information
Showing
4 changed files
with
48 additions
and
3 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
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestUpdateAllowedFromIP(t *testing.T) { | ||
userWithAllow := newACMETxt() | ||
userWithAllow.AllowFrom = cidrslice{"192.168.1.2/32", "[::1]/128"} | ||
userWithoutAllow := newACMETxt() | ||
|
||
for i, test := range []struct { | ||
remoteaddr string | ||
expected bool | ||
}{ | ||
{"192.168.1.2:1234", true}, | ||
{"192.168.1.1:1234", false}, | ||
{"invalid", false}, | ||
{"[::1]:4567", true}, | ||
} { | ||
newreq, _ := http.NewRequest("GET", "/whatever", nil) | ||
newreq.RemoteAddr = test.remoteaddr | ||
ret := updateAllowedFromIP(newreq, userWithAllow) | ||
if test.expected != ret { | ||
t.Errorf("Test %d: Unexpected result for user with allowForm set", i) | ||
} | ||
|
||
if !updateAllowedFromIP(newreq, userWithoutAllow) { | ||
t.Errorf("Test %d: Unexpected result for user without allowForm set", i) | ||
} | ||
} | ||
} |
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