Merge branch 'master' of github.com:JoN1oP/namp2

This commit is contained in:
marco
2015-07-21 22:17:20 +02:00
3 changed files with 67 additions and 0 deletions

BIN
codecept.phar Normal file

Binary file not shown.

23
lib/util/dkim.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace MailPoet\Util;
class DKIM {
public static function generate_keys() {
try {
$certificate = openssl_pkey_new(array('private_bits' => 1024));
$keys = array('public' => '', 'private' => '');
// get private key
openssl_pkey_export($certificate, $keys['private']);
// get public key
$details = openssl_pkey_get_details($certificate);
$keys['public'] = $details['key'];
return $keys;
} catch(Exception $e) {
return false;
}
}
}

44
tests/unit/DKIMCest.php Normal file
View File

@ -0,0 +1,44 @@
<?php
use \UnitTester;
class DKIMCest
{
public function _before(UnitTester $I)
{
}
public function _after(UnitTester $I)
{
}
public function it_can_generate_keys(UnitTester $I) {
$I->wantTo('generate public and private keys');
$keys = \MailPoet\Util\DKIM::generate_keys();
$I->expect('public key is not empty');
$I->assertNotEmpty($keys['public']);
$I->expect('private key is not empty');
$I->assertNotEmpty($keys['private']);
$I->expect('public key starts with proper header');
$I->assertTrue(
strpos(
$keys['public'],
'-----BEGIN PUBLIC KEY-----'
) === 0
);
$I->expect('private key starts with proper header');
$I->assertTrue(
strpos(
$keys['private'],
'-----BEGIN RSA PRIVATE KEY-----'
) === 0
);
}
}