1
0
Fork 0
telegraf/plugins/common/auth/basic_auth_test.go

35 lines
745 B
Go
Raw Permalink Normal View History

package auth
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestBasicAuth_VerifyWithCredentials(t *testing.T) {
auth := BasicAuth{"username", "password"}
r := httptest.NewRequest("GET", "/github", nil)
r.SetBasicAuth(auth.Username, auth.Password)
require.True(t, auth.Verify(r))
}
func TestBasicAuth_VerifyWithoutCredentials(t *testing.T) {
auth := BasicAuth{}
r := httptest.NewRequest("GET", "/github", nil)
require.True(t, auth.Verify(r))
}
func TestBasicAuth_VerifyWithInvalidCredentials(t *testing.T) {
auth := BasicAuth{"username", "password"}
r := httptest.NewRequest("GET", "/github", nil)
r.SetBasicAuth("wrong-username", "wrong-password")
require.False(t, auth.Verify(r))
}