public function testIsValidShortCustomKeyName() { $invalidToken = 'fajdhkahkjha'; $this->keyLengthValidator->setName('Custom Key'); $this->keyLengthValidator->isValid($invalidToken); $expected = ['stringLengthTooShort' => "Custom Key '{$invalidToken}' is less than 32 characters long"]; $this->assertEquals($expected, $this->keyLengthValidator->getMessages()); }
/** * {@inheritdoc} */ public function validate() { if ($this->getCallbackUrl() || $this->getRejectedCallbackUrl()) { $this->setCallbackUrl(trim($this->getCallbackUrl())); $this->setRejectedCallbackUrl(trim($this->getRejectedCallbackUrl())); if ($this->getCallbackUrl() && !$this->urlValidator->isValid($this->getCallbackUrl())) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Callback URL')); } if ($this->getRejectedCallbackUrl() && !$this->urlValidator->isValid($this->getRejectedCallbackUrl())) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Rejected Callback URL')); } } $this->keyLengthValidator ->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY) ->setName('Consumer Key'); if (!$this->keyLengthValidator->isValid($this->getKey())) { $messages = $this->keyLengthValidator->getMessages(); throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages))); } $this->keyLengthValidator ->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET) ->setName('Consumer Secret'); if (!$this->keyLengthValidator->isValid($this->getSecret())) { $messages = $this->keyLengthValidator->getMessages(); throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages))); } return true; }