Skip to content

Commit edf967f

Browse files
authored
MG-94 - Add authorization on downstream messages in WS (#96)
* feat(ws.go): add auth on downstream publish Signed-off-by: Felix Gateru <[email protected]> * ci: add no contextcheck on failing cases Signed-off-by: Felix Gateru <[email protected]> * refactor: rearrange nolint comment lines Signed-off-by: Felix Gateru <[email protected]> --------- Signed-off-by: Felix Gateru <[email protected]>
1 parent abf4dfc commit edf967f

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

pkg/http/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7979
}
8080

8181
if isWebSocketRequest(r) {
82+
//nolint:contextcheck // handleWebSocket does not need context
8283
p.handleWebSocket(w, r, s)
8384
return
8485
}

pkg/http/ws.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,18 @@ func (p *Proxy) stream(ctx context.Context, topic string, src, dest *websocket.C
101101
if err != nil {
102102
return handleStreamErr(err, upstream)
103103
}
104-
if upstream {
104+
switch upstream {
105+
case true:
105106
if err := p.session.AuthPublish(ctx, &topic, &payload); err != nil {
106107
return err
107108
}
108109
if err := p.session.Publish(ctx, &topic, &payload); err != nil {
109110
return err
110111
}
112+
default:
113+
if err := p.session.AuthSubscribe(ctx, &[]string{topic}); err != nil {
114+
return err
115+
}
111116
}
112117
if err := dest.WriteMessage(messageType, payload); err != nil {
113118
return err

pkg/mqtt/websocket/websocket.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6767
return
6868
}
6969

70+
//nolint:contextcheck // new context is created in pass method
7071
go p.pass(cconn)
7172
}
7273

0 commit comments

Comments
 (0)