2021-12-24 00:57:39 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2022-01-09 12:05:37 +00:00
|
|
|
"fmt"
|
2021-12-24 00:57:39 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
2022-01-17 06:02:13 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/envstore"
|
2021-12-24 00:57:39 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
2022-01-09 12:05:37 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/utils"
|
2021-12-24 00:57:39 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
func verificationRequestsTest(t *testing.T, s TestSetup) {
|
|
|
|
t.Helper()
|
|
|
|
|
2021-12-24 00:57:39 +00:00
|
|
|
t.Run(`should get verification requests with admin secret only`, func(t *testing.T) {
|
|
|
|
req, ctx := createContext(s)
|
|
|
|
|
|
|
|
email := "verification_requests." + 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-17 06:02:13 +00:00
|
|
|
requests, err := resolvers.VerificationRequestsResolver(ctx)
|
|
|
|
assert.NotNil(t, err, "unauthorized")
|
2021-12-24 00:57:39 +00:00
|
|
|
|
2022-01-20 11:22:37 +00:00
|
|
|
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
|
2022-01-09 12:05:37 +00:00
|
|
|
assert.Nil(t, err)
|
2022-01-20 11:22:37 +00:00
|
|
|
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminCookieName), h))
|
2022-01-17 06:02:13 +00:00
|
|
|
requests, err = resolvers.VerificationRequestsResolver(ctx)
|
2021-12-24 00:57:39 +00:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
rLen := len(requests)
|
|
|
|
assert.GreaterOrEqual(t, rLen, 1)
|
|
|
|
|
|
|
|
cleanData(email)
|
|
|
|
})
|
|
|
|
}
|