password connectors: allow overriding the username attribute (password prompt)
This allows users of the LDAP connector to give users of Dex' login prompt an idea of what they should enter for a username. Before, irregardless of how the LDAP connector was set up, the prompt was Username [_________________] Password [_________________] Now, this is configurable, and can be used to say "MyCorp SSO Login" if that's what it is. If it's not configured, it will default to "Username". For the passwordDB connector (local users), it is set to "Email Address", since this is what it uses. Signed-off-by: Stephan Renatus <srenatus@chef.io>
This commit is contained in:
@@ -77,6 +77,11 @@ type Config struct {
|
||||
BindDN string `json:"bindDN"`
|
||||
BindPW string `json:"bindPW"`
|
||||
|
||||
// UsernamePrompt allows users to override the username attribute (displayed
|
||||
// in the username/password prompt). If unset, the handler will use
|
||||
// "Username".
|
||||
UsernamePrompt string `json:"usernamePrompt"`
|
||||
|
||||
// User entry search configuration.
|
||||
UserSearch struct {
|
||||
// BsaeDN to start the search from. For example "cn=users,dc=example,dc=com"
|
||||
@@ -545,3 +550,7 @@ func (c *ldapConnector) groups(ctx context.Context, user ldap.Entry) ([]string,
|
||||
}
|
||||
return groupNames, nil
|
||||
}
|
||||
|
||||
func (c *ldapConnector) Prompt() string {
|
||||
return c.UsernamePrompt
|
||||
}
|
||||
|
@@ -437,6 +437,31 @@ userpassword: foo
|
||||
runTests(t, schema, connectLDAPS, c, tests)
|
||||
}
|
||||
|
||||
func TestUsernamePrompt(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
config Config
|
||||
expected string
|
||||
}{
|
||||
"with usernamePrompt unset it returns \"\"": {
|
||||
config: Config{},
|
||||
expected: "",
|
||||
},
|
||||
"with usernamePrompt set it returns that": {
|
||||
config: Config{UsernamePrompt: "Email address"},
|
||||
expected: "Email address",
|
||||
},
|
||||
}
|
||||
|
||||
for n, d := range tests {
|
||||
t.Run(n, func(t *testing.T) {
|
||||
conn := &ldapConnector{Config: d.config}
|
||||
if actual := conn.Prompt(); actual != d.expected {
|
||||
t.Errorf("expected %v, got %v", d.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// runTests runs a set of tests against an LDAP schema. It does this by
|
||||
// setting up an OpenLDAP server and injecting the provided scheme.
|
||||
//
|
||||
|
Reference in New Issue
Block a user