Skip to content

Commit

Permalink
Hardcode mustUnderstand for the cases where it MUST be 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jun 3, 2023
1 parent 38c246b commit 078bc59
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 84 deletions.
21 changes: 4 additions & 17 deletions src/SAML2/XML/ecp/RelayState.php
Expand Up @@ -30,28 +30,15 @@ final class RelayState extends AbstractEcpElement
/**
* Create a ECP RelayState element.
*
* @param bool $mustUnderstand
* @param string $relayState
*/
public function __construct(
protected bool $mustUnderstand,
string $relayState,
) {
$this->setContent($relayState);
}


/**
* Collect the value of the mustUnderstand-property
*
* @return bool
*/
public function getMustUnderstand(): bool
{
return $this->mustUnderstand;
}


/**
* Convert XML into a RelayState
*
Expand Down Expand Up @@ -81,9 +68,9 @@ public static function fromXML(DOMElement $xml): static
);

$mustUnderstand = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand');
$mustUnderstand = ($mustUnderstand === '') ? null : boolval(intval($mustUnderstand));
Assert::nullOrBoolean(
Assert::same(
$mustUnderstand,
'1',
'Invalid value of env:mustUnderstand attribute in <ecp:RelayState>.',
ProtocolViolationException::class,
);
Expand All @@ -96,7 +83,7 @@ public static function fromXML(DOMElement $xml): static
ProtocolViolationException::class,
);

return new static($mustUnderstand, $xml->textContent);
return new static($xml->textContent);
}


Expand All @@ -109,7 +96,7 @@ public static function fromXML(DOMElement $xml): static
public function toXML(DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand())));
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', '1');
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', C::SOAP_ACTOR_NEXT);
$e->textContent = $this->getContent();

Expand Down
28 changes: 7 additions & 21 deletions src/SAML2/XML/ecp/Request.php
Expand Up @@ -31,14 +31,12 @@ final class Request extends AbstractEcpElement
/**
* Create a ECP Request element.
*
* @param bool $mustUnderstand
* @param \SimpleSAML\SAML2\XML\saml\Issuer $issuer
* @param \SimpleSAML\SAML2\XML\samlp\IDPList|null $idpList
* @param string|null $providerName
* @param bool|null $isPassive
*/
public function __construct(
protected bool $mustUnderstand,
protected Issuer $issuer,
protected ?IDPList $idpList = null,
protected ?string $providerName = null,
Expand All @@ -47,23 +45,12 @@ public function __construct(
}


/**
* Collect the value of the mustUnderstand-property
*
* @return bool
*/
public function getMustUnderstand(): bool
{
return $this->mustUnderstand;
}


/**
* Collect the value of the isPassive-property
*
* @return bool
* @return bool|null
*/
public function getIsPassive(): bool
public function getIsPassive(): ?bool
{
return $this->isPassive;
}
Expand All @@ -72,9 +59,9 @@ public function getIsPassive(): bool
/**
* Collect the value of the providerName-property
*
* @return string
* @return string|null
*/
public function getProviderName(): string
public function getProviderName(): ?string
{
return $this->providerName;
}
Expand Down Expand Up @@ -129,9 +116,9 @@ public static function fromXML(DOMElement $xml): static
);

$mustUnderstand = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand');
$mustUnderstand = ($mustUnderstand === '') ? null : boolval(intval($mustUnderstand));
Assert::nullOrBoolean(
Assert::same(
$mustUnderstand,
'1',
'Invalid value of env:mustUnderstand attribute in <ecp:Request>.',
ProtocolViolationException::class,
);
Expand All @@ -155,7 +142,6 @@ public static function fromXML(DOMElement $xml): static
$idpList = IDPList::getChildrenOfClass($xml);

return new static(
$mustUnderstand,
array_pop($issuer),
array_pop($idpList),
self::getOptionalAttribute($xml, 'ProviderName', null),
Expand All @@ -173,7 +159,7 @@ public static function fromXML(DOMElement $xml): static
public function toXML(DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand())));
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', '1');
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', C::SOAP_ACTOR_NEXT);

