]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/tests/MagicEnvelopeTest.php
Making sure scripts and tests check for GNUSOCIAL defined (instead of STATUSNET)
[quix0rs-gnu-social.git] / plugins / OStatus / tests / MagicEnvelopeTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
9 define('GNUSOCIAL', true);
10 define('STATUSNET', true);  // compatibility
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 class MagicEnvelopeTest extends PHPUnit_Framework_TestCase
15 {
16     /**
17      * Test that MagicEnvelope builds the correct plaintext for signing.
18      * @dataProvider provider
19      */
20     public function testSignatureText($env, $expected)
21     {
22         $magic = new MagicEnvelope;
23         $text = $magic->signingText($env);
24
25         $this->assertEquals($expected, $text, "'$text' should be '$expected'");
26     }
27
28     static public function provider()
29     {
30         return array(
31             array(
32                 // Sample case given in spec:
33                 // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-00.html#signing
34                 array(
35                     'data' => 'Tm90IHJlYWxseSBBdG9t',
36                     'data_type' => 'application/atom+xml',
37                     'encoding' => 'base64url',
38                     'alg' => 'RSA-SHA256'
39                 ),
40                 'Tm90IHJlYWxseSBBdG9t.YXBwbGljYXRpb24vYXRvbSt4bWw=.YmFzZTY0dXJs.UlNBLVNIQTI1Ng=='
41             )
42         );
43     }
44
45
46     /**
47      * Test that MagicEnvelope builds the correct plaintext for signing.
48      * @dataProvider provider
49      */
50     public function testSignatureTextCompat($env, $expected)
51     {
52         // Our old code didn't add the extra fields, just used the armored text.
53         $alt = $env['data'];
54
55         $magic = new MagicEnvelopeCompat;
56         $text = $magic->signingText($env);
57
58         $this->assertEquals($alt, $text, "'$text' should be '$alt'");
59     }
60
61 }