| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @author     Chris Hilsdon <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @package    ComodoDecodeCSR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright  2016 Xigen | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license    GNU General Public License v3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @link       https://github.com/XigenChris/ComodoDecodeCSR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace Xigen\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Xigen\ComodoDecodeCSR; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | class ComodoDecodeCSRTest extends XigenUnit | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     protected $ComodoDecodeCSR; | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 18 | 5 |  |     public function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 | 5 |  |         $this->ComodoDecodeCSR = new ComodoDecodeCSR(); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 | 5 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 | 1 |  |     public function testSettingCSR() | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         //Load the test CSR | 
            
                                                                        
                            
            
                                    
            
            
                | 26 | 1 |  |         $csr = $this->loadTestCSR(); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 | 1 |  |         $this->ComodoDecodeCSR->setCSR($csr); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 | 1 |  |         $this->assertSame( | 
            
                                                                        
                            
            
                                    
            
            
                | 29 | 1 |  |             $csr, | 
            
                                                                        
                            
            
                                    
            
            
                | 30 | 1 |  |             $this->ComodoDecodeCSR->getCSR(), | 
            
                                                                        
                            
            
                                    
            
            
                | 31 | 1 |  |             "Unable to set the CSR via ->setCSR()" | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     public function testGettingHashes() | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $this->ComodoDecodeCSR->setCSR($this->loadTestCSR()); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         $hashes = $this->ComodoDecodeCSR->fetchHashes(); | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $this->assertSame($this->validMD5, $hashes["md5"], "md5 didn't match the correct value"); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         $this->assertSame($this->validMD5, $this->ComodoDecodeCSR->getMD5(), "md5 didn't match the correct value"); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 | 5 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertSame($this->validSHA1, $hashes["sha1"], "sha1 didn't match the correct value"); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         $this->assertSame($this->validSHA1, $this->ComodoDecodeCSR->getSHA1(), "sha1 didn't match the correct value"); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 | 5 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 46 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  |     public function testGettingHashesFromInvalidCSR() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |         $hashes = $this->ComodoDecodeCSR->fetchHashes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |         $this->assertSame($hashes["md5"], '', "a md5 was set"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |         $this->assertSame($hashes["sha1"], '', "a sha1 was set"); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     public function testCheckingInstalled() | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 1 |  |         $csr = $this->loadTestCSR(); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $this->ComodoDecodeCSR->setCSR($csr); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 1 |  |         $this->ComodoDecodeCSR->fetchHashes(); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 1 |  |         $installed = $this->ComodoDecodeCSR->checkInstalled(); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 1 |  |         $this->assertTrue($installed); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function testCheckInstalledFail() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 1 |  |         $csr = $this->createFakeCSR(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 1 |  |         $this->ComodoDecodeCSR->setCSR($csr); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->ComodoDecodeCSR->fetchHashes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 1 |  |         $installed = $this->ComodoDecodeCSR->checkInstalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 1 |  |         $this->assertFalse($installed); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 74 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 75 |  |  |  |