1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
<?php
class sspmod_core_Auth_UserPassBaseTest extends \PHPUnit_Framework_TestCase
{
public function testAuthenticateECPCallsLoginAndSetsAttributes()
{
$state = [
'saml:Binding' => \SAML2\Constants::BINDING_PAOS,
];
$attributes = array('attrib' => 'val');
$username = $_SERVER['PHP_AUTH_USER'] = 'username';
$password = $_SERVER['PHP_AUTH_PW'] = 'password';
$stub = $this->getMockBuilder('sspmod_core_Auth_UserPassBase')
->disableOriginalConstructor()
->setMethods(array('login'))
->getMockForAbstractClass();
$stub->expects($this->once())
->method('login')
->with($username, $password)
->will($this->returnValue($attributes));
$stub->authenticate($state);
$this->assertSame($attributes, $state['Attributes']);
}
public function testAuthenticateECPMissingUsername()
{
$this->setExpectedException('SimpleSAML_Error_Error', 'WRONGUSERPASS');
$state = [
'saml:Binding' => \SAML2\Constants::BINDING_PAOS,
];
unset($_SERVER['PHP_AUTH_USER']);
$_SERVER['PHP_AUTH_PW'] = 'password';
$stub = $this->getMockBuilder('sspmod_core_Auth_UserPassBase')
->disableOriginalConstructor()
->getMockForAbstractClass();
$stub->authenticate($state);
}
public function testAuthenticateECPMissingPassword()
{
$this->setExpectedException('SimpleSAML_Error_Error', 'WRONGUSERPASS');
$state = [
'saml:Binding' => \SAML2\Constants::BINDING_PAOS,
];
$_SERVER['PHP_AUTH_USER'] = 'username';
unset($_SERVER['PHP_AUTH_PW']);
$stub = $this->getMockBuilder('sspmod_core_Auth_UserPassBase')
->disableOriginalConstructor()
->getMockForAbstractClass();
$stub->authenticate($state);
}
public function testAuthenticateECPCallsLoginWithForcedUsername()
{
$state = [
'saml:Binding' => \SAML2\Constants::BINDING_PAOS,
];
$attributes = array();
$forcedUsername = 'forcedUsername';
$_SERVER['PHP_AUTH_USER'] = 'username';
$password = $_SERVER['PHP_AUTH_PW'] = 'password';
$stub = $this->getMockBuilder('sspmod_core_Auth_UserPassBase')
->disableOriginalConstructor()
->setMethods(array('login'))
->getMockForAbstractClass();
$stub->expects($this->once())
->method('login')
->with($forcedUsername, $password)
->will($this->returnValue($attributes));
$stub->setForcedUsername($forcedUsername);
$stub->authenticate($state);
}
}
|