From 95f2a207194768782d8b00b33ba6f39f9a8f35fe Mon Sep 17 00:00:00 2001 From: Owen Cabalceta Date: Mon, 15 Jul 2024 22:04:49 -0400 Subject: [PATCH] patch: mocktr181 returns 520 for unsupported commands - mocktr181 currently only supports `set` and `get` commands --- internal/wrphandlers/mocktr181/handler.go | 3 ++- internal/wrphandlers/mocktr181/handler_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/wrphandlers/mocktr181/handler.go b/internal/wrphandlers/mocktr181/handler.go index 1ee5198..c3183ad 100644 --- a/internal/wrphandlers/mocktr181/handler.go +++ b/internal/wrphandlers/mocktr181/handler.go @@ -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 diff --git a/internal/wrphandlers/mocktr181/handler_test.go b/internal/wrphandlers/mocktr181/handler_test.go index 717b31a..de3cba4 100644 --- a/internal/wrphandlers/mocktr181/handler_test.go +++ b/internal/wrphandlers/mocktr181/handler_test.go @@ -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 }, },