public function testClaims() { if (version_compare(PHP_VERSION, '5.2.0', '<')) { $this->markTestSkipped('DOMDocument::C14N() not available until PHP 5.2.0'); } try { $infoCard = new InfoCard\InfoCard(); } catch (InfoCard\Exception $e) { $message = $e->getMessage(); if (preg_match('/requires.+mcrypt/', $message)) { $this->markTestSkipped($message); } else { throw $e; } } $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey); $claims = $infoCard->process($this->_xmlDocument); $this->assertTrue($claims instanceof InfoCard\Claims); $this->assertFalse($claims->isValid()); $this->assertSame($claims->getCode(), InfoCard\Claims::RESULT_VALIDATION_FAILURE); $errormsg = $claims->getErrorMsg(); $this->assertTrue(!empty($errormsg)); @$claims->forceValid(); $this->assertTrue($claims->isValid()); $this->assertSame($claims->emailaddress, "*****@*****.**"); $this->assertSame($claims->givenname, "John"); $this->assertSame($claims->surname, "Coggeshall"); $this->assertSame($claims->getCardID(), "rW1/y9BuncoBK4WSipF2hHYParxxgMHk6ANBrhz1Zr4="); $this->assertSame($claims->getClaim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"), "*****@*****.**"); $this->assertSame($claims->getDefaultNamespace(), "http://schemas.xmlsoap.org/ws/2005/05/identity/claims"); try { unset($claims->givenname); } catch (InfoCard\Exception $e) { } catch (\Exception $e) { $this->assertFalse(true); } try { $claims->givenname = "Test"; } catch (InfoCard\Exception $e) { } catch (\Exception $e) { $this->assertFalse(true); } $this->assertTrue(isset($claims->givenname)); }
public function testClaimsThrowsExceptionOnMutation() { $this->requireMcryptAndOpensslOrSkip(); $infoCard = new InfoCard\InfoCard(); $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey); $claims = $infoCard->process($this->_xmlDocument); $this->setExpectedException('Zend\\InfoCard\\Exception\\InvalidArgumentException', 'Claim objects are read-only'); $claims->givenname = "Test"; }
/** * Add a Certificate Pair to the list of certificates searched by the component * * @param string $privateKeyFile The path to the private key file for the pair * @param string $publicKeyFile The path to the certificate / public key for the pair * @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding) * @param string $password (optional) The password for the private key file if necessary * @throws Zend\InfoCard\Exception * @return string A key ID representing this key pair in the component */ public function addCertificatePair($privateKeyFile, $publicKeyFile, $type = ZendInfoCard\Cipher::ENC_RSA_OAEP_MGF1P, $password = null) { return $this->_infoCard->addCertificatePair($privateKeyFile, $publicKeyFile, $type, $password); }