From 7a594338c550814b0485634d99e59954056f958f Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sat, 30 Dec 2023 00:54:38 +0100 Subject: [PATCH] Add securitypolicy classes --- src/XML/sp/KerberosToken.php | 16 ++++ src/XML/sp/SecurityContextToken.php | 16 ++++ src/XML/sp/X509Token.php | 16 ++++ tests/WSSecurity/XML/sp/KerberosTokenTest.php | 84 +++++++++++++++++++ .../XML/sp/SecurityContextTokenTest.php | 84 +++++++++++++++++++ tests/WSSecurity/XML/sp/X509TokenTest.php | 84 +++++++++++++++++++ tests/resources/xml/sp_KerberosToken.xml | 3 + .../resources/xml/sp_SecurityContextToken.xml | 3 + tests/resources/xml/sp_X509Token.xml | 3 + 9 files changed, 309 insertions(+) create mode 100644 src/XML/sp/KerberosToken.php create mode 100644 src/XML/sp/SecurityContextToken.php create mode 100644 src/XML/sp/X509Token.php create mode 100644 tests/WSSecurity/XML/sp/KerberosTokenTest.php create mode 100644 tests/WSSecurity/XML/sp/SecurityContextTokenTest.php create mode 100644 tests/WSSecurity/XML/sp/X509TokenTest.php create mode 100644 tests/resources/xml/sp_KerberosToken.xml create mode 100644 tests/resources/xml/sp_SecurityContextToken.xml create mode 100644 tests/resources/xml/sp_X509Token.xml diff --git a/src/XML/sp/KerberosToken.php b/src/XML/sp/KerberosToken.php new file mode 100644 index 00000000..bf7fb8ee --- /dev/null +++ b/src/XML/sp/KerberosToken.php @@ -0,0 +1,16 @@ +assertEquals( + "", + 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( + 'some' + )->documentElement); + + $kerberosToken = new KerberosToken(IncludeToken::Always, [$chunk], [$attr]); + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($kerberosToken), + ); + } +} diff --git a/tests/WSSecurity/XML/sp/SecurityContextTokenTest.php b/tests/WSSecurity/XML/sp/SecurityContextTokenTest.php new file mode 100644 index 00000000..e888b408 --- /dev/null +++ b/tests/WSSecurity/XML/sp/SecurityContextTokenTest.php @@ -0,0 +1,84 @@ +assertEquals( + "", + 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( + 'some' + )->documentElement); + + $securityContextToken = new SecurityContextToken(IncludeToken::Always, [$chunk], [$attr]); + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($securityContextToken), + ); + } +} diff --git a/tests/WSSecurity/XML/sp/X509TokenTest.php b/tests/WSSecurity/XML/sp/X509TokenTest.php new file mode 100644 index 00000000..2b88ca0d --- /dev/null +++ b/tests/WSSecurity/XML/sp/X509TokenTest.php @@ -0,0 +1,84 @@ +assertEquals( + "", + 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( + 'some' + )->documentElement); + + $x509Token = new X509Token(IncludeToken::Always, [$chunk], [$attr]); + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($x509Token), + ); + } +} diff --git a/tests/resources/xml/sp_KerberosToken.xml b/tests/resources/xml/sp_KerberosToken.xml new file mode 100644 index 00000000..2cc83de2 --- /dev/null +++ b/tests/resources/xml/sp_KerberosToken.xml @@ -0,0 +1,3 @@ + + some + diff --git a/tests/resources/xml/sp_SecurityContextToken.xml b/tests/resources/xml/sp_SecurityContextToken.xml new file mode 100644 index 00000000..cefa9b0a --- /dev/null +++ b/tests/resources/xml/sp_SecurityContextToken.xml @@ -0,0 +1,3 @@ + + some + diff --git a/tests/resources/xml/sp_X509Token.xml b/tests/resources/xml/sp_X509Token.xml new file mode 100644 index 00000000..7cd7f958 --- /dev/null +++ b/tests/resources/xml/sp_X509Token.xml @@ -0,0 +1,3 @@ + + some +