| 
									
										
										
										
											2011-01-05 23:26:09 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { | 
					
						
							|  |  |  |     print "This script must be run from the command line\n"; | 
					
						
							|  |  |  |     exit(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); | 
					
						
							| 
									
										
										
										
											2013-09-28 15:20:10 +02:00
										 |  |  | define('GNUSOCIAL', true); | 
					
						
							|  |  |  | define('STATUSNET', true);  // compatibility
 | 
					
						
							| 
									
										
										
										
											2011-01-05 23:26:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | require_once INSTALLDIR . '/lib/common.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MagicEnvelopeTest extends PHPUnit_Framework_TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Test that MagicEnvelope builds the correct plaintext for signing. | 
					
						
							|  |  |  |      * @dataProvider provider | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-05-27 11:32:12 +02:00
										 |  |  |     public function testSignatureText(MagicEnvelope $env, $expected) | 
					
						
							| 
									
										
										
										
											2011-01-05 23:26:09 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-05-27 11:32:12 +02:00
										 |  |  |         $text = $env->signingText(); | 
					
						
							| 
									
										
										
										
											2011-01-05 23:26:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->assertEquals($expected, $text, "'$text' should be '$expected'"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static public function provider() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-05-27 11:32:12 +02:00
										 |  |  |         // Sample case given in spec:
 | 
					
						
							| 
									
										
										
										
											2016-03-21 12:25:04 +01:00
										 |  |  |         // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-00.html#signing
 | 
					
						
							| 
									
										
										
										
											2014-05-27 11:32:12 +02:00
										 |  |  |         $magic_env = new MagicEnvelope(); | 
					
						
							|  |  |  |         $magic_env->data = 'Tm90IHJlYWxseSBBdG9t'; | 
					
						
							|  |  |  |         $magic_env->data_type = 'application/atom+xml'; | 
					
						
							|  |  |  |         $magic_env->encoding = 'base64url'; | 
					
						
							|  |  |  |         $magic_env->alg = 'RSA-SHA256'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-05 23:26:09 +00:00
										 |  |  |         return array( | 
					
						
							|  |  |  |             array( | 
					
						
							| 
									
										
										
										
											2014-05-27 11:32:12 +02:00
										 |  |  |                 $magic_env, | 
					
						
							| 
									
										
										
										
											2011-01-05 23:26:09 +00:00
										 |  |  |                 'Tm90IHJlYWxseSBBdG9t.YXBwbGljYXRpb24vYXRvbSt4bWw=.YmFzZTY0dXJs.UlNBLVNIQTI1Ng==' | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |