From 01bbf7ee06ef8ebadfad256c45be8695b2ae8b98 Mon Sep 17 00:00:00 2001 From: "alex.alequin" Date: Mon, 26 Feb 2024 16:48:43 -0500 Subject: [PATCH 1/2] add a break in inner loop once mech is found to cause the outer loop to decrement avoiding "panic: runtime error: index out of range" --- pkg/authmechs/authemechs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/authmechs/authemechs.go b/pkg/authmechs/authemechs.go index ff3790c..2406e61 100644 --- a/pkg/authmechs/authemechs.go +++ b/pkg/authmechs/authemechs.go @@ -33,6 +33,7 @@ func removeMechsInDB(db AuthDB, mechList []string) AuthDB { for _, mechToRemove := range mechList { if db.Mechanisms[i] == mechToRemove { db.Mechanisms = append(db.Mechanisms[:i], db.Mechanisms[i+1:]...) + break } } } From 89e6e3be94a9744af7a2f5c97f05b63c19c21195 Mon Sep 17 00:00:00 2001 From: "alex.alequin" Date: Mon, 26 Feb 2024 16:50:52 -0500 Subject: [PATCH 2/2] - Added simplified test to represent failure cause. - Added real world data for scenario that caused failures originally. --- pkg/authmechs/authmechs_test.go | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pkg/authmechs/authmechs_test.go b/pkg/authmechs/authmechs_test.go index 9439b0a..53fd1ce 100644 --- a/pkg/authmechs/authmechs_test.go +++ b/pkg/authmechs/authmechs_test.go @@ -26,12 +26,63 @@ func TestRemoveMechsInDB(t *testing.T) { mechList: []string{"mech1", "mech2"}, want: AuthDB{Mechanisms: []string{"mech3"}}, }, + { + name: "Test with non-empty db and mechList where the removed mechs are at the end of the slice", + db: AuthDB{Mechanisms: []string{"mech1", "mech2", "mech3"}}, + mechList: []string{"mech2", "mech3"}, + want: AuthDB{Mechanisms: []string{"mech1"}}, + }, { name: "Test with non-empty db and empty mechList", db: AuthDB{Mechanisms: []string{"mech1", "mech2", "mech3"}}, mechList: []string{}, want: AuthDB{Mechanisms: []string{"mech1", "mech2", "mech3"}}, }, + { + name: "Test with real data on device updated from python Crypt", + db: AuthDB{Mechanisms: []string{ + "builtin:prelogin", + "builtin:policy-banner", + "loginwindow:login", + "builtin:login-begin", + "builtin:reset-password,privileged", + "loginwindow:FDESupport,privileged", + "builtin:forward-login,privileged", + "builtin:auto-login,privileged", + "builtin:authenticate,privileged", + "PKINITMechanism:auth,privileged", + "builtin:login-success", + "loginwindow:success", + "HomeDirMechanism:login,privileged", + "HomeDirMechanism:status", + "MCXMechanism:login", + "CryptoTokenKit:login", + "loginwindow:done", + "Crypt:Check,privileged", + "Crypt:CryptGUI", + "Crypt:Enablement,privileged", + }}, + mechList: []string{"Crypt:Check,privileged", "Crypt:CryptGUI", "Crypt:Enablement,privileged"}, + want: AuthDB{Mechanisms: []string{ + "builtin:prelogin", + "builtin:policy-banner", + "loginwindow:login", + "builtin:login-begin", + "builtin:reset-password,privileged", + "loginwindow:FDESupport,privileged", + "builtin:forward-login,privileged", + "builtin:auto-login,privileged", + "builtin:authenticate,privileged", + "PKINITMechanism:auth,privileged", + "builtin:login-success", + "loginwindow:success", + "HomeDirMechanism:login,privileged", + "HomeDirMechanism:status", + "MCXMechanism:login", + "CryptoTokenKit:login", + "loginwindow:done", + }}, + }, } for _, tt := range tests {