]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/tests/slap.php
MagicEnvelope object orientation (no passing arrays)
[quix0rs-gnu-social.git] / plugins / OStatus / tests / slap.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2010, StatusNet, Inc.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
22
23 $longoptions = array('verify', 'slap=', 'notice=');
24
25 $helptext = <<<END_OF_HELP
26 slap.php [options]
27
28 Test generation and sending of magic envelopes for Salmon slaps.
29
30      --notice=N   generate entry for this notice number
31      --verify     send signed magic envelope to Tuomas Koski's test service
32      --slap=<url> send signed Salmon slap to the destination endpoint
33
34
35 END_OF_HELP;
36
37 require_once INSTALLDIR.'/scripts/commandline.inc';
38
39 if (!have_option('--notice')) {
40     print "$helptext";
41     exit(1);
42 }
43
44 $notice_id = get_option_value('--notice');
45
46 $notice = Notice::getKV('id', $notice_id);
47 $profile = $notice->getProfile();
48 $entry = $notice->asAtomEntry(true);
49
50 echo "== Original entry ==\n\n";
51 print $entry;
52 print "\n\n";
53
54 $magic_env = MagicEnvelope::signForProfile($entry, $profile);
55 $envxml = $magic_env->toXML();
56
57 echo "== Signed envelope ==\n\n";
58 print $envxml;
59 print "\n\n";
60
61 echo "== Testing local verification ==\n\n";
62 $magic_env = new MagicEnvelope($envxml);
63 $ok = $magic_env->verify();
64 if ($ok) {
65     print "OK\n\n";
66 } else {
67     print "FAIL\n\n";
68 }
69
70 if (have_option('--verify')) {
71     $url = 'http://www.madebymonsieur.com/ostatus_discovery/magic_env/validate/';
72     echo "== Testing remote verification ==\n\n";
73     print "Sending for verification to $url ...\n";
74
75     $client = new HTTPClient();
76     $response = $client->post($url, array(), array('magic_env' => $envxml));
77
78     print $response->getStatus() . "\n\n";
79     print $response->getBody() . "\n\n";
80 }
81
82 if (have_option('--slap')) {
83     $url = get_option_value('--slap');
84     echo "== Remote salmon slap ==\n\n";
85     print "Sending signed Salmon slap to $url ...\n";
86
87     $ok = $salmon->post($url, $entry, $profile);
88     if ($ok) {
89         print "OK\n\n";
90     } else {
91         print "FAIL\n\n";
92     }
93 }