-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ldap] Allow user customization of field mapping
Attributes from a user's LDAP record are used during account-linking to populate the erchef user record when it is created. Previously, the mapping between LDAP attributes and chef user attributes were fixed. Now, they are configurable. For example, if the user's LDAP record stores their email address in a field named 'address' instead of 'mail', then you could set the following in private-chef.rb: ldap['email_attribute'] = "address" Fixes #151 Fixes #800 Fixes #104 Partially addresses #675 Issue #800 was also addressed in #863 which allowed common_name to service as a fallback for display name. The fallback is still in place but now any field can be used for the display_name. Issue #675 is an issue which our unicode handling. The unicode handling is still broken; however, this would allow users to use a different field that might not contain multi-byte characters. Signed-off-by: Steven Danna <[email protected]>
- Loading branch information
1 parent
af590a3
commit 925cbaa
Showing
4 changed files
with
174 additions
and
22 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 |
---|---|---|
|
@@ -21,6 +21,50 @@ | |
-module(oc_chef_wm_authn_ldap_tests). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
-define(DEFAULT_CONFIG, [{host,"192.168.33.152"}, | ||
{port,389}, | ||
{timeout,60000}, | ||
{bind_dn,"cn=admin,dc=chef-server,dc=dev"}, | ||
{bind_password,"H0\\/\\/!|\\/|3tY0ur|\\/|0th3r"}, | ||
{base_dn,"ou=chefs,dc=chef-server,dc=dev"}, | ||
{group_dn,[]}, | ||
{login_attribute,"uid"}, | ||
{display_name_attribute,"displayname"}, | ||
{first_name_attribute,"givenname"}, | ||
{last_name_attribute,"sn"}, | ||
{common_name_attribute,"cn"}, | ||
{country_attribute,"c"}, | ||
{city_attribute,"l"}, | ||
{email_attribute,"mail"}, | ||
{case_sensitive_login_attribute,false}, | ||
{encryption,none}]). | ||
|
||
-define(CUSTOM_CONFIG, [{host,"192.168.33.152"}, | ||
{port,389}, | ||
{timeout,60000}, | ||
{bind_dn,"cn=admin,dc=chef-server,dc=dev"}, | ||
{bind_password,"H0\\/\\/!|\\/|3tY0ur|\\/|0th3r"}, | ||
{base_dn,"ou=chefs,dc=chef-server,dc=dev"}, | ||
{group_dn,[]}, | ||
{login_attribute,"uid"}, | ||
%% This is changed from the default of 'displayname' | ||
{display_name_attribute,"nomdeguerre"}, | ||
%% This is changed from the default of 'givenname' | ||
{first_name_attribute,"nomdeplume"}, | ||
%% This is changed from the default of 'sn' | ||
{last_name_attribute,"surname"}, | ||
%% This is changed from the default of 'cn' | ||
{common_name_attribute,"uncommonname"}, | ||
%% This is changed from the default of 'c' | ||
{country_attribute,"notc"}, | ||
%% This is changed from the default of 'l' | ||
{city_attribute,"homebase"}, | ||
%% This is changed from the default of 'mail' | ||
{email_attribute,"email"}, | ||
{case_sensitive_login_attribute,false}, | ||
{encryption,none}]). | ||
|
||
|
||
value_of_test_() -> | ||
Data = [{"key1", ["a_value"]}, {"key2", ["first", "second"]}], | ||
[{"returns a scalar (binary) value for the given key in a proplist where the values are arrays", | ||
|
@@ -60,6 +104,7 @@ canonical_username_test_() -> | |
]. | ||
|
||
result_to_user_ejson_test_() -> | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG), | ||
LoginAttr = "uid", | ||
UserName = <<"bob^bob">>, | ||
LdapUser = [{eldap_entry, "uid=bob^bob,ou=Person,dc=example,dc=com", | ||
|
@@ -73,6 +118,17 @@ result_to_user_ejson_test_() -> | |
{"o",["BigCorporation"]}, | ||
{"objectClass", ["person","organizationalPerson","inetOrgPerson"]}, | ||
{"uid",["bob^bob"]}]}], | ||
StrangeLdapUser = [{eldap_entry, "uid=bob^bob,ou=Person,dc=example,dc=com", | ||
[{"notc", ["USA"]}, | ||
{"homebase",["Seattle"]}, | ||
{"surname", ["Rabbit"]}, | ||
{"email", ["[email protected]"]}, | ||
{"nomdeplume",["Bob"]}, | ||
{"nomdeguerre", ["Bobby"]}, | ||
{"uncommonname", ["Bobby Bob"]}, | ||
{"o",["BigCorporation"]}, | ||
{"objectClass", ["person","organizationalPerson","inetOrgPerson"]}, | ||
{"uid",["bob^bob"]}]}], | ||
LdapUserExtraUid = [{eldap_entry, "uid=bob^bob,ou=Person,dc=example,dc=com", | ||
[{"c", ["USA"]}, | ||
{"l",["Seattle"]}, | ||
|
@@ -155,4 +211,54 @@ result_to_user_ejson_test_() -> | |
fun() -> | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,LdapUserExtraUid), | ||
?assertEqual(<<"[email protected]">>, proplists:get_value(<<"email">>, RetUser)) | ||
end}]. | ||
end}, | ||
{"uses a non-default display_name field when configurd to", | ||
fun() -> | ||
application:set_env(oc_chef_wm, ldap, ?CUSTOM_CONFIG), | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,StrangeLdapUser), | ||
?assertEqual(<<"Bobby">>, proplists:get_value(<<"display_name">>, RetUser)), | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG) | ||
end}, | ||
{"uses a non-default first_name field when configurd to", | ||
fun() -> | ||
application:set_env(oc_chef_wm, ldap, ?CUSTOM_CONFIG), | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,StrangeLdapUser), | ||
?assertEqual(<<"Bob">>, proplists:get_value(<<"first_name">>, RetUser)), | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG) | ||
end}, | ||
{"uses a non-default last_name field when configurd to", | ||
fun() -> | ||
application:set_env(oc_chef_wm, ldap, ?CUSTOM_CONFIG), | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,StrangeLdapUser), | ||
?assertEqual(<<"Rabbit">>, proplists:get_value(<<"last_name">>, RetUser)), | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG) | ||
end}, | ||
{"uses a non-default common_name field when configurd to", | ||
fun() -> | ||
application:set_env(oc_chef_wm, ldap, ?CUSTOM_CONFIG), | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,StrangeLdapUser), | ||
?assertEqual(<<"Bobby Bob">>, proplists:get_value(<<"common_name">>, RetUser)), | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG) | ||
end}, | ||
{"uses a non-default country field when configurd to", | ||
fun() -> | ||
application:set_env(oc_chef_wm, ldap, ?CUSTOM_CONFIG), | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,StrangeLdapUser), | ||
?assertEqual(<<"USA">>, proplists:get_value(<<"country">>, RetUser)), | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG) | ||
end}, | ||
{"uses a non-default city field when configurd to", | ||
fun() -> | ||
application:set_env(oc_chef_wm, ldap, ?CUSTOM_CONFIG), | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,StrangeLdapUser), | ||
?assertEqual(<<"Seattle">>, proplists:get_value(<<"city">>, RetUser)), | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG) | ||
end}, | ||
{"uses a non-default mail field when configurd to", | ||
fun() -> | ||
application:set_env(oc_chef_wm, ldap, ?CUSTOM_CONFIG), | ||
{_, _, {RetUser}} = oc_chef_wm_authn_ldap:result_to_user_ejson(LoginAttr,UserName,StrangeLdapUser), | ||
?assertEqual(<<"[email protected]">>, proplists:get_value(<<"email">>, RetUser)), | ||
application:set_env(oc_chef_wm, ldap, ?DEFAULT_CONFIG) | ||
end} | ||
]. |