Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tinyauth/internal/docker"
"tinyauth/internal/handlers"
"tinyauth/internal/hooks"
"tinyauth/internal/ldap"
"tinyauth/internal/providers"
"tinyauth/internal/server"
"tinyauth/internal/types"
Expand Down Expand Up @@ -58,10 +59,6 @@
users, err := utils.GetUsers(config.Users, config.UsersFile)
HandleError(err, "Failed to parse users")

if len(users) == 0 && !utils.OAuthConfigured(config) {
HandleError(errors.New("no users or OAuth configured"), "No users or OAuth configured")
}

// Get domain
log.Debug().Msg("Getting domain")
domain, err := utils.GetUpperDomain(config.AppURL)
Expand Down Expand Up @@ -143,8 +140,35 @@
docker, err := docker.NewDocker()
HandleError(err, "Failed to initialize docker")

// Create LDAP service if configured
var ldapService *ldap.LDAP

if config.LdapAddress != "" {
log.Info().Msg("Using LDAP for authentication")

ldapConfig := types.LdapConfig{
Address: config.LdapAddress,
BindDN: config.LdapBindDN,
BindPassword: config.LdapBindPassword,
BaseDN: config.LdapBaseDN,
Insecure: config.LdapInsecure,
SearchFilter: config.LdapSearchFilter,
}

// Create LDAP service
ldapService, err = ldap.NewLDAP(ldapConfig)
HandleError(err, "Failed to create LDAP service")
} else {
log.Info().Msg("LDAP not configured, using local users or OAuth")
}

Check warning on line 163 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L143-L163

Added lines #L143 - L163 were not covered by tests

// Check if we have any users configured
if len(users) == 0 && !utils.OAuthConfigured(config) && ldapService == nil {
HandleError(errors.New("err no users"), "Unable to find a source of users")
}

Check warning on line 168 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L166-L168

Added lines #L166 - L168 were not covered by tests

// Create auth service
auth := auth.NewAuth(authConfig, docker)
auth := auth.NewAuth(authConfig, docker, ldapService)

Check warning on line 171 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L171

Added line #L171 was not covered by tests

// Create OAuth providers service
providers := providers.NewProviders(oauthConfig)
Expand Down Expand Up @@ -221,6 +245,12 @@
rootCmd.Flags().String("app-title", "Tinyauth", "Title of the app.")
rootCmd.Flags().String("forgot-password-message", "You can reset your password by changing the `USERS` environment variable.", "Message to show on the forgot password page.")
rootCmd.Flags().String("background-image", "/background.jpg", "Background image URL for the login page.")
rootCmd.Flags().String("ldap-address", "", "LDAP server address (e.g. ldap://localhost:389).")
rootCmd.Flags().String("ldap-bind-dn", "", "LDAP bind DN (e.g. uid=user,dc=example,dc=com).")
rootCmd.Flags().String("ldap-bind-password", "", "LDAP bind password.")
rootCmd.Flags().String("ldap-base-dn", "", "LDAP base DN (e.g. dc=example,dc=com).")
rootCmd.Flags().Bool("ldap-insecure", false, "Skip certificate verification for the LDAP server.")
rootCmd.Flags().String("ldap-search-filter", "(uid=%s)", "LDAP search filter for user lookup.")

Check warning on line 253 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L248-L253

Added lines #L248 - L253 were not covered by tests

// Bind flags to environment
viper.BindEnv("port", "PORT")
Expand Down Expand Up @@ -256,6 +286,12 @@
viper.BindEnv("login-max-retries", "LOGIN_MAX_RETRIES")
viper.BindEnv("forgot-password-message", "FORGOT_PASSWORD_MESSAGE")
viper.BindEnv("background-image", "BACKGROUND_IMAGE")
viper.BindEnv("ldap-address", "LDAP_ADDRESS")
viper.BindEnv("ldap-bind-dn", "LDAP_BIND_DN")
viper.BindEnv("ldap-bind-password", "LDAP_BIND_PASSWORD")
viper.BindEnv("ldap-base-dn", "LDAP_BASE_DN")
viper.BindEnv("ldap-insecure", "LDAP_INSECURE")
viper.BindEnv("ldap-search-filter", "LDAP_SEARCH_FILTER")

Check warning on line 294 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L289-L294

Added lines #L289 - L294 were not covered by tests

// Bind flags to viper
viper.BindPFlags(rootCmd.Flags())
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/login-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export const LoginPage = () => {
/>
)}
{configuredProviders.length == 0 && (
<h3 className="text-center text-xl text-red-600">
<p className="text-center text-red-600 max-w-sm">
{t("failedToFetchProvidersTitle")}
</h3>
</p>
)}
</CardContent>
</Card>
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ require (
)

