[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
Этот коммит содержится в:
Farhan Munshi
2020-08-11 10:24:26 -04:00
коммит произвёл GitHub
родитель a540dcdf9c
Коммит 101c6c7c01
8 изменённых файлов: 48 добавлений и 10 удалений

Просмотреть файл

@@ -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())
})
}
}