home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / test_unix.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  7.4 KB  |  244 lines

  1. <?php
  2. require_once 'System.php';
  3. require_once 'PHPUnit.php';
  4. require_once 'File/Passwd/Unix.php';
  5.  
  6.  
  7. $GLOBALS['tmpfile'] = System::mktemp();
  8. $GLOBALS['users']   = array(
  9.             'mike' => array(
  10.                 'pass' =>   'q4M4mpfilkNnU',
  11.                 'uid' =>    '501',
  12.                 'gid' =>    '502',
  13.                 'gecos' =>  'User1',
  14.                 'home' =>   '/home/mike',
  15.                 'shell' =>  '/bin/bash'
  16.             ),
  17.             'pete' => array(
  18.                 'pass' =>   'dS80VTLQHZ6VM',
  19.                 'uid' =>    '502',
  20.                 'gid' =>    '503',
  21.                 'gecos' =>  'User2',
  22.                 'home' =>   '/home/pete',
  23.                 'shell' =>  '/bin/sh'
  24.             ),
  25.             'mary' => array(
  26.                 'pass' =>   'jHSiqFjaEiKPM',
  27.                 'uid' =>    '503',
  28.                 'gid' =>    '504',
  29.                 'gecos' =>  'User3',
  30.                 'home' =>   '/home/mary',
  31.                 'shell' =>  '/bin/ksh'
  32.             )
  33.         );
  34.  
  35. /**
  36.  * TestCase for File_Passwd_UnixTest class
  37.  * Generated by PHPEdit.XUnit Plugin
  38.  * 
  39.  */
  40. class File_Passwd_UnixTest extends PHPUnit_TestCase{
  41.  
  42.     var $pwd;
  43.     
  44.     /**
  45.      * Constructor
  46.      * @param string $name The name of the test.
  47.      * @access protected
  48.      */
  49.     function File_Passwd_UnixTest($name){
  50.         $this->PHPUnit_TestCase($name);
  51.     }
  52.     
  53.     /**
  54.      * Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
  55.      * @access protected
  56.      */
  57.     function setUp(){
  58.         $this->pwd = &new File_Passwd_Unix();
  59.     }
  60.     
  61.     /**
  62.      * Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
  63.      * @access protected
  64.      */
  65.     function tearDown(){
  66.         $this->pwd = null;
  67.     }
  68.     
  69.     /**
  70.      * Regression test for File_Passwd_Unix.File_Passwd_Unix method
  71.      * @access public
  72.      */
  73.     function testFile_Passwd_Unix(){
  74.         $this->assertTrue(is_a($this->pwd, 'File_Passwd_Unix'));
  75.     }
  76.     
  77.     /**
  78.      * Regression test for File_Passwd_Unix.save method
  79.      * @access public
  80.      */
  81.     function testsave(){
  82.         $this->pwd->setFile($GLOBALS['tmpfile']);
  83.         $this->pwd->_users = $GLOBALS['users'];
  84.         $e = $this->pwd->save();
  85.         if (PEAR::isError($e)) {
  86.             echo $e->getMessage();
  87.         }
  88.         $this->assertTrue(!PEAR::isError($e));
  89.         $t = file($GLOBALS['tmpfile']);
  90.         $u = file('passwd.unix.txt');
  91.         $this->assertEquals($t,$u);
  92.     }
  93.     
  94.     /**
  95.      * Regression test for File_Passwd_Unix.parse method
  96.      * @access public
  97.      */
  98.     function testparse(){
  99.         $this->pwd->setFile('passwd.unix.txt');
  100.         $this->assertTrue($this->pwd->load());
  101.         $this->assertEquals($this->pwd->_users, $GLOBALS['users']);
  102.     }
  103.     
  104.     /**
  105.      * Regression test for File_Passwd_Unix.setMode method
  106.      * @access public
  107.      */
  108.     function testsetMode(){
  109.         $this->assertTrue($this->pwd->setMode('md5'));
  110.         $this->assertTrue($this->pwd->getMode() === 'md5');
  111.         $this->assertTrue(PEAR::isError($this->pwd->setMode('no')));
  112.         $this->assertTrue($this->pwd->setMode('des'));
  113.         $this->assertTrue($this->pwd->getMode() === 'des');
  114.     }
  115.     
  116.     /**
  117.      * Regression test for File_Passwd_Unix.listModes method
  118.      * @access public
  119.      */
  120.     function testlistModes(){
  121.         $this->assertTrue($this->pwd->listModes() == array('des' => 'des', 'md5' => 'md5'));
  122.     }
  123.     
  124.     /**
  125.      * Regression test for File_Passwd_Unix.getMode method
  126.      * @access public
  127.      */
  128.     function testgetMode(){
  129.         $this->assertTrue($this->pwd->setMode('md5'));
  130.         $this->assertTrue($this->pwd->getMode() === 'md5');
  131.         $this->assertTrue(PEAR::isError($this->pwd->setMode('no')));
  132.         $this->assertTrue($this->pwd->setMode('des'));
  133.         $this->assertTrue($this->pwd->getMode() === 'des');
  134.     }
  135.     
  136.     /**
  137.      * Regression test for File_Passwd_Unix.useMap method
  138.      * @access public
  139.      */
  140.     function testuseMap(){
  141.         $this->assertTrue($this->pwd->useMap());
  142.         $this->assertTrue($this->pwd->useMap(false));
  143.         $this->assertFalse($this->pwd->useMap());
  144.         $this->assertTrue($this->pwd->useMap(true));
  145.     }
  146.     
  147.     /**
  148.      * Regression test for File_Passwd_Unix.setMap method
  149.      * @access public
  150.      */
  151.     function testsetMap(){
  152.         $array = array('uid','gid','gecos','home','shell');
  153.         $new = array('none');
  154.         $this->assertTrue($this->pwd->setMap($new));
  155.         $this->assertTrue($this->pwd->getMap() == $new);
  156.         $this->assertTrue($this->pwd->setMap($array));
  157.         $this->assertTrue($this->pwd->getMap() == $array);
  158.     }
  159.     
  160.     /**
  161.      * Regression test for File_Passwd_Unix.getMap method
  162.      * @access public
  163.      */
  164.     function testgetMap(){
  165.         $array = array('uid','gid','gecos','home','shell');
  166.         $this->assertTrue($array == $this->pwd->getMap());
  167.     }
  168.     
  169.     /**
  170.      * Regression test for File_Passwd_Unix.isShadowed method
  171.      * @access public
  172.      */
  173.     function testisShadowed(){
  174.         $this->assertFalse($this->pwd->isShadowed());
  175.     }
  176.     
  177.     /**
  178.      * Regression test for File_Passwd_Unix.addUser method
  179.      * @access public
  180.      */
  181.     function testaddUser(){
  182.         $this->assertTrue($this->pwd->addUser('add', 'pass'));
  183.         $user = $this->pwd->listUser('add');
  184.         $array = array(
  185.             'pass' => $this->pwd->_genPass('pass', $user['pass']),
  186.             'uid' =>'',
  187.             'gid' =>'',
  188.             'gecos' =>'',
  189.             'home' =>'',
  190.             'shell' =>''
  191.         );
  192.         $this->assertTrue($array == $user);
  193.     }
  194.     
  195.     /**
  196.      * Regression test for File_Passwd_Unix.modUser method
  197.      * @access public
  198.      */
  199.     function testmodUser(){
  200.         $this->assertTrue($this->pwd->addUser('mod', 'pass', array('uid' => 555)));
  201.         $this->assertTrue($this->pwd->modUser('mod', array('uid' => 600)));
  202.         $user = $this->pwd->listUser('mod');
  203.         $this->assertTrue(600 == $user['uid']);
  204.     }
  205.     
  206.     /**
  207.      * Regression test for File_Passwd_Unix.changePasswd method
  208.      * @access public
  209.      */
  210.     function testchangePasswd(){
  211.         $this->pwd->addUser('change', 'pass');
  212.         $this->assertTrue($this->pwd->changePasswd('change', 'new'));
  213.         $this->assertTrue($this->pwd->verifyPasswd('change', 'new'));
  214.     }
  215.     
  216.     /**
  217.      * Regression test for File_Passwd_Unix.verifyPasswd method
  218.      * @access public
  219.      */
  220.     function testverifyPasswd(){
  221.         $this->pwd->addUser('verify', 'pass');
  222.         $this->assertTrue($this->pwd->verifyPasswd('verify', 'pass'));
  223.         $this->assertFalse($this->pwd->verifyPasswd('verify', 'other'));
  224.     }
  225.     
  226.     /**
  227.      * Regression test for File_Passwd_Unix._genPass method
  228.      * @access public
  229.      */
  230.     function test_genPass(){
  231.         $this->pwd->setMode('des');
  232.         $this->assertTrue('12wGUVd8lAOJY' === $this->pwd->_genPass('12','12'));
  233.         $this->pwd->setMode('md5');
  234.         $this->assertTrue('$1$45678901$8Dc8D8vusJXlDQUC7akws/' === $this->pwd->_genPass('12', '$1$456789012'));
  235.     }
  236.     
  237.     function teststaticAuth(){
  238.         $this->assertTrue(true === File_Passwd::staticAuth('Unix', 'passwd.unix.txt', 'mike', 123, 'des'));
  239.         $this->assertTrue(false === File_Passwd::staticAuth('Unix', 'passwd.unix.txt', 'mike', 'abc', 'des'));
  240.         $this->assertFalse((File_Passwd::staticAuth('Unix', 'passwd.unix.txt', 'nonexist', 'asd', 'des')));
  241.     }
  242. }
  243.  
  244. ?>