require (
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
Comment thread
steveiliop56 marked this conversation as resolved.
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
github.com/moby/sys/atomicwriter v0.1.0 // indirect
github.com/moby/term v0.5.2 // indirect
Expand Down Expand Up @@ -60,6 +62,7 @@ require (
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gin-contrib/sse v1.0.0 // indirect
github.com/go-ldap/ldap/v3 v3.4.11
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand Down
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa h1:LHTHcTQiSGT7VVbI0o4wBRNQIgn917usHWOd6VAffYI=
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand Down Expand Up @@ -90,6 +94,10 @@ github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 h1:BP4M0CvQ4S3TGls2FvczZtj5Re/2ZzkV9VwqPHH/3Bo=
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-ldap/ldap/v3 v3.4.11 h1:4k0Yxweg+a3OyBLjdYn5OKglv18JNvfDykSoI8bW0gU=
github.com/go-ldap/ldap/v3 v3.4.11/go.mod h1:bY7t0FLK8OAVpp/vV6sSlpz3EQDGcQwc8pF0ujLgKvM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down Expand Up @@ -126,8 +134,22 @@ github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzq
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1/go.mod h1:RBRO7fro65R6tjKzYgLAFo0t1QEXY1Dp+i/bvpRiqiQ=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
96 changes: 91 additions & 5 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"sync"
"time"
"tinyauth/internal/docker"
"tinyauth/internal/ldap"
"tinyauth/internal/types"
"tinyauth/internal/utils"

Expand All @@ -22,9 +23,10 @@
LoginAttempts map[string]*types.LoginAttempt
LoginMutex sync.RWMutex
Store *sessions.CookieStore
LDAP *ldap.LDAP
}

func NewAuth(config types.AuthConfig, docker *docker.Docker) *Auth {
func NewAuth(config types.AuthConfig, docker *docker.Docker, ldap *ldap.LDAP) *Auth {
// Create cookie store
store := sessions.NewCookieStore([]byte(config.HMACSecret), []byte(config.EncryptionSecret))

Expand All @@ -42,6 +44,7 @@
Docker: docker,
LoginAttempts: make(map[string]*types.LoginAttempt),
Store: store,
LDAP: ldap,
}
}

Expand All @@ -68,14 +71,97 @@
return session, nil
}

