mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-11-01 18:38:06 +00:00
add new test to auto expire user records
This commit is contained in:
@@ -108,7 +108,7 @@ func init() {
|
||||
cfg.Policy.MaxSessionRetentionPeriod = "1h"
|
||||
cfg.Policy.MaxShareableRecordRetentionPeriod = "1m"
|
||||
}
|
||||
e := mainEnv{db, cfg, make(chan struct{})}
|
||||
e = mainEnv{db, cfg, make(chan struct{})}
|
||||
rootToken2, err := e.db.getRootXtoken()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to retrieve root token: %s\n", err)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
@@ -19,6 +22,14 @@ func helpStartExp(utoken string) (map[string]interface{}, error) {
|
||||
return helpServe(request)
|
||||
}
|
||||
|
||||
func helpStartExp2(utoken string, t int32) (map[string]interface{}, error) {
|
||||
data := fmt.Sprintf(`{"expiration": %d}`, t)
|
||||
url := "http://localhost:3000/v1/exp/start/token/" + utoken
|
||||
request := httptest.NewRequest("POST", url, strings.NewReader(data))
|
||||
request.Header.Set("X-Bunker-Token", rootToken)
|
||||
return helpServe(request)
|
||||
}
|
||||
|
||||
func helpRetainData(exptoken string) (map[string]interface{}, error) {
|
||||
url := "http://localhost:3000/v1/exp/retain/" + exptoken
|
||||
request := httptest.NewRequest("GET", url, nil)
|
||||
@@ -116,3 +127,28 @@ func TestExpCancel(t *testing.T) {
|
||||
t.Fatalf("Failed to get status")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpAuto(t *testing.T) {
|
||||
userJSON := `{"login":"william4"}`
|
||||
now := int32(time.Now().Unix())+1
|
||||
fmt.Printf("time %d\n", now)
|
||||
raw, _ := helpCreateUser(userJSON)
|
||||
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
|
||||
t.Fatalf("Failed to create user")
|
||||
}
|
||||
userTOKEN := raw["token"].(string)
|
||||
raw, _ = helpStartExp2(userTOKEN, now)
|
||||
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
|
||||
t.Fatalf("Failed to start expiration")
|
||||
}
|
||||
raw, _ = helpGetExpStatus(userTOKEN)
|
||||
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
|
||||
t.Fatalf("Failed to get status")
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
e.expUsers()
|
||||
raw, _ = helpGetExpStatus(userTOKEN)
|
||||
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
|
||||
t.Fatalf("Failed to get status")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user