Private
Public Access
1
0

server: enforce auth for updates

This commit is contained in:
2024-04-04 22:59:59 -07:00
parent c666083e4b
commit 63876104aa

View File

@@ -330,6 +330,15 @@ func (m *MockHTTPServer) handleMarkConversation(w http.ResponseWriter, r *http.R
w.WriteHeader(http.StatusOK)
}
func (m *MockHTTPServer) handleUpdates(w http.ResponseWriter, r *http.Request) {
if !m.requireAuthentication(w, r) {
return
}
s := websocket.Server{Handler: websocket.Handler(m.handleUpdatesWebsocket)}
s.ServeHTTP(w, r)
}
func (m *MockHTTPServer) handleUpdatesWebsocket(c *websocket.Conn) {
// Fetch updates continuously
defer c.Close()
@@ -371,12 +380,7 @@ func NewMockHTTPServer(config MockHTTPServerConfiguration) *MockHTTPServer {
this.mux.Handle("/pollUpdates", http.HandlerFunc(this.handlePollUpdates))
this.mux.Handle("/sendMessage", http.HandlerFunc(this.handleSendMessage))
this.mux.Handle("/markConversation", http.HandlerFunc(this.handleMarkConversation))
// /updates websocket
this.mux.Handle("/updates", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s := websocket.Server{Handler: websocket.Handler(this.handleUpdatesWebsocket)}
s.ServeHTTP(w, r)
}))
this.mux.Handle("/updates", http.HandlerFunc(this.handleUpdates))
this.mux.Handle("/", http.HandlerFunc(this.handleNotFound))