-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support ad rotate-root with userattr="userPrincipalName" (#80)
- Loading branch information
1 parent
aeb8323
commit 86195e1
Showing
5 changed files
with
199 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,10 @@ import ( | |
|
||
"github.com/go-ldap/ldap/v3" | ||
"github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/vault-plugin-secrets-openldap/ldapifc" | ||
"github.com/hashicorp/vault/sdk/helper/ldaputil" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/hashicorp/vault-plugin-secrets-openldap/ldapifc" | ||
) | ||
|
||
func TestSearch(t *testing.T) { | ||
|
@@ -304,3 +306,33 @@ func testSearchResult() *ldap.SearchResult { | |
}, | ||
} | ||
} | ||
|
||
func TestToString(t *testing.T) { | ||
tcs := map[string]struct { | ||
filters map[*Field][]string | ||
expectedFilterString string | ||
}{ | ||
"no-filters": { | ||
filters: nil, | ||
expectedFilterString: "", | ||
}, | ||
"single-filter": { | ||
filters: map[*Field][]string{FieldRegistry.DomainName: {"bob"}}, | ||
expectedFilterString: "(dn=bob)", | ||
}, | ||
"two-filters": { | ||
filters: map[*Field][]string{ | ||
FieldRegistry.DomainName: {"bob"}, | ||
FieldRegistry.UserPrincipalName: {"[email protected]"}, | ||
}, | ||
expectedFilterString: "(&(dn=bob)([email protected]))", | ||
}, | ||
} | ||
|
||
for name, tc := range tcs { | ||
t.Run(name, func(t *testing.T) { | ||
got := toString(tc.filters) | ||
assert.Equal(t, tc.expectedFilterString, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package openldap | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-ldap/ldap/v3" | ||
"github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/vault/sdk/helper/ldaputil" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/hashicorp/vault-plugin-secrets-openldap/client" | ||
"github.com/hashicorp/vault-plugin-secrets-openldap/ldapifc" | ||
) | ||
|
||
func GetTestClient(fake *ldapifc.FakeLDAPConnection) *Client { | ||
ldapClient := client.NewWithClient(hclog.NewNullLogger(), &ldapifc.FakeLDAPClient{ | ||
ConnToReturn: fake, | ||
}) | ||
|
||
return &Client{ldap: ldapClient} | ||
} | ||
|
||
// UpdateDNPassword when the UserAttr is "userPrincipalName" | ||
func Test_UpdateDNPassword_AD_UserPrincipalName(t *testing.T) { | ||
newPassword := "newpassword" | ||
conn := &ldapifc.FakeLDAPConnection{ | ||
ModifyRequestToExpect: &ldap.ModifyRequest{ | ||
DN: "CN=Bob,CN=Users,DC=example,DC=net", | ||
}, | ||
SearchRequestToExpect: &ldap.SearchRequest{ | ||
BaseDN: "cn=users", | ||
Scope: ldap.ScopeWholeSubtree, | ||
Filter: "(&(objectClass=*)([email protected]))", | ||
}, | ||
SearchResultToReturn: &ldap.SearchResult{ | ||
Entries: []*ldap.Entry{ | ||
{ | ||
DN: "CN=Bob,CN=Users,DC=example,DC=net", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
c := GetTestClient(conn) | ||
config := &client.Config{ | ||
ConfigEntry: &ldaputil.ConfigEntry{ | ||
Url: "ldaps://ldap:386", | ||
UserDN: "cn=users", | ||
UPNDomain: "example.net", | ||
UserAttr: "userPrincipalName", | ||
BindDN: "username", | ||
BindPassword: "password", | ||
}, | ||
Schema: client.SchemaAD, | ||
} | ||
|
||
// depending on the schema, the password may be formatted, so we leverage this helper function | ||
fields, err := client.GetSchemaFieldRegistry(config.Schema, newPassword) | ||
assert.NoError(t, err) | ||
for k, v := range fields { | ||
conn.ModifyRequestToExpect.Replace(k.String(), v) | ||
} | ||
|
||
err = c.UpdateDNPassword(config, "bob", newPassword) | ||
assert.NoError(t, err) | ||
} | ||
|
||
// UpdateDNPassword when the UserAttr is "dn" | ||
func Test_UpdateDNPassword_AD_DN(t *testing.T) { | ||
newPassword := "newpassword" | ||
conn := &ldapifc.FakeLDAPConnection{ | ||
ModifyRequestToExpect: &ldap.ModifyRequest{ | ||
DN: "CN=Bob,CN=Users,DC=example,DC=net", | ||
}, | ||
SearchRequestToExpect: &ldap.SearchRequest{ | ||
BaseDN: "CN=Bob,CN=Users,DC=example,DC=net", | ||
Scope: ldap.ScopeBaseObject, | ||
Filter: "(objectClass=*)", | ||
}, | ||
SearchResultToReturn: &ldap.SearchResult{ | ||
Entries: []*ldap.Entry{ | ||
{ | ||
DN: "CN=Bob,CN=Users,DC=example,DC=net", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
c := GetTestClient(conn) | ||
config := &client.Config{ | ||
ConfigEntry: &ldaputil.ConfigEntry{ | ||
Url: "ldaps://ldap:386", | ||
UserAttr: "dn", | ||
BindDN: "username", | ||
BindPassword: "password", | ||
}, | ||
Schema: client.SchemaAD, | ||
} | ||
|
||
// depending on the schema, the password may be formatted, so we leverage this helper function | ||
fields, err := client.GetSchemaFieldRegistry(config.Schema, newPassword) | ||
assert.NoError(t, err) | ||
for k, v := range fields { | ||
conn.ModifyRequestToExpect.Replace(k.String(), v) | ||
} | ||
|
||
err = c.UpdateDNPassword(config, "CN=Bob,CN=Users,DC=example,DC=net", newPassword) | ||
assert.NoError(t, err) | ||
|
||
} |