if ($this->getProviderName() !== null) {
Expand Down
37 changes: 11 additions & 26 deletions src/SAML2/XML/ecp/RequestAuthenticated.php
Expand Up @@ -26,26 +26,20 @@ final class RequestAuthenticated extends AbstractEcpElement
/**
* Create a ECP RequestAuthenticated element.
*
* @param bool|null $mustUnderstand
* @param bool $mustUnderstand
*/
public function __construct(
protected ?bool $mustUnderstand,
protected bool $mustUnderstand
) {
Assert::oneOf(
$mustUnderstand,
[null, false, true],
'Invalid value of env:mustUnderstand attribute in <ecp:Response>.',
ProtocolViolationException::class,
);
}


/**
* Collect the value of the mustUnderstand-property
*
* @return bool|null
* @return bool
*/
public function getMustUnderstand(): ?bool
public function getMustUnderstand(): bool
{
return $this->mustUnderstand;
}
Expand Down Expand Up @@ -79,7 +73,7 @@ public static function fromXML(DOMElement $xml): static

Assert::oneOf(
$mustUnderstand,
['', '0', '1'],
['0', '1'],
'Invalid value of env:mustUnderstand attribute in <ecp:RequestAuthenticated>.',
ProtocolViolationException::class,
);
Expand All @@ -90,9 +84,7 @@ public static function fromXML(DOMElement $xml): static
ProtocolViolationException::class,
);

$mustUnderstand = ($mustUnderstand === '') ? null : boolval($mustUnderstand);

return new static($mustUnderstand);
return new static(boolval($mustUnderstand));
}


Expand All @@ -104,17 +96,10 @@ public static function fromXML(DOMElement $xml): static
*/
public function toXML(DOMElement $parent = null): DOMElement
{
$response = $this->instantiateParentElement($parent);

if ($this->getMustUnderstand() !== null) {
$response->setAttributeNS(
C::NS_SOAP_ENV_11,
'env:mustUnderstand',
strval(intval($this->getMustUnderstand())),
);
}
$response->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', 'http://schemas.xmlsoap.org/soap/actor/next');

return $response;
$e = $this->instantiateParentElement($parent);
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand())));
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', C::SOAP_ACTOR_NEXT);

return $e;
}
}
20 changes: 3 additions & 17 deletions src/SAML2/XML/ecp/SubjectConfirmation.php
Expand Up @@ -30,30 +30,17 @@ final class SubjectConfirmation extends AbstractEcpElement
/**
* Create a ECP SubjectConfirmation element.
*
* @param bool $mustUnderstand
* @param string $method
* @param \SimpleSAML\SAML2\XML\saml\SubjectConfirmationData|null $subjectConfirmationData
*/
public function __construct(
protected bool $mustUnderstand,
protected string $method,
protected ?SubjectConfirmationData $subjectConfirmationData = null,
) {
Assert::validURI($method, SchemaViolationException::class);
}


/**
* Collect the value of the mustUnderstand-property
*
* @return bool
*/
public function getMustUnderstand(): bool
{
return $this->mustUnderstand;
}


/**
* Collect the value of the method-property
*
Expand Down Expand Up @@ -105,9 +92,9 @@ public static function fromXML(DOMElement $xml): static
);

$mustUnderstand = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand');
$mustUnderstand = ($mustUnderstand === '') ? null : boolval(intval($mustUnderstand));
Assert::nullOrBoolean(
Assert::same(
$mustUnderstand,
'1',
'Invalid value of env:mustUnderstand attribute in <ecp:SubjectConfirmation>.',
ProtocolViolationException::class,
);
Expand All @@ -129,7 +116,6 @@ public static function fromXML(DOMElement $xml): static
);

return new static(
$mustUnderstand,
self::getAttribute($xml, 'Method'),
array_pop($subjectConfirmationData),
);
Expand All @@ -145,7 +131,7 @@ public static function fromXML(DOMElement $xml): static
public function toXML(DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand())));
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', '1');
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', C::SOAP_ACTOR_NEXT);
$e->setAttribute('Method', $this->getMethod());

Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/ecp/RelayStateTest.php
Expand Up @@ -50,7 +50,7 @@ public static function setUpBeforeClass(): void
*/
public function testMarshalling(): void
{
$relayState = new RelayState(true, 'AGDY854379dskssda');
$relayState = new RelayState('AGDY854379dskssda');

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/ecp/RequestTest.php
Expand Up @@ -66,7 +66,7 @@ public function testMarshalling(): void
$getComplete = new GetComplete('https://some/location');
$idpList = new IDPList([$entry1, $entry2], $getComplete);

$request = new Request(true, $issuer, $idpList, 'PHPUnit', true);
$request = new Request($issuer, $idpList, 'PHPUnit', true);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/ecp/SubjectConfirmationTest.php
Expand Up @@ -73,7 +73,7 @@ public function testMarshalling(): void
[$attr1, $attr2]
);

$subjectConfirmation = new SubjectConfirmation(true, C::CM_BEARER, $subjectConfirmationData);
$subjectConfirmation = new SubjectConfirmation(C::CM_BEARER, $subjectConfirmationData);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
Expand Down

0 comments on commit 078bc59

Please sign in to comment.