style: Some minor fixes (#548)
* chore(deps): update dependencies in go.mod and go.sum Signed-off-by: Jason Cameron <git@jasoncameron.dev> * refactor: rename variables for clarity in anubis.go and main.go Signed-off-by: Jason Cameron <git@jasoncameron.dev> * fix(checker): handle error when inserting IP range in ranger Signed-off-by: Jason Cameron <git@jasoncameron.dev> * fix(tests): simplify boolean checks in header and URL value tests Signed-off-by: Jason Cameron <git@jasoncameron.dev> * refactor(api): remove unused /test-error endpoint and restrict /make-challenge to development Signed-off-by: Jason Cameron <git@jasoncameron.dev> * build(deps): update golang-set to v2.8.0 in go.sum Signed-off-by: Jason Cameron <git@jasoncameron.dev> * Update metadata check-spelling run (pull_request) for json/stuff Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com> on-behalf-of: @check-spelling <check-spelling-bot@check-spelling.dev> --------- Signed-off-by: Jason Cameron <git@jasoncameron.dev> Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
This commit is contained in:
parent
8eff57fcb6
commit
9539668049
11 changed files with 112 additions and 56 deletions
|
|
@ -66,10 +66,10 @@ type Server struct {
|
|||
policy *policy.ParsedConfig
|
||||
DNSBLCache *decaymap.Impl[string, dnsbl.DroneBLResponse]
|
||||
OGTags *ogtags.OGTagCache
|
||||
cookieName string
|
||||
priv ed25519.PrivateKey
|
||||
pub ed25519.PublicKey
|
||||
opts Options
|
||||
cookieName string
|
||||
}
|
||||
|
||||
func (s *Server) challengeFor(r *http.Request, difficulty int) string {
|
||||
|
|
@ -402,11 +402,6 @@ func (s *Server) PassChallenge(w http.ResponseWriter, r *http.Request) {
|
|||
http.Redirect(w, r, redir, http.StatusFound)
|
||||
}
|
||||
|
||||
func (s *Server) TestError(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.FormValue("err")
|
||||
s.respondWithError(w, r, err)
|
||||
}
|
||||
|
||||
func cr(name string, rule config.Rule) policy.CheckResult {
|
||||
return policy.CheckResult{
|
||||
Name: name,
|
||||
|
|
|
|||
|
|
@ -145,12 +145,16 @@ func New(opts Options) (*Server, error) {
|
|||
}), "GET")
|
||||
}
|
||||
|
||||
registerWithPrefix(anubis.APIPrefix+"make-challenge", http.HandlerFunc(result.MakeChallenge), "POST")
|
||||
registerWithPrefix(anubis.APIPrefix+"pass-challenge", http.HandlerFunc(result.PassChallenge), "GET")
|
||||
registerWithPrefix(anubis.APIPrefix+"check", http.HandlerFunc(result.maybeReverseProxyHttpStatusOnly), "")
|
||||
registerWithPrefix(anubis.APIPrefix+"test-error", http.HandlerFunc(result.TestError), "GET")
|
||||
registerWithPrefix("/", http.HandlerFunc(result.maybeReverseProxyOrPage), "")
|
||||
|
||||
//goland:noinspection GoBoolExpressions
|
||||
if anubis.Version == "devel" {
|
||||
// make-challenge is only used in tests. Only enable while version is devel
|
||||
registerWithPrefix(anubis.APIPrefix+"make-challenge", http.HandlerFunc(result.MakeChallenge), "POST")
|
||||
}
|
||||
|
||||
for _, implKind := range challenge.Methods() {
|
||||
impl, _ := challenge.Get(implKind)
|
||||
impl.Setup(mux)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,10 @@ func NewRemoteAddrChecker(cidrs []string) (Checker, error) {
|
|||
return nil, fmt.Errorf("%w: range %s not parsing: %w", ErrMisconfiguration, cidr, err)
|
||||
}
|
||||
|
||||
ranger.Insert(cidranger.NewBasicRangerEntry(*rng))
|
||||
err = ranger.Insert(cidranger.NewBasicRangerEntry(*rng))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: error inserting ip range: %w", ErrMisconfiguration, err)
|
||||
}
|
||||
fmt.Fprintln(&sb, cidr)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@ func TestHTTPHeaders(t *testing.T) {
|
|||
|
||||
t.Run("contains-existing-header", func(t *testing.T) {
|
||||
resp := headers.Contains(types.String("User-Agent"))
|
||||
if !bool(resp.(types.Bool)) {
|
||||
if !resp.(types.Bool) {
|
||||
t.Fatal("headers does not contain User-Agent")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not-contains-missing-header", func(t *testing.T) {
|
||||
resp := headers.Contains(types.String("Xxx-Random-Header"))
|
||||
if bool(resp.(types.Bool)) {
|
||||
if resp.(types.Bool) {
|
||||
t.Fatal("headers does not contain User-Agent")
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ func TestURLValues(t *testing.T) {
|
|||
|
||||
t.Run("contains-existing-key", func(t *testing.T) {
|
||||
resp := headers.Contains(types.String("format"))
|
||||
if !bool(resp.(types.Bool)) {
|
||||
if !resp.(types.Bool) {
|
||||
t.Fatal("headers does not contain User-Agent")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not-contains-missing-key", func(t *testing.T) {
|
||||
resp := headers.Contains(types.String("not-there"))
|
||||
if bool(resp.(types.Bool)) {
|
||||
if resp.(types.Bool) {
|
||||
t.Fatal("headers does not contain User-Agent")
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue