Skip to content

Commit f5527aa

Browse files
fix: signing logic and body mismatch
1 parent 0788109 commit f5527aa

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

jamq-replica/globals/global.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package globals
2+
3+
var Body string = ""

jamq-replica/router/middleware/auth.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/base64"
55
"fmt"
66
"jamq-replica/constants"
7+
"jamq-replica/globals"
78
"net/http"
89
"os"
910
"strconv"
@@ -14,15 +15,18 @@ import (
1415
"crypto/sha256"
1516

1617
"github.com/labstack/echo/v4"
18+
"github.com/valyala/bytebufferpool"
1719
)
1820

1921
func Authenticate(next echo.HandlerFunc) echo.HandlerFunc {
2022
return func(c echo.Context) error {
21-
var bodyBytes []byte
23+
bodyBytesBuffer := &bytebufferpool.ByteBuffer{}
2224
request := c.Request()
2325
header := request.Header
24-
request.Body.Read(bodyBytes)
25-
body := string(bodyBytes)
26+
bodyBytesBuffer.ReadFrom(request.Body)
27+
body := bodyBytesBuffer.String()
28+
globals.Body = body
29+
fmt.Println("Body is: " + body)
2630
queryString := strings.ToValidUTF8(c.QueryString(), "")
2731
nonce := header.Get(constants.GetHeaders().X_AUTH_NONCE)
2832
sentTimestamp, err := strconv.Atoi(nonce)

jamq-replica/utils/json.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package utils
22

33
import (
4-
"bytes"
54
"encoding/json"
6-
7-
"github.com/labstack/echo/v4"
5+
"jamq-replica/globals"
86
)
97

10-
func GetRequestBody(c echo.Context, requestBody interface{}) error {
11-
bytesBuff := new(bytes.Buffer)
12-
bytesBuff.ReadFrom(c.Request().Body)
13-
err := json.Unmarshal(bytesBuff.Bytes(), requestBody)
8+
func GetRequestBody(requestBody interface{}) error {
9+
err := json.Unmarshal([]byte(globals.Body), requestBody)
1410
return err
1511
}

jamq-replica/v1/handler.go

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func HandleSendMessage(c echo.Context) error {
4343
if err != nil {
4444
return echo.NewHTTPError(400, err.Error())
4545
}
46+
err = utils.GetRequestBody(request)
47+
if err != nil {
48+
return echo.NewHTTPError(400, err.Error())
49+
}
4650
err = queueService.SendMessage(c.Param("queueName"), request.Message, request.Timestamp)
4751
if err != nil {
4852
return echo.NewHTTPError(400, err.Error())

0 commit comments

Comments
 (0)