Skip to content

Commit

Permalink
Do not send sent events to the server for multipart messages with inv…
Browse files Browse the repository at this point in the history
…alid ID
  • Loading branch information
AchoArnold committed Nov 28, 2023
1 parent b751051 commit f333120
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/pkg/handlers/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func (h *MessageHandler) PostEvent(c *fiber.Ctx) error {
return h.responseUnprocessableEntity(c, errors, "validation errors while storing event")
}

request.Sanitize()
message, err := h.service.GetMessage(ctx, h.userIDFomContext(c), uuid.MustParse(request.MessageID))
if err != nil && stacktrace.GetCode(err) == repositories.ErrCodeNotFound {
return h.responseNotFound(c, fmt.Sprintf("cannot find message with ID [%s]", request.MessageID))
Expand Down
10 changes: 9 additions & 1 deletion api/pkg/requests/message_event_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

// MessageEvent is the payload for sending and SMS message
type MessageEvent struct {
request

// Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible
Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"`

Expand All @@ -26,8 +28,14 @@ type MessageEvent struct {
MessageID string `json:"messageID" swaggerignore:"true"` // used internally for validation
}

// Sanitize the message event
func (input *MessageEvent) Sanitize() *MessageEvent {
input.MessageID = input.sanitizeMessageID(input.MessageID)
return input
}

// ToMessageStoreEventParams converts MessageEvent to services.MessageStoreEventParams
func (input MessageEvent) ToMessageStoreEventParams(source string) services.MessageStoreEventParams {
func (input *MessageEvent) ToMessageStoreEventParams(source string) services.MessageStoreEventParams {
return services.MessageStoreEventParams{
MessageID: uuid.MustParse(input.MessageID),
Source: source,
Expand Down
11 changes: 11 additions & 0 deletions api/pkg/requests/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ func (input *request) removeStringDuplicates(values []string) []string {
return result
}

func (input *request) sanitizeMessageID(value string) string {
id := strings.Builder{}
for _, char := range value {
if char == '.' {
return id.String()
}
id.WriteRune(char)
}
return id.String()
}

// getLimit gets the take as a string
func (input *request) getBool(value string) bool {
if value == "true" {
Expand Down

0 comments on commit f333120

Please sign in to comment.