authorizer/server/test/users_test.go

52 lines
1.4 KiB
Go
Raw Permalink Normal View History

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-02-28 15:56:49 +00:00
"github.com/authorizerdev/authorizer/server/crypto"
2021-12-24 00:57:39 +00:00
"github.com/authorizerdev/authorizer/server/graph/model"
2022-05-30 03:49:55 +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 usersTest(t *testing.T, s TestSetup) {
t.Helper()
2021-12-24 00:57:39 +00:00
t.Run(`should get users list with admin secret only`, func(t *testing.T) {
req, ctx := createContext(s)
email := "users." + 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,
})
limit := int64(10)
page := int64(1)
pagination := &model.PaginatedInput{
Pagination: &model.PaginationInput{
Limit: &limit,
Page: &page,
},
}
usersRes, err := resolvers.UsersResolver(ctx, pagination)
2021-12-24 00:57:39 +00:00
assert.NotNil(t, err, "unauthorized")
assert.Nil(t, usersRes)
2022-05-30 07:17:50 +00:00
adminSecret, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret)
2022-01-09 12:05:37 +00:00
assert.Nil(t, err)
2022-05-30 07:17:50 +00:00
h, err := crypto.EncryptPassword(adminSecret)
assert.Nil(t, err)
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
usersRes, err = resolvers.UsersResolver(ctx, pagination)
2021-12-24 00:57:39 +00:00
assert.Nil(t, err)
rLen := len(usersRes.Users)
2021-12-24 00:57:39 +00:00
assert.GreaterOrEqual(t, rLen, 1)
cleanData(email)
})
}