2022-07-11 05:12:42 +00:00
|
|
|
package test
|
2022-07-11 14:10:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
|
|
|
"github.com/authorizerdev/authorizer/server/crypto"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
|
|
|
"github.com/authorizerdev/authorizer/server/memorystore"
|
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testEndpointTest(t *testing.T, s TestSetup) {
|
|
|
|
t.Helper()
|
|
|
|
t.Run("should test endpoint", func(t *testing.T) {
|
|
|
|
req, ctx := createContext(s)
|
|
|
|
adminSecret, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
h, err := crypto.EncryptPassword(adminSecret)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
|
|
|
|
|
|
|
|
res, err := resolvers.TestEndpointResolver(ctx, model.TestEndpointRequest{
|
|
|
|
Endpoint: s.TestInfo.WebhookEndpoint,
|
|
|
|
EventName: constants.UserLoginWebhookEvent,
|
|
|
|
Headers: map[string]interface{}{
|
|
|
|
"x-test": "test",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, res)
|
2022-12-24 21:52:42 +00:00
|
|
|
assert.GreaterOrEqual(t, *res.HTTPStatus, int64(200))
|
2022-07-11 14:10:54 +00:00
|
|
|
assert.NotEmpty(t, res.Response)
|
|
|
|
})
|
|
|
|
}
|