1818use Magento \Integration \Model \ResourceModel \Oauth \Token \CollectionFactory ;
1919use Magento \Integration \Model \Oauth \Token \RequestLog \Config as TokenThrottlerConfig ;
2020use Magento \Integration \Api \CustomerTokenServiceInterface ;
21+ use Magento \Customer \Model \CustomerFactory ;
2122
2223/**
2324 * api-functional test for \Magento\Integration\Model\CustomerTokenService.
2627 */
2728class CustomerTokenServiceTest extends WebapiAbstract
2829{
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 " ;
3233
3334 /**
3435 * @var CustomerTokenServiceInterface
@@ -60,6 +61,11 @@ class CustomerTokenServiceTest extends WebapiAbstract
6061 */
6162 private $ tokenReader ;
6263
64+ /**
65+ * @var CustomerFactory
66+ */
67+ private $ customerFactory ;
68+
6369 /**
6470 * Setup CustomerTokenService
6571 */
@@ -81,6 +87,7 @@ protected function setUp(): void
8187 $ tokenThrottlerConfig = Bootstrap::getObjectManager ()->get (TokenThrottlerConfig::class);
8288 $ this ->attemptsCountToLockAccount = $ tokenThrottlerConfig ->getMaxFailuresCount ();
8389 $ this ->tokenReader = Bootstrap::getObjectManager ()->get (UserTokenReaderInterface::class);
90+ $ this ->customerFactory = Bootstrap::getObjectManager ()->get (CustomerFactory::class);
8491 }
8592
8693 /**
@@ -103,9 +110,26 @@ public function testCreateCustomerAccessToken(?string $store): void
103110 'httpMethod ' => Request::HTTP_METHOD_POST ,
104111 ],
105112 ];
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 ());
106127 $ requestData = ['username ' => $ userName , 'password ' => $ password ];
107128 $ 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 ());
109133 $ this ->assertToken ($ accessToken , $ userName , $ password );
110134 }
111135
0 commit comments