1<?php 2/** 3 * Tests for accessing a public PGP keyserver. 4 * 5 * @author Michael Slusarz <slusarz@horde.org> 6 * @category Horde 7 * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 8 * @package Crypt 9 * @subpackage UnitTests 10 */ 11 12class Horde_Crypt_PgpKeyserverTest extends Horde_Test_Case 13{ 14 protected $_ks; 15 protected $_gnupg; 16 17 protected function setUp() 18 { 19 $c = self::getConfig('CRYPT_TEST_CONFIG', __DIR__); 20 $this->_gnupg = isset($c['gnupg']) 21 ? $c['gnupg'] 22 : '/usr/bin/gpg'; 23 24 if (!is_executable($this->_gnupg)) { 25 $this->markTestSkipped(sprintf( 26 'GPG binary not found at %s.', 27 $this->_gnupg 28 )); 29 } 30 31 $this->_ks = new Horde_Crypt_Pgp_Keyserver( 32 Horde_Crypt::factory('Pgp', array( 33 'program' => $this->_gnupg 34 )) 35 ); 36 } 37 38 public function testKeyserverRetrieve() 39 { 40 try { 41 $this->_ks->get('4DE5B969'); 42 } catch (Horde_Crypt_Exception $e) { 43 if ($e->getPrevious() instanceof Horde_Http_Exception) { 44 $this->markTestSkipped($e->getMessage()); 45 } else { 46 throw $e; 47 } 48 } 49 } 50 51 public function testKeyserverRetrieveByEmail() 52 { 53 try { 54 $this->assertEquals( 55 '4DE5B969', 56 $this->_ks->getKeyID('jan@horde.org') 57 ); 58 } catch (Horde_Crypt_Exception $e) { 59 if ($e->getPrevious() instanceof Horde_Http_Exception) { 60 $this->markTestSkipped($e->getMessage()); 61 } else { 62 throw $e; 63 } 64 } 65 } 66 67 public function testBrokenKeyserver() 68 { 69 $ks = new Horde_Crypt_Pgp_Keyserver( 70 Horde_Crypt::factory('Pgp', array( 71 'program' => $this->_gnupg 72 )), 73 array('keyserver' => 'http://pgp.key-server.io') 74 ); 75 try { 76 $this->assertEquals( 77 '4DE5B969', 78 $ks->getKeyID('jan@horde.org') 79 ); 80 } catch (Horde_Crypt_Exception $e) { 81 if ($e->getPrevious() instanceof Horde_Http_Exception) { 82 $this->markTestSkipped($e->getMessage()); 83 } else { 84 throw $e; 85 } 86 } 87 } 88} 89