Skip to content

Commit

Permalink
Merge pull request #176 from croessner/features
Browse files Browse the repository at this point in the history
Fix: Refactor and standardize function names
  • Loading branch information
croessner authored Nov 29, 2024
2 parents 107ac3d + 08ad60e commit 1691439
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 313 deletions.
128 changes: 50 additions & 78 deletions server/core/auth.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions server/core/bindjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func getErrorMsg(fe validator.FieldError) string {
return "Unknown error"
}

// handleJSONError handles JSON validation errors by aborting the request and returning a JSON response with error details.
func handleJSONError(ctx *gin.Context, err error) {
// HandleJSONError handles JSON validation errors by aborting the request and returning a JSON response with error details.
func HandleJSONError(ctx *gin.Context, err error) {
var validationErrors validator.ValidationErrors

if errors.As(err, &validationErrors) {
Expand Down
8 changes: 4 additions & 4 deletions server/core/bruteforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ func (a *AuthState) checkRepeatingBruteForcer(rules []config.BruteForceRule, net
return withError, alreadyTriggered, ruleNumber
}

// checkBruteForce is a method of the `AuthState` struct and is responsible for
// CheckBruteForce is a method of the `AuthState` struct and is responsible for
// telling whether the client IP should be blocked due to unrestricted unauthorized access attempts
// (i.e., a Brute Force attack on the system).
//
Expand All @@ -974,7 +974,7 @@ func (a *AuthState) checkRepeatingBruteForcer(rules []config.BruteForceRule, net
// the appropriate message, and runs a Lua script for handling the detected brute force attempt.
//
// It returns 'true' if a Brute Force attack is detected, otherwise returns 'false'.
func (a *AuthState) checkBruteForce() (blockClientIP bool) {
func (a *AuthState) CheckBruteForce() (blockClientIP bool) {
var (
ruleTriggered bool
message string
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func (a *AuthState) checkBruteForce() (blockClientIP bool) {
return a.processBruteForce(ruleTriggered, alreadyTriggered, &rules[ruleNumber], network, message)
}

// updateBruteForceBucketsCounter updates the brute force buckets counter for the current authentication
// UpdateBruteForceBucketsCounter updates the brute force buckets counter for the current authentication
// It checks if brute force is enabled for the current protocol and if the client IP is not in the whitelist
// Then it iterates through the loaded brute force rules and saves the bucket counter to Redis
// The method also logs debug information related to the authentication
Expand All @@ -1064,7 +1064,7 @@ func (a *AuthState) checkBruteForce() (blockClientIP bool) {
// - a: a pointer to the AuthState struct which contains the authentication details
//
// Returns: none
func (a *AuthState) updateBruteForceBucketsCounter() {
func (a *AuthState) UpdateBruteForceBucketsCounter() {
if !config.LoadableConfig.HasFeature(definitions.FeatureBruteForce) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/core/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/croessner/nauthilus/server/util"
)

// cachePassDB implements the redis password database backend.
func cachePassDB(auth *AuthState) (passDBResult *PassDBResult, err error) {
// CachePassDB implements the redis password database backend.
func CachePassDB(auth *AuthState) (passDBResult *PassDBResult, err error) {
var (
accountName string
ppc *backend.PositivePasswordCache
Expand Down
16 changes: 8 additions & 8 deletions server/core/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func logAddLocalhost(auth *AuthState, feature string) {
auth.AdditionalLogs = append(auth.AdditionalLogs, definitions.Localhost)
}

// featureLua runs Lua scripts and returns a trigger result.
func (a *AuthState) featureLua(ctx *gin.Context) (triggered bool, abortFeatures bool, err error) {
// FeatureLua runs Lua scripts and returns a trigger result.
func (a *AuthState) FeatureLua(ctx *gin.Context) (triggered bool, abortFeatures bool, err error) {
if isLocalOrEmptyIP(a.ClientIP) {
logAddLocalhost(a, definitions.FeatureLua)

Expand Down Expand Up @@ -162,8 +162,8 @@ func (a *AuthState) featureLua(ctx *gin.Context) (triggered bool, abortFeatures
return
}

// featureTLSEncryption checks, if the remote client connection was secured.
func (a *AuthState) featureTLSEncryption() (triggered bool) {
// FeatureTLSEncryption checks, if the remote client connection was secured.
func (a *AuthState) FeatureTLSEncryption() (triggered bool) {
if isLocalOrEmptyIP(a.ClientIP) {
logAddLocalhost(a, definitions.FeatureTLSEncryption)

Expand Down Expand Up @@ -193,9 +193,9 @@ func (a *AuthState) featureTLSEncryption() (triggered bool) {
return
}

// featureRelayDomains triggers if a user sent an email address as a login name and the domain component does not
// FeatureRelayDomains triggers if a user sent an email address as a login name and the domain component does not
// match the list of known domains.
func (a *AuthState) featureRelayDomains() (triggered bool) {
func (a *AuthState) FeatureRelayDomains() (triggered bool) {
if config.LoadableConfig.RelayDomains == nil {
return
}
Expand Down Expand Up @@ -361,10 +361,10 @@ func (a *AuthState) checkRBLs(ctx *gin.Context) (totalRBLScore int, err error) {
return
}

// featureRBLs is a method that checks if the client IP address is whitelisted, and then performs an RBL check
// FeatureRBLs is a method that checks if the client IP address is whitelisted, and then performs an RBL check
// on the client's IP address. If the RBL score exceeds the configured threshold, the 'triggered' flag is set to true.
// It returns the 'triggered' flag and any error that occurred during the check.
func (a *AuthState) featureRBLs(ctx *gin.Context) (triggered bool, err error) {
func (a *AuthState) FeatureRBLs(ctx *gin.Context) (triggered bool, err error) {
var (
totalRBLScore int
)
Expand Down
Loading

0 comments on commit 1691439

Please sign in to comment.