[MM-27623] Add new session prop for oauth (#15221)
* Add new session prop for oauth * Make it isOAuthUser to differentiate better * Fix up caps * Fix tests * Add tests for IsOAuthUser
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a540dcdf9c
Коммит
101c6c7c01
@@ -15,6 +15,7 @@ const (
|
||||
USER_AUTH_SERVICE_SAML_TEXT = "SAML"
|
||||
USER_AUTH_SERVICE_IS_SAML = "isSaml"
|
||||
USER_AUTH_SERVICE_IS_MOBILE = "isMobile"
|
||||
USER_AUTH_SERVICE_IS_OAUTH = "isOAuthUser"
|
||||
)
|
||||
|
||||
type SamlAuthRequest struct {
|
||||
|
||||
@@ -175,8 +175,21 @@ func (me *Session) IsSaml() bool {
|
||||
return isSaml
|
||||
}
|
||||
|
||||
func (me *Session) IsOAuthUser() bool {
|
||||
val, ok := me.Props[USER_AUTH_SERVICE_IS_OAUTH]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
isOAuthUser, err := strconv.ParseBool(val)
|
||||
if err != nil {
|
||||
mlog.Error("Error parsing boolean property from Session", mlog.Err(err))
|
||||
return false
|
||||
}
|
||||
return isOAuthUser
|
||||
}
|
||||
|
||||
func (me *Session) IsSSOLogin() bool {
|
||||
return me.IsOAuth || me.IsSaml()
|
||||
return me.IsOAuthUser() || me.IsSaml()
|
||||
}
|
||||
|
||||
func (me *Session) GetUserRoles() []string {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -72,3 +73,23 @@ func TestSessionCSRF(t *testing.T) {
|
||||
assert.NotEmpty(t, token2)
|
||||
assert.Equal(t, token, token2)
|
||||
}
|
||||
|
||||
func TestSessionIsOAuthUser(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Description string
|
||||
Session Session
|
||||
isOAuthUser bool
|
||||
}{
|
||||
{"False on empty props", Session{}, false},
|
||||
{"True when key is set to true", Session{Props: StringMap{USER_AUTH_SERVICE_IS_OAUTH: strconv.FormatBool(true)}}, true},
|
||||
{"False when key is set to false", Session{Props: StringMap{USER_AUTH_SERVICE_IS_OAUTH: strconv.FormatBool(false)}}, false},
|
||||
{"Not affected by Session.IsOauth being true", Session{IsOAuth: true}, false},
|
||||
{"Not affected by Session.IsOauth being false", Session{IsOAuth: false, Props: StringMap{USER_AUTH_SERVICE_IS_OAUTH: strconv.FormatBool(true)}}, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Description, func(t *testing.T) {
|
||||
require.Equal(t, tc.isOAuthUser, tc.Session.IsOAuthUser())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user