Skip to content

Commit

Permalink
Merge pull request #120 from Arequ/fix_removeMechsInDB
Browse files Browse the repository at this point in the history
Fix remove mechs in db
  • Loading branch information
grahamgilbert authored Apr 24, 2024
2 parents 612593d + 89e6e3b commit dcc2ea5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/authmechs/authemechs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/authmechs/authmechs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit dcc2ea5

Please sign in to comment.