Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
AuthenticationTest Class Reference
Inheritance diagram for AuthenticationTest:

Public Member Functions

 testGetCredentials ($server, $expectedLogin, $expectedPass)
 
 getCredentialsDataProvider ()
 
 testSetAuthenticationFailed ()
 

Detailed Description

Definition at line 8 of file AuthenticationTest.php.

Member Function Documentation

◆ getCredentialsDataProvider()

getCredentialsDataProvider ( )
Returns
array

Definition at line 28 of file AuthenticationTest.php.

29  {
30  $login = 'login';
31  $password = 'password';
32  $header = 'Basic bG9naW46cGFzc3dvcmQ=';
33 
34  $anotherLogin = 'another_login';
35  $anotherPassword = 'another_password';
36  $anotherHeader = 'Basic YW5vdGhlcl9sb2dpbjphbm90aGVyX3Bhc3N3b3Jk';
37 
38  return [
39  [[], '', ''],
40  [['REDIRECT_HTTP_AUTHORIZATION' => $header], $login, $password],
41  [['HTTP_AUTHORIZATION' => $header], $login, $password],
42  [['Authorization' => $header], $login, $password],
43  [
44  [
45  'REDIRECT_HTTP_AUTHORIZATION' => $header,
46  'PHP_AUTH_USER' => $anotherLogin,
47  'PHP_AUTH_PW' => $anotherPassword,
48  ],
49  $anotherLogin,
50  $anotherPassword
51  ],
52  [
53  [
54  'REDIRECT_HTTP_AUTHORIZATION' => $header,
55  'PHP_AUTH_USER' => $anotherLogin,
56  'PHP_AUTH_PW' => $anotherPassword,
57  ],
58  $anotherLogin,
59  $anotherPassword
60  ],
61  [
62  ['REDIRECT_HTTP_AUTHORIZATION' => $header, 'HTTP_AUTHORIZATION' => $anotherHeader],
63  $anotherLogin,
64  $anotherPassword
65  ]
66  ];
67  }

◆ testGetCredentials()

testGetCredentials (   $server,
  $expectedLogin,
  $expectedPass 
)
Parameters
array$server
string$expectedLogin
string$expectedPass@dataProvider getCredentialsDataProvider

Definition at line 16 of file AuthenticationTest.php.

17  {
18  $request = $this->createMock(\Magento\Framework\App\Request\Http::class);
19  $request->expects($this->once())->method('getServerValue')->will($this->returnValue($server));
20  $response = $this->createMock(\Magento\Framework\App\Response\Http::class);
21  $authentication = new \Magento\Framework\HTTP\Authentication($request, $response);
22  $this->assertSame([$expectedLogin, $expectedPass], $authentication->getCredentials());
23  }
$response
Definition: 404.php:11

◆ testSetAuthenticationFailed()

testSetAuthenticationFailed ( )

Definition at line 69 of file AuthenticationTest.php.

70  {
71  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
72 
73  $request = $objectManager->getObject(\Magento\Framework\App\Request\Http::class);
74  $response = $objectManager->getObject(\Magento\Framework\App\Response\Http::class);
75 
76  $authentication = $objectManager->getObject(
77  \Magento\Framework\HTTP\Authentication::class,
78  [
79  'httpRequest' => $request,
80  'httpResponse' => $response
81  ]
82  );
83  $realm = uniqid();
84  $authentication->setAuthenticationFailed($realm);
85  $headers = $response->getHeaders();
86 
87  $this->assertTrue($headers->has('WWW-Authenticate'));
88  $header = $headers->get('WWW-Authenticate');
89  $this->assertEquals('Basic realm="' . $realm . '"', $header->current()->getFieldValue());
90  $this->assertContains('401', $response->getBody());
91  }
$response
Definition: 404.php:11
$objectManager
Definition: bootstrap.php:17

The documentation for this class was generated from the following file: