Esempio n. 1
0
    /**
     * {@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;
    }
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Invalid type given for Key. String expected
  */
 public function testIsValidInvalidType()
 {
     $invalidTokenType = 1;
     $this->keyLengthValidator->isValid($invalidTokenType);
 }