feat: add API support for additional LDAP auth method fields. (#3679)

* feat (auth/ldap): add Repo support for max page size and deref aliases (#3670)

* chore: update cap/ldap dependency

This latest version of cap/ldap adds support for MaxPageSize and
DerefAliases

* feat (auth/ldap): add MaxPageSize and DerefAliases to storage proto

* feat (api/authmethods): add new ldap fields.

Add support for maximum_page_size and dereference_aliases

* feat (auth/ldap): schema changes to support new LDAP attributes

* feat (auth/ldap): add Repo support for max page size and deref aliases

* feat (handlers/ldap): add support for new fields (#3674)

Added API support for new ldap fields: MaximumPageSize and
DereferenceAliases

* chore: add CHANGELOG entry for new api auth ldap fields
This commit is contained in:
Jim authored and GitHub committed 2023-09-06 15:07:45 -04:00
1 parent b2c0300dac
commit dc89ca28a1
28 files changed
+1166 -237

No files matched your search

+39
View File
@@ -64,6 +64,8 @@ func TestNewAuthMethod(t *testing.T) {
WithCertificates(testCtx, testCert),
WithClientCertificate(testCtx, derPrivKey, testCert), // not a client cert but good enough for this test.
WithAccountAttributeMap(testCtx, map[string]AccountToAttribute{"mail": "email"}),
WithDerefAliases(testCtx, DerefAlways),
WithMaximumPageSize(testCtx, 10),
},
want: &AuthMethod{
AuthMethod: &store.AuthMethod{
@@ -90,6 +92,8 @@ func TestNewAuthMethod(t *testing.T) {
ClientCertificate: testCertEncoded,
ClientCertificateKey: derPrivKey,
AccountAttributeMaps: []string{"mail=email"},
DereferenceAliases: string(DerefAlways),
MaximumPageSize: 10,
},
},
},
@@ -127,6 +131,18 @@ func TestNewAuthMethod(t *testing.T) {
wantErrCode: errors.InvalidParameter,
wantErrContains: `https scheme in url "https://alice.com" is not either ldap or ldaps`,
},
{
name: "invalid-deref-aliases",
ctx: testCtx,
scopeId: "global",
urls: TestConvertToUrls(t, "ldaps://alice.com"),
opts: []Option{
WithDerefAliases(testCtx, "invalid"),
},
wantErr: true,
wantErrCode: errors.InvalidParameter,
wantErrContains: `"invalid" is not a valid ldap dereference alias type`,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
@@ -208,6 +224,8 @@ func TestAuthMethod_clone(t *testing.T) {
WithBindCredential(testCtx, "bind-dn", "bind-password"),
WithCertificates(testCtx, testCert),
WithClientCertificate(testCtx, derPrivKey, testCert), // not a client cert but good enough for this test.
WithDerefAliases(testCtx, DerefAlways),
WithMaximumPageSize(testCtx, 10),
)
require.NoError(err)
cp := am.clone()
@@ -370,6 +388,9 @@ func Test_convertValueObjects(t *testing.T) {
testBindCredential, err := NewBindCredential(testCtx, testPublicId, "bind-dn", []byte("bind-password"))
require.NoError(t, err)
testDerefAliases, err := NewDerefAliases(testCtx, testPublicId, DerefAlways)
require.NoError(t, err)
tests := []struct {
name string
am *AuthMethod
@@ -393,6 +414,7 @@ func Test_convertValueObjects(t *testing.T) {
BindDn: "bind-dn",
BindPassword: "bind-password",
AccountAttributeMaps: testAttrMaps,
DereferenceAliases: string(DerefAlways),
},
},
wantValues: &convertedValues{
@@ -403,6 +425,7 @@ func Test_convertValueObjects(t *testing.T) {
ClientCertificate: testClientCertificate,
BindCredential: testBindCredential,
AccountAttributeMaps: testAccountAttributeMaps,
DerefAliases: testDerefAliases,
},
},
{
@@ -490,6 +513,17 @@ func Test_convertValueObjects(t *testing.T) {
wantErrMatch: errors.T(errors.InvalidParameter),
wantErrContains: "failed to parse certificate",
},
{
name: "invalid-deref-aliases",
am: &AuthMethod{
AuthMethod: &store.AuthMethod{
PublicId: testPublicId,
DereferenceAliases: "invalid",
},
},
wantErrMatch: errors.T(errors.InvalidParameter),
wantErrContains: `"invalid" is not a valid ldap dereference alias type:`,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
@@ -561,6 +595,11 @@ func Test_convertValueObjects(t *testing.T) {
require.Error(err)
assert.Nil(convertedBindCredential)
assert.Truef(errors.Match(wantErrMatch, err), "wanted err %q and got: %+v", wantErrMatch.Code, err)
convertedDerefAliases, err := am.convertDerefAliases(testCtx)
require.Error(err)
assert.Nil(convertedDerefAliases)
assert.Truef(errors.Match(wantErrMatch, err), "wanted err %q and got: %+v", wantErrMatch.Code, err)
})
}