2021-12-24 00:57:39 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2022-01-09 12:05:37 +00:00
|
|
|
"fmt"
|
2022-03-02 12:12:31 +00:00
|
|
|
"strings"
|
2021-12-24 00:57:39 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-01-09 12:05:37 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
2021-12-24 00:57:39 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/db"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
2022-05-27 17:50:38 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/memorystore"
|
2021-12-24 00:57:39 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
func sessionTests(t *testing.T, s TestSetup) {
|
|
|
|
t.Helper()
|
2021-12-24 00:57:39 +00:00
|
|
|
t.Run(`should allow access to profile with session only`, func(t *testing.T) {
|
|
|
|
req, ctx := createContext(s)
|
|
|
|
email := "session." + s.TestInfo.Email
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
resolvers.SignupResolver(ctx, model.SignUpInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Email: email,
|
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password,
|
|
|
|
})
|
|
|
|
|
2022-01-23 19:02:06 +00:00
|
|
|
_, err := resolvers.SessionResolver(ctx, &model.SessionQueryInput{})
|
2021-12-24 00:57:39 +00:00
|
|
|
assert.NotNil(t, err, "unauthorized")
|
|
|
|
|
2022-01-21 08:04:04 +00:00
|
|
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
2022-01-17 06:02:13 +00:00
|
|
|
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Token: verificationRequest.Token,
|
|
|
|
})
|
|
|
|
|
|
|
|
token := *verifyRes.AccessToken
|
2022-06-11 13:40:39 +00:00
|
|
|
session, err := memorystore.Provider.GetUserSession(verifyRes.User.ID, token)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, session)
|
|
|
|
cookie := fmt.Sprintf("%s=%s;", constants.AppCookieName+"_session", session)
|
2022-03-02 12:12:31 +00:00
|
|
|
cookie = strings.TrimSuffix(cookie, ";")
|
2022-01-09 12:05:37 +00:00
|
|
|
|
2022-01-22 19:54:41 +00:00
|
|
|
req.Header.Set("Cookie", cookie)
|
|
|
|
|
2022-01-23 19:02:06 +00:00
|
|
|
_, err = resolvers.SessionResolver(ctx, &model.SessionQueryInput{})
|
2021-12-24 00:57:39 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
cleanData(email)
|
|
|
|
})
|
|
|
|
}
|