Commit 17567196 authored by ale's avatar ale

Add method to check for supported 2FA mechanism in response

parent aedc1339
Pipeline #2830 failed with stages
in 1 minute and 17 seconds
......@@ -146,6 +146,17 @@ type Response struct {
UserInfo *UserInfo
}
// Has2FAMethod checks for the presence of a two-factor authentication
// method in the Response.
func (r *Response) Has2FAMethod(needle TFAMethod) bool {
for _, m := range r.TFAMethods {
if m == needle {
return true
}
}
return false
}
func encodeTFAMethodList(m map[string]string, prefix string, l []TFAMethod) {
if len(l) == 0 {
return
......
......@@ -171,17 +171,8 @@ func runAuthenticationTest(t *testing.T, client client.Client) {
if resp.Status != td.expectedStatus {
t.Errorf("authentication error: s=interactive u=%s p=%s, expected=%v got=%v", td.username, td.password, td.expectedStatus, resp.Status)
}
if td.expectedTFAMethod != auth.TFAMethodNone {
found := false
for _, m := range resp.TFAMethods {
if m == td.expectedTFAMethod {
found = true
break
}
}
if !found {
t.Errorf("mismatch in TFAMethod hint in authentication response: s=interactive u=%s p=%s, expected=%v got=%v", td.username, td.password, td.expectedTFAMethod, resp.TFAMethods)
}
if td.expectedTFAMethod != auth.TFAMethodNone && !resp.Has2FAMethod(td.expectedTFAMethod) {
t.Errorf("mismatch in TFAMethod hint in authentication response: s=interactive u=%s p=%s, expected=%v got=%v", td.username, td.password, td.expectedTFAMethod, resp.TFAMethods)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment