Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.phpunit.result.cache
composer.lock
/vendor
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
"require": {
"php": "^7.4 || ^8.0",
"lib-openssl": "*",
"composer/ca-bundle": "^1.2"
"composer/ca-bundle": "^1.2",
"ext-openssl": "*"
},

"require-dev": {
"phpunit/phpunit": "^5",
"phpunit/phpunit": "^9.0",
"php-vfs/php-vfs": "^1.3"
},

Expand Down
9 changes: 2 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
<testsuites>
<testsuite>
<testsuite name="Tests">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
4 changes: 4 additions & 0 deletions src/Punkstar/Ssl/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public function signedBy(Certificate $cert): bool

protected function extractCertData($certificate): array
{
if (null === $certificate) {
throw new Exception("Unable to extract data from certificate.", Exception::MALFORMED_CERTIFICATE);
}

$parsedData = openssl_x509_parse($certificate);

if ($parsedData === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Punkstar/Ssl/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class Exception extends \Exception
const MALFORMED_CERTIFICATE = 2001;

const CONNECTION_PROBLEM = 3001;
}
}
14 changes: 7 additions & 7 deletions tests/Punkstar/SslTest/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public function testExampleCerts($certFileName)
$reader = new Reader();
$cert = $reader->readFromFile($certFileName);

$this->assertInternalType('string', $cert->certName());
$this->assertInternalType('string', $cert->toString());
$this->assertInternalType('string', (string) $cert);
$this->assertIsString($cert->certName());
$this->assertIsString($cert->toString());
$this->assertIsString((string) $cert);
$this->assertInstanceOf('DateTime', $cert->validTo());
$this->assertInstanceOf('DateTime', $cert->validFrom());
$this->assertInternalType('array', $cert->subject());
$this->assertInternalType('array', $cert->issuer());
$this->assertInternalType('array', $cert->sans());
$this->assertInternalType('string', $cert->signatureAlgorithm());
$this->assertIsArray($cert->subject());
$this->assertIsArray($cert->issuer());
$this->assertIsArray($cert->sans());
$this->assertIsString($cert->signatureAlgorithm());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Punkstar/SslTest/Parser/SanParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testParse()
$sanParser = new SanParser();
$result = $sanParser->parse($input);

$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertCount(count($output), $result);

foreach ($output as $outputItem) {
Expand Down
13 changes: 8 additions & 5 deletions tests/Punkstar/SslTest/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,36 @@
namespace Punkstar\SslTest;

use PHPUnit\Framework\TestCase;
use Punkstar\Ssl\Exception;
use Punkstar\Ssl\Reader;
use VirtualFileSystem\FileSystem;

class ReaderTest extends TestCase
{
/**
* @test
* @expectedException \Punkstar\Ssl\Exception
* @expectedExceptionCode 1001
*/
public function testFileNotFound()
{
$this->expectException(Exception::class);
$this->expectExceptionCode(1001);

$reader = new Reader();
$reader->readFromFile("idontexist.tstst.stst.stst");
}

/**
* @test
* @expectedException \Punkstar\Ssl\Exception
* @expectedExceptionCode 2001
*/
public function testJunkCert()
{
$this->expectException(Exception::class);
$this->expectExceptionCode(2001);

$fs = new FileSystem();
$fs->createFile("/junk.crt", "junk-content");

$reader = new Reader();
$reader->readFromFile($fs->path("/junk.crt"));
}
}
}