]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/tests/MagicEnvelopeTest.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 0.9.x
[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('STATUSNET', true);
10
11 require_once INSTALLDIR . '/lib/common.php';
12
13 class MagicEnvelopeTest extends PHPUnit_Framework_TestCase
14 {
15     /**
16      * Test that MagicEnvelope builds the correct plaintext for signing.
17      * @dataProvider provider
18      */
19     public function testSignatureText($env, $expected)
20     {
21         $magic = new MagicEnvelope;
22         $text = $magic->signingText($env);
23
24         $this->assertEquals($expected, $text, "'$text' should be '$expected'");
25     }
26
27     static public function provider()
28     {
29         return array(
30             array(
31                 // Sample case given in spec:
32                 // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-00.html#signing
33                 array(
34                     'data' => 'Tm90IHJlYWxseSBBdG9t',
35                     'data_type' => 'application/atom+xml',
36                     'encoding' => 'base64url',
37                     'alg' => 'RSA-SHA256'
38                 ),
39                 'Tm90IHJlYWxseSBBdG9t.YXBwbGljYXRpb24vYXRvbSt4bWw=.YmFzZTY0dXJs.UlNBLVNIQTI1Ng=='
40             )
41         );
42     }
43
44
45     /**
46      * Test that MagicEnvelope builds the correct plaintext for signing.
47      * @dataProvider provider
48      */
49     public function testSignatureTextCompat($env, $expected)
50     {
51         // Our old code didn't add the extra fields, just used the armored text.
52         $alt = $env['data'];
53
54         $magic = new MagicEnvelopeCompat;
55         $text = $magic->signingText($env);
56
57         $this->assertEquals($alt, $text, "'$text' should be '$alt'");
58     }
59
60 }