<commit_before><?php
/**
 * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 * @filesource
 * @package Authentication
 * @version //autogen//
 * @subpackage Tests
 */

/**
 * @package Authentication
 * @version //autogen//
 * @subpackage Tests
 */
class ezcAuthenticationLdapTest extends ezcTestCase
{
    public static $host = 'localhost';
    public static $format = 'uid=%id%';
    public static $base = 'dc=foo,dc=bar';
    public static $port = 389;
    public static $portSSL = 636;
    public static $formatAdmin = 'cn=%id%';

    public static function suite()
    {
        return new PHPUnit_Framework_TestSuite( "ezcAuthenticationLdapTest" );
    }

    public function setUp()
    {
        if ( !ezcBaseFeatures::hasExtensionSupport( 'ldap' ) )
        {
            $this->markTestSkipped( "PHP must be compiled with --with-ldap." );
        }
    }

    public function tearDown()
    {

    }

    public function testLdapTLS()
    {
        $credentials = new ezcAuthenticationPasswordCredentials( '<PASSWORD>', '<PASSWORD>' );
        $ldap = new ezcAuthenticationLdapInfo( self::$host, self::$format, self::$base, self::$port, ezcAuthenticationLdapFilter::PROTOCOL_TLS );
        $authentication = new ezcAuthentication( $credentials );
        $authentication->addFilter( new ezcAuthenticationLdapFilter( $ldap ) );
        $this->assertEquals( true, $authentication->run() );
    }

    public function testLdapWrongServer()
    {
        $credentials = new ezcAuthenticationPasswordCredentials( '<PASSWORD>', '<PASSWORD>' );
        $ldap = new ezcAuthenticationLdapInfo( 'unknown_host', self::$format, self::$base, self::$port );
        $authentication = new ezcAuthentication( $credentials );
        $authentication->addFilter( new ezcAuthenticationLdapFilter( $ldap ) );
        try<commit_msg>- Skip LDAP tests for now, until we install LDAP on a test server.<commit_after><?php
/**
 * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 * @filesource
 * @package Authentication
 * @version //autogen//
 * @subpackage Tests
 */

/**
 * @package Authentication
 * @version //autogen//
 * @subpackage Tests
 */
class ezcAuthenticationLdapTest extends ezcTestCase
{
    public static $host = 'localhost';
    public static $format = 'uid=%id%';
    public static $base = 'dc=foo,dc=bar';
    public static $port = 389;
    public static $portSSL = 636;
    public static $formatAdmin = 'cn=%id%';

    public static function suite()
    {
        return new PHPUnit_Framework_TestSuite( "ezcAuthenticationLdapTest" );
    }

    public function setUp()
    {
        if ( !ezcBaseFeatures::hasExtensionSupport( 'ldap' ) )
        {
            $this->markTestSkipped( "PHP must be compiled with --with-ldap." );
        }
        try
        {
            $credentials = new ezcAuthenticationPasswordCredentials( 'zhang.<PASSWORD>', '<PASSWORD>' );
            $ldap = new ezcAuthenticationLdapInfo( self::$host, self::$format, self::$base, self::$port );
            $authentication = new ezcAuthentication( $credentials );
            $authentication->addFilter( new ezcAuthenticationLdapFilter( $ldap ) );
            $authentication->run();
        }
        catch ( ezcAuthenticationLdapException $e )
        {
            // this will be changed later when we will have a test server with LDAP
            $this->markTestSkipped( "Cannot connect to LDAP. Probably you didn't setup the LDAP enviroment." );
        }
    }

    public function tearDown()
    {

    }

    public function testLdapTLS()
    {
        $credentials = new ezcAuthenticationPasswordCredentials( '<PASSWORD>', '<PASSWORD>' );
        $ldap = new ezcAuthenticationLdapInfo( self::$host, self::$format, self::$base, self::$port, ezcAuthenticationLdapFilter::PROTOCOL_TLS );
        $authentication = new ezcAuthentication( $credentials );
        $authentication->addFilter( new ezcAuthenticationLdapFilter( $ldap ) );
        $this->assertEquals( true, $authentication->run() );
    }

    public function testLdapWrongServer()
    {
        $credentials = new ezcAuthenticationPasswordCredentials( '<PASSWORD>', '<PASSWORD>' );
        $ldap = new ezcAuthenticationLdapInfo( 'unknown_host', self::$format, self::$base, self::$port );
        $authentication = new ezcAuthentication( $credentials );
        $authentication->addFilter( new ezcAuthenticationLdapFilter( $ldap ) );
        try
{'fraction_non_alphanumeric': 0.12571303203159281, 'fraction_numerical': 0.00614304519526108, 'mean_word_length': 3.171088746569076, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2865536', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1318, 'n_words': 328}