Migrate user name to login name (#255)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-08-11 17:25:00 -04:00
1 parent 6f886976e4
commit 4cfab04307
50 files changed
+528 -527

No files matched your search

+2 -2
View File
@@ -19,8 +19,8 @@ func (c *authmethodsClient) Authenticate(ctx context.Context, authMethodId, name
reqBody := map[string]interface{}{
"credentials": map[string]string{
"name": name,
"password": password,
"login_name": name,
"password": password,
},
}
+3 -2
View File
@@ -6,6 +6,7 @@ import (
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/internal/servers/controller"
"github.com/kr/pretty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -16,7 +17,7 @@ func TestAuthenticate(t *testing.T) {
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultAuthMethodId: amId,
DefaultUsername: "user",
DefaultLoginName: "user",
DefaultPassword: "passpass",
})
defer tc.Shutdown()
@@ -26,7 +27,7 @@ func TestAuthenticate(t *testing.T) {
tok, apiErr, err := methods.Authenticate(tc.Context(), amId, "user", "passpass")
require.NoError(err)
assert.Nil(apiErr)
assert.Nil(apiErr, pretty.Sprint(apiErr))
assert.NotNil(tok)
_, apiErr, err = methods.Authenticate(tc.Context(), amId, "user", "wrong")
+48 -48
View File
@@ -89,6 +89,54 @@ func DefaultDisabled() Option {
}
}
func WithPasswordAccountLoginName(inLoginName string) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["login_name"] = inLoginName
o.valueMap["attributes"] = val
}
}
func DefaultPasswordAccountLoginName() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["login_name"] = nil
o.valueMap["attributes"] = val
}
}
func WithPasswordAuthMethodMinLoginNameLength(inMinLoginNameLength uint32) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_login_name_length"] = inMinLoginNameLength
o.valueMap["attributes"] = val
}
}
func DefaultPasswordAuthMethodMinLoginNameLength() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_login_name_length"] = nil
o.valueMap["attributes"] = val
}
}
func WithPasswordAuthMethodMinPasswordLength(inMinPasswordLength uint32) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
@@ -113,30 +161,6 @@ func DefaultPasswordAuthMethodMinPasswordLength() Option {
}
}
func WithPasswordAuthMethodMinUserNameLength(inMinUserNameLength uint32) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_user_name_length"] = inMinUserNameLength
o.valueMap["attributes"] = val
}
}
func DefaultPasswordAuthMethodMinUserNameLength() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_user_name_length"] = nil
o.valueMap["attributes"] = val
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
@@ -184,27 +208,3 @@ func DefaultType() Option {
o.valueMap["type"] = nil
}
}
func WithPasswordAccountUsername(inUsername string) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["username"] = inUsername
o.valueMap["attributes"] = val
}
}
func DefaultPasswordAccountUsername() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["username"] = nil
o.valueMap["attributes"] = val
}
}
@@ -2,6 +2,6 @@
package authmethods
type PasswordAccountAttributes struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
LoginName string `json:"login_name,omitempty"`
Password string `json:"password,omitempty"`
}
@@ -2,6 +2,6 @@
package authmethods
type PasswordAuthMethodAttributes struct {
MinUserNameLength uint32 `json:"min_user_name_length,omitempty"`
MinPasswordLength uint32 `json:"min_password_length,omitempty"`
MinLoginNameLength uint32 `json:"min_login_name_length,omitempty"`
MinPasswordLength uint32 `json:"min_password_length,omitempty"`
}