]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/tests/slap.php
Merge commit 'refs/merge-requests/199' of git://gitorious.org/statusnet/mainline...
[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 $salmon = new Salmon();
55 $envelope = $salmon->createMagicEnv($entry, $profile);
56
57 echo "== Signed envelope ==\n\n";
58 print $envelope;
59 print "\n\n";
60
61 echo "== Testing local verification ==\n\n";
62 $ok = $salmon->verifyMagicEnv($envelope);
63 if ($ok) {
64     print "OK\n\n";
65 } else {
66     print "FAIL\n\n";
67 }
68
69 if (have_option('--verify')) {
70     $url = 'http://www.madebymonsieur.com/ostatus_discovery/magic_env/validate/';
71     echo "== Testing remote verification ==\n\n";
72     print "Sending for verification to $url ...\n";
73
74     $client = new HTTPClient();
75     $response = $client->post($url, array(), array('magic_env' => $envelope));
76
77     print $response->getStatus() . "\n\n";
78     print $response->getBody() . "\n\n";
79 }
80
81 if (have_option('--slap')) {
82     $url = get_option_value('--slap');
83     echo "== Remote salmon slap ==\n\n";
84     print "Sending signed Salmon slap to $url ...\n";
85
86     $ok = $salmon->post($url, $entry, $profile);
87     if ($ok) {
88         print "OK\n\n";
89     } else {
90         print "FAIL\n\n";
91     }
92 }