From 067008c5f094ba9606daacbe540f6b929dc124ea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:31:28 +0200 Subject: Adding upstream version 1:1.3.2. Signed-off-by: Daniel Baumann --- .../library/X509/Model/Behavior/DERBase64Test.php | 69 ++++++++++++++++ .../X509/Model/Behavior/ExpressionInjectorTest.php | 38 +++++++++ test/php/library/X509/Model/Behavior/IpTest.php | 92 ++++++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 test/php/library/X509/Model/Behavior/DERBase64Test.php create mode 100644 test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php create mode 100644 test/php/library/X509/Model/Behavior/IpTest.php (limited to 'test/php/library/X509/Model') diff --git a/test/php/library/X509/Model/Behavior/DERBase64Test.php b/test/php/library/X509/Model/Behavior/DERBase64Test.php new file mode 100644 index 0000000..d451ac2 --- /dev/null +++ b/test/php/library/X509/Model/Behavior/DERBase64Test.php @@ -0,0 +1,69 @@ +assertNull($this->behavior()->retrieveProperty(null, static::COLUMN)); + } + + public function testFromDBTransformsPemToDer() + { + $this->assertSame( + static::CERT, + $this->behavior()->retrieveProperty(hex2bin(str_replace("\n", '', static::CERT_BASE64_HEX)), static::COLUMN) + ); + } + + public function testToDbReturnsNullWhenNullIsPassed() + { + $this->assertNull($this->behavior()->persistProperty(null, static::COLUMN)); + } + + public function testToDbTransformsDerToPem() + { + $this->assertSame( + hex2bin(str_replace("\n", '', static::CERT_BASE64_HEX)), + $this->behavior()->persistProperty(static::CERT, static::COLUMN) + ); + } + + protected function behavior(): DERBase64 + { + return new DERBase64(['cert']); + } +} diff --git a/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php b/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php new file mode 100644 index 0000000..5481ce9 --- /dev/null +++ b/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php @@ -0,0 +1,38 @@ +metaData()->set('columnName', 'duration'); + $this->assertSame('duration', $cond->getColumn()); + $this->assertSame('FOOO', $cond->getValue()); + + $this->behavior()->rewriteCondition($cond); + + $this->assertSame('FOOO', $cond->getValue()); + $this->assertSame(TestModel::EXPRESSION, $cond->getColumn()); + } + + protected function behavior(): ExpressionInjector + { + return (new ExpressionInjector('duration')) + ->setQuery( + (new Query()) + ->setDb(new Connection(['db' => 'mysql'])) + ->setModel(new TestModel()) + ); + } +} diff --git a/test/php/library/X509/Model/Behavior/IpTest.php b/test/php/library/X509/Model/Behavior/IpTest.php new file mode 100644 index 0000000..87c4c68 --- /dev/null +++ b/test/php/library/X509/Model/Behavior/IpTest.php @@ -0,0 +1,92 @@ +assertNull($this->behavior()->retrieveProperty(null, static::COLUMN)); + $this->assertNull($this->behavior(true)->retrieveProperty(null, static::COLUMN)); + } + + public function testFromDBTransformsBinaryIpToHumanReadable() + { + $this->assertSame( + static::IPV4, + $this->behavior()->retrieveProperty(hex2bin(static::IPV4_HEX), static::COLUMN) + ); + $this->assertSame( + static::IPV6, + $this->behavior()->retrieveProperty(hex2bin(static::IPV6_HEX), static::COLUMN) + ); + + $this->assertSame( + static::IPV4, + $this->behavior(true)->retrieveProperty(hex2bin(static::IPV4_HEX), static::COLUMN) + ); + $this->assertSame( + static::IPV6, + $this->behavior(true)->retrieveProperty(hex2bin(static::IPV6_HEX), static::COLUMN) + ); + } + + public function testToDbReturnsInvalidValueAsIs() + { + $this->assertNull($this->behavior()->persistProperty(null, static::COLUMN)); + $this->assertSame('*', $this->behavior()->persistProperty('*', static::COLUMN)); + + $this->assertNull($this->behavior(true)->persistProperty(null, static::COLUMN)); + $this->assertSame('*', $this->behavior(true)->persistProperty('*', static::COLUMN)); + + $ipv4Bin = hex2bin(static::IPV4_HEX); + $ipv6Bin = hex2bin(static::IPV6_HEX); + + $this->assertSame($ipv4Bin, $this->behavior()->persistProperty($ipv4Bin, static::COLUMN)); + $this->assertSame($ipv6Bin, $this->behavior()->persistProperty($ipv6Bin, static::COLUMN)); + + $this->assertSame($ipv4Bin, $this->behavior(true)->persistProperty($ipv4Bin, static::COLUMN)); + $this->assertSame($ipv6Bin, $this->behavior(true)->persistProperty($ipv6Bin, static::COLUMN)); + } + + public function testToDbTransformsIpToBinaryCorrectly() + { + $this->assertSame(hex2bin(static::IPV4_HEX), $this->behavior()->persistProperty(static::IPV4, static::COLUMN)); + $this->assertSame(hex2bin(static::IPV6_HEX), $this->behavior()->persistProperty(static::IPV6, static::COLUMN)); + + $this->assertSame( + sprintf('\\x%s', static::IPV4_HEX), + $this->behavior(true)->persistProperty(static::IPV4, static::COLUMN) + ); + $this->assertSame( + sprintf('\\x%s', static::IPV6_HEX), + $this->behavior(true)->persistProperty(static::IPV6, static::COLUMN) + ); + } + + protected function behavior(bool $postgres = false): Ip + { + return (new Ip(['ip'])) + ->setQuery( + (new Query()) + ->setDb(new Connection(['db' => $postgres ? 'pgsql' : 'mysql'])) + ); + } +} -- cgit v1.2.3