MCPcopy
hub / github.com/influxdata/telegraf / TestAuthenticationBasic

Function TestAuthenticationBasic

plugins/secretstores/http/http_test.go:373–402  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

371}
372
373func TestAuthenticationBasic(t *testing.T) {
374 dummy, err := net.Listen("tcp", "127.0.0.1:0")
375 require.NoError(t, err)
376 defer dummy.Close()
377
378 var header http.Header
379 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
380 header = r.Header
381 if _, err = w.Write([]byte(`{}`)); err != nil {
382 w.WriteHeader(http.StatusInternalServerError)
383 t.Error(err)
384 return
385 }
386 }))
387 defer server.Close()
388
389 plugin := &HTTP{
390 URL: server.URL,
391 Username: config.NewSecret([]byte("myuser")),
392 Password: config.NewSecret([]byte("mypass")),
393 SuccessStatusCodes: []int{200, 300},
394 }
395 plugin.Timeout = config.Duration(200 * time.Millisecond)
396 require.NoError(t, plugin.Init())
397 require.NoError(t, plugin.download())
398
399 auth := header.Get("Authorization")
400 require.NotEmpty(t, auth)
401 require.Equal(t, "Basic bXl1c2VyOm15cGFzcw==", auth)
402}
403
404func TestAuthenticationToken(t *testing.T) {
405 dummy, err := net.Listen("tcp", "127.0.0.1:0")

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
InitMethod · 0.95
downloadMethod · 0.95
NewSecretFunction · 0.92
DurationTypeAlias · 0.92
WriteHeaderMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.65
GetMethod · 0.65
ListenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…