server: enforce auth for updates
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user