2020-08-07 15:18:44 -04:00
|
|
|
package authmethods_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2020-09-24 14:34:58 -07:00
|
|
|
"github.com/hashicorp/boundary/api"
|
2020-08-10 17:15:02 -04:00
|
|
|
"github.com/hashicorp/boundary/api/authmethods"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/servers/controller"
|
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)
|
2021-02-11 13:14:18 -05:00
|
|
|
tc := controller.NewTestController(t, nil)
|
2020-08-07 15:18:44 -04:00
|
|
|
defer tc.Shutdown()
|
|
|
|
|
|
|
|
|
|
client := tc.Client()
|
2020-08-27 20:43:33 -04:00
|
|
|
methods := authmethods.NewClient(client)
|
2020-08-07 15:18:44 -04:00
|
|
|
|
2021-02-11 13:14:18 -05:00
|
|
|
tok, err := methods.Authenticate(tc.Context(), tc.Server().DevAuthMethodId, map[string]interface{}{"login_name": "user", "password": "passpass"})
|
2020-08-07 15:18:44 -04:00
|
|
|
require.NoError(err)
|
|
|
|
|
assert.NotNil(tok)
|
|
|
|
|
|
2021-02-11 13:14:18 -05:00
|
|
|
_, err = methods.Authenticate(tc.Context(), tc.Server().DevAuthMethodId, map[string]interface{}{"login_name": "user", "password": "wrong"})
|
2020-09-24 14:34:58 -07:00
|
|
|
require.Error(err)
|
|
|
|
|
apiErr := api.AsServerError(err)
|
|
|
|
|
require.NotNil(apiErr)
|
2021-02-25 12:43:17 -05:00
|
|
|
assert.EqualValuesf(http.StatusUnauthorized, apiErr.Response().StatusCode(), "Expected unauthorized, got %q", apiErr.Message)
|
2020-08-07 15:18:44 -04:00
|
|
|
}
|