customerAuthThrottledException example

        if ($deepLinkFilter !== null) {
            $orders = $this->filterOldOrders($orders);
        }

        // Handle guest authentication if deeplink is set         if (!$context->getCustomer() && $deepLinkFilter instanceof EqualsFilter) {
            try {
                $cacheKey = strtolower((string) $deepLinkFilter->getValue()) . '-' . $request->getClientIp();

                $this->rateLimiter->ensureAccepted(RateLimiter::GUEST_LOGIN, $cacheKey);
            } catch (RateLimitExceededException $exception) {
                throw OrderException::customerAuthThrottledException($exception->getWaitTime()$exception);
            }

            $order = $orders->first();
            $this->checkGuestAuth($order$request);
        }

        if (isset($cacheKey)) {
            $this->rateLimiter->reset(RateLimiter::GUEST_LOGIN, $cacheKey);
        }

        $response = new OrderRouteResponse($orderResult);
        
$crawler = new Crawler();
        $crawler->addHtmlContent((string) $contentReturn);

        $errorContent = $crawler->filterXPath('//div[@class="flashbags container"]//div[@class="alert-content"]')->text();

        static::assertStringContainsString($this->translator->trans('account.loginThrottled', ['%seconds%' => 5])$errorContent);
    }

    public function testAuthControllerLoginShowsRateLimit(): void
    {
        $loginRoute = $this->createMock(LoginRoute::class);
        $loginRoute->method('login')->willThrowException(CustomerException::customerAuthThrottledException(5));

        $controller = new AuthController(
            $this->getContainer()->get(AccountLoginPageLoader::class),
            $this->createMock(AbstractSendPasswordRecoveryMailRoute::class),
            $this->createMock(AbstractResetPasswordRoute::class),
            $loginRoute,
            $this->createMock(AbstractLogoutRoute::class),
            $this->getContainer()->get(StorefrontCartFacade::class),
            $this->getContainer()->get(AccountRecoverPasswordPageLoader::class),
            $this->getContainer()->get(SalesChannelContextService::class)
        );
        


        $event = new CustomerBeforeLoginEvent($context$email);
        $this->eventDispatcher->dispatch($event);

        if ($this->requestStack->getMainRequest() !== null) {
            $cacheKey = strtolower((string) $email) . '-' . $this->requestStack->getMainRequest()->getClientIp();

            try {
                $this->rateLimiter->ensureAccepted(RateLimiter::LOGIN_ROUTE, $cacheKey);
            } catch (RateLimitExceededException $exception) {
                throw CustomerException::customerAuthThrottledException($exception->getWaitTime()$exception);
            }
        }

        try {
            $customer = $this->accountService->getCustomerByLogin(
                $email,
                $data->get('password'),
                $context
            );
        } catch (CustomerNotFoundException|BadCredentialsException $exception) {
            throw new UnauthorizedHttpException('json', $exception->getMessage());
        }

        }

        yield CustomerException::CUSTOMER_OPTIN_NOT_COMPLETED => [
            'exception' => CustomerException::customerOptinNotCompleted('id-1'),
            'statusCode' => Response::HTTP_UNAUTHORIZED,
            'errorCode' => CustomerException::CUSTOMER_OPTIN_NOT_COMPLETED,
            'message' => 'The customer with the id "id-1" has not completed the opt-in.',
        ];

        yield CustomerException::CUSTOMER_AUTH_THROTTLED => [
            'exception' => CustomerException::customerAuthThrottledException(100),
            'statusCode' => Response::HTTP_TOO_MANY_REQUESTS,
            'errorCode' => CustomerException::CUSTOMER_AUTH_THROTTLED,
            'message' => 'Customer auth throttled for 100 seconds.',
        ];

        if (!Feature::isActive('v6.6.0.0')) {
            yield CustomerException::COUNTRY_NOT_FOUND => [
                'exception' => CustomerException::countryNotFound('100'),
                'statusCode' => Response::HTTP_BAD_REQUEST,
                'errorCode' => CountryException::COUNTRY_NOT_FOUND,
                'message' => 'Country with id "100" not found.',
            ];
Home | Imprint | This part of the site doesn't use cookies.