MagicEnvelopeTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
  3. print "This script must be run from the command line\n";
  4. exit();
  5. }
  6. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  7. define('GNUSOCIAL', true);
  8. define('STATUSNET', true); // compatibility
  9. require_once INSTALLDIR . '/lib/common.php';
  10. class MagicEnvelopeTest extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * Test that MagicEnvelope builds the correct plaintext for signing.
  14. * @dataProvider provider
  15. */
  16. public function testSignatureText(MagicEnvelope $env, $expected)
  17. {
  18. $text = $env->signingText();
  19. $this->assertEquals($expected, $text, "'$text' should be '$expected'");
  20. }
  21. static public function provider()
  22. {
  23. // Sample case given in spec:
  24. // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-00.html#signing
  25. $magic_env = new MagicEnvelope();
  26. $magic_env->data = 'Tm90IHJlYWxseSBBdG9t';
  27. $magic_env->data_type = 'application/atom+xml';
  28. $magic_env->encoding = 'base64url';
  29. $magic_env->alg = 'RSA-SHA256';
  30. return array(
  31. array(
  32. $magic_env,
  33. 'Tm90IHJlYWxseSBBdG9t.YXBwbGljYXRpb24vYXRvbSt4bWw=.YmFzZTY0dXJs.UlNBLVNIQTI1Ng=='
  34. )
  35. );
  36. }
  37. }