18
18
use Magento \Integration \Model \ResourceModel \Oauth \Token \CollectionFactory ;
19
19
use Magento \Integration \Model \Oauth \Token \RequestLog \Config as TokenThrottlerConfig ;
20
20
use Magento \Integration \Api \CustomerTokenServiceInterface ;
21
+ use Magento \Customer \Model \CustomerFactory ;
21
22
22
23
/**
23
24
* api-functional test for \Magento\Integration\Model\CustomerTokenService.
26
27
*/
27
28
class CustomerTokenServiceTest extends WebapiAbstract
28
29
{
29
- const SERVICE_NAME = "integrationCustomerTokenServiceV1 " ;
30
- const SERVICE_VERSION = "V1 " ;
31
- const RESOURCE_PATH_CUSTOMER_TOKEN = "/V1/integration/customer/token " ;
30
+ private const SERVICE_NAME = "integrationCustomerTokenServiceV1 " ;
31
+ private const SERVICE_VERSION = "V1 " ;
32
+ private const RESOURCE_PATH_CUSTOMER_TOKEN = "/V1/integration/customer/token " ;
32
33
33
34
/**
34
35
* @var CustomerTokenServiceInterface
@@ -60,6 +61,11 @@ class CustomerTokenServiceTest extends WebapiAbstract
60
61
*/
61
62
private $ tokenReader ;
62
63
64
+ /**
65
+ * @var CustomerFactory
66
+ */
67
+ private $ customerFactory ;
68
+
63
69
/**
64
70
* Setup CustomerTokenService
65
71
*/
@@ -81,6 +87,7 @@ protected function setUp(): void
81
87
$ tokenThrottlerConfig = Bootstrap::getObjectManager ()->get (TokenThrottlerConfig::class);
82
88
$ this ->attemptsCountToLockAccount = $ tokenThrottlerConfig ->getMaxFailuresCount ();
83
89
$ this ->tokenReader = Bootstrap::getObjectManager ()->get (UserTokenReaderInterface::class);
90
+ $ this ->customerFactory = Bootstrap::getObjectManager ()->get (CustomerFactory::class);
84
91
}
85
92
86
93
/**
@@ -103,9 +110,26 @@ public function testCreateCustomerAccessToken(?string $store): void
103
110
'httpMethod ' => Request::HTTP_METHOD_POST ,
104
111
],
105
112
];
113
+
114
+ $ invalidCredentials = [
115
+ 'username ' => $ userName ,
116
+ 'password ' => 'invalid ' ,
117
+ ];
118
+ try {
119
+ $ this ->_webApiCall ($ serviceInfo , $ invalidCredentials );
120
+ } catch (\Exception $ e ) {
121
+ }
122
+ $ customerData = $ this ->customerAccountManagement ->authenticate ($ userName , $ password );
123
+ $ customer = $ this ->customerFactory ->create ()->setWebsiteId ($ customerData ->getWebsiteId ())
124
+ ->loadByEmail ($ customerData ->getEmail ());
125
+ $ this ->assertEquals (1 , $ customer ->getFailuresNum ());
126
+ $ this ->assertNotNull ($ customer ->getFirstFailure ());
106
127
$ requestData = ['username ' => $ userName , 'password ' => $ password ];
107
128
$ accessToken = $ this ->_webApiCall ($ serviceInfo , $ requestData , null , $ store );
108
-
129
+ $ customer = $ this ->customerFactory ->create ()->setWebsiteId ($ customerData ->getWebsiteId ())
130
+ ->loadByEmail ($ customerData ->getEmail ());
131
+ $ this ->assertEquals (0 , $ customer ->getFailuresNum ());
132
+ $ this ->assertNull ($ customer ->getFirstFailure ());
109
133
$ this ->assertToken ($ accessToken , $ userName , $ password );
110
134
}
111
135
0 commit comments