Skip to content

Commit

Permalink
Add aut for health handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dkeysil committed Mar 29, 2024
1 parent 0ce9b61 commit 90882b0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions services/json-rpc/cache/json_rpc_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,16 @@ func (p *JsonRpcCache) Name() string {

func (c *JsonRpcCache) Handler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var err error
t := time.Now()
req, err := decodeBody(r)
agentConfig, err := c.botAuthenticator.FindAgentFromRemoteAddr(r.RemoteAddr)
if err != nil {
writeBadRequest(w, req, err)
writeUnauthorized(w, nil)
return
}

agentConfig, err := c.botAuthenticator.FindAgentFromRemoteAddr(r.RemoteAddr)
if agentConfig == nil || err != nil {
writeUnauthorized(w, req)
t := time.Now()
req, err := decodeBody(r)
if err != nil {
writeBadRequest(w, req, err)
return
}

Expand Down Expand Up @@ -165,6 +164,12 @@ func (c *JsonRpcCache) Handler() http.Handler {

func (c *JsonRpcCache) HealthHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := c.botAuthenticator.FindAgentFromRemoteAddr(r.RemoteAddr)
if err != nil {
writeUnauthorized(w, nil)
return
}

chainID, err := strconv.ParseInt(mux.Vars(r)["chainID"], 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
Expand Down

0 comments on commit 90882b0

Please sign in to comment.