mirror of
https://github.com/FlipsideCrypto/convox.git
synced 2026-02-06 19:07:13 +00:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package api_test
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/convox/logger"
|
|
"github.com/convox/convox/pkg/api"
|
|
"github.com/convox/convox/pkg/structs"
|
|
"github.com/convox/convox/sdk"
|
|
"github.com/convox/stdsdk"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAuthentication(t *testing.T) {
|
|
p := &structs.MockProvider{}
|
|
p.On("Initialize", mock.Anything).Return(nil)
|
|
|
|
s := api.NewWithProvider(p)
|
|
s.Logger = logger.Discard
|
|
s.Password = "pass1"
|
|
s.Server.Recover = func(err error) {
|
|
require.NoError(t, err, "httptest server panic")
|
|
}
|
|
|
|
ht := httptest.NewServer(s)
|
|
defer ht.Close()
|
|
|
|
c, err := sdk.New(ht.URL)
|
|
require.NoError(t, err)
|
|
|
|
res, err := c.GetStream("/apps", stdsdk.RequestOptions{})
|
|
require.EqualError(t, err, "invalid authentication")
|
|
require.Nil(t, res)
|
|
|
|
u, err := url.Parse(ht.URL)
|
|
require.NoError(t, err)
|
|
|
|
u.User = url.UserPassword("convox", "pass1")
|
|
|
|
c, err = sdk.New(u.String())
|
|
require.NoError(t, err)
|
|
|
|
_, err = c.GetStream("/auth", stdsdk.RequestOptions{})
|
|
require.NoError(t, err)
|
|
}
|