MCPcopy Create free account
hub / github.com/gotify/server / Test_UpdateConfig_malformedYAML_expect400

Method Test_UpdateConfig_malformedYAML_expect400

api/plugin_test.go:534–564  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

532}
533
534func (s *PluginSuite) Test_UpdateConfig_malformedYAML_expect400() {
535 conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath)
536 assert.NoError(s.T(), err)
537 inst, err := s.manager.Instance(conf.ID)
538 assert.Nil(s.T(), err)
539 mockInst := inst.(*mock.PluginInstance)
540 origConfig := mockInst.Config
541
542 newConfigYAML := []byte(`--- "rg e""`)
543
544 {
545 test.WithUser(s.ctx, 1)
546
547 s.ctx.Request = httptest.NewRequest("POST", fmt.Sprintf("/plugin/%d/config", conf.ID), bytes.NewReader(newConfigYAML))
548 s.ctx.Header("Content-Type", "application/x-yaml")
549 s.ctx.Params = gin.Params{{Key: "id", Value: fmt.Sprint(conf.ID)}}
550 s.a.UpdateConfig(s.ctx)
551
552 assert.Equal(s.T(), 400, s.recorder.Code)
553 assert.Equal(s.T(), origConfig, mockInst.Config, "config should not be received by plugin")
554
555 var pluginFromDBBytes []byte
556 if pluginConf, err := s.db.GetPluginConfByID(conf.ID); assert.NoError(s.T(), err) {
557 pluginFromDBBytes = pluginConf.Config
558 }
559 pluginFromDB := new(mock.PluginConfig)
560 err := yaml.Unmarshal(pluginFromDBBytes, pluginFromDB)
561 assert.Nil(s.T(), err)
562 assert.Equal(s.T(), origConfig, pluginFromDB, "config should not be updated in database")
563 }
564}
565
566func (s *PluginSuite) Test_UpdateConfig_ioError_expect500() {
567 conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath)

Callers

nothing calls this directly

Calls 5

WithUserFunction · 0.92
InstanceMethod · 0.80
UpdateConfigMethod · 0.80
GetPluginConfByIDMethod · 0.65

Tested by

no test coverage detected