Revamp authenticate (#1025)
This commit is contained in:
1 parent
aa570f4e48
commit
6605b4c9f8
14 files changed
+276
-207
No files matched your search
@@ -1,11 +1,13 @@
|
||||
package authmethods_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/authmethods"
|
||||
"github.com/hashicorp/boundary/api/authtokens"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -19,13 +21,30 @@ func TestAuthenticate(t *testing.T) {
|
||||
client := tc.Client()
|
||||
methods := authmethods.NewClient(client)
|
||||
|
||||
tok, err := methods.Authenticate(tc.Context(), tc.Server().DevAuthMethodId, map[string]interface{}{"login_name": "user", "password": "passpass"})
|
||||
tok, err := methods.Authenticate(tc.Context(), tc.Server().DevAuthMethodId, "login", map[string]interface{}{"login_name": "user", "password": "passpass"})
|
||||
require.NoError(err)
|
||||
assert.NotNil(tok)
|
||||
|
||||
_, err = methods.Authenticate(tc.Context(), tc.Server().DevAuthMethodId, map[string]interface{}{"login_name": "user", "password": "wrong"})
|
||||
_, err = methods.Authenticate(tc.Context(), tc.Server().DevAuthMethodId, "login", map[string]interface{}{"login_name": "user", "password": "wrong"})
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValuesf(http.StatusUnauthorized, apiErr.Response().StatusCode(), "Expected unauthorized, got %q", apiErr.Message)
|
||||
|
||||
// Also ensure that, for now, using "credentials" still works, as well as no command.
|
||||
reqBody := map[string]interface{}{
|
||||
"credentials": map[string]interface{}{"login_name": "user", "password": "passpass"},
|
||||
}
|
||||
req, err := client.NewRequest(tc.Context(), "POST", fmt.Sprintf("auth-methods/%s:authenticate", tc.Server().DevAuthMethodId), reqBody)
|
||||
require.NoError(err)
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(err)
|
||||
|
||||
target := new(authtokens.AuthTokenReadResult)
|
||||
target.Item = new(authtokens.AuthToken)
|
||||
apiErr, err = resp.Decode(target.Item)
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(target.GetItem())
|
||||
require.NotEmpty(target.GetItem().(*authtokens.AuthToken).Token)
|
||||
}
|
||||
Reference in new issue
Block a user