func (auth *Auth) GetUser(username string) *types.User {
func (auth *Auth) SearchUser(username string) types.UserSearch {

Check warning on line 74 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L74

Added line #L74 was not covered by tests
// Loop through users and return the user if the username matches
log.Debug().Str("username", username).Msg("Searching for user")

if auth.GetLocalUser(username).Username != "" {
log.Debug().Str("username", username).Msg("Found local user")

// If user found, return a user with the username and type "local"
return types.UserSearch{
Username: username,
Type: "local",
}
}

Check warning on line 86 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L76-L86

Added lines #L76 - L86 were not covered by tests

// If no user found, check LDAP
if auth.LDAP != nil {
log.Debug().Str("username", username).Msg("Checking LDAP for user")

userDN, err := auth.LDAP.Search(username)
Comment thread
steveiliop56 marked this conversation as resolved.
if err != nil {
log.Warn().Err(err).Str("username", username).Msg("Failed to find user in LDAP")
return types.UserSearch{}
}

Check warning on line 96 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L89-L96

Added lines #L89 - L96 were not covered by tests

// If user found in LDAP, return a user with the DN as username
return types.UserSearch{
Username: userDN,
Type: "ldap",
}

Check warning on line 102 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L99-L102

Added lines #L99 - L102 were not covered by tests
}

return types.UserSearch{}

Check warning on line 105 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L105

Added line #L105 was not covered by tests
}

func (auth *Auth) VerifyUser(search types.UserSearch, password string) bool {
// Authenticate the user based on the type
switch search.Type {
case "local":
// Get local user
user := auth.GetLocalUser(search.Username)

// Check if password is correct
return auth.CheckPassword(user, password)
case "ldap":
// If LDAP is configured, bind to the LDAP server with the user DN and password
if auth.LDAP != nil {
log.Debug().Str("username", search.Username).Msg("Binding to LDAP for user authentication")

// Bind to the LDAP server
err := auth.LDAP.Bind(search.Username, password)
if err != nil {
log.Warn().Err(err).Str("username", search.Username).Msg("Failed to bind to LDAP")
return false
}

Check warning on line 127 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L108-L127

Added lines #L108 - L127 were not covered by tests

// If bind is successful, rebind with the LDAP bind user
err = auth.LDAP.Bind(auth.LDAP.Config.BindDN, auth.LDAP.Config.BindPassword)
if err != nil {
log.Error().Err(err).Msg("Failed to rebind with service account after user authentication")
// Consider closing the connection or creating a new one
return false
}

Check warning on line 135 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L130-L135

Added lines #L130 - L135 were not covered by tests

log.Debug().Str("username", search.Username).Msg("LDAP authentication successful")

// Return true if the bind was successful
return true

Check warning on line 140 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L137-L140

Added lines #L137 - L140 were not covered by tests
}
default:
log.Warn().Str("type", search.Type).Msg("Unknown user type for authentication")
return false

Check warning on line 144 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L142-L144

Added lines #L142 - L144 were not covered by tests
}

// If no user found or authentication failed, return false
log.Warn().Str("username", search.Username).Msg("User authentication failed")
return false

Check warning on line 149 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L148-L149

Added lines #L148 - L149 were not covered by tests
}
Comment on lines +74 to +150
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding comprehensive unit tests for LDAP functionality

The static analysis shows extensive test coverage gaps for the new LDAP functionality. Given the security-critical nature of authentication code and the complexity of the dual authentication flow, comprehensive unit tests are essential.

Would you like me to help generate unit tests that cover:

  • SearchUser method with both local and LDAP scenarios
  • VerifyUser method for both authentication types
  • Error handling paths and edge cases
  • LDAP connection failures and timeouts
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 74-74: internal/auth/auth.go#L74
Added line #L74 was not covered by tests


[warning] 76-86: internal/auth/auth.go#L76-L86
Added lines #L76 - L86 were not covered by tests


[warning] 89-96: internal/auth/auth.go#L89-L96
Added lines #L89 - L96 were not covered by tests


[warning] 99-102: internal/auth/auth.go#L99-L102
Added lines #L99 - L102 were not covered by tests


[warning] 105-105: internal/auth/auth.go#L105
Added line #L105 was not covered by tests


[warning] 108-127: internal/auth/auth.go#L108-L127
Added lines #L108 - L127 were not covered by tests


[warning] 130-135: internal/auth/auth.go#L130-L135
Added lines #L130 - L135 were not covered by tests


[warning] 137-140: internal/auth/auth.go#L137-L140
Added lines #L137 - L140 were not covered by tests


[warning] 142-144: internal/auth/auth.go#L142-L144
Added lines #L142 - L144 were not covered by tests


[warning] 148-149: internal/auth/auth.go#L148-L149
Added lines #L148 - L149 were not covered by tests

🤖 Prompt for AI Agents
In internal/auth/auth.go from lines 74 to 150, the LDAP functionality in
SearchUser and VerifyUser lacks comprehensive unit tests. Add unit tests
covering SearchUser for both local user found and LDAP user found scenarios,
VerifyUser for local and LDAP authentication success and failure cases,
including error handling paths such as LDAP search errors, bind failures, and
rebind failures. Also include tests for edge cases like nil LDAP configuration
and unknown user types to ensure full coverage of the dual authentication flow.


func (auth *Auth) GetLocalUser(username string) types.User {
// Loop through users and return the user if the username matches
log.Debug().Str("username", username).Msg("Searching for local user")

Check warning on line 155 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L152-L155

Added lines #L152 - L155 were not covered by tests
for _, user := range auth.Config.Users {
if user.Username == username {
return &user
return user

Check warning on line 158 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L158

Added line #L158 was not covered by tests
}
}
return nil

// If no user found, return an empty user
log.Warn().Str("username", username).Msg("Local user not found")
return types.User{}

Check warning on line 164 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L163-L164

Added lines #L163 - L164 were not covered by tests
}

func (auth *Auth) CheckPassword(user types.User, password string) bool {
Expand Down Expand Up @@ -275,7 +361,7 @@

func (auth *Auth) UserAuthConfigured() bool {
// If there are users, return true
return len(auth.Config.Users) > 0
return len(auth.Config.Users) > 0 || auth.LDAP != nil

Check warning on line 364 in internal/auth/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/auth/auth.go#L364

Added line #L364 was not covered by tests
}

func (auth *Auth) ResourceAllowed(c *gin.Context, context types.UserContext, labels types.Labels) bool {
Expand Down
8 changes: 4 additions & 4 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLoginRateLimiting(t *testing.T) {
// Initialize a new auth service with 3 max retries and 5 seconds timeout
config.LoginMaxRetries = 3
config.LoginTimeout = 5
authService := auth.NewAuth(config, &docker.Docker{})
authService := auth.NewAuth(config, &docker.Docker{}, nil)

// Test identifier
identifier := "test_user"
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestLoginRateLimiting(t *testing.T) {
// Reinitialize auth service with a shorter timeout for testing
config.LoginTimeout = 1
config.LoginMaxRetries = 3
authService = auth.NewAuth(config, &docker.Docker{})
authService = auth.NewAuth(config, &docker.Docker{}, nil)

// Add enough failed attempts to lock the account
for i := 0; i < 3; i++ {
Expand All @@ -87,7 +87,7 @@ func TestLoginRateLimiting(t *testing.T) {
t.Log("Testing disabled rate limiting")
config.LoginMaxRetries = 0
config.LoginTimeout = 0
authService = auth.NewAuth(config, &docker.Docker{})
authService = auth.NewAuth(config, &docker.Docker{}, nil)

for i := 0; i < 10; i++ {
authService.RecordLoginAttempt(identifier, false)
Expand All @@ -103,7 +103,7 @@ func TestConcurrentLoginAttempts(t *testing.T) {
// Initialize a new auth service with 2 max retries and 5 seconds timeout
config.LoginMaxRetries = 2
config.LoginTimeout = 5
authService := auth.NewAuth(config, &docker.Docker{})
authService := auth.NewAuth(config, &docker.Docker{}, nil)

// Test multiple identifiers
identifiers := []string{"user1", "user2", "user3"}
Expand Down
Loading