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
|
<?php
class Swift_Transport_Esmtp_Auth_PlainAuthenticatorTest extends \SwiftMailerTestCase
{
private $agent;
protected function setUp(): void
{
$this->agent = $this->getMockery('Swift_Transport_SmtpAgent')->shouldIgnoreMissing();
}
public function testKeywordIsPlain()
{
/* -- RFC 4616, 1.
The name associated with this mechanism is "PLAIN".
*/
$login = $this->getAuthenticator();
$this->assertEquals('PLAIN', $login->getAuthKeyword());
}
public function testSuccessfulAuthentication()
{
/* -- RFC 4616, 2.
The client presents the authorization identity (identity to act as),
followed by a NUL (U+0000) character, followed by the authentication
identity (identity whose password will be used), followed by a NUL
(U+0000) character, followed by the clear-text password.
*/
$plain = $this->getAuthenticator();
$this->agent->shouldReceive('executeCommand')
->once()
->with('AUTH PLAIN '.base64_encode(
'jack'.\chr(0).'jack'.\chr(0).'pass'
)."\r\n", [235]);
$this->assertTrue($plain->authenticate($this->agent, 'jack', 'pass'),
'%s: The buffer accepted all commands authentication should succeed'
);
}
public function testAuthenticationFailureSendRset()
{
$this->expectException(\Swift_TransportException::class);
$plain = $this->getAuthenticator();
$this->agent->shouldReceive('executeCommand')
->once()
->with('AUTH PLAIN '.base64_encode(
'jack'.\chr(0).'jack'.\chr(0).'pass'
)."\r\n", [235])
->andThrow(new Swift_TransportException(''));
$this->agent->shouldReceive('executeCommand')
->once()
->with("RSET\r\n", [250]);
$plain->authenticate($this->agent, 'jack', 'pass');
}
private function getAuthenticator()
{
return new Swift_Transport_Esmtp_Auth_PlainAuthenticator();
}
}
|