Skip to content

Commit

Permalink
ZF2-11, ZF2-91 - Remove loadClass in InfoCard
Browse files Browse the repository at this point in the history
  • Loading branch information
sasezaki committed Oct 29, 2011
1 parent 2815974 commit ae358ca
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 42 deletions.
37 changes: 0 additions & 37 deletions library/Zend/InfoCard/Adapter/Exception.php

This file was deleted.

2 changes: 1 addition & 1 deletion library/Zend/InfoCard/XML/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static public function convertToDOM(Element $e)
static public function convertToObject(\DOMElement $e, $classname)
{
if (!class_exists($classname)) {
\Zend\Loader::loadClass($classname);
throw new Exception\InvalidArgumentException('Class provided for converting does not exist');
}

if(!is_subclass_of($classname, 'Zend\InfoCard\XML\Element')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function applyTransforms($strXmlDocument)
{
foreach($this->_transformList as $transform) {
if (!class_exists($transform['class'])) {
\Zend\Loader::loadClass($transform['class']);
throw new Security\Exception\InvalidArgumentException('Transform Class not exist');
}

$transformer = new $transform['class'];
Expand Down
8 changes: 8 additions & 0 deletions tests/Zend/InfoCard/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ public function testTransforms()
$this->assertTrue(is_array($trans->getTransformList()));
}

public function testTransformsClassLoad()
{
$trans = new \ZendTest\InfoCard\TestAsset\UserTransformChain();
$trans->addTransform('http://www.w3.org/2000/09/xmldsig#enveloped-signature');
$this->setExpectedException('Zend\InfoCard\XML\Security\Exception\InvalidArgumentException', 'Transform Class not exist');
$trans->applyTransforms('');
}

public function testTransformsThrowsExceptionOnInvalidInput()
{
$trans = new \Zend\InfoCard\XML\Security\Transform\TransformChain();
Expand Down
19 changes: 19 additions & 0 deletions tests/Zend/InfoCard/TestAsset/UserTransformChain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace ZendTest\Infocard\TestAsset;
use Zend\InfoCard\XML\Security\Transform\TransformChain;

class UserTransformChain extends TransformChain
{
protected function _findClassbyURI($uri)
{
switch($uri) {
case 'http://www.w3.org/2000/09/xmldsig#enveloped-signature':
return 'ZendTest\InfoCard\XML\Security\Transform\EnvelopedSignatureUsersNotExists';
case 'http://www.w3.org/2001/10/xml-exc-c14n#':
return 'ZendTest\InfoCard\XML\Security\Transform\XMLExcC14NUsersNotExists';
default:
throw new Security\Exception\InvalidArgumentException("Unknown or Unsupported Transformation Requested");
}
}
}
19 changes: 16 additions & 3 deletions tests/Zend/InfoCard/XmlParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
* @namespace
*/
namespace ZendTest\InfoCard;
use Zend\InfoCard\XML\EncryptedData;
use Zend\InfoCard\XML\KeyInfo;
use Zend\InfoCard\XML;
use Zend\InfoCard\XML\EncryptedData,
Zend\InfoCard\XML\KeyInfo,
Zend\InfoCard\XML,
Zend\InfoCard\XML\Exception;


/**
Expand Down Expand Up @@ -112,6 +113,18 @@ public function testConversion()
$this->assertTrue($sxe instanceof KeyInfo\XMLDSig);
}

public function testConvertObjectClassLoad()
{
$encryptedData = EncryptedData\Factory::getInstance($this->_xmlDocument);
$keyInfo = $encryptedData->getKeyInfo();
$dom = KeyInfo\XMLDSig::convertToDOM($keyInfo);

try {
$sxe = KeyInfo\XMLDSig::convertToObject($dom, '\ZendTest\InfoCard\XML\KeyInfo\InvalidClassName');
} catch (Exception\InvalidArgumentException $e) {
}
}

public function testEncryptedDataKeyInfo()
{
$keyinfo = EncryptedData\Factory::getInstance($this->_xmlDocument)->getKeyInfo();
Expand Down

0 comments on commit ae358ca

Please sign in to comment.