Compare commits
7 Commits
feat/webho
...
fix/passwo
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2de0ea57d0 | ||
![]() |
f2886e6da8 | ||
![]() |
6b57bce6d9 | ||
![]() |
bfbeb6add2 | ||
![]() |
1fe0d65874 | ||
![]() |
bfaa0f9d89 | ||
![]() |
4f5a6c77f8 |
@@ -23,4 +23,6 @@ const (
|
||||
DbTypeScyllaDB = "scylladb"
|
||||
// DbTypeCockroachDB is the cockroach database type
|
||||
DbTypeCockroachDB = "cockroachdb"
|
||||
// DbTypePlanetScaleDB is the planetscale database type
|
||||
DbTypePlanetScaleDB = "planetscale"
|
||||
)
|
||||
|
@@ -6,8 +6,7 @@ package models
|
||||
type Session struct {
|
||||
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty"` // for arangodb
|
||||
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id"`
|
||||
UserID string `gorm:"type:char(36),index:" json:"user_id" bson:"user_id" cql:"user_id"`
|
||||
User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" bson:"-" cql:"-"`
|
||||
UserID string `gorm:"type:char(36)" json:"user_id" bson:"user_id" cql:"user_id"`
|
||||
UserAgent string `json:"user_agent" bson:"user_agent" cql:"user_agent"`
|
||||
IP string `json:"ip" bson:"ip" cql:"ip"`
|
||||
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`
|
||||
|
@@ -38,8 +38,13 @@ func (user *User) AsAPIUser() *model.User {
|
||||
email := user.Email
|
||||
createdAt := user.CreatedAt
|
||||
updatedAt := user.UpdatedAt
|
||||
|
||||
id := user.ID
|
||||
if strings.Contains(id, Collections.WebhookLog+"/") {
|
||||
id = strings.TrimPrefix(id, Collections.WebhookLog+"/")
|
||||
}
|
||||
return &model.User{
|
||||
ID: user.ID,
|
||||
ID: id,
|
||||
Email: user.Email,
|
||||
EmailVerified: isEmailVerified,
|
||||
SignupMethods: user.SignupMethods,
|
||||
|
@@ -1,6 +1,10 @@
|
||||
package models
|
||||
|
||||
import "github.com/authorizerdev/authorizer/server/graph/model"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
)
|
||||
|
||||
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
|
||||
|
||||
@@ -27,8 +31,13 @@ func (v *VerificationRequest) AsAPIVerificationRequest() *model.VerificationRequ
|
||||
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: v.ID,
|
||||
ID: id,
|
||||
Token: &token,
|
||||
Identifier: &identifier,
|
||||
Expires: &expires,
|
||||
|
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
)
|
||||
@@ -23,8 +24,13 @@ type Webhook struct {
|
||||
func (w *Webhook) AsAPIWebhook() *model.Webhook {
|
||||
headersMap := make(map[string]interface{})
|
||||
json.Unmarshal([]byte(w.Headers), &headersMap)
|
||||
|
||||
id := w.ID
|
||||
if strings.Contains(id, Collections.Webhook+"/") {
|
||||
id = strings.TrimPrefix(id, Collections.Webhook+"/")
|
||||
}
|
||||
return &model.Webhook{
|
||||
ID: w.ID,
|
||||
ID: id,
|
||||
EventName: &w.EventName,
|
||||
Endpoint: &w.EndPoint,
|
||||
Headers: headersMap,
|
||||
|
@@ -1,6 +1,10 @@
|
||||
package models
|
||||
|
||||
import "github.com/authorizerdev/authorizer/server/graph/model"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
)
|
||||
|
||||
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
|
||||
|
||||
@@ -11,15 +15,18 @@ type WebhookLog struct {
|
||||
HttpStatus int64 `json:"http_status" bson:"http_status" cql:"http_status"`
|
||||
Response string `gorm:"type:text" json:"response" bson:"response" cql:"response"`
|
||||
Request string `gorm:"type:text" json:"request" bson:"request" cql:"request"`
|
||||
WebhookID string `gorm:"type:char(36),index:" json:"webhook_id" bson:"webhook_id" cql:"webhook_id"`
|
||||
Webhook Webhook `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" bson:"-" cql:"-"`
|
||||
WebhookID string `gorm:"type:char(36)" json:"webhook_id" bson:"webhook_id" cql:"webhook_id"`
|
||||
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`
|
||||
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
|
||||
}
|
||||
|
||||
func (w *WebhookLog) AsAPIWebhookLog() *model.WebhookLog {
|
||||
id := w.ID
|
||||
if strings.Contains(id, Collections.WebhookLog+"/") {
|
||||
id = strings.TrimPrefix(id, Collections.WebhookLog+"/")
|
||||
}
|
||||
return &model.WebhookLog{
|
||||
ID: w.ID,
|
||||
ID: id,
|
||||
HTTPStatus: &w.HttpStatus,
|
||||
Response: &w.Response,
|
||||
Request: &w.Request,
|
||||
|
@@ -2,7 +2,6 @@ package arangodb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
@@ -24,17 +23,3 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
query := fmt.Sprintf(`FOR d IN %s FILTER d.user_id == @userId REMOVE { _key: d._key } IN %s`, models.Collections.Session, models.Collections.Session)
|
||||
bindVars := map[string]interface{}{
|
||||
"userId": userId,
|
||||
}
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cursor.Close()
|
||||
return nil
|
||||
}
|
||||
|
@@ -63,6 +63,16 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
||||
return err
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`FOR d IN %s FILTER d.user_id == @user_id REMOVE { _key: d._key } IN %s`, models.Collections.Session, models.Collections.Session)
|
||||
bindVars := map[string]interface{}{
|
||||
"user_id": user.ID,
|
||||
}
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -83,7 +83,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
||||
// GetWebhookByID to get webhook by id
|
||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||
var webhook models.Webhook
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d._id == @webhook_id RETURN d", models.Collections.Webhook)
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d._key == @webhook_id RETURN d", models.Collections.Webhook)
|
||||
bindVars := map[string]interface{}{
|
||||
"webhook_id": webhookID,
|
||||
}
|
||||
@@ -146,9 +146,9 @@ func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) er
|
||||
return err
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d.event_id == @event_id REMOVE { _key: d._key }", models.Collections.WebhookLog)
|
||||
query := fmt.Sprintf("FOR d IN %s FILTER d.webhook_id == @webhook_id REMOVE { _key: d._key } IN %s", models.Collections.WebhookLog, models.Collections.WebhookLog)
|
||||
bindVars := map[string]interface{}{
|
||||
"event_id": webhook.ID,
|
||||
"webhook_id": webhook.ID,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
|
@@ -37,11 +37,12 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||
|
||||
if webhookID != "" {
|
||||
query = fmt.Sprintf("FOR d in %s FILTER d.webhook_id == @webhookID SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||
query = fmt.Sprintf("FOR d in %s FILTER d.webhook_id == @webhook_id SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||
bindVariables = map[string]interface{}{
|
||||
"webhook_id": webhookID,
|
||||
}
|
||||
}
|
||||
|
||||
sctx := driver.WithQueryFullCount(ctx)
|
||||
cursor, err := p.db.Query(sctx, query, bindVariables)
|
||||
if err != nil {
|
||||
|
@@ -143,6 +143,11 @@ func NewProvider() (*provider, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sessionIndexQuery := fmt.Sprintf("CREATE INDEX IF NOT EXISTS authorizer_session_user_id ON %s.%s (user_id)", KeySpace, models.Collections.Session)
|
||||
err = session.Query(sessionIndexQuery).Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userCollectionQuery := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s.%s (id text, email text, email_verified_at bigint, password text, signup_methods text, given_name text, family_name text, middle_name text, nickname text, gender text, birthdate text, phone_number text, phone_number_verified_at bigint, picture text, roles text, updated_at bigint, created_at bigint, revoked_timestamp bigint, PRIMARY KEY (id))", KeySpace, models.Collections.User)
|
||||
err = session.Query(userCollectionQuery).Exec()
|
||||
@@ -177,7 +182,7 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
webhookCollectionQuery := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s.%s (id text, event_name text, endpoint text, enabled boolean, updated_at bigint, created_at bigint, PRIMARY KEY (id))", KeySpace, models.Collections.Webhook)
|
||||
webhookCollectionQuery := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s.%s (id text, event_name text, endpoint text, enabled boolean, headers text, updated_at bigint, created_at bigint, PRIMARY KEY (id))", KeySpace, models.Collections.Webhook)
|
||||
err = session.Query(webhookCollectionQuery).Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -25,13 +25,3 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
deleteSessionQuery := fmt.Sprintf("DELETE FROM %s WHERE user_id = '%s'", KeySpace+"."+models.Collections.Session, userId)
|
||||
err := p.db.Query(deleteSessionQuery).Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -102,6 +102,10 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
||||
continue
|
||||
}
|
||||
|
||||
if key == "_key" {
|
||||
continue
|
||||
}
|
||||
|
||||
if value == nil {
|
||||
updateFields += fmt.Sprintf("%s = null,", key)
|
||||
continue
|
||||
@@ -131,9 +135,31 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
||||
query := fmt.Sprintf("DELETE FROM %s WHERE id = '%s'", KeySpace+"."+models.Collections.User, user.ID)
|
||||
err := p.db.Query(query).Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
getSessionsQuery := fmt.Sprintf("SELECT id FROM %s WHERE user_id = '%s' ALLOW FILTERING", KeySpace+"."+models.Collections.Session, user.ID)
|
||||
scanner := p.db.Query(getSessionsQuery).Iter().Scanner()
|
||||
sessionIDs := ""
|
||||
for scanner.Next() {
|
||||
var wlID string
|
||||
err = scanner.Scan(&wlID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sessionIDs += fmt.Sprintf("'%s',", wlID)
|
||||
}
|
||||
sessionIDs = strings.TrimSuffix(sessionIDs, ",")
|
||||
deleteSessionQuery := fmt.Sprintf("DELETE FROM %s WHERE id IN (%s)", KeySpace+"."+models.Collections.Session, sessionIDs)
|
||||
err = p.db.Query(deleteSessionQuery).Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListUsers to get list of users from database
|
||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
||||
responseUsers := []*model.User{}
|
||||
@@ -171,7 +197,7 @@ func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (
|
||||
// GetUserByEmail to get user information from database using email address
|
||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
||||
var user models.User
|
||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, created_at, updated_at FROM %s WHERE email = '%s' LIMIT 1", KeySpace+"."+models.Collections.User, email)
|
||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, created_at, updated_at FROM %s WHERE email = '%s' LIMIT 1 ALLOW FILTERING", KeySpace+"."+models.Collections.User, email)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.CreatedAt, &user.UpdatedAt)
|
||||
if err != nil {
|
||||
return user, err
|
||||
|
@@ -24,6 +24,11 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||
webhook.CreatedAt = time.Now().Unix()
|
||||
webhook.UpdatedAt = time.Now().Unix()
|
||||
|
||||
existingHook, _ := p.GetWebhookByEventName(ctx, webhook.EventName)
|
||||
if existingHook != nil {
|
||||
return nil, fmt.Errorf("Webhook with %s event_name already exists", webhook.EventName)
|
||||
}
|
||||
|
||||
insertQuery := fmt.Sprintf("INSERT INTO %s (id, event_name, endpoint, headers, enabled, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', %t, %d, %d)", KeySpace+"."+models.Collections.Webhook, webhook.ID, webhook.EventName, webhook.EndPoint, webhook.Headers, webhook.Enabled, webhook.CreatedAt, webhook.UpdatedAt)
|
||||
err := p.db.Query(insertQuery).Exec()
|
||||
if err != nil {
|
||||
@@ -56,6 +61,10 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
||||
continue
|
||||
}
|
||||
|
||||
if key == "_key" {
|
||||
continue
|
||||
}
|
||||
|
||||
if value == nil {
|
||||
updateFields += fmt.Sprintf("%s = null,", key)
|
||||
continue
|
||||
@@ -72,7 +81,6 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
||||
updateFields = strings.TrimSuffix(updateFields, ",")
|
||||
|
||||
query := fmt.Sprintf("UPDATE %s SET %s WHERE id = '%s'", KeySpace+"."+models.Collections.Webhook, updateFields, webhook.ID)
|
||||
|
||||
err = p.db.Query(query).Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -130,7 +138,7 @@ func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model
|
||||
// GetWebhookByEventName to get webhook by event_name
|
||||
func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string) (*model.Webhook, error) {
|
||||
var webhook models.Webhook
|
||||
query := fmt.Sprintf(`SELECT id, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s WHERE event_name = '%s' LIMIT 1`, KeySpace+"."+models.Collections.Webhook, eventName)
|
||||
query := fmt.Sprintf(`SELECT id, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s WHERE event_name = '%s' LIMIT 1 ALLOW FILTERING`, KeySpace+"."+models.Collections.Webhook, eventName)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&webhook.ID, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -146,7 +154,19 @@ func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) er
|
||||
return err
|
||||
}
|
||||
|
||||
query = fmt.Sprintf("DELETE FROM %s WHERE webhook_id = '%s'", KeySpace+"."+models.Collections.WebhookLog, webhook.ID)
|
||||
getWebhookLogQuery := fmt.Sprintf("SELECT id FROM %s WHERE webhook_id = '%s' ALLOW FILTERING", KeySpace+"."+models.Collections.WebhookLog, webhook.ID)
|
||||
scanner := p.db.Query(getWebhookLogQuery).Iter().Scanner()
|
||||
webhookLogIDs := ""
|
||||
for scanner.Next() {
|
||||
var wlID string
|
||||
err = scanner.Scan(&wlID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
webhookLogIDs += fmt.Sprintf("'%s',", wlID)
|
||||
}
|
||||
webhookLogIDs = strings.TrimSuffix(webhookLogIDs, ",")
|
||||
query = fmt.Sprintf("DELETE FROM %s WHERE id IN (%s)", KeySpace+"."+models.Collections.WebhookLog, webhookLogIDs)
|
||||
err = p.db.Query(query).Exec()
|
||||
return err
|
||||
}
|
||||
|
@@ -40,8 +40,8 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
||||
query := fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.WebhookLog, pagination.Limit+pagination.Offset)
|
||||
|
||||
if webhookID != "" {
|
||||
totalCountQuery = fmt.Sprintf(`SELECT COUNT(*) FROM %s WHERE webhook_id='%s'`, KeySpace+"."+models.Collections.WebhookLog, webhookID)
|
||||
query = fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s WHERE webhook_id = '%s' LIMIT %d", KeySpace+"."+models.Collections.WebhookLog, webhookID, pagination.Limit+pagination.Offset)
|
||||
totalCountQuery = fmt.Sprintf(`SELECT COUNT(*) FROM %s WHERE webhook_id='%s' ALLOW FILTERING`, KeySpace+"."+models.Collections.WebhookLog, webhookID)
|
||||
query = fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s WHERE webhook_id = '%s' LIMIT %d ALLOW FILTERING", KeySpace+"."+models.Collections.WebhookLog, webhookID, pagination.Limit+pagination.Offset)
|
||||
}
|
||||
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
"github.com/google/uuid"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
@@ -26,13 +25,3 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
|
||||
_, err := sessionCollection.DeleteMany(ctx, bson.M{"user_id": userId}, options.Delete())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -57,6 +57,12 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
||||
return err
|
||||
}
|
||||
|
||||
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
|
||||
_, err = sessionCollection.DeleteMany(ctx, bson.M{"user_id": user.ID}, options.Delete())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -111,7 +111,7 @@ func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) er
|
||||
}
|
||||
|
||||
webhookLogCollection := p.db.Collection(models.Collections.WebhookLog, options.Collection())
|
||||
_, err = webhookLogCollection.DeleteOne(nil, bson.M{"webhook_id": webhook.ID}, options.Delete())
|
||||
_, err = webhookLogCollection.DeleteMany(nil, bson.M{"webhook_id": webhook.ID}, options.Delete())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -34,8 +34,6 @@ type Provider interface {
|
||||
|
||||
// AddSession to save session information in database
|
||||
AddSession(ctx context.Context, session models.Session) error
|
||||
// DeleteSession to delete session information from database
|
||||
DeleteSession(ctx context.Context, userId string) error
|
||||
|
||||
// AddEnv to save environment information in database
|
||||
AddEnv(ctx context.Context, env models.Env) (models.Env, error)
|
||||
|
@@ -50,7 +50,7 @@ func NewProvider() (*provider, error) {
|
||||
sqlDB, err = gorm.Open(postgres.Open(dbURL), ormConfig)
|
||||
case constants.DbTypeSqlite:
|
||||
sqlDB, err = gorm.Open(sqlite.Open(dbURL), ormConfig)
|
||||
case constants.DbTypeMysql, constants.DbTypeMariaDB:
|
||||
case constants.DbTypeMysql, constants.DbTypeMariaDB, constants.DbTypePlanetScaleDB:
|
||||
sqlDB, err = gorm.Open(mysql.Open(dbURL), ormConfig)
|
||||
case constants.DbTypeSqlserver:
|
||||
sqlDB, err = gorm.Open(sqlserver.Open(dbURL), ormConfig)
|
||||
|
@@ -27,13 +27,3 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
result := p.db.Where("user_id = ?", userId).Delete(&models.Session{})
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -63,6 +63,11 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
result = p.db.Where("user_id = ?", user.ID).Delete(&models.Session{})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
4
server/env/persist_env.go
vendored
4
server/env/persist_env.go
vendored
@@ -113,7 +113,7 @@ func PersistEnv() error {
|
||||
ctx := context.Background()
|
||||
env, err := db.Provider.GetEnv(ctx)
|
||||
// config not found in db
|
||||
if err != nil {
|
||||
if err != nil || env.EnvData == "" {
|
||||
// AES encryption needs 32 bit key only, so we chop off last 4 characters from 36 bit uuid
|
||||
hash := uuid.New().String()[:36-4]
|
||||
err := memorystore.Provider.UpdateEnvVariable(constants.EnvKeyEncryptionKey, hash)
|
||||
@@ -174,7 +174,7 @@ func PersistEnv() error {
|
||||
|
||||
err = json.Unmarshal(decryptedConfigs, &storeData)
|
||||
if err != nil {
|
||||
log.Debug("Error while unmarshalling env data: ", err)
|
||||
log.Debug("Error while un-marshalling env data: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -173,7 +173,7 @@ type ComplexityRoot struct {
|
||||
ValidateJwtToken func(childComplexity int, params model.ValidateJWTTokenInput) int
|
||||
VerificationRequests func(childComplexity int, params *model.PaginatedInput) int
|
||||
Webhook func(childComplexity int, params model.WebhookRequest) int
|
||||
WebhookLogs func(childComplexity int, params model.ListWebhookLogRequest) int
|
||||
WebhookLogs func(childComplexity int, params *model.ListWebhookLogRequest) int
|
||||
Webhooks func(childComplexity int, params *model.PaginatedInput) int
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ type QueryResolver interface {
|
||||
Env(ctx context.Context) (*model.Env, error)
|
||||
Webhook(ctx context.Context, params model.WebhookRequest) (*model.Webhook, error)
|
||||
Webhooks(ctx context.Context, params *model.PaginatedInput) (*model.Webhooks, error)
|
||||
WebhookLogs(ctx context.Context, params model.ListWebhookLogRequest) (*model.WebhookLogs, error)
|
||||
WebhookLogs(ctx context.Context, params *model.ListWebhookLogRequest) (*model.WebhookLogs, error)
|
||||
}
|
||||
|
||||
type executableSchema struct {
|
||||
@@ -1220,7 +1220,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Query.WebhookLogs(childComplexity, args["params"].(model.ListWebhookLogRequest)), true
|
||||
return e.complexity.Query.WebhookLogs(childComplexity, args["params"].(*model.ListWebhookLogRequest)), true
|
||||
|
||||
case "Query._webhooks":
|
||||
if e.complexity.Query.Webhooks == nil {
|
||||
@@ -2026,7 +2026,7 @@ type TestEndpointResponse {
|
||||
}
|
||||
|
||||
input ListWebhookLogRequest {
|
||||
pagination: PaginationInput!
|
||||
pagination: PaginationInput
|
||||
webhook_id: String
|
||||
}
|
||||
|
||||
@@ -2100,7 +2100,7 @@ type Query {
|
||||
_env: Env!
|
||||
_webhook(params: WebhookRequest!): Webhook!
|
||||
_webhooks(params: PaginatedInput): Webhooks!
|
||||
_webhook_logs(params: ListWebhookLogRequest!): WebhookLogs!
|
||||
_webhook_logs(params: ListWebhookLogRequest): WebhookLogs!
|
||||
}
|
||||
`, BuiltIn: false},
|
||||
}
|
||||
@@ -2503,10 +2503,10 @@ func (ec *executionContext) field_Query__webhook_args(ctx context.Context, rawAr
|
||||
func (ec *executionContext) field_Query__webhook_logs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
var arg0 model.ListWebhookLogRequest
|
||||
var arg0 *model.ListWebhookLogRequest
|
||||
if tmp, ok := rawArgs["params"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("params"))
|
||||
arg0, err = ec.unmarshalNListWebhookLogRequest2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐListWebhookLogRequest(ctx, tmp)
|
||||
arg0, err = ec.unmarshalOListWebhookLogRequest2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐListWebhookLogRequest(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -6493,7 +6493,7 @@ func (ec *executionContext) _Query__webhook_logs(ctx context.Context, field grap
|
||||
fc.Args = args
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Query().WebhookLogs(rctx, args["params"].(model.ListWebhookLogRequest))
|
||||
return ec.resolvers.Query().WebhookLogs(rctx, args["params"].(*model.ListWebhookLogRequest))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -9675,7 +9675,7 @@ func (ec *executionContext) unmarshalInputListWebhookLogRequest(ctx context.Cont
|
||||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("pagination"))
|
||||
it.Pagination, err = ec.unmarshalNPaginationInput2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐPaginationInput(ctx, v)
|
||||
it.Pagination, err = ec.unmarshalOPaginationInput2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐPaginationInput(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
@@ -12329,11 +12329,6 @@ func (ec *executionContext) unmarshalNInviteMemberInput2githubᚗcomᚋauthorize
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNListWebhookLogRequest2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐListWebhookLogRequest(ctx context.Context, v interface{}) (model.ListWebhookLogRequest, error) {
|
||||
res, err := ec.unmarshalInputListWebhookLogRequest(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNLoginInput2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐLoginInput(ctx context.Context, v interface{}) (model.LoginInput, error) {
|
||||
res, err := ec.unmarshalInputLoginInput(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
@@ -12373,11 +12368,6 @@ func (ec *executionContext) marshalNPagination2ᚖgithubᚗcomᚋauthorizerdev
|
||||
return ec._Pagination(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNPaginationInput2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐPaginationInput(ctx context.Context, v interface{}) (*model.PaginationInput, error) {
|
||||
res, err := ec.unmarshalInputPaginationInput(ctx, v)
|
||||
return &res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNResendVerifyEmailInput2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐResendVerifyEmailInput(ctx context.Context, v interface{}) (model.ResendVerifyEmailInput, error) {
|
||||
res, err := ec.unmarshalInputResendVerifyEmailInput(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
@@ -13122,6 +13112,14 @@ func (ec *executionContext) marshalOInt642ᚖint64(ctx context.Context, sel ast.
|
||||
return graphql.MarshalInt64(*v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOListWebhookLogRequest2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐListWebhookLogRequest(ctx context.Context, v interface{}) (*model.ListWebhookLogRequest, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
res, err := ec.unmarshalInputListWebhookLogRequest(ctx, v)
|
||||
return &res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOMap2map(ctx context.Context, v interface{}) (map[string]interface{}, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
@@ -355,7 +355,7 @@ type TestEndpointResponse {
|
||||
}
|
||||
|
||||
input ListWebhookLogRequest {
|
||||
pagination: PaginationInput!
|
||||
pagination: PaginationInput
|
||||
webhook_id: String
|
||||
}
|
||||
|
||||
@@ -429,5 +429,5 @@ type Query {
|
||||
_env: Env!
|
||||
_webhook(params: WebhookRequest!): Webhook!
|
||||
_webhooks(params: PaginatedInput): Webhooks!
|
||||
_webhook_logs(params: ListWebhookLogRequest!): WebhookLogs!
|
||||
_webhook_logs(params: ListWebhookLogRequest): WebhookLogs!
|
||||
}
|
||||
|
@@ -147,7 +147,7 @@ func (r *queryResolver) Webhooks(ctx context.Context, params *model.PaginatedInp
|
||||
return resolvers.WebhooksResolver(ctx, params)
|
||||
}
|
||||
|
||||
func (r *queryResolver) WebhookLogs(ctx context.Context, params model.ListWebhookLogRequest) (*model.WebhookLogs, error) {
|
||||
func (r *queryResolver) WebhookLogs(ctx context.Context, params *model.ListWebhookLogRequest) (*model.WebhookLogs, error) {
|
||||
return resolvers.WebhookLogsResolver(ctx, params)
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,7 @@
|
||||
package stores
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
)
|
||||
|
||||
// EnvStore struct to store the env variables
|
||||
@@ -23,12 +20,10 @@ func NewEnvStore() *EnvStore {
|
||||
|
||||
// UpdateEnvStore to update the whole env store object
|
||||
func (e *EnvStore) UpdateStore(store map[string]interface{}) {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
e.mutex.Lock()
|
||||
defer e.mutex.Unlock()
|
||||
}
|
||||
// just override the keys + new keys
|
||||
|
||||
// just override the keys + new keys
|
||||
for key, value := range store {
|
||||
e.store[key] = value
|
||||
}
|
||||
@@ -46,9 +41,8 @@ func (e *EnvStore) Get(key string) interface{} {
|
||||
|
||||
// Set sets the value of the key in env store
|
||||
func (e *EnvStore) Set(key string, value interface{}) {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
e.mutex.Lock()
|
||||
defer e.mutex.Unlock()
|
||||
}
|
||||
|
||||
e.store[key] = value
|
||||
}
|
||||
|
@@ -1,11 +1,8 @@
|
||||
package stores
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
)
|
||||
|
||||
// SessionStore struct to store the env variables
|
||||
@@ -29,10 +26,9 @@ func (s *SessionStore) Get(key, subKey string) string {
|
||||
|
||||
// Set sets the value of the key in state store
|
||||
func (s *SessionStore) Set(key string, subKey, value string) {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
}
|
||||
|
||||
if _, ok := s.store[key]; !ok {
|
||||
s.store[key] = make(map[string]string)
|
||||
}
|
||||
@@ -41,19 +37,15 @@ func (s *SessionStore) Set(key string, subKey, value string) {
|
||||
|
||||
// RemoveAll all values for given key
|
||||
func (s *SessionStore) RemoveAll(key string) {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
}
|
||||
delete(s.store, key)
|
||||
}
|
||||
|
||||
// Remove value for given key and subkey
|
||||
func (s *SessionStore) Remove(key, subKey string) {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
}
|
||||
if _, ok := s.store[key]; ok {
|
||||
delete(s.store[key], subKey)
|
||||
}
|
||||
@@ -69,11 +61,8 @@ func (s *SessionStore) GetAll(key string) map[string]string {
|
||||
|
||||
// RemoveByNamespace to delete session for a given namespace example google,github
|
||||
func (s *SessionStore) RemoveByNamespace(namespace string) error {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
}
|
||||
|
||||
for key := range s.store {
|
||||
if strings.Contains(key, namespace+":") {
|
||||
delete(s.store, key)
|
||||
|
@@ -1,10 +1,7 @@
|
||||
package stores
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
)
|
||||
|
||||
// StateStore struct to store the env variables
|
||||
@@ -28,19 +25,16 @@ func (s *StateStore) Get(key string) string {
|
||||
|
||||
// Set sets the value of the key in state store
|
||||
func (s *StateStore) Set(key string, value string) {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
}
|
||||
|
||||
s.store[key] = value
|
||||
}
|
||||
|
||||
// Remove removes the key from state store
|
||||
func (s *StateStore) Remove(key string) {
|
||||
if os.Getenv("ENV") != constants.TestEnv {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
}
|
||||
|
||||
delete(s.store, key)
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||
}
|
||||
|
||||
// validate if all params are not empty
|
||||
if params.GivenName == nil && params.FamilyName == nil && params.Picture == nil && params.MiddleName == nil && params.Nickname == nil && params.OldPassword == nil && params.Email == nil && params.Birthdate == nil && params.Gender == nil && params.PhoneNumber == nil {
|
||||
if params.GivenName == nil && params.FamilyName == nil && params.Picture == nil && params.MiddleName == nil && params.Nickname == nil && params.OldPassword == nil && params.Email == nil && params.Birthdate == nil && params.Gender == nil && params.PhoneNumber == nil && params.NewPassword == nil && params.ConfirmNewPassword == nil {
|
||||
log.Debug("All params are empty")
|
||||
return res, fmt.Errorf("please enter at least one param to update")
|
||||
}
|
||||
@@ -61,70 +61,108 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if params.GivenName != nil && user.GivenName != params.GivenName {
|
||||
if params.GivenName != nil && utils.StringValue(user.GivenName) != utils.StringValue(params.GivenName) {
|
||||
user.GivenName = params.GivenName
|
||||
}
|
||||
|
||||
if params.FamilyName != nil && user.FamilyName != params.FamilyName {
|
||||
if params.FamilyName != nil && utils.StringValue(user.FamilyName) != utils.StringValue(params.FamilyName) {
|
||||
user.FamilyName = params.FamilyName
|
||||
}
|
||||
|
||||
if params.MiddleName != nil && user.MiddleName != params.MiddleName {
|
||||
if params.MiddleName != nil && utils.StringValue(user.MiddleName) != utils.StringValue(params.MiddleName) {
|
||||
user.MiddleName = params.MiddleName
|
||||
}
|
||||
|
||||
if params.Nickname != nil && user.Nickname != params.Nickname {
|
||||
if params.Nickname != nil && utils.StringValue(user.Nickname) != utils.StringValue(params.Nickname) {
|
||||
user.Nickname = params.Nickname
|
||||
}
|
||||
|
||||
if params.Birthdate != nil && user.Birthdate != params.Birthdate {
|
||||
if params.Birthdate != nil && utils.StringValue(user.Birthdate) != utils.StringValue(params.Birthdate) {
|
||||
user.Birthdate = params.Birthdate
|
||||
}
|
||||
|
||||
if params.Gender != nil && user.Gender != params.Gender {
|
||||
if params.Gender != nil && utils.StringValue(user.Gender) != utils.StringValue(params.Gender) {
|
||||
user.Gender = params.Gender
|
||||
}
|
||||
|
||||
if params.PhoneNumber != nil && user.PhoneNumber != params.PhoneNumber {
|
||||
if params.PhoneNumber != nil && utils.StringValue(user.PhoneNumber) != utils.StringValue(params.PhoneNumber) {
|
||||
user.PhoneNumber = params.PhoneNumber
|
||||
}
|
||||
|
||||
if params.Picture != nil && user.Picture != params.Picture {
|
||||
if params.Picture != nil && utils.StringValue(user.Picture) != utils.StringValue(params.Picture) {
|
||||
user.Picture = params.Picture
|
||||
}
|
||||
|
||||
if params.OldPassword != nil {
|
||||
if err = bcrypt.CompareHashAndPassword([]byte(*user.Password), []byte(*params.OldPassword)); err != nil {
|
||||
log.Debug("Failed to compare hash and old password: ", err)
|
||||
return res, fmt.Errorf("incorrect old password")
|
||||
}
|
||||
|
||||
if params.NewPassword == nil {
|
||||
log.Debug("Failed to get new password: ")
|
||||
return res, fmt.Errorf("new password is required")
|
||||
}
|
||||
|
||||
if params.ConfirmNewPassword == nil {
|
||||
log.Debug("Failed to get confirm new password: ")
|
||||
isPasswordChanging := false
|
||||
if params.NewPassword != nil && params.ConfirmNewPassword == nil {
|
||||
isPasswordChanging = true
|
||||
log.Debug("confirm password is empty")
|
||||
return res, fmt.Errorf("confirm password is required")
|
||||
}
|
||||
|
||||
if *params.ConfirmNewPassword != *params.NewPassword {
|
||||
if params.ConfirmNewPassword != nil && params.NewPassword == nil {
|
||||
isPasswordChanging = true
|
||||
log.Debug("new password is empty")
|
||||
return res, fmt.Errorf("new password is required")
|
||||
}
|
||||
|
||||
if params.NewPassword != nil && params.ConfirmNewPassword != nil {
|
||||
isPasswordChanging = true
|
||||
}
|
||||
|
||||
if isPasswordChanging && user.Password != nil && params.OldPassword == nil {
|
||||
log.Debug("old password is empty")
|
||||
return res, fmt.Errorf("old password is required")
|
||||
}
|
||||
|
||||
if isPasswordChanging && user.Password != nil && params.OldPassword != nil {
|
||||
if err = bcrypt.CompareHashAndPassword([]byte(utils.StringValue(user.Password)), []byte(utils.StringValue(params.OldPassword))); err != nil {
|
||||
log.Debug("Failed to compare hash and old password: ", err)
|
||||
return res, fmt.Errorf("incorrect old password")
|
||||
}
|
||||
}
|
||||
|
||||
shouldAddBasicSignUpMethod := false
|
||||
isBasicAuthDisabled, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyDisableBasicAuthentication)
|
||||
if err != nil {
|
||||
log.Debug("Error getting basic auth disabled: ", err)
|
||||
isBasicAuthDisabled = true
|
||||
}
|
||||
|
||||
if params.NewPassword != nil && params.ConfirmNewPassword != nil {
|
||||
if isBasicAuthDisabled {
|
||||
log.Debug("Cannot update password as basic authentication is disabled")
|
||||
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
||||
}
|
||||
|
||||
if utils.StringValue(params.ConfirmNewPassword) != utils.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`)
|
||||
}
|
||||
|
||||
password, _ := crypto.EncryptPassword(*params.NewPassword)
|
||||
if user.Password == nil || utils.StringValue(user.Password) == "" {
|
||||
shouldAddBasicSignUpMethod = true
|
||||
}
|
||||
|
||||
if err := validators.IsValidPassword(utils.StringValue(params.NewPassword)); err != nil {
|
||||
log.Debug("Invalid password")
|
||||
return res, err
|
||||
}
|
||||
|
||||
password, _ := crypto.EncryptPassword(utils.StringValue(params.NewPassword))
|
||||
user.Password = &password
|
||||
|
||||
if shouldAddBasicSignUpMethod {
|
||||
user.SignupMethods = user.SignupMethods + "," + constants.AuthRecipeMethodBasicAuth
|
||||
}
|
||||
}
|
||||
|
||||
hasEmailChanged := false
|
||||
|
||||
if params.Email != nil && user.Email != *params.Email {
|
||||
if params.Email != nil && user.Email != utils.StringValue(params.Email) {
|
||||
// check if valid email
|
||||
if !validators.IsValidEmail(*params.Email) {
|
||||
log.Debug("Failed to validate email: ", *params.Email)
|
||||
log.Debug("Failed to validate email: ", utils.StringValue(params.Email))
|
||||
return res, fmt.Errorf("invalid email address")
|
||||
}
|
||||
newEmail := strings.ToLower(*params.Email)
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// WebhookLogsResolver resolver for getting the list of webhook_logs based on pagination & webhook identifier
|
||||
func WebhookLogsResolver(ctx context.Context, params model.ListWebhookLogRequest) (*model.WebhookLogs, error) {
|
||||
func WebhookLogsResolver(ctx context.Context, params *model.ListWebhookLogRequest) (*model.WebhookLogs, error) {
|
||||
gc, err := utils.GinContextFromContext(ctx)
|
||||
if err != nil {
|
||||
log.Debug("Failed to get GinContext: ", err)
|
||||
@@ -24,11 +24,20 @@ func WebhookLogsResolver(ctx context.Context, params model.ListWebhookLogRequest
|
||||
return nil, fmt.Errorf("unauthorized")
|
||||
}
|
||||
|
||||
pagination := utils.GetPagination(&model.PaginatedInput{
|
||||
var pagination model.Pagination
|
||||
var webhookID string
|
||||
|
||||
if params != nil {
|
||||
pagination = utils.GetPagination(&model.PaginatedInput{
|
||||
Pagination: params.Pagination,
|
||||
})
|
||||
webhookID = utils.StringValue(params.WebhookID)
|
||||
} else {
|
||||
pagination = utils.GetPagination(nil)
|
||||
webhookID = ""
|
||||
}
|
||||
|
||||
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, pagination, utils.StringValue(params.WebhookID))
|
||||
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, pagination, webhookID)
|
||||
if err != nil {
|
||||
log.Debug("failed to get webhook logs: ", err)
|
||||
return nil, err
|
||||
|
@@ -24,7 +24,11 @@ func deleteWebhookTest(t *testing.T, s TestSetup) {
|
||||
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
|
||||
|
||||
// get all webhooks
|
||||
webhooks, err := db.Provider.ListWebhook(ctx, model.Pagination{})
|
||||
webhooks, err := db.Provider.ListWebhook(ctx, model.Pagination{
|
||||
Limit: 10,
|
||||
Page: 1,
|
||||
Offset: 0,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
for _, w := range webhooks.Webhooks {
|
||||
@@ -37,12 +41,17 @@ func deleteWebhookTest(t *testing.T, s TestSetup) {
|
||||
assert.NotEmpty(t, res.Message)
|
||||
}
|
||||
|
||||
webhooks, err = db.Provider.ListWebhook(ctx, model.Pagination{})
|
||||
webhooks, err = db.Provider.ListWebhook(ctx, model.Pagination{
|
||||
Limit: 10,
|
||||
Page: 1,
|
||||
Offset: 0,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, webhooks.Webhooks, 0)
|
||||
|
||||
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, model.Pagination{
|
||||
Limit: 10,
|
||||
Limit: 100,
|
||||
Page: 1,
|
||||
Offset: 0,
|
||||
}, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, webhookLogs.WebhookLogs, 0)
|
||||
|
@@ -2,8 +2,8 @@ package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db"
|
||||
@@ -16,28 +16,42 @@ func TestResolvers(t *testing.T) {
|
||||
constants.DbTypeSqlite: "../../data.db",
|
||||
// constants.DbTypeArangodb: "http://localhost:8529",
|
||||
// constants.DbTypeMongodb: "mongodb://localhost:27017",
|
||||
// constants.DbTypeCassandraDB: "127.0.0.1:9042",
|
||||
// constants.DbTypeScyllaDB: "127.0.0.1:9042",
|
||||
}
|
||||
|
||||
for dbType, dbURL := range databases {
|
||||
testDb := "authorizer_test"
|
||||
s := testSetup()
|
||||
defer s.Server.Close()
|
||||
|
||||
for dbType, dbURL := range databases {
|
||||
ctx := context.Background()
|
||||
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDatabaseURL, dbURL)
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDatabaseType, dbType)
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDatabaseName, testDb)
|
||||
os.Setenv(constants.EnvKeyDatabaseURL, dbURL)
|
||||
os.Setenv(constants.EnvKeyDatabaseType, dbType)
|
||||
os.Setenv(constants.EnvKeyDatabaseName, testDb)
|
||||
memorystore.InitRequiredEnv()
|
||||
|
||||
err := db.InitDB()
|
||||
if err != nil {
|
||||
t.Errorf("Error initializing database: %s", err)
|
||||
t.Errorf("Error initializing database: %s", err.Error())
|
||||
}
|
||||
|
||||
// clean the persisted config for test to use fresh config
|
||||
envData, err := db.Provider.GetEnv(ctx)
|
||||
if err == nil {
|
||||
envData.EnvData = ""
|
||||
db.Provider.UpdateEnv(ctx, envData)
|
||||
_, err = db.Provider.UpdateEnv(ctx, envData)
|
||||
if err != nil {
|
||||
t.Errorf("Error updating env: %s", err.Error())
|
||||
}
|
||||
}
|
||||
err = env.PersistEnv()
|
||||
if err != nil {
|
||||
t.Errorf("Error persisting env: %s", err.Error())
|
||||
}
|
||||
env.PersistEnv()
|
||||
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyEnv, "test")
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyIsProd, false)
|
||||
@@ -78,7 +92,6 @@ func TestResolvers(t *testing.T) {
|
||||
inviteUserTest(t, s)
|
||||
validateJwtTokenTest(t, s)
|
||||
|
||||
time.Sleep(5 * time.Second) // add sleep for webhooklogs to get generated as they are async
|
||||
webhookLogsTest(t, s) // get logs after above resolver tests are done
|
||||
deleteWebhookTest(t, s) // delete webhooks (admin resolver)
|
||||
})
|
||||
|
@@ -59,7 +59,6 @@ func cleanData(email string) {
|
||||
dbUser, err := db.Provider.GetUserByEmail(ctx, email)
|
||||
if err == nil {
|
||||
db.Provider.DeleteUser(ctx, dbUser)
|
||||
db.Provider.DeleteSession(ctx, dbUser.ID)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package test
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/crypto"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func webhookLogsTest(t *testing.T, s TestSetup) {
|
||||
time.Sleep(30 * time.Second) // add sleep for webhooklogs to get generated as they are async
|
||||
t.Helper()
|
||||
t.Run("should get webhook logs", func(t *testing.T) {
|
||||
req, ctx := createContext(s)
|
||||
@@ -23,16 +25,17 @@ func webhookLogsTest(t *testing.T, s TestSetup) {
|
||||
assert.NoError(t, err)
|
||||
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
|
||||
|
||||
webhookLogs, err := resolvers.WebhookLogsResolver(ctx, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Greater(t, len(webhookLogs.WebhookLogs), 1)
|
||||
|
||||
webhooks, err := resolvers.WebhooksResolver(ctx, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, webhooks)
|
||||
|
||||
webhookLogs, err := resolvers.WebhookLogsResolver(ctx, model.ListWebhookLogRequest{})
|
||||
assert.NoError(t, err)
|
||||
assert.Greater(t, len(webhookLogs.WebhookLogs), 1)
|
||||
|
||||
for _, w := range webhooks.Webhooks {
|
||||
webhookLogs, err := resolvers.WebhookLogsResolver(ctx, model.ListWebhookLogRequest{
|
||||
t.Run(fmt.Sprintf("should get webhook for webhook_id:%s", w.ID), func(t *testing.T) {
|
||||
webhookLogs, err := resolvers.WebhookLogsResolver(ctx, &model.ListWebhookLogRequest{
|
||||
WebhookID: &w.ID,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -40,6 +43,7 @@ func webhookLogsTest(t *testing.T, s TestSetup) {
|
||||
for _, wl := range webhookLogs.WebhookLogs {
|
||||
assert.Equal(t, utils.StringValue(wl.WebhookID), w.ID)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user