コード例 #1
0
 /**
  * Validate sample resource (file or URL)
  *
  * @param LinkContentInterface $linkContent
  * @throws InputException
  * @return void
  */
 protected function validateSampleResource(LinkContentInterface $linkContent)
 {
     if ($linkContent->getSampleType() == 'url' && !$this->urlValidator->isValid($linkContent->getSampleUrl())) {
         throw new InputException(__('Sample URL must have valid format.'));
     }
     if ($linkContent->getSampleType() == 'file' && (!$linkContent->getSampleFile() || !$this->fileContentValidator->isValid($linkContent->getSampleFile()))) {
         throw new InputException(__('Provided file content must be valid base64 encoded data.'));
     }
 }
コード例 #2
0
 /**
  * Validate sample resource (file or URL)
  *
  * @param DownloadableSampleContent $sampleContent
  * @throws InputException
  * @return void
  */
 protected function validateSampleResource(DownloadableSampleContent $sampleContent)
 {
     $sampleFile = $sampleContent->getSampleFile();
     if ($sampleContent->getSampleType() == 'file' && (!$sampleFile || !$this->fileContentValidator->isValid($sampleFile))) {
         throw new InputException('Provided file content must be valid base64 encoded data.');
     }
     if ($sampleContent->getSampleType() == 'url' && !$this->urlValidator->isValid($sampleContent->getSampleUrl())) {
         throw new InputException('Sample URL must have valid format.');
     }
 }
コード例 #3
0
ファイル: Token.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * Validate data
  *
  * @return bool
  * @throws OauthException Throw exception on fail validation
  */
 public function validate()
 {
     if (OauthHelper::CALLBACK_ESTABLISHED != $this->getCallbackUrl() && !$this->_urlValidator->isValid($this->getCallbackUrl())) {
         $messages = $this->_urlValidator->getMessages();
         throw new OauthException(__(array_shift($messages)));
     }
     /** @var $validatorLength \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength */
     $validatorLength = $this->_keyLengthFactory->create();
     $validatorLength->setLength(OauthHelper::LENGTH_TOKEN_SECRET);
     $validatorLength->setName('Token Secret Key');
     if (!$validatorLength->isValid($this->getSecret())) {
         $messages = $validatorLength->getMessages();
         throw new OauthException(__(array_shift($messages)));
     }
     $validatorLength->setLength(OauthHelper::LENGTH_TOKEN);
     $validatorLength->setName('Token Key');
     if (!$validatorLength->isValid($this->getToken())) {
         $messages = $validatorLength->getMessages();
         throw new OauthException(__(array_shift($messages)));
     }
     if (null !== ($verifier = $this->getVerifier())) {
         $validatorLength->setLength(OauthHelper::LENGTH_TOKEN_VERIFIER);
         $validatorLength->setName('Verifier Key');
         if (!$validatorLength->isValid($verifier)) {
             $messages = $validatorLength->getMessages();
             throw new OauthException(__(array_shift($messages)));
         }
     }
     return true;
 }
コード例 #4
0
ファイル: Consumer.php プロジェクト: shabbirvividads/magento2
 /**
  * {@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'));
         }
     }
     /** @var $validatorLength \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength */
     $validatorLength = $this->_keyLengthFactory->create(['options' => ['length' => \Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY]]);
     $validatorLength->setName('Consumer Key');
     if (!$validatorLength->isValid($this->getKey())) {
         $messages = $validatorLength->getMessages();
         throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
     }
     $validatorLength->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET);
     $validatorLength->setName('Consumer Secret');
     if (!$validatorLength->isValid($this->getSecret())) {
         $messages = $validatorLength->getMessages();
         throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
     }
     return true;
 }
コード例 #5
0
ファイル: Consumer.php プロジェクト: razbakov/magento2
    /**
     * {@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;
    }
コード例 #6
0
ファイル: TokenTest.php プロジェクト: razbakov/magento2
    public function testValidate()
    {
        $token = 'token';
        $secret = 'secret';
        $verifier = 'verifier';

        $this->tokenModel->setCallbackUrl('notCallbackEstablished');
        $this->validatorMock->expects($this->once())->method('isValid')->willReturn(true);

        $this->keyLengthFactoryMock->expects($this->once())->method('create')->willReturn(
            $this->validatorKeyLengthMock
        );

        $this->tokenModel->setSecret($secret);
        $this->tokenModel->setToken($token);
        $this->tokenModel->setData('verifier', $verifier);
        $this->validatorKeyLengthMock->expects($this->exactly(3))->method('isValid')->willReturnMap(
            [
                [$secret, true],
                [$token, true],
                [$verifier, true],
            ]
        );
        $this->assertTrue($this->tokenModel->validate());
    }
コード例 #7
0
 public function testIsValidWhenInvalid()
 {
     $this->assertEquals(false, $this->object->isValid('%value%'));
     $this->assertEquals($this->expectedValidationMessages, $this->object->getMessages());
 }