(t *testing.T)
| 725 | } |
| 726 | |
| 727 | func TestSessionExpirationDateTimeFormat(t *testing.T) { |
| 728 | rt := NewRestTester(t, nil) |
| 729 | defer rt.Close() |
| 730 | |
| 731 | authenticator := auth.NewAuthenticator(rt.MetadataStore(), nil, rt.GetDatabase().AuthenticatorOptions(rt.Context())) |
| 732 | user, err := authenticator.NewUser("alice", "letMe!n", channels.BaseSetOf(t, "*")) |
| 733 | assert.NoError(t, err, "Couldn't create new user") |
| 734 | assert.NoError(t, authenticator.Save(user), "Couldn't save new user") |
| 735 | |
| 736 | var body db.Body |
| 737 | response := rt.SendAdminRequest(http.MethodPost, "/db/_session", `{"name":"alice"}`) |
| 738 | RequireStatus(t, response, http.StatusOK) |
| 739 | |
| 740 | require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body)) |
| 741 | expires, err := time.Parse(time.RFC3339, body["expires"].(string)) |
| 742 | assert.NoError(t, err, "Couldn't parse session expiration datetime") |
| 743 | assert.True(t, expires.Sub(time.Now()).Hours() <= 24, "Couldn't validate session expiration") |
| 744 | |
| 745 | sessionId := body["session_id"].(string) |
| 746 | require.NotEmpty(t, sessionId, "Couldn't parse sessionID from response body") |
| 747 | response = rt.SendAdminRequest(http.MethodGet, fmt.Sprintf("/db/_session/%s", sessionId), "") |
| 748 | RequireStatus(t, response, http.StatusOK) |
| 749 | |
| 750 | require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body)) |
| 751 | expires, err = time.Parse(time.RFC3339, body["expires"].(string)) |
| 752 | assert.NoError(t, err, "Couldn't parse session expiration datetime") |
| 753 | assert.True(t, expires.Sub(time.Now()).Hours() <= 24, "Couldn't validate session expiration") |
| 754 | } |
| 755 | |
| 756 | func TestOneTimeSessionWithCookie(t *testing.T) { |
| 757 | rt := NewRestTesterPersistentConfig(t) |
nothing calls this directly
no test coverage detected