Skip to content

Commit

Permalink
patch: mocktr181 returns 520 for unsupported commands
Browse files Browse the repository at this point in the history
- mocktr181 currently only supports `set` and `get` commands
  • Loading branch information
denopink committed Jul 16, 2024
1 parent a22907f commit 95f2a20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/wrphandlers/mocktr181/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func (h Handler) HandleWrp(msg wrp.Message) error {

default:
// currently only get and set are implemented for existing mocktr181
statusCode = http.StatusOK
statusCode = 520
payloadResponse = []byte(fmt.Sprintf(`{"message": "command %s is not support"}`, command))
}

response := msg
Expand Down
15 changes: 15 additions & 0 deletions internal/wrphandlers/mocktr181/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ func TestHandler_HandleWrp(t *testing.T) {
a.Equal(int64(520), *msg.Status)
a.True(h.Enabled())

return nil
},
}, {
description: "unknown command",
egressCallCount: 1,
msg: wrp.Message{
Type: wrp.SimpleEventMessageType,
Source: "dns:tr1d1um.example.com/service/ignored",
Destination: "event:event_1/ignored",
Payload: []byte("{\"command\":\"FOOBAR\",\"parameters\":[{\"name\":\"Device.Bridging.MaxBridgeEntries\",\"dataType\":0,\"value\":\"anothername\",\"attributes\":{\"notify\":0}}]}"),
},
validate: func(a *assert.Assertions, msg wrp.Message, h *Handler) error {
a.Equal(int64(520), *msg.Status)
a.True(h.Enabled())

return nil
},
},
Expand Down

0 comments on commit 95f2a20

Please sign in to comment.