Changeset 1625

Show
Ignore:
Timestamp:
06/16/08 17:05:37 (2 months ago)
Author:
richi
Message:

peer::ldap: added LDAP options | switched to debian server in tests | polished tests and code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPConnection.php

    r1570 r1625  
    66 * @package     stubbles 
    77 * @subpackage  peer_ldap 
     8 * @see         RFC 4510  LDAP: Technical Specification Road Map              http://tools.ietf.org/html/rfc4510 
     9 * @see         RFC 4515  LDAP: String Representation of Search Filters       http://tools.ietf.org/html/rfc4515 
    810 */ 
    911stubClassLoader::load('net::stubbles::peer::ldap::stubLDAPURL', 
     
    1618 * @package     stubbles 
    1719 * @subpackage  peer_ldap 
     20 * @see         RFC 4510  LDAP: Technical Specification Road Map              http://tools.ietf.org/html/rfc4510 
     21 * @see         RFC 4515  LDAP: String Representation of Search Filters       http://tools.ietf.org/html/rfc4515 
    1822 */ 
    1923class stubLDAPConnection extends stubBaseObject 
     
    3135     */ 
    3236    protected $handle; 
     37    /** 
     38     * decision provider for protocol choice (default is LDAPv3). 
     39     * 
     40     * @var bool 
     41     */ 
     42    protected $usesProtocolVersionDefault; 
     43    /** 
     44     * ldap options 
     45     * Keys are used for equality check, the values are actually superfluous. 
     46     * 
     47     * @var  array(int, int) 
     48     */ 
     49    protected static $options = array(LDAP_OPT_DEREF            => LDAP_OPT_DEREF, 
     50                                      LDAP_OPT_SIZELIMIT        => LDAP_OPT_SIZELIMIT, 
     51                                      LDAP_OPT_NETWORK_TIMEOUT  => LDAP_OPT_NETWORK_TIMEOUT, 
     52                                      LDAP_OPT_TIMELIMIT        => LDAP_OPT_TIMELIMIT, 
     53                                      LDAP_OPT_PROTOCOL_VERSION => LDAP_OPT_PROTOCOL_VERSION, 
     54                                      LDAP_OPT_ERROR_NUMBER     => LDAP_OPT_ERROR_NUMBER, 
     55                                      LDAP_OPT_REFERRALS        => LDAP_OPT_REFERRALS, 
     56                                      LDAP_OPT_RESTART          => LDAP_OPT_RESTART, 
     57                                      LDAP_OPT_HOST_NAME        => LDAP_OPT_HOST_NAME, 
     58                                      LDAP_OPT_ERROR_STRING     => LDAP_OPT_ERROR_STRING, 
     59                                      LDAP_OPT_MATCHED_DN       => LDAP_OPT_MATCHED_DN, 
     60                                      LDAP_OPT_SERVER_CONTROLS  => LDAP_OPT_SERVER_CONTROLS, 
     61                                      LDAP_OPT_CLIENT_CONTROLS  => LDAP_OPT_CLIENT_CONTROLS); 
    3362 
    3463    /** 
     
    3766     * @param  stubLDAPURL  $ldapUrl 
    3867     */ 
    39     public function __construct($ldapUrl) 
     68    public function __construct(stubLDAPURL $ldapUrl) 
    4069    { 
    4170        $this->ldap   = $ldapUrl; 
    4271        $this->handle = ldap_connect($this->ldap->getHost(), $this->ldap->getPort()); 
     72        $this->usesProtocolVersionDefault = true; 
     73    } 
     74 
     75    /** 
     76     * Checks a LDAP option. 
     77     * 
     78     * @param   string  $name 
     79     * @param   string  $value 
     80     * @return  bool 
     81     * @link    http://de.php.net/manual/de/function.ldap-set-option.php 
     82     */ 
     83    public function isOptionValid($name) 
     84    { 
     85        return isset(self::$options[$name]); 
    4386    } 
    4487 
    4588    /** 
    4689     * Sets a LDAP option. 
    47      * TODO 
    48      *  
    49      * @param   string              $name 
    50      * @param   string              $value 
     90     * 
     91     * Possible options and their type: 
     92     * (depends also on which types the server returns) 
     93     * 
     94     * LDAP_OPT_DEREF               integer 
     95     * LDAP_OPT_SIZELIMIT           integer 
     96     * LDAP_OPT_TIMELIMIT           integer 
     97     * LDAP_OPT_NETWORK_TIMEOUT     integer 
     98     * LDAP_OPT_PROTOCOL_VERSION    integer 
     99     * LDAP_OPT_ERROR_NUMBER        integer 
     100     * LDAP_OPT_REFERRALS           bool 
     101     * LDAP_OPT_RESTART             bool 
     102     * LDAP_OPT_HOST_NAME           string 
     103     * LDAP_OPT_ERROR_STRING        string 
     104     * LDAP_OPT_MATCHED_DN          string 
     105     * LDAP_OPT_SERVER_CONTROLS     array 
     106     * LDAP_OPT_CLIENT_CONTROLS     array 
     107     * 
     108     * @param   string                        $name 
     109     * @param   string                        $value 
     110     * @throws  stubConnectionException 
     111     * @throws  stubIllegalArgumentException 
    51112     * @return  stubLDAPConnection 
    52113     */ 
    53114    public function option($name, $value) 
    54115    { 
     116        if($this->isOptionValid($name) === false) { 
     117            throw new stubIllegalArgumentException($name . ' is no valid LDAP option.'); 
     118        } 
     119 
     120        if($name === LDAP_OPT_PROTOCOL_VERSION && $value != 3) { 
     121            $this->usesProtocolVersionDefault = false; 
     122        } 
     123 
     124        $success = @ldap_set_option($this->handle, $name, $value); 
     125        if($success === false) { 
     126            throw new stubConnectionException(ldap_error($this->handle)); 
     127        } 
     128 
    55129        return $this; 
    56130    } 
     
    58132    /** 
    59133     * Gets a LDAP option. 
    60      * TODO 
    61      *  
    62      * @param  string  $name 
     134     * 
     135     * Possible options and their type: 
     136     * (depends also on which types the server returns) 
     137     * 
     138     * LDAP_OPT_DEREF               integer 
     139     * LDAP_OPT_SIZELIMIT           integer 
     140     * LDAP_OPT_TIMELIMIT           integer 
     141     * LDAP_OPT_NETWORK_TIMEOUT     integer 
     142     * LDAP_OPT_PROTOCOL_VERSION    integer 
     143     * LDAP_OPT_ERROR_NUMBER        integer 
     144     * LDAP_OPT_REFERRALS           bool 
     145     * LDAP_OPT_RESTART             bool 
     146     * LDAP_OPT_HOST_NAME           string 
     147     * LDAP_OPT_ERROR_STRING        string 
     148     * LDAP_OPT_MATCHED_DN          string 
     149     * LDAP_OPT_SERVER_CONTROLS     array 
     150     * LDAP_OPT_CLIENT_CONTROLS     array 
     151     * 
     152     * @param   string  $name 
     153     * @return  mixed   $retValue 
    63154     */ 
    64155    public function getOption($name) 
    65156    { 
    66         // ldap_get_option(); 
    67     } 
    68  
    69     /** 
    70      * Binds the LDAP connection (authenticate & specifiy LDAP protocol version) 
    71      * 
    72      * @throws  stubException 
     157        if($this->isOptionValid($name) === false) { 
     158            throw new stubIllegalArgumentException($name . ' is no valid LDAP Option.'); 
     159        } 
     160 
     161        $success = @ldap_get_option($this->handle, $name, $retValue); 
     162        if($succes === false) { 
     163            throw new stubConnectionException(ldap_error($this->handle)); 
     164        } 
     165 
     166        return $retValue; 
     167    } 
     168 
     169    /** 
     170     * Binds the LDAP connection (authentication). 
     171     * Uses per default LDAPv3. 
     172     * 
     173     * @throws  stubConnectionException 
    73174     * @return  stubLDAPConnection 
    74175     */ 
    75176    public function bind() 
    76177    { 
     178        if($this->usesProtocolVersionDefault === true) { 
     179            $this->option(LDAP_OPT_PROTOCOL_VERSION, 3); 
     180        } 
     181 
    77182        if($this->ldap->getUser() === null || $this->ldap->getPassword() === null) { 
    78183            // anonymous bind 
    79             $success = ldap_bind($this->handle); 
     184            $success = @ldap_bind($this->handle); 
    80185        } else { 
    81             $success = ldap_bind($this->handle, $this->ldap->getUser(), $this->ldap->getPassword()); 
     186            $success = @ldap_bind($this->handle, $this->ldap->getUser(), $this->ldap->getPassword()); 
    82187        } 
    83188 
    84189        if($success === false) { 
    85             throw new stubException(ldap_error($this->handle)); 
     190            throw new stubConnectionException(ldap_error($this->handle)); 
    86191        } 
    87192 
     
    108213        $this->ldap->setBaseDn($newBaseDn); 
    109214    } 
    110      
     215 
    111216    /** 
    112217     * Retrieves the LDAP entries. 
    113      * If no parameters set, the paramteres from the LDAP url are used. 
    114      * 
    115      * @param   string                $attributes  ldap attributes 
    116      * @param   string                $scope       ldap scope (base|one|sub) 
    117      * @param   string                $filter      ldap filter 
    118      * @throws  stubException 
     218     * If no parameters set, the paramteres from the LDAP url are used (or the defaults). 
     219     * 
     220     * @param   string                        $attributes  ldap attributes  narrow result set 
     221     * @param   string                        $scope       ldap scope       (base|one|sub) 
     222     * @param   string                        $filter      ldap filter      must be surrounded with parentheses 
     223     * @throws  stubConnectionException 
     224     * @throws  stubIllegalArgumentException 
    119225     * @return  stubLDAPSearchResult 
    120226     */ 
     
    141247        } 
    142248 
    143         // TODO isParamValid() nötig? 
    144249        switch($scope) { 
    145             case 'base'
    146                 $result = ldap_read($this->handle, $this->ldap->getBaseDn(), $filter, $attributes); 
     250            case stubLDAPURL::SCOPE_BASE
     251                $result = @ldap_read($this->handle, $this->ldap->getBaseDn(), $filter, $attributes); 
    147252                break; 
    148253 
    149             case 'sub'
    150                 $result = ldap_search($this->handle, $this->ldap->getBaseDn(), $filter, $attributes); 
     254            case stubLDAPURL::SCOPE_ONE
     255                $result = @ldap_list($this->handle, $this->ldap->getBaseDn(), $filter, $attributes); 
    151256                break; 
    152257 
    153             case 'one'
    154                 $result = ldap_list($this->handle, $this->ldap->getBaseDn(), $filter, $attributes); 
     258            case stubLDAPURL::SCOPE_SUB
     259                $result = @ldap_search($this->handle, $this->ldap->getBaseDn(), $filter, $attributes); 
    155260                break; 
    156                  
     261 
    157262            default: 
    158                 // intentionally empty 
     263                throw new stubIllegalArgumentException('Inavlid scope: ' . $scope . ', must be one of "base", "sub" or "one".'); 
    159264        } 
    160265 
    161266        if($result === false) { 
    162             throw new stubException(ldap_error($this->handle)); 
     267            throw new stubConnectionException(ldap_error($this->handle)); 
    163268        } 
    164269 
  • trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPEntry.php

    r1570 r1625  
    2828    protected $objectClass; 
    2929    /** 
    30      * amount of attributes 
     30     * amount of attributes (inclusive objectClass) 
    3131     * 
    3232     * @var  int 
     
    9797    public function getAttributeValuesByName($name) 
    9898    { 
    99         // new ArrayAccessor 
    10099        return (isset($this->attributes[$name]) !== false) ? $this->attributes[$name] : null; 
    101100    } 
  • trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPSearchResult.php

    r1570 r1625  
    8787        $dn = ldap_get_dn($this->handle, $entryId); 
    8888        if(empty($objectClass)) { 
    89             $objectClass = ldap_read($this->handle, $dn, 'objectClass=*', array('objectclass')); 
     89            $objectClass = ldap_read($this->handle, $dn, '(objectClass=*)', array('objectclass')); 
    9090        } 
    9191 
  • trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPURL.php

    r1570 r1625  
    66 * @package     stubbles 
    77 * @subpackage  peer_ldap 
     8 * @see         RFC 4510  LDAP: Technical Specification Road Map              http://tools.ietf.org/html/rfc4510 
     9 * @see         RFC 4514  LDAP: String Representation of Distinguished Names  http://tools.ietf.org/html/rfc4514 
    810 * @see         RFC 4516  LDAP: Uniform Resource Locator                      http://tools.ietf.org/html/rfc4516 
    911 * @see         RFC 4515  LDAP: String Representation of Search Filters       http://tools.ietf.org/html/rfc4515 
    10  * @see         RFC 4514  LDAP: String Representation of Distinguished Names  http://tools.ietf.org/html/rfc4514 
    1112 */ 
    1213stubClassLoader::load('net::stubbles::peer::stubURL', 
     
    1920 * @package     stubbles 
    2021 * @subpackage  peer_ldap 
     22 * @see         RFC 4510  LDAP: Technical Specification Road Map              http://tools.ietf.org/html/rfc4510 
     23 * @see         RFC 4514  LDAP: String Representation of Distinguished Names  http://tools.ietf.org/html/rfc4514 
    2124 * @see         RFC 4516  LDAP: Uniform Resource Locator                      http://tools.ietf.org/html/rfc4516 
    2225 * @see         RFC 4515  LDAP: String Representation of Search Filters       http://tools.ietf.org/html/rfc4515 
    23  * @see         RFC 4514  LDAP: String Representation of Distinguished Names  http://tools.ietf.org/html/rfc4514 
    2426 */ 
    2527class stubLDAPURL extends stubURL 
    2628{ 
    2729    /** 
     30     * LDAP scope constant for one 
     31     */ 
     32    const SCOPE_ONE    = 'one'; 
     33    /** 
     34     * LDAP scope constant for base 
     35     */ 
     36    const SCOPE_BASE   = 'base'; 
     37    /** 
     38     * LDAP scope constant for sub 
     39     */ 
     40    const SCOPE_SUB    = 'sub'; 
     41 
     42    /** 
    2843     * constructor 
    2944     * 
     
    98113 
    99114        // check dn 
    100         // TODO regex 
    101         if(preg_match('/(([A-Za-z]+=[A-Za-z ]+),?)/', $this->url['base_dn']) === 0) { 
    102             return false; 
    103         } 
    104  
    105         // check (optional) attributes 
    106         // TODO regex 
    107         if($this->getParam('attributes') !== null && 
    108                     preg_match('/([a-zA-Z],?|)+/', $this->getParam('attributes')) === 0) { 
    109             return false; 
    110         } 
    111  
    112         // check (optional) scope 
    113         // TODO regex 
    114         if($this->getParam('scope') !== null && 
    115                 preg_match('/(base|one|sub|)/', $this->getParam('scope')) === 0) { 
    116             return false; 
    117         } 
    118  
    119         // check (optional) filter 
    120         // TODO: regex 
    121         if($this->getParam('filter') !== null && 
    122                 preg_match('/(.*|)/', $this->getParam('filter')) === 0) { 
     115        if(preg_match('/^([A-Za-z]+=[A-Za-z ]+,?)*$/', $this->url['base_dn']) === 0) { 
     116            return false; 
     117        } 
     118 
     119        // (optional) attributes & (optional) filters are passed through only scope is checked 
     120        if($this->getParam('scope') !== null 
     121             && (self::SCOPE_ONE !== $this->getParam('scope') 
     122                 && self::SCOPE_BASE !== $this->getParam('scope') 
     123                 && self::SCOPE_SUB !== $this->getParam('scope'))) { 
    123124            return false; 
    124125        } 
     
    184185     * attributes = '' 
    185186     * scope      = 'base' 
    186      * filters    = 'objectClass=*
     187     * filters    = '(objectClass=*)
    187188     * 
    188189     * possibilities for query string: 
     
    224225                $result = ($queryValues !== null 
    225226                                && count($queryValues) >= 3 
    226                                 && $queryValues[2] !== '') ? $queryValues[2] : 'objectClass=*'; 
     227                                && $queryValues[2] !== '') ? $queryValues[2] : '(objectClass=*)'; 
    227228                break; 
    228              
     229 
    229230            default: 
    230231                // intentionally empty 
     
    240241     * @return  string 
    241242     */ 
    242     public function get($port = false) 
     243    public function get($withPort = false) 
    243244    { 
    244245        $url  = ''; 
     
    253254        } 
    254255 
    255         if ($port === true && isset($this->url['port']) === true) { 
     256        if ($withPort === true && isset($this->url['port']) === true) { 
    256257            $port =  ':' . $this->url['port']; 
    257258        } else { 
  • trunk/src/test/php/net/stubbles/peer/ldap/stubLDAPConnectionTestCase.php

    r1570 r1625  
    1010/** 
    1111 * Test for net::stubbles::peer::http::stubLDAPConnectionTestCase. 
     12 * 
     13 * Preconditions: 
     14 *  - db.debian.org (LDAP Server) 
     15 *  - ou=hosts,dc=debian,dc=org (dn exists) 
    1216 * 
    1317 * @package     stubbles 
     
    3135            $this->markTestSkipped('The LDAP extension is not available.'); 
    3236        } 
    33          
    34         $url = 'ldap://x500.bund.de/ou=BPjM,o=BUND,c=DE'; 
     37 
     38        $url = 'ldap://db.debian.org/ou=hosts,dc=debian,dc=org'; 
    3539        $this->ldap = stubLDAPURL::fromString($url)->connect(); 
     40    } 
     41 
     42    /** 
     43     * invalid bind 
     44     * 
     45     * @test 
     46     * @expectedException  stubConnectionException 
     47     */ 
     48    public function invalidBind() 
     49    { 
     50        stubLDAPURL::fromString('ldap://badUser:pw@db.debian.org/ou=hosts,dc=debian,dc=org')->connect()->bind(); 
    3651    } 
    3752 
     
    4459    { 
    4560        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search()); 
    46         $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, 'sub', null)); 
    4761        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, 'base', null)); 
    4862        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, 'one', null)); 
     63        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, 'sub', null)); 
    4964        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search('objectClass', null, null)); 
    5065        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search('objectclass', null, null)); 
    5166        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search('iDontExist', null, null)); 
    52         $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, null, 'sn=iDontExist')); 
    53         $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, null, 'sn=A*')); 
     67        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, null, '(sn=A*)')); 
     68        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, null, '(sn=iDontExist)')); 
     69        $this->assertType('stubLDAPSearchResult', $this->ldap->bind()->search(null, null, '(&(abc=def)(def=ghi))')); 
    5470    } 
    5571 
    5672    /** 
    57      * ldap searches with bad input 
     73     * ldap search with bad scope input 
    5874     * 
    5975     * @test 
    60      * @expectedException  stubException 
     76     * @expectedException  stubIllegalArgumentException 
    6177     */ 
    62     public function searchFailure() 
     78    public function searchFailureBadScopeInput() 
    6379    { 
    64         // TODO more tests 
    6580        $this->ldap->bind()->search(null, 'notBaseOneOrSub', null); 
    6681    } 
    6782 
    6883    /** 
    69      * assure option settings 
     84     * ldap search with bad filter input 
     85     * 
     86     * @test 
     87     * @expectedException  stubConnectionException 
     88     */ 
     89    public function searchFailureBadFilterInput() 
     90    { 
     91        $this->ldap->bind()->search(null, null, '(noEqualSign)'); 
     92    } 
     93 
     94    /** 
     95     * ldap search with bad base dn 
     96     * 
     97     * @test 
     98     * @expectedException  stubConnectionException 
     99     */ 
     100    public function searchWithBadBaseDn() 
     101    { 
     102        $this->ldap->setBaseDn('badDN'); 
     103        $this->ldap->bind()->search(); 
     104    } 
     105 
     106    /** 
     107     * assure setting of default protocol during bind() 
    70108     * 
    71109     * @test 
    72110     */ 
    73     public function option() 
     111    public function defaultProtocolVersion() 
    74112    { 
    75         // TODO 
     113        $this->assertEquals(3, $this->ldap->bind()->getOption(LDAP_OPT_PROTOCOL_VERSION)); 
     114    } 
     115 
     116    /** 
     117     * assure option() and getOption() 
     118     * 
     119     * @test 
     120     */ 
     121    public function protocolVersionAndOverriding() 
     122    { 
     123        $this->ldap->option(LDAP_OPT_PROTOCOL_VERSION, 3); 
     124        $this->assertEquals(3, $this->ldap->getOption(LDAP_OPT_PROTOCOL_VERSION)); 
     125        $this->ldap->option(LDAP_OPT_PROTOCOL_VERSION, 2); 
     126        $this->assertEquals(2, $this->ldap->getOption(LDAP_OPT_PROTOCOL_VERSION)); 
     127    } 
     128 
     129    /** 
     130     * assure option getting 
     131     * 
     132     * @test 
     133     */ 
     134    public function validOptionGetting() 
     135    { 
     136        $this->assertType('string', $this->ldap->getOption(LDAP_OPT_HOST_NAME)); 
     137        $this->assertType('int', $this->ldap->getOption(LDAP_OPT_PROTOCOL_VERSION)); 
     138    } 
     139 
     140    /** 
     141     * invalid option setting 
     142     * 
     143     * @test 
     144     * @expectedException  stubIllegalArgumentException 
     145     */ 
     146    public function invalidOptionSetting() 
     147    { 
     148        $this->ldap->option('badInput', 123); 
     149    } 
     150 
     151    /** 
     152     * invalid option getting 
     153     * 
     154     * @test 
     155     * @expectedException  stubIllegalArgumentException 
     156     */ 
     157    public function invalidOptionGetting() 
     158    { 
     159        $this->ldap->getOption('badInput'); 
     160    } 
     161 
     162    /** 
     163     * assure option validity 
     164     * 
     165     * @test 
     166     */ 
     167    public function optionValidity() 
     168    { 
     169        $this->assertTrue($this->ldap->isOptionValid(LDAP_OPT_PROTOCOL_VERSION)); 
     170        $this->assertFalse($this->ldap->isOptionValid('badInput')); 
    76171    } 
    77172 
  • trunk/src/test/php/net/stubbles/peer/ldap/stubLDAPEntryTestCase.php

    r1570 r1625  
    1212/** 
    1313 * Test for net::stubbles::peer::http::stubLDAPEntryTestCase. 
     14 * 
     15 * Preconditions: 
     16 *  - db.debian.org (LDAP Server) 
     17 *  - uid=aaron,ou=users,dc=debian,dc=org (dn exists & attributes of entry exist) 
    1418 * 
    1519 * @package     stubbles 
     
    3943            $this->markTestSkipped('The LDAP extension is not available.'); 
    4044        } 
    41          
    42         $url = 'ldap://x500.bund.de/ou=BPjM,o=BUND,c=DE??sub?sn=Aufmkolk'; 
     45 
     46        $url = 'ldap://db.debian.org/ou=users,dc=debian,dc=org??sub?(sn=Howell)'; 
    4347        $this->entry = stubLDAPURL::fromString($url)->connect()->bind()->search()->getEntry(); 
    4448    } 
     
    4650    /** 
    4751     * assure getter functionality with good input 
    48      *  
     52     * 
    4953     * @test 
    5054     */ 
    5155    public function getterSuccessful() 
    5256    { 
    53         $this->assertEquals(array('ivbbPerson', 'top', 'person', 'organizationalPerson', 'inetOrgPerson'), $this->entry->getObjectClassValues()); 
    54         $this->assertEquals(6, count($this->entry->getAttributes())); 
    55         $this->assertEquals(array('Aufmkolk'), $this->entry->getAttributeValuesByName('sn')); 
    56         $this->assertEquals(array('cn','sn','givenName', 'mail', 'collectiveOrganizationalUnitName', 'ivbbLastDeliveryCollective'), $this->entry->getAttributeNames()); 
    57         $this->assertEquals(7, $this->entry->getAttributeCount()); 
    58         $this->assertEquals('cn=Aufmkolk Ingrid,l=Bonn,ou=BPjM,o=Bund,c=DE', $this->entry->getDn()); 
     57        $this->assertEquals(array('inetOrgPerson', 
     58                                  'debianAccount', 
     59                                  'shadowAccount', 
     60                                  'debianDeveloper'), $this->entry->getObjectClassValues()); 
     61 
     62        $this->assertEquals(13, count($this->entry->getAttributes())); 
     63 
     64        $this->assertEquals(array('Howell'), $this->entry->getAttributeValuesByName('sn')); 
     65 
     66        $this->assertEquals(array('cn', 
     67                                  'gidNumber', 
     68                                  'uid', 
     69                                  'sn', 
     70                                  'shadowWarning', 
     71                                  'shadowMin', 
     72                                  'shadowMax', 
     73                                  'gecos', 
     74                                  'homeDirectory', 
     75                                  'shadowLastChange', 
     76                                  'uidNumber', 
     77                                  'comment', 
     78                                  'shadowExpire' 
     79        ), $this->entry->getAttributeNames()); 
     80 
     81        $this->assertEquals(14, $this->entry->getAttributeCount()); 
     82 
     83        $this->assertEquals('uid=aaron,ou=users,dc=debian,dc=org', $this->entry->getDn()); 
    5984    } 
    6085 
    6186    /** 
    6287     * assure getter functionality with bad input 
    63      *  
     88     * 
    6489     * @test 
    6590     */ 
    6691    public function getterFailures() 
    6792    { 
    68         // TODO 
    6993        $this->assertNull($this->entry->getAttributeValuesByName('iDontExist')); 
    7094    } 
  • trunk/src/test/php/net/stubbles/peer/ldap/stubLDAPSearchResultTestCase.php

    r1570 r1625  
    1313 * Test for net::stubbles::peer::http::stubLDAPSearchResultTestCase.php. 
    1414 * 
     15 * Preconditions: 
     16 *  - db.debian.org (LDAP Server) 
     17 *  - ou=users,dc=debian,dc=org (dn exists) 
     18 * 
    1519 * @package     stubbles 
    1620 * @subpackage  peer_ldap_test 
     
    2630 
    2731    /** 
    28      * set up test envioronment 
     32     * set up test environment 
    2933     */ 
    3034    public function setUp() 
     
    3337            $this->markTestSkipped('The LDAP extension is not available.'); 
    3438        } 
    35          
    36         $url = 'ldap://x500.bund.de/ou=BPjM,o=BUND,c=DE??sub?sn=A*';  // exactly 2 
     39 
     40 
     41        $url = 'ldap://db.debian.org/ou=users,dc=debian,dc=org??sub?(sn=A*)'; 
    3742        $this->searchResult = stubLDAPURL::fromString($url)->connect()->bind()->search(); 
    3843    } 
    3944 
    4045    /** 
    41      * assure getting an entry 
    42      *  
     46     * assure getting an entry (valid(), next(), getEntry(), rewind()) 
     47     * 
    4348     * @test 
    4449     */ 
    45     public function getEntry() 
     50    public function getEntryNextValidRewind() 
    4651    { 
    4752        $this->assertType('stubLDAPEntry', $this->searchResult->getEntry()); 
    48         $this->searchResult->next(); 
    49         $this->searchResult->next(); 
     53        for(;$this->searchResult->valid(); $this->searchResult->next()) { 
     54            $this->assertType('stubLDAPEntry', $this->searchResult->getEntry()); 
     55        } 
    5056        $this->assertNull($this->searchResult->getEntry()); 
     57 
     58        $this->searchResult->rewind(); 
     59        $this->assertType('stubLDAPEntry', $this->searchResult->getEntry()); 
    5160    } 
    5261 
    5362    /** 
    5463     * assure getting the current item 
    55      *  
     64     * 
    5665     * @test 
    5766     */ 
     
    6372    /** 
    6473     * assure getting the key of an item 
    65      *  
     74     * 
    6675     * @test 
    6776     */ 
     
    7079        $this->assertEquals('resource', gettype($this->searchResult->key())); 
    7180    } 
    72  
    73     /** 
    74      * assure setting the cursor to the next item 
    75      *  
    76      * @test 
    77      */ 
    78     public function next() 
    79     { 
    80         $this->searchResult->next(); 
    81         $this->assertEquals('resource', gettype($this->searchResult->current())); 
    82         $this->searchResult->next(); 
    83         $this->assertNull($this->searchResult->current()); 
    84     } 
    85  
    86     /** 
    87      * assure rewinding the cursor 
    88      *  
    89      * @test 
    90      */ 
    91     public function rewind() 
    92     { 
    93         $this->searchResult->next(); 
    94         $next = $this->searchResult->current(); 
    95         $this->searchResult->rewind(); 
    96         $first = $this->searchResult->current(); 
    97         $this->assertNotEquals($next, $first); 
    98     } 
    99  
    100     /** 
    101      * assure validity of the cursor position 
    102      *  
    103      * @test 
    104      */ 
    105     public function valid() 
    106     { 
    107         $this->searchResult->next(); 
    108         $this->assertTrue($this->searchResult->valid()); 
    109         $this->searchResult->next(); 
    110         $this->assertFalse($this->searchResult->valid()); 
    111     } 
    11281} 
    11382?> 
  • trunk/src/test/php/net/stubbles/peer/ldap/stubLDAPURLTestCase.php

    <
    r1570 r1625  
    1717{ 
    1818    /** 
    19      * set up test envioronment 
     19     * set up test environment 
    2020     */ 
    2121    public function setUp() 
     
    2525        } 
    2626    } 
    27      
     27 
    2828    /** 
    2929     * assure url roundtrip without port 
     
    4343    /** 
    4444     * assure url roundtrip with standard port 
    45      *  
     45     * 
    4646     * @test 
    4747     */ 
     
    5555    /** 
    5656     * assure url roundtrip with arbitrary port 
    57      *  
     57     * 
    5858     * @test 
    5959     */ 
     
    6767    /** 
    6868     * assure url roundtrip with host ip 
    69      *  
     69     * 
    7070     * @test 
    7171     */ 
     
    7979    /** 
    8080     * assure url roundtrip with localhost 
    81      *  
     81     * 
    8282     * @test 
    8383     */ 
     
    9191    /** 
    9292     * assure url roundtrip without host and port 
    93      *  
     93     * 
    9494     * @test 
    9595     */ 
     
    104104    /** 
    105105     * assure url roundtrip without authentication data 
    106      *  
     106     * 
    107107     * @test 
    108108     */ 
     
    116116    /** 
    117117     * assure url roundtrip with params (all possibilitiess) 
    118      *  
     118     * 
    119119     * @test 
    120120     */ 
     
    122122    { 
    123123        $url      = 'ldap://localhost:389/dc=example,dc=com?cn'; 
    124         $expected = 'ldap://localhost:389/dc=example,dc=com?cn?base?objectClass=*'; 
     124        $expected = 'ldap://localhost:389/dc=example,dc=com?cn?base?(objectClass=*)'; 
    125125        $ldap = stubLDAPURL::fromString($url); 
    126126        $this->assertEquals($expected, $ldap->get(true)); 
    127127 
    128128        $url      = 'ldap://localhost:389/dc=example,dc=com?cn?sub'; 
    129         $expected = 'ldap://localhost:389/dc=example,dc=com?cn?sub?objectClass=*'; 
    130         $ldap = stubLDAPURL::fromString($url); 
    131         $this->assertEquals($expected, $ldap->get(true)); 
    132  
    133         $url = 'ldap://localhost:389/dc=example,dc=com?cn?sub?(cn=John Doe)'; 
    134         $ldap = stubLDAPURL::fromString($url); 
    135         $this->assertEquals($url, $ldap->get(true)); 
    136  
    137         $url = 'ldap://localhost:389/dc=example,dc=com??sub?(cn=John Doe)'; 
     129        $expected = 'ldap://localhost:389/dc=example,dc=com?cn?sub?(objectClass=*)'; 
     130        $ldap = stubLDAPURL::fromString($url); 
     131        $this->assertEquals($expected, $ldap->get(true)); 
     132 
     133        $url = 'ldap://localhost:389/dc=example,dc=com?cn?sub?(cn=John Doe)'; 
     134        $ldap = stubLDAPURL::fromString($url); 
     135        $this->assertEquals($url, $ldap->get(true)); 
     136 
     137        $url = 'ldap://localhost:389/dc=example,dc=com??sub?(cn=John Doe)'; 
    138138        $ldap = stubLDAPURL::fromString($url); 
    139139        $this->assertEquals($url, $ldap->get(true)); 
     
    152152    /** 
    153153     * assure url roundtrip with params (attributes) 
    154      *  
     154     * 
    155155     * @test 
    156156     */ 
     
    158158    { 
    159159        $url      = 'ldap://localhost:389/dc=example,dc=com?cn'; 
    160         $expected = 'ldap://localhost:389/dc=example,dc=com?cn?base?objectClass=*'; 
     160        $expected = 'ldap://localhost:389/dc=example,dc=com?cn?base?(objectClass=*)'; 
    161161        $ldap = stubLDAPURL::fromString($url); 
    162162        $this->assertEquals($expected, $ldap->get(true)); 
    163163 
    164164        $url      = 'ldap://localhost:389/dc=example,dc=com?cn,uid'; 
    165         $expected = 'ldap://localhost:389/dc=example,dc=com?cn,uid?base?objectClass=*'; 
     165        $expected = 'ldap://localhost:389/dc=example,dc=com?cn,uid?base?(objectClass=*)'; 
    166166        $ldap = stubLDAPURL::fromString($url); 
    167167        $this->assertEquals($expected, $ldap->get(true)); 
     
    170170    /** 
    171171     * assure url roundtrip with params (filter) 
    172      *  
    173      * @test 
    174      * TODO more complex filter 
     172     * 
     173     * @test 
    175174     */ 
    176175    public function urlWithParamsFilterValues() 
     
    184183    /** 
    185184     * assure url roundtrip with params (scope) 
    186      *  
     185     * 
    187186     * @test 
    188187     */ 
     
    190189    { 
    191190        $url      = 'ldap://ldap.example.com:389/dc=example,dc=com??base'; 
    192         $expected = 'ldap://ldap.example.com:389/dc=example,dc=com??base?objectClass=*'; 
     191        $expected = 'ldap://ldap.example.com:389/dc=example,dc=com??base?(objectClass=*)'; 
    193192        $ldap = stubLDAPURL::fromString($url); 
    194193        $this->assertEquals($expected, $ldap->get(true)); 
    195194 
    196195        $url      = 'ldap://ldap.example.com:389/dc=example,dc=com??one'; 
    197         $expected = 'ldap://ldap.example.com:389/dc=example,dc=com??one?objectClass=*'; 
     196        $expected = 'ldap://ldap.example.com:389/dc=example,dc=com??one?(objectClass=*)'; 
    198197        $ldap = stubLDAPURL::fromString($url); 
    199198        $this->assertEquals($expected, $ldap->get(true)); 
    200199 
    201200        $url      = 'ldap://ldap.example.com:389/dc=example,dc=com??sub'; 
    202         $expected = 'ldap://ldap.example.com:389/dc=example,dc=com??sub?objectClass=*'; 
     201        $expected = 'ldap://ldap.example.com:389/dc=example,dc=com??sub?(objectClass=*)'; 
    203202        $ldap = stubLDAPURL::fromString($url); 
    204203        $this->assertEquals($expected, $ldap->get(true)); 
     
    207206    /** 
    208207     * assure url roundtrip with ssl port 
    209      *  
     208     * 
    210209     * @test 
    211210     */ 
    212211    public function urlSSL() 
    213212    { 
    214         $url = 'ldaps://ldap.example.com:636/dc=example,dc=com'; 
     213        $url = 'ldaps://ldap.example.com:636/dc=example,dc=com'; 
    215214        $ldap = stubLDAPURL::fromString($url); 
    216215        $this->assertEquals($url, $ldap->get(true)); 
     
    223222 
    224223    /** 
     224     * assure url with empty string returns 
     225     * 
     226     * @test 
     227     */ 
     228    public function urlBadFormatEmptyString() 
     229    { 
     230        $this->assertNull(stubLDAPURL::fromString('')); 
     231    } 
     232 
     233    /** 
     234     * data provider for assurance of throwing stubMalformedURLException 
     235     * 
     236     * @return array<array<string>> 
     237     */ 
     238    public static function malformedUrlProvider() 
     239    { 
     240        return array( 
     241            // no ldap:// 
     242            array('ldap.example.com/dc=example,dc=com'), 
     243            // bad scheme 
     244            array('badScheme://ldap.example.com/dc=example,dc=com'), 
     245            // bad url 
     246            array('ldap://ldapexamplecom/dc=example,dc=com'), 
     247            // bad base dn 
     248            array('ldap://ldap.example.com/dc=example|dc=com'),