|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\LDAP\Tests\Authenticators; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
6
|
|
|
use SilverStripe\Core\Config\Config; |
|
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
8
|
|
|
use SilverStripe\Forms\Form; |
|
9
|
|
|
use SilverStripe\LDAP\Authenticators\LDAPAuthenticator; |
|
10
|
|
|
use SilverStripe\LDAP\Authenticators\LDAPLostPasswordHandler; |
|
11
|
|
|
use SilverStripe\LDAP\Services\LDAPService; |
|
12
|
|
|
use SilverStripe\ORM\FieldType\DBField; |
|
13
|
|
|
|
|
14
|
|
|
class LDAPLostPasswordHandlerTest extends SapphireTest |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var LDAPLostPasswordHandler |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $handler; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
parent::setUp(); |
|
24
|
|
|
|
|
25
|
|
|
$authenticator = new LDAPAuthenticator(); |
|
26
|
|
|
$this->handler = LDAPLostPasswordHandler::create('foo', $authenticator); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetAndSetLdapService() |
|
30
|
|
|
{ |
|
31
|
|
|
$service = new LDAPService(); |
|
32
|
|
|
|
|
33
|
|
|
$this->handler->setService($service); |
|
34
|
|
|
$this->assertSame($service, $this->handler->getService()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testLostPasswordFormLabels() |
|
38
|
|
|
{ |
|
39
|
|
|
Config::modify()->set(LDAPAuthenticator::class, 'allow_email_login', 'no'); |
|
40
|
|
|
$result = $this->handler->lostpassword(); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertInternalType('array', $result); |
|
43
|
|
|
$this->assertInstanceOf(DBField::class, $result['Content']); |
|
44
|
|
|
$this->assertInstanceOf(Form::class, $result['Form']); |
|
45
|
|
|
$this->assertContains('Enter your username and we will send you a link', $result['Content']->getValue()); |
|
46
|
|
|
|
|
47
|
|
|
Config::modify()->set(LDAPAuthenticator::class, 'allow_email_login', 'yes'); |
|
48
|
|
|
$result = $this->handler->lostpassword(); |
|
49
|
|
|
$this->assertInternalType('array', $result); |
|
50
|
|
|
$this->assertContains('Enter your username or your email address', $result['Content']->getValue()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testPasswordSentMessage() |
|
54
|
|
|
{ |
|
55
|
|
|
$request = (new HTTPRequest('GET', '/'))->setRouteParams(['OtherID' => 'banana']); |
|
56
|
|
|
|
|
57
|
|
|
$this->handler->setRequest($request); |
|
58
|
|
|
|
|
59
|
|
|
$result = $this->handler->passwordsent(); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$this->assertSame([ |
|
62
|
|
|
'Title' => "Password reset link sent to 'banana'", |
|
63
|
|
|
'Content' => "Thank you! A reset link has been sent to 'banana', provided an account exists.", |
|
64
|
|
|
'Username' => 'banana' |
|
65
|
|
|
], $this->handler->passwordsent()); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|