MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestCreateMachineAlreadyExist

Function TestCreateMachineAlreadyExist

pkg/apiserver/machines_test.go:133–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

131}
132
133func TestCreateMachineAlreadyExist(t *testing.T) {
134 ctx := t.Context()
135 router, _ := NewAPITest(t, ctx)
136
137 body := CreateTestMachine(t, ctx, router, "")
138
139 w := httptest.NewRecorder()
140 req, err := http.NewRequestWithContext(ctx, http.MethodPost, "/v1/watchers", strings.NewReader(body))
141 require.NoError(t, err)
142 req.Header.Add("User-Agent", UserAgent)
143 router.ServeHTTP(w, req)
144
145 w = httptest.NewRecorder()
146 req, err = http.NewRequestWithContext(ctx, http.MethodPost, "/v1/watchers", strings.NewReader(body))
147 require.NoError(t, err)
148 req.Header.Add("User-Agent", UserAgent)
149 router.ServeHTTP(w, req)
150
151 assert.Equal(t, http.StatusForbidden, w.Code)
152 assert.JSONEq(t, `{"message":"user 'test': user already exist"}`, w.Body.String())
153}
154
155func TestAutoRegistration(t *testing.T) {
156 ctx := t.Context()

Callers

nothing calls this directly

Calls 5

NewAPITestFunction · 0.85
CreateTestMachineFunction · 0.85
NewReaderMethod · 0.80
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…