MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestSessionExpirationDateTimeFormat

Function TestSessionExpirationDateTimeFormat

rest/session_test.go:727–754  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

725}
726
727func 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
756func TestOneTimeSessionWithCookie(t *testing.T) {
757 rt := NewRestTesterPersistentConfig(t)

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
MetadataStoreMethod · 0.95
GetDatabaseMethod · 0.95
ContextMethod · 0.95
NewUserMethod · 0.95
SaveMethod · 0.95
SendAdminRequestMethod · 0.95
NewAuthenticatorFunction · 0.92
BaseSetOfFunction · 0.92
JSONUnmarshalFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85

Tested by

no test coverage detected