2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
2015-06-14 23:53:32 -08:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package store
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
2015-07-05 09:33:08 -08:00
|
|
|
"time"
|
2017-02-21 21:07:57 +09:00
|
|
|
|
|
|
|
|
"github.com/mattermost/platform/model"
|
2015-06-14 23:53:32 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSqlAuditStore(t *testing.T) {
|
|
|
|
|
Setup()
|
|
|
|
|
|
|
|
|
|
audit := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"}
|
2016-01-20 13:36:16 -06:00
|
|
|
Must(store.Audit().Save(audit))
|
2015-07-05 09:33:08 -08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2016-01-20 13:36:16 -06:00
|
|
|
Must(store.Audit().Save(audit))
|
2015-07-05 09:33:08 -08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2016-01-20 13:36:16 -06:00
|
|
|
Must(store.Audit().Save(audit))
|
2015-07-05 09:33:08 -08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2015-06-14 23:53:32 -08:00
|
|
|
audit.ExtraInfo = "extra"
|
2015-07-05 09:33:08 -08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2016-01-20 13:36:16 -06:00
|
|
|
Must(store.Audit().Save(audit))
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-07-05 09:33:08 -08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
2017-02-21 21:07:57 +09:00
|
|
|
c := store.Audit().Get(audit.UserId, 0, 100)
|
2015-06-14 23:53:32 -08:00
|
|
|
result := <-c
|
|
|
|
|
audits := result.Data.(model.Audits)
|
|
|
|
|
|
|
|
|
|
if len(audits) != 4 {
|
|
|
|
|
t.Fatal("Failed to save and retrieve 4 audit logs")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if audits[0].ExtraInfo != "extra" {
|
|
|
|
|
t.Fatal("Failed to save property for extra info")
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-21 21:07:57 +09:00
|
|
|
c = store.Audit().Get("missing", 0, 100)
|
2015-06-14 23:53:32 -08:00
|
|
|
result = <-c
|
|
|
|
|
audits = result.Data.(model.Audits)
|
|
|
|
|
|
|
|
|
|
if len(audits) != 0 {
|
|
|
|
|
t.Fatal("Should have returned empty because user_id is missing")
|
|
|
|
|
}
|
2015-11-15 18:18:02 -08:00
|
|
|
|
2017-02-21 21:07:57 +09:00
|
|
|
c = store.Audit().Get("", 0, 100)
|
2016-02-02 16:49:27 -05:00
|
|
|
result = <-c
|
|
|
|
|
audits = result.Data.(model.Audits)
|
|
|
|
|
|
2017-04-03 13:32:58 -04:00
|
|
|
if len(audits) < 4 {
|
2016-02-02 16:49:27 -05:00
|
|
|
t.Fatal("Failed to save and retrieve 4 audit logs")
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-20 13:36:16 -06:00
|
|
|
if r2 := <-store.Audit().PermanentDeleteByUser(audit.UserId); r2.Err != nil {
|
2015-11-15 18:18:02 -08:00
|
|
|
t.Fatal(r2.Err)
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|