MM-23935 extend session expiry on user activity (#14275)

* MM-23935  extend session expiry on user activity

- if user types anything before a session expires the session will be extended to now + session length

- ensures new session expiries are not written to DB too frequently

- new session store func for updating session ExpiresAt

- session length defaults for mobile and web/ldap changed from 180 days to 30 days
Этот коммит содержится в:
Doug Lauder
2020-05-06 15:41:10 -04:00
коммит произвёл GitHub
родитель 58305b080f
Коммит 5e59b5f70c
18 изменённых файлов: 349 добавлений и 5 удалений

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

@@ -213,6 +213,22 @@ func (_m *SessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int
return r0, r1
}
// UpdateExpiresAt provides a mock function with given fields: sessionId, time
func (_m *SessionStore) UpdateExpiresAt(sessionId string, time int64) *model.AppError {
ret := _m.Called(sessionId, time)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, int64) *model.AppError); ok {
r0 = rf(sessionId, time)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
}
return r0
}
// UpdateLastActivityAt provides a mock function with given fields: sessionId, time
func (_m *SessionStore) UpdateLastActivityAt(sessionId string, time int64) *model.AppError {
ret := _m.Called(sessionId, time)

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

@@ -26,6 +26,7 @@ func TestSessionStore(t *testing.T, ss store.Store) {
t.Run("SessionRemoveToken", func(t *testing.T) { testSessionRemoveToken(t, ss) })
t.Run("SessionUpdateDeviceId", func(t *testing.T) { testSessionUpdateDeviceId(t, ss) })
t.Run("SessionUpdateDeviceId2", func(t *testing.T) { testSessionUpdateDeviceId2(t, ss) })
t.Run("UpdateExpiresAt", func(t *testing.T) { testSessionStoreUpdateExpiresAt(t, ss) })
t.Run("UpdateLastActivityAt", func(t *testing.T) { testSessionStoreUpdateLastActivityAt(t, ss) })
t.Run("SessionCount", func(t *testing.T) { testSessionCount(t, ss) })
}
@@ -212,6 +213,21 @@ func testSessionUpdateDeviceId2(t *testing.T, ss store.Store) {
require.Nil(t, err)
}
func testSessionStoreUpdateExpiresAt(t *testing.T, ss store.Store) {
s1 := &model.Session{}
s1.UserId = model.NewId()
s1, err := ss.Session().Save(s1)
require.Nil(t, err)
err = ss.Session().UpdateExpiresAt(s1.Id, 1234567890)
require.Nil(t, err)
session, err := ss.Session().Get(s1.Id)
require.Nil(t, err)
require.EqualValues(t, session.ExpiresAt, 1234567890, "ExpiresAt not updated correctly")
}
func testSessionStoreUpdateLastActivityAt(t *testing.T, ss store.Store) {
s1 := &model.Session{}
s1.UserId = model.NewId()