fix: refs

This commit is contained in:
Lakhan Samani 2022-07-15 22:11:08 +05:30
parent fed092bb65
commit 847c364ad1
16 changed files with 142 additions and 125 deletions

View File

@ -4,6 +4,7 @@ import (
"strings"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
)
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
@ -35,9 +36,6 @@ type User struct {
func (user *User) AsAPIUser() *model.User {
isEmailVerified := user.EmailVerifiedAt != nil
isPhoneVerified := user.PhoneNumberVerifiedAt != nil
email := user.Email
createdAt := user.CreatedAt
updatedAt := user.UpdatedAt
id := user.ID
if strings.Contains(id, Collections.WebhookLog+"/") {
@ -52,7 +50,7 @@ func (user *User) AsAPIUser() *model.User {
FamilyName: user.FamilyName,
MiddleName: user.MiddleName,
Nickname: user.Nickname,
PreferredUsername: &email,
PreferredUsername: refs.NewStringRef(user.Email),
Gender: user.Gender,
Birthdate: user.Birthdate,
PhoneNumber: user.PhoneNumber,
@ -60,7 +58,7 @@ func (user *User) AsAPIUser() *model.User {
Picture: user.Picture,
Roles: strings.Split(user.Roles, ","),
RevokedTimestamp: user.RevokedTimestamp,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
CreatedAt: refs.NewInt64Ref(user.CreatedAt),
UpdatedAt: refs.NewInt64Ref(user.UpdatedAt),
}
}

View File

@ -4,6 +4,7 @@ import (
"strings"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
)
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
@ -23,28 +24,20 @@ type VerificationRequest struct {
}
func (v *VerificationRequest) AsAPIVerificationRequest() *model.VerificationRequest {
token := v.Token
createdAt := v.CreatedAt
updatedAt := v.UpdatedAt
email := v.Email
nonce := v.Nonce
redirectURI := v.RedirectURI
expires := v.ExpiresAt
identifier := v.Identifier
id := v.ID
if strings.Contains(id, Collections.WebhookLog+"/") {
id = strings.TrimPrefix(id, Collections.WebhookLog+"/")
}
return &model.VerificationRequest{
ID: id,
Token: &token,
Identifier: &identifier,
Expires: &expires,
Email: &email,
Nonce: &nonce,
RedirectURI: &redirectURI,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Token: refs.NewStringRef(v.Token),
Identifier: refs.NewStringRef(v.Identifier),
Expires: refs.NewInt64Ref(v.ExpiresAt),
Email: refs.NewStringRef(v.Email),
Nonce: refs.NewStringRef(v.Nonce),
RedirectURI: refs.NewStringRef(v.RedirectURI),
CreatedAt: refs.NewInt64Ref(v.CreatedAt),
UpdatedAt: refs.NewInt64Ref(v.UpdatedAt),
}
}

View File

@ -5,6 +5,7 @@ import (
"strings"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
)
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
@ -29,13 +30,14 @@ func (w *Webhook) AsAPIWebhook() *model.Webhook {
if strings.Contains(id, Collections.Webhook+"/") {
id = strings.TrimPrefix(id, Collections.Webhook+"/")
}
return &model.Webhook{
ID: id,
EventName: &w.EventName,
Endpoint: &w.EndPoint,
EventName: refs.NewStringRef(w.EventName),
Endpoint: refs.NewStringRef(w.EndPoint),
Headers: headersMap,
Enabled: &w.Enabled,
CreatedAt: &w.CreatedAt,
UpdatedAt: &w.UpdatedAt,
Enabled: refs.NewBoolRef(w.Enabled),
CreatedAt: refs.NewInt64Ref(w.CreatedAt),
UpdatedAt: refs.NewInt64Ref(w.UpdatedAt),
}
}

View File

@ -4,6 +4,7 @@ import (
"strings"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
)
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
@ -27,11 +28,11 @@ func (w *WebhookLog) AsAPIWebhookLog() *model.WebhookLog {
}
return &model.WebhookLog{
ID: id,
HTTPStatus: &w.HttpStatus,
Response: &w.Response,
Request: &w.Request,
WebhookID: &w.WebhookID,
CreatedAt: &w.CreatedAt,
UpdatedAt: &w.UpdatedAt,
HTTPStatus: refs.NewInt64Ref(w.HttpStatus),
Response: refs.NewStringRef(w.Response),
Request: refs.NewStringRef(w.Request),
WebhookID: refs.NewStringRef(w.WebhookID),
CreatedAt: refs.NewInt64Ref(w.CreatedAt),
UpdatedAt: refs.NewInt64Ref(w.UpdatedAt),
}
}

14
server/refs/bool.go Normal file
View File

@ -0,0 +1,14 @@
package refs
// NewBoolRef returns a reference to a bool with given value
func NewBoolRef(v bool) *bool {
return &v
}
// BoolValue returns the value of the given bool ref
func BoolValue(r *bool) bool {
if r == nil {
return false
}
return *r
}

14
server/refs/int.go Normal file
View File

@ -0,0 +1,14 @@
package refs
// NewInt64Ref returns a reference to a int64 with given value
func NewInt64Ref(v int64) *int64 {
return &v
}
// Int64Value returns the value of the given bool ref
func Int64Value(r *int64) int64 {
if r == nil {
return 0
}
return *r
}

View File

@ -1,4 +1,4 @@
package utils
package refs
// NewStringRef returns a reference to a string with given value
func NewStringRef(v string) *string {
@ -16,15 +16,4 @@ func StringValue(r *string, defaultValue ...string) string {
return ""
}
// NewBoolRef returns a reference to a bool with given value
func NewBoolRef(v bool) *bool {
return &v
}
// BoolValue returns the value of the given bool ref
func BoolValue(r *bool) bool {
if r == nil {
return false
}
return *r
}

View File

@ -10,6 +10,7 @@ import (
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/token"
"github.com/authorizerdev/authorizer/server/utils"
)
@ -38,10 +39,10 @@ func EnvResolver(ctx context.Context) (*model.Env, error) {
}
if val, ok := store[constants.EnvKeyAccessTokenExpiryTime]; ok {
res.AccessTokenExpiryTime = utils.NewStringRef(val.(string))
res.AccessTokenExpiryTime = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyAdminSecret]; ok {
res.AdminSecret = utils.NewStringRef(val.(string))
res.AdminSecret = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyClientID]; ok {
res.ClientID = val.(string)
@ -50,103 +51,103 @@ func EnvResolver(ctx context.Context) (*model.Env, error) {
res.ClientSecret = val.(string)
}
if val, ok := store[constants.EnvKeyDatabaseURL]; ok {
res.DatabaseURL = utils.NewStringRef(val.(string))
res.DatabaseURL = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyDatabaseName]; ok {
res.DatabaseName = utils.NewStringRef(val.(string))
res.DatabaseName = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyDatabaseType]; ok {
res.DatabaseType = utils.NewStringRef(val.(string))
res.DatabaseType = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyDatabaseUsername]; ok {
res.DatabaseUsername = utils.NewStringRef(val.(string))
res.DatabaseUsername = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyDatabasePassword]; ok {
res.DatabasePassword = utils.NewStringRef(val.(string))
res.DatabasePassword = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyDatabaseHost]; ok {
res.DatabaseHost = utils.NewStringRef(val.(string))
res.DatabaseHost = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyDatabasePort]; ok {
res.DatabasePort = utils.NewStringRef(val.(string))
res.DatabasePort = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyCustomAccessTokenScript]; ok {
res.CustomAccessTokenScript = utils.NewStringRef(val.(string))
res.CustomAccessTokenScript = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeySmtpHost]; ok {
res.SMTPHost = utils.NewStringRef(val.(string))
res.SMTPHost = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeySmtpPort]; ok {
res.SMTPPort = utils.NewStringRef(val.(string))
res.SMTPPort = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeySmtpUsername]; ok {
res.SMTPUsername = utils.NewStringRef(val.(string))
res.SMTPUsername = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeySmtpPassword]; ok {
res.SMTPPassword = utils.NewStringRef(val.(string))
res.SMTPPassword = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeySenderEmail]; ok {
res.SenderEmail = utils.NewStringRef(val.(string))
res.SenderEmail = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyJwtType]; ok {
res.JwtType = utils.NewStringRef(val.(string))
res.JwtType = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyJwtSecret]; ok {
res.JwtSecret = utils.NewStringRef(val.(string))
res.JwtSecret = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyJwtRoleClaim]; ok {
res.JwtRoleClaim = utils.NewStringRef(val.(string))
res.JwtRoleClaim = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyJwtPublicKey]; ok {
res.JwtPublicKey = utils.NewStringRef(val.(string))
res.JwtPublicKey = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyJwtPrivateKey]; ok {
res.JwtPrivateKey = utils.NewStringRef(val.(string))
res.JwtPrivateKey = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyAppURL]; ok {
res.AppURL = utils.NewStringRef(val.(string))
res.AppURL = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyRedisURL]; ok {
res.RedisURL = utils.NewStringRef(val.(string))
res.RedisURL = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyResetPasswordURL]; ok {
res.ResetPasswordURL = utils.NewStringRef(val.(string))
res.ResetPasswordURL = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyGoogleClientID]; ok {
res.GoogleClientID = utils.NewStringRef(val.(string))
res.GoogleClientID = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyGoogleClientSecret]; ok {
res.GoogleClientSecret = utils.NewStringRef(val.(string))
res.GoogleClientSecret = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyFacebookClientID]; ok {
res.FacebookClientID = utils.NewStringRef(val.(string))
res.FacebookClientID = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyFacebookClientSecret]; ok {
res.FacebookClientSecret = utils.NewStringRef(val.(string))
res.FacebookClientSecret = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyGithubClientID]; ok {
res.GithubClientID = utils.NewStringRef(val.(string))
res.GithubClientID = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyGithubClientSecret]; ok {
res.GithubClientSecret = utils.NewStringRef(val.(string))
res.GithubClientSecret = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyLinkedInClientID]; ok {
res.LinkedinClientID = utils.NewStringRef(val.(string))
res.LinkedinClientID = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyLinkedInClientSecret]; ok {
res.LinkedinClientSecret = utils.NewStringRef(val.(string))
res.LinkedinClientSecret = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyAppleClientID]; ok {
res.AppleClientID = utils.NewStringRef(val.(string))
res.AppleClientID = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyAppleClientSecret]; ok {
res.AppleClientSecret = utils.NewStringRef(val.(string))
res.AppleClientSecret = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyOrganizationName]; ok {
res.OrganizationName = utils.NewStringRef(val.(string))
res.OrganizationName = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeyOrganizationLogo]; ok {
res.OrganizationLogo = utils.NewStringRef(val.(string))
res.OrganizationLogo = refs.NewStringRef(val.(string))
}
// string slice vars

View File

@ -11,6 +11,7 @@ import (
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/token"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/authorizerdev/authorizer/server/validators"
@ -41,8 +42,8 @@ func TestEndpointResolver(ctx context.Context, params model.TestEndpointRequest)
Email: "test_endpoint@foo.com",
EmailVerified: true,
SignupMethods: constants.AuthRecipeMethodMagicLinkLogin,
GivenName: utils.NewStringRef("Foo"),
FamilyName: utils.NewStringRef("Bar"),
GivenName: refs.NewStringRef("Foo"),
FamilyName: refs.NewStringRef("Bar"),
}
userBytes, err := json.Marshal(user)

View File

@ -17,6 +17,7 @@ import (
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/authorizerdev/authorizer/server/parsers"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/token"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/authorizerdev/authorizer/server/validators"
@ -61,35 +62,35 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
return res, err
}
if params.GivenName != nil && utils.StringValue(user.GivenName) != utils.StringValue(params.GivenName) {
if params.GivenName != nil && refs.StringValue(user.GivenName) != refs.StringValue(params.GivenName) {
user.GivenName = params.GivenName
}
if params.FamilyName != nil && utils.StringValue(user.FamilyName) != utils.StringValue(params.FamilyName) {
if params.FamilyName != nil && refs.StringValue(user.FamilyName) != refs.StringValue(params.FamilyName) {
user.FamilyName = params.FamilyName
}
if params.MiddleName != nil && utils.StringValue(user.MiddleName) != utils.StringValue(params.MiddleName) {
if params.MiddleName != nil && refs.StringValue(user.MiddleName) != refs.StringValue(params.MiddleName) {
user.MiddleName = params.MiddleName
}
if params.Nickname != nil && utils.StringValue(user.Nickname) != utils.StringValue(params.Nickname) {
if params.Nickname != nil && refs.StringValue(user.Nickname) != refs.StringValue(params.Nickname) {
user.Nickname = params.Nickname
}
if params.Birthdate != nil && utils.StringValue(user.Birthdate) != utils.StringValue(params.Birthdate) {
if params.Birthdate != nil && refs.StringValue(user.Birthdate) != refs.StringValue(params.Birthdate) {
user.Birthdate = params.Birthdate
}
if params.Gender != nil && utils.StringValue(user.Gender) != utils.StringValue(params.Gender) {
if params.Gender != nil && refs.StringValue(user.Gender) != refs.StringValue(params.Gender) {
user.Gender = params.Gender
}
if params.PhoneNumber != nil && utils.StringValue(user.PhoneNumber) != utils.StringValue(params.PhoneNumber) {
if params.PhoneNumber != nil && refs.StringValue(user.PhoneNumber) != refs.StringValue(params.PhoneNumber) {
user.PhoneNumber = params.PhoneNumber
}
if params.Picture != nil && utils.StringValue(user.Picture) != utils.StringValue(params.Picture) {
if params.Picture != nil && refs.StringValue(user.Picture) != refs.StringValue(params.Picture) {
user.Picture = params.Picture
}
@ -116,7 +117,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
}
if isPasswordChanging && user.Password != nil && params.OldPassword != nil {
if err = bcrypt.CompareHashAndPassword([]byte(utils.StringValue(user.Password)), []byte(utils.StringValue(params.OldPassword))); err != nil {
if err = bcrypt.CompareHashAndPassword([]byte(refs.StringValue(user.Password)), []byte(refs.StringValue(params.OldPassword))); err != nil {
log.Debug("Failed to compare hash and old password: ", err)
return res, fmt.Errorf("incorrect old password")
}
@ -135,21 +136,21 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
}
if utils.StringValue(params.ConfirmNewPassword) != utils.StringValue(params.NewPassword) {
if refs.StringValue(params.ConfirmNewPassword) != refs.StringValue(params.NewPassword) {
log.Debug("Failed to compare new password and confirm new password")
return res, fmt.Errorf(`password and confirm password does not match`)
}
if user.Password == nil || utils.StringValue(user.Password) == "" {
if user.Password == nil || refs.StringValue(user.Password) == "" {
shouldAddBasicSignUpMethod = true
}
if err := validators.IsValidPassword(utils.StringValue(params.NewPassword)); err != nil {
if err := validators.IsValidPassword(refs.StringValue(params.NewPassword)); err != nil {
log.Debug("Invalid password")
return res, err
}
password, _ := crypto.EncryptPassword(utils.StringValue(params.NewPassword))
password, _ := crypto.EncryptPassword(refs.StringValue(params.NewPassword))
user.Password = &password
if shouldAddBasicSignUpMethod {
@ -159,10 +160,10 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
hasEmailChanged := false
if params.Email != nil && user.Email != utils.StringValue(params.Email) {
if params.Email != nil && user.Email != refs.StringValue(params.Email) {
// check if valid email
if !validators.IsValidEmail(*params.Email) {
log.Debug("Failed to validate email: ", utils.StringValue(params.Email))
log.Debug("Failed to validate email: ", refs.StringValue(params.Email))
return res, fmt.Errorf("invalid email address")
}
newEmail := strings.ToLower(*params.Email)

View File

@ -8,6 +8,7 @@ import (
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/db/models"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/token"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/authorizerdev/authorizer/server/validators"
@ -45,27 +46,27 @@ func UpdateWebhookResolver(ctx context.Context, params model.UpdateWebhookReques
webhookDetails := models.Webhook{
ID: webhook.ID,
Key: webhook.ID,
EventName: utils.StringValue(webhook.EventName),
EndPoint: utils.StringValue(webhook.Endpoint),
Enabled: utils.BoolValue(webhook.Enabled),
EventName: refs.StringValue(webhook.EventName),
EndPoint: refs.StringValue(webhook.Endpoint),
Enabled: refs.BoolValue(webhook.Enabled),
Headers: headersString,
CreatedAt: *webhook.CreatedAt,
}
if params.EventName != nil && webhookDetails.EventName != utils.StringValue(params.EventName) {
if isValid := validators.IsValidWebhookEventName(utils.StringValue(params.EventName)); !isValid {
log.Debug("invalid event name: ", utils.StringValue(params.EventName))
return nil, fmt.Errorf("invalid event name %s", utils.StringValue(params.EventName))
if params.EventName != nil && webhookDetails.EventName != refs.StringValue(params.EventName) {
if isValid := validators.IsValidWebhookEventName(refs.StringValue(params.EventName)); !isValid {
log.Debug("invalid event name: ", refs.StringValue(params.EventName))
return nil, fmt.Errorf("invalid event name %s", refs.StringValue(params.EventName))
}
webhookDetails.EventName = utils.StringValue(params.EventName)
webhookDetails.EventName = refs.StringValue(params.EventName)
}
if params.Endpoint != nil && webhookDetails.EndPoint != utils.StringValue(params.Endpoint) {
webhookDetails.EventName = utils.StringValue(params.EventName)
if params.Endpoint != nil && webhookDetails.EndPoint != refs.StringValue(params.Endpoint) {
webhookDetails.EventName = refs.StringValue(params.EventName)
}
if params.Enabled != nil && webhookDetails.Enabled != utils.BoolValue(params.Enabled) {
webhookDetails.Enabled = utils.BoolValue(params.Enabled)
if params.Enabled != nil && webhookDetails.Enabled != refs.BoolValue(params.Enabled) {
webhookDetails.Enabled = refs.BoolValue(params.Enabled)
}
if params.Headers != nil {

View File

@ -6,6 +6,7 @@ import (
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/token"
"github.com/authorizerdev/authorizer/server/utils"
log "github.com/sirupsen/logrus"
@ -31,7 +32,7 @@ func WebhookLogsResolver(ctx context.Context, params *model.ListWebhookLogReques
pagination = utils.GetPagination(&model.PaginatedInput{
Pagination: params.Pagination,
})
webhookID = utils.StringValue(params.WebhookID)
webhookID = refs.StringValue(params.WebhookID)
} else {
pagination = utils.GetPagination(nil)
webhookID = ""

View File

@ -9,8 +9,8 @@ import (
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/stretchr/testify/assert"
)
@ -32,7 +32,7 @@ func updateWebhookTest(t *testing.T, s TestSetup) {
res, err := resolvers.UpdateWebhookResolver(ctx, model.UpdateWebhookRequest{
ID: webhook.ID,
Headers: webhook.Headers,
Enabled: utils.NewBoolRef(false),
Enabled: refs.NewBoolRef(false),
})
assert.NoError(t, err)
@ -43,15 +43,15 @@ func updateWebhookTest(t *testing.T, s TestSetup) {
assert.NoError(t, err)
assert.NotNil(t, updatedWebhook)
assert.Equal(t, webhook.ID, updatedWebhook.ID)
assert.Equal(t, utils.StringValue(webhook.EventName), utils.StringValue(updatedWebhook.EventName))
assert.Equal(t, utils.StringValue(webhook.Endpoint), utils.StringValue(updatedWebhook.Endpoint))
assert.Equal(t, refs.StringValue(webhook.EventName), refs.StringValue(updatedWebhook.EventName))
assert.Equal(t, refs.StringValue(webhook.Endpoint), refs.StringValue(updatedWebhook.Endpoint))
assert.Len(t, updatedWebhook.Headers, 2)
assert.False(t, utils.BoolValue(updatedWebhook.Enabled))
assert.False(t, refs.BoolValue(updatedWebhook.Enabled))
res, err = resolvers.UpdateWebhookResolver(ctx, model.UpdateWebhookRequest{
ID: webhook.ID,
Headers: webhook.Headers,
Enabled: utils.NewBoolRef(true),
Enabled: refs.NewBoolRef(true),
})
assert.NoError(t, err)
assert.NotEmpty(t, res)

View File

@ -9,8 +9,8 @@ import (
"github.com/authorizerdev/authorizer/server/crypto"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/stretchr/testify/assert"
)
@ -41,7 +41,7 @@ func webhookLogsTest(t *testing.T, s TestSetup) {
assert.NoError(t, err)
assert.GreaterOrEqual(t, len(webhookLogs.WebhookLogs), 1)
for _, wl := range webhookLogs.WebhookLogs {
assert.Equal(t, utils.StringValue(wl.WebhookID), w.ID)
assert.Equal(t, refs.StringValue(wl.WebhookID), w.ID)
}
})
}

View File

@ -9,8 +9,8 @@ import (
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/stretchr/testify/assert"
)
@ -34,9 +34,9 @@ func webhookTest(t *testing.T, s TestSetup) {
})
assert.NoError(t, err)
assert.Equal(t, res.ID, webhook.ID)
assert.Equal(t, utils.StringValue(res.Endpoint), utils.StringValue(webhook.Endpoint))
assert.Equal(t, utils.StringValue(res.EventName), utils.StringValue(webhook.EventName))
assert.Equal(t, utils.BoolValue(res.Enabled), utils.BoolValue(webhook.Enabled))
assert.Equal(t, refs.StringValue(res.Endpoint), refs.StringValue(webhook.Endpoint))
assert.Equal(t, refs.StringValue(res.EventName), refs.StringValue(webhook.EventName))
assert.Equal(t, refs.BoolValue(res.Enabled), refs.BoolValue(webhook.Enabled))
assert.Len(t, res.Headers, len(webhook.Headers))
})
}

View File

@ -11,6 +11,7 @@ import (
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/db/models"
"github.com/authorizerdev/authorizer/server/refs"
log "github.com/sirupsen/logrus"
)
@ -20,7 +21,7 @@ func RegisterEvent(ctx context.Context, eventName string, authRecipe string, use
return err
}
if !BoolValue(webhook.Enabled) {
if !refs.BoolValue(webhook.Enabled) {
return nil
}
@ -52,7 +53,7 @@ func RegisterEvent(ctx context.Context, eventName string, authRecipe string, use
}
requestBytesBuffer := bytes.NewBuffer(requestBody)
req, err := http.NewRequest("POST", StringValue(webhook.Endpoint), requestBytesBuffer)
req, err := http.NewRequest("POST", refs.StringValue(webhook.Endpoint), requestBytesBuffer)
if err != nil {
log.Debug("error creating webhook post request: ", err)
return err