PUT /api/config took a whole config, so an app could move the server's location; the location is the server's own, from its flags.
- commit
- 71151f59be443b65522c7e2ccfd70859155e73e2
- parent
- b15ab0845c3b1b1e2e8f8a00c82e7e8c3e28ddd4
- author
- FelineStateMachine <226808055+FelineStateMachine@users.noreply.github.com>
- kind
- fix risk score 1.9 of 3, Jev's estimate
| M | internal/ | 10 | +++++++++- |
| M | internal/ | 9 | ++++++--- |
@@ -136,12 +136,20 @@ func (s *Server) Handler() http.Handler {
136136 mux.HandleFunc("GET /api/config", func(w http.ResponseWriter, r *http.Request) {137137 reply(w)(b.Config(r.Context()))138138 })139+ // Apps change only the hours of listings: the location is the140+ // server's own, from its flags.139141 mux.HandleFunc("PUT /api/config", func(w http.ResponseWriter, r *http.Request) {140142 var c service.Config141143 if !decode(w, r, &c) {142144 return143145 }144- reply(w)(b.SetConfig(r.Context(), c))146+ cur, err := b.Config(r.Context())147+ if err != nil {148+ reply(w)(nil, err)149+ return150+ }151+ cur.GuideHours = c.GuideHours152+ reply(w)(b.SetConfig(r.Context(), cur))145153 })146154 mux.HandleFunc("GET /api/snapshot", func(w http.ResponseWriter, r *http.Request) {147155 reply(w)(b.Snapshot(r.Context(), r.URL.Query().Get("refresh") == "1"))@@ -81,7 +81,7 @@ func (f *fake) Stop(_ context.Context, client string) error { f.stopped = client
8181 func (f *fake) Heartbeat(_ context.Context, client string) (bool, error) {8282 return client == "mac" && f.stopped == "", nil8383 }84-func (f *fake) DVR(context.Context) (*dvr.State, error) { return &dvr.State{Available: true}, nil }84+func (f *fake) DVR(context.Context) (*dvr.State, error) { return &dvr.State{Available: true}, nil }8585 func (f *fake) Record(_ context.Context, r dvr.Request) (*dvr.Rule, error) {8686 return &dvr.Rule{ID: "r1", Kind: r.Kind, Channel: r.Channel}, nil8787 }@@ -137,8 +137,11 @@ func TestClientServerRoundTrip(t *testing.T) {
137137 if be.tuned != "mac:7.1" || pb.URL != srv.URL+"/live/abc/index.m3u8" {138138 t.Errorf("tune: backend saw %q, playback URL %q", be.tuned, pb.URL)139139 }140- if _, err := c.SetConfig(ctx, service.Config{ZIP: "80302"}); err != nil || be.cfg.ZIP != "80302" {141- t.Errorf("set config: %v, backend has %+v", err, be.cfg)140+ // An app changes the hours of listings, never the location.141+ be.cfg = service.Config{ZIP: "80302", RadiusKm: 160, GuideHours: 24}142+ if got, err := c.SetConfig(ctx, service.Config{ZIP: "10001", Lat: 40.7, Lon: -74, GuideHours: 48}); err != nil ||143+ be.cfg != (service.Config{ZIP: "80302", RadiusKm: 160, GuideHours: 48}) || got != be.cfg {144+ t.Errorf("set config: %+v, %v, backend has %+v", got, err, be.cfg)142145 }143146 if err := c.DeleteRecording(ctx, "e/1"); err != nil || be.deleted != "e/1" {144147 t.Errorf("delete: %v, backend saw %q", err, be.deleted)