diff --git a/src/bunker_test.go b/src/bunker_test.go index 4ec0264..0d80a74 100644 --- a/src/bunker_test.go +++ b/src/bunker_test.go @@ -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) diff --git a/src/expiration_test.go b/src/expiration_test.go index 0828330..ba06b32 100644 --- a/src/expiration_test.go +++ b/src/expiration_test.go @@ -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") + } +}