4
0

local_user_login_test.go 813 B

1234567891011121314151617181920212223242526272829303132333435
  1. package api
  2. import (
  3. "context"
  4. "testing"
  5. "connectrpc.com/connect"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. apiv1 "github.com/OliveTin/OliveTin/gen/olivetin/api/v1"
  9. config "github.com/OliveTin/OliveTin/internal/config"
  10. )
  11. func TestLocalUserLoginRejectsUserWithNoPassword(t *testing.T) {
  12. t.Parallel()
  13. cfg := config.DefaultConfig()
  14. cfg.AuthLocalUsers.Enabled = true
  15. cfg.AuthLocalUsers.Users = []*config.LocalUser{{
  16. Username: "onlykey",
  17. ApiKey: "k",
  18. Password: "",
  19. }}
  20. ts, client := getNewTestServerAndClient(cfg)
  21. defer ts.Close()
  22. resp, err := client.LocalUserLogin(context.Background(), connect.NewRequest(&apiv1.LocalUserLoginRequest{
  23. Username: "onlykey",
  24. Password: "anything",
  25. }))
  26. require.NoError(t, err)
  27. assert.False(t, resp.Msg.GetSuccess())
  28. }