Skip to content

Commit

Permalink
Remove deprecated code and fix new project tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jannfis committed Apr 16, 2020
1 parent e94869a commit d8a3a5e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
6 changes: 3 additions & 3 deletions server/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestProjectServer(t *testing.T) {
})

t.Run("TestCreateTokenWithIDSuccessfully", func(t *testing.T) {
sessionMgr := session.NewSessionManager(settingsMgr, "")
sessionMgr := session.NewSessionManager(settingsMgr, "", newSessionCache())
projectWithRole := existingProj.DeepCopy()
projectWithRole.Spec.Roles = []v1alpha1.ProjectRole{{Name: tokenName}}
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projectWithRole), enforcer, util.NewKeyLock(), sessionMgr)
Expand All @@ -348,7 +348,7 @@ func TestProjectServer(t *testing.T) {
})

t.Run("TestCreateTokenWithSameIdDeny", func(t *testing.T) {
sessionMgr := session.NewSessionManager(settingsMgr, "")
sessionMgr := session.NewSessionManager(settingsMgr, "", newSessionCache())
projectWithRole := existingProj.DeepCopy()
projectWithRole.Spec.Roles = []v1alpha1.ProjectRole{{Name: tokenName}}
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projectWithRole), enforcer, util.NewKeyLock(), sessionMgr)
Expand Down Expand Up @@ -423,7 +423,7 @@ p, role:admin, projects, update, *, allow`)
p, role:admin, projects, update, *, allow`)

t.Run("TestDeleteTokenByIdSuccessfully", func(t *testing.T) {
sessionMgr := session.NewSessionManager(settingsMgr, "")
sessionMgr := session.NewSessionManager(settingsMgr, "", newSessionCache())
projWithToken := existingProj.DeepCopy()
issuedAt := int64(1)
secondIssuedAt := issuedAt + 1
Expand Down
13 changes: 0 additions & 13 deletions util/session/sessionmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ const (
envLoginMaxCacheSize = "ARGOCD_SESSION_MAX_CACHE_SIZE"
)

// Returns the cache key to use for a given user
func getSessionCacheKeyForUser(username string) string {
return fmt.Sprintf("%s|%s", loginAttemptsCacheKey, username)
}

// Helper function to parse a number from an environment variable. Returns a
// default if env is not set, is not parseable to a number, exceeds max (if
// max is greater than 0) or is less than min.
Expand Down Expand Up @@ -330,18 +325,10 @@ func (mgr *SessionManager) updateFailureCount(username string, failed bool) {
if failed {
attempt.FailCount += 1
attempt.LastFailed = time.Now()
err := mgr.cache.SetItem(getSessionCacheKeyForUser(username), attempt, 0, false)
if err != nil {
log.Errorf("Could not update session cache: %s", err.Error())
}
failures[username] = attempt
log.Warnf("User %s failed login %d time(s)", username, attempt.FailCount)
} else {
if attempt.FailCount > 0 {
err := mgr.cache.SetItem(getSessionCacheKeyForUser(username), attempt, 0, true)
if err != nil {
log.Errorf("Could not update session cache: %s", err.Error())
}
// Forget username for cache size enforcement, since entry in cache was deleted
delete(failures, username)
}
Expand Down

0 comments on commit d8a3a5e

Please sign in to comment.