function LdapAuthorizationDeriveFromAttr::testDeriveFromAttr in Lightweight Directory Access Protocol (LDAP) 7
File
- ldap_authorization/tests/DeriveFromAttr/DeriveFromAttr.test, line 21
Class
- LdapAuthorizationDeriveFromAttr
Code
function testDeriveFromAttr() {
return;
$this->ldapTestId = 'DeriveFromAttr';
$this->serversData = 'DeriveFromAttr/ldap_servers.inc';
$this->authorizationData = 'DeriveFromAttr/ldap_authorization.inc';
$this->authenticationData = 'DeriveFromAttr/ldap_authentication.inc';
$this->consumerType = 'drupal_role';
$this
->prepTestData();
$user = $this
->drupalCreateUser(array());
$unkool = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'unkool',
'mail' => 'unkool@nowhere.myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($unkool, 'query', $this->consumerType);
$this
->assertTrue(count($new_authorizations[$this->consumerType]) == 0, 'user account unkool tested for granting no drupal roles ', $this->ldapTestId . '.nomatch');
$user = $this
->drupalCreateUser(array());
$jkool = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'jkool',
'mail' => 'jkool@guests.myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($jkool, 'query', $this->consumerType);
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('sysadmins', $new_authorizations['drupal_role']));
$this
->assertTrue($correct_roles, 'user account jkool tested for granting drupal_role "sysadmins"', $this->ldapTestId . '.onematch');
$correct_roles = (bool) (isset($new_authorizations['drupal_role']) && in_array('mailgroup17', $new_authorizations['drupal_role']));
$this
->assertTrue($correct_roles, 'user account jkool tested for granting drupal_role "mailgroup17" from numeric ldap value', $this->ldapTestId . '.numeric_attr_value');
user_delete($user->uid);
$user = $this
->drupalCreateUser(array());
$wilmaf = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'wilmaf',
'mail' => 'wilmaf@guests.myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($wilmaf, 'query', $this->consumerType);
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('sysadmins', $new_authorizations['drupal_role']));
$this
->assertTrue($correct_roles, 'user account wilma tested for granting drupal_role "sysadmins"', $this->ldapTestId . '.escaped');
user_delete($user->uid);
$user = $this
->drupalCreateUser(array());
$verykool = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'verykool',
'mail' => 'verykool@myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($verykool, 'query', $this->consumerType);
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('netadmins', $new_authorizations[$this->consumerType]) && in_array('sysadmins', $new_authorizations[$this->consumerType]));
$this
->assertTrue($correct_roles, 'user account verykool tested for granting "netadmins" and "sysadmins" drupal roles ', $this->ldapTestId . '.manymatch');
$this
->assertTrue($correct_roles, 'user account verykool tested for case insensitivity ', $this->ldapTestId . '.caseinsensitive');
user_delete($user->uid);
$consumer_conf_admin = ldap_authorization_get_consumer_admin_object($this->consumerType);
$consumer_conf_admin->deriveFromAttrUseFirstAttr = 1;
$consumer_conf_admin
->save();
$user = $this
->drupalCreateUser(array());
$verykool = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'verykool',
'mail' => 'verykool@guests.myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($verykool, 'query', $this->consumerType);
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('netadmins2', $new_authorizations['drupal_role']));
if (!$correct_roles) {
debug('new authorizations');
debug($new_authorizations);
}
$this
->assertTrue($correct_roles, 'user account verykool tested for granting drupal_role "netadmins2"', $this->ldapTestId . '.deriveFromAttrUseFirstAttr');
$consumer_conf_admin->deriveFromAttrUseFirstAttr = 0;
$consumer_conf_admin
->save();
user_delete($user->uid);
$consumer_conf_admin->deriveFromAttrUseFirstAttr = 1;
$consumer_conf_admin
->save();
$user = $this
->drupalCreateUser(array());
$wilmaf = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'wilmaf',
'mail' => 'wilmaf@guests.myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($wilmaf, 'query', $this->consumerType);
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('comma freaks', $new_authorizations['drupal_role']));
$this
->assertTrue($correct_roles, 'user account wilmaf tested for granting drupal_role "comma freaks"', $this->ldapTestId . '.deriveFromAttrUseFirstAttr.escaped');
$consumer_conf_admin->deriveFromAttrUseFirstAttr = 0;
$consumer_conf_admin
->save();
user_delete($user->uid);
$consumer_conf_admin->deriveFromAttrUseFirstAttr = 1;
$consumer_conf_admin
->save();
$user = $this
->drupalCreateUser(array());
$barneyr = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'barneyr',
'mail' => 'barneyr@guests.myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($barneyr, 'query', $this->consumerType);
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('comma freaks', $new_authorizations['drupal_role']));
$this
->assertTrue($correct_roles, 'user account barneyr tested for granting drupal_role "comma freaks"', $this->ldapTestId . '.deriveFromAttrUseFirstAttr.quoted');
$consumer_conf_admin->deriveFromAttrUseFirstAttr = 0;
$consumer_conf_admin
->save();
user_delete($user->uid);
module_enable(array(
'php',
));
$php = " \$parts = explode(\"@\", \$name); \n if (count(\$parts) == 2) {\n print \$parts[0];\n }; \n ";
$this->testFunctions
->setFakeServerProperty('ldapauthor1', 'ldapToDrupalUserPhp', $php);
$user = $this
->drupalCreateUser(array());
$verykool = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'verykool@gmail.com',
'mail' => 'verykool@gmail.com',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($verykool, 'query', $this->consumerType);
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('netadmins', $new_authorizations['drupal_role']) && in_array('sysadmins', $new_authorizations['drupal_role']));
$this
->assertTrue($correct_roles, 'php transform drupal username verykool@gmail.com to ldap username attribute verykool"', $this->ldapTestId . '.ldapToDrupalUserPhp');
$this->testFunctions
->setFakeServerProperty('ldap_test_server__ldapauthor1', 'ldapToDrupalUserPhp', NULL);
user_delete($user->uid);
module_disable(array(
'php',
));
}