Skip to content

Commit

Permalink
Add securitypolicy classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 29, 2023
1 parent f325fb2 commit 7a59433
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/XML/sp/KerberosToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\sp;

use SimpleSAML\Assert\Assert;

/**
* An KerberosToken element
*
* @package tvdijen/ws-security
*/
final class KerberosToken extends AbstractTokenAssertionType
{
}
16 changes: 16 additions & 0 deletions src/XML/sp/SecurityContextToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\sp;

use SimpleSAML\Assert\Assert;

/**
* An SecurityContextToken element
*
* @package tvdijen/ws-security
*/
final class SecurityContextToken extends AbstractTokenAssertionType
{
}
16 changes: 16 additions & 0 deletions src/XML/sp/X509Token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\sp;

use SimpleSAML\Assert\Assert;

/**
* An X509Token element
*
* @package tvdijen/ws-security
*/
final class X509Token extends AbstractTokenAssertionType
{
}
84 changes: 84 additions & 0 deletions tests/WSSecurity/XML/sp/KerberosTokenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\sp;

use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\Utils\XPath;
use SimpleSAML\WSSecurity\XML\sp\IncludeToken;
use SimpleSAML\WSSecurity\XML\sp\KerberosToken;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;

/**
* Class \SimpleSAML\WSSecurity\XML\sp\KerberosTokenTest
*
* @covers \SimpleSAML\WSSecurity\XML\sp\KerberosToken
* @covers \SimpleSAML\WSSecurity\XML\sp\AbstractAssertionTokenType
* @covers \SimpleSAML\WSSecurity\XML\sp\AbstractSpElement
*
* @package tvdijen/ws-security
*/
final class KerberosTokenTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-securitypolicy-1.2.xsd';

self::$testedClass = KerberosToken::class;

self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 4) . '/resources/xml/sp_KerberosToken.xml',
);
}


// test marshalling


/**
* Adding an empty KerberosToken element should yield an empty element.
*/
public function testMarshallingEmptyElement(): void
{
$spns = C::NS_SEC_POLICY;
$kerberosToken = new KerberosToken();
$this->assertEquals(
"<sp:KerberosToken xmlns:sp=\"$spns\"/>",
strval($kerberosToken),
);
$this->assertTrue($kerberosToken->isEmptyElement());
}


/**
* Test that creating a KerberosToken from scratch works.
*/
public function testMarshalling(): void
{
$attr = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'value1');
$chunk = new Chunk(DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>'
)->documentElement);

$kerberosToken = new KerberosToken(IncludeToken::Always, [$chunk], [$attr]);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($kerberosToken),
);
}
}
84 changes: 84 additions & 0 deletions tests/WSSecurity/XML/sp/SecurityContextTokenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\sp;

use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\Utils\XPath;
use SimpleSAML\WSSecurity\XML\sp\IncludeToken;
use SimpleSAML\WSSecurity\XML\sp\SecurityContextToken;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;

/**
* Class \SimpleSAML\WSSecurity\XML\sp\SecurityContextTokenTest
*
* @covers \SimpleSAML\WSSecurity\XML\sp\SecurityContextToken
* @covers \SimpleSAML\WSSecurity\XML\sp\AbstractAssertionTokenType
* @covers \SimpleSAML\WSSecurity\XML\sp\AbstractSpElement
*
* @package tvdijen/ws-security
*/
final class SecurityContextTokenTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-securitypolicy-1.2.xsd';

self::$testedClass = SecurityContextToken::class;

self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 4) . '/resources/xml/sp_SecurityContextToken.xml',
);
}


// test marshalling


/**
* Adding an empty SecurityContextToken element should yield an empty element.
*/
public function testMarshallingEmptyElement(): void
{
$spns = C::NS_SEC_POLICY;
$securityContextToken = new SecurityContextToken();
$this->assertEquals(
"<sp:SecurityContextToken xmlns:sp=\"$spns\"/>",
strval($securityContextToken),
);
$this->assertTrue($securityContextToken->isEmptyElement());
}


/**
* Test that creating a SecurityContextToken from scratch works.
*/
public function testMarshalling(): void
{
$attr = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'value1');
$chunk = new Chunk(DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>'
)->documentElement);

$securityContextToken = new SecurityContextToken(IncludeToken::Always, [$chunk], [$attr]);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($securityContextToken),
);
}
}
84 changes: 84 additions & 0 deletions tests/WSSecurity/XML/sp/X509TokenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\sp;

use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\Utils\XPath;
use SimpleSAML\WSSecurity\XML\sp\IncludeToken;
use SimpleSAML\WSSecurity\XML\sp\X509Token;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;

/**
* Class \SimpleSAML\WSSecurity\XML\sp\X509lTokenTest
*
* @covers \SimpleSAML\WSSecurity\XML\sp\X509Token
* @covers \SimpleSAML\WSSecurity\XML\sp\AbstractAssertionTokenType
* @covers \SimpleSAML\WSSecurity\XML\sp\AbstractSpElement
*
* @package tvdijen/ws-security
*/
final class X509TokenTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-securitypolicy-1.2.xsd';

self::$testedClass = X509Token::class;

self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 4) . '/resources/xml/sp_X509Token.xml',
);
}


// test marshalling


/**
* Adding an empty X509lToken element should yield an empty element.
*/
public function testMarshallingEmptyElement(): void
{
$spns = C::NS_SEC_POLICY;
$x509Token = new X509Token();
$this->assertEquals(
"<sp:X509Token xmlns:sp=\"$spns\"/>",
strval($x509Token),
);
$this->assertTrue($x509Token->isEmptyElement());
}


/**
* Test that creating a X509Token from scratch works.
*/
public function testMarshalling(): void
{
$attr = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'value1');
$chunk = new Chunk(DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>'
)->documentElement);

$x509Token = new X509Token(IncludeToken::Always, [$chunk], [$attr]);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($x509Token),
);
}
}
3 changes: 3 additions & 0 deletions tests/resources/xml/sp_KerberosToken.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<sp:KerberosToken xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:ssp="urn:x-simplesamlphp:namespace" IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Always" ssp:attr1="value1">
<ssp:Chunk>some</ssp:Chunk>
</sp:KerberosToken>
3 changes: 3 additions & 0 deletions tests/resources/xml/sp_SecurityContextToken.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<sp:SecurityContextToken xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:ssp="urn:x-simplesamlphp:namespace" IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Always" ssp:attr1="value1">
<ssp:Chunk>some</ssp:Chunk>
</sp:SecurityContextToken>
3 changes: 3 additions & 0 deletions tests/resources/xml/sp_X509Token.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<sp:X509Token xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:ssp="urn:x-simplesamlphp:namespace" IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Always" ssp:attr1="value1">
<ssp:Chunk>some</ssp:Chunk>
</sp:X509Token>

0 comments on commit 7a59433

Please sign in to comment.