2020-08-07 15:18:44 -04:00
|
|
|
package authmethods_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2020-08-10 17:15:02 -04:00
|
|
|
"github.com/hashicorp/boundary/api/authmethods"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/servers/controller"
|
2020-08-11 17:25:00 -04:00
|
|
|
"github.com/kr/pretty"
|
2020-08-07 15:18:44 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestAuthenticate(t *testing.T) {
|
|
|
|
|
assert, require := assert.New(t), require.New(t)
|
2020-08-25 00:21:08 -04:00
|
|
|
amId := "ampw_1234567890"
|
2020-08-07 15:18:44 -04:00
|
|
|
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
|
|
|
|
DisableAuthorizationFailures: true,
|
|
|
|
|
DefaultAuthMethodId: amId,
|
2020-08-11 17:25:00 -04:00
|
|
|
DefaultLoginName: "user",
|
2020-08-07 15:18:44 -04:00
|
|
|
DefaultPassword: "passpass",
|
|
|
|
|
})
|
|
|
|
|
defer tc.Shutdown()
|
|
|
|
|
|
|
|
|
|
client := tc.Client()
|
|
|
|
|
methods := authmethods.NewAuthMethodsClient(client)
|
|
|
|
|
|
|
|
|
|
tok, apiErr, err := methods.Authenticate(tc.Context(), amId, "user", "passpass")
|
|
|
|
|
require.NoError(err)
|
2020-08-11 17:25:00 -04:00
|
|
|
assert.Nil(apiErr, pretty.Sprint(apiErr))
|
2020-08-07 15:18:44 -04:00
|
|
|
assert.NotNil(tok)
|
|
|
|
|
|
|
|
|
|
_, apiErr, err = methods.Authenticate(tc.Context(), amId, "user", "wrong")
|
|
|
|
|
require.NoError(err)
|
|
|
|
|
require.NotNil(t, apiErr)
|
|
|
|
|
assert.EqualValuesf(http.StatusUnauthorized, apiErr.Status, "Expected unauthenticated, got %q", apiErr.Message)
|
|
|
|
|
}
|