Fix breakage after change to template from previous PR

This commit is contained in:
Jeff Mitchell committed 2020-08-07 15:18:44 -04:00
1 parent df4730b1a0
commit f07bb9dae6
11 files changed
+59 -43

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ import (
// TODO: This will need to be changed when we add Auth Method API to watchtower. We'll also need a better
// way to handle different auth method types.
func (c *authmethodClient) Authenticate(ctx context.Context, authMethodId, name, password string, opt ...Option) (*authtokens.AuthToken, *api.Error, error) {
func (c *authmethodsClient) Authenticate(ctx context.Context, authMethodId, name, password string, opt ...Option) (*authtokens.AuthToken, *api.Error, error) {
if c.client == nil {
return nil, nil, fmt.Errorf("nil client in Authenticate request")
}
+36
View File
@@ -0,0 +1,36 @@
package authmethods_test
import (
"net/http"
"testing"
"github.com/hashicorp/watchtower/api/authmethods"
"github.com/hashicorp/watchtower/internal/servers/controller"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAuthenticate(t *testing.T) {
assert, require := assert.New(t), require.New(t)
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultAuthMethodId: amId,
DefaultUsername: "user",
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)
assert.Nil(apiErr)
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)
}