gnu-social/plugins/OStatus/tests/MagicEnvelopeTest.php
Mikael Nordfeldth 633191d808 Making sure scripts and tests check for GNUSOCIAL defined (instead of STATUSNET)
Orbited plugin may not work at all anymore, I had no means to try it.
But there's a check whether 'LACONICA' is defined there, which is a
very unlikely thing in the future. So far only tests and scripts have
been migrated consistently, though.
2013-09-28 15:20:10 +02:00

62 lines
1.8 KiB
PHP

<?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__) . '/../../..'));
define('GNUSOCIAL', true);
define('STATUSNET', true); // compatibility
require_once INSTALLDIR . '/lib/common.php';
class MagicEnvelopeTest extends PHPUnit_Framework_TestCase
{
/**
* Test that MagicEnvelope builds the correct plaintext for signing.
* @dataProvider provider
*/
public function testSignatureText($env, $expected)
{
$magic = new MagicEnvelope;
$text = $magic->signingText($env);
$this->assertEquals($expected, $text, "'$text' should be '$expected'");
}
static public function provider()
{
return array(
array(
// Sample case given in spec:
// http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-00.html#signing
array(
'data' => 'Tm90IHJlYWxseSBBdG9t',
'data_type' => 'application/atom+xml',
'encoding' => 'base64url',
'alg' => 'RSA-SHA256'
),
'Tm90IHJlYWxseSBBdG9t.YXBwbGljYXRpb24vYXRvbSt4bWw=.YmFzZTY0dXJs.UlNBLVNIQTI1Ng=='
)
);
}
/**
* Test that MagicEnvelope builds the correct plaintext for signing.
* @dataProvider provider
*/
public function testSignatureTextCompat($env, $expected)
{
// Our old code didn't add the extra fields, just used the armored text.
$alt = $env['data'];
$magic = new MagicEnvelopeCompat;
$text = $magic->signingText($env);
$this->assertEquals($alt, $text, "'$text' should be '$alt'");
}
}