2010-12-14 20:33:28 +00:00
|
|
|
#!/usr/bin/env php
|
2010-12-14 01:48:23 +00:00
|
|
|
<?php
|
2010-12-14 20:33:28 +00:00
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2010, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-07-25 01:29:20 +01:00
|
|
|
if (!defined('INSTALLDIR')) {
|
|
|
|
define('INSTALLDIR', dirname(dirname(__DIR__)));
|
|
|
|
}
|
2010-12-14 20:33:28 +00:00
|
|
|
|
|
|
|
$shortoptions = 'n:p:';
|
2020-06-24 13:08:11 +01:00
|
|
|
$longoptions = ['nickname=', 'password=', 'dry-run'];
|
2010-12-14 20:33:28 +00:00
|
|
|
|
|
|
|
$helptext = <<<END_OF_HELP
|
|
|
|
USAGE: atompub_test.php [options]
|
|
|
|
|
|
|
|
Runs some tests on the AtomPub interface for the site. You must provide
|
|
|
|
a user account to authenticate as; it will be used to make some test
|
|
|
|
posts on the site.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-n<user> --nickname=<user> Nickname of account to post as
|
|
|
|
-p<pass> --password=<pass> Password for account
|
|
|
|
--dry-run Skip tests that modify the site (post, delete)
|
|
|
|
|
|
|
|
END_OF_HELP;
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
require_once INSTALLDIR . '/scripts/commandline.inc';
|
2010-12-14 01:48:23 +00:00
|
|
|
|
2010-12-14 20:33:28 +00:00
|
|
|
$user = get_option_value('n', 'nickname');
|
|
|
|
$pass = get_option_value('p', 'password');
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
die("Must set a user: --nickname=<username>\n");
|
|
|
|
}
|
|
|
|
if (!$pass) {
|
|
|
|
die("Must set a password: --password=<username>\n");
|
|
|
|
}
|
|
|
|
|
2010-12-14 01:48:23 +00:00
|
|
|
// discover the feed...
|
2010-12-14 20:33:28 +00:00
|
|
|
// @fixme will this actually work?
|
2020-06-24 13:08:11 +01:00
|
|
|
$url = common_local_url('ApiTimelineUser', ['format' => 'atom', 'id' => $user]);
|
2010-12-14 20:33:28 +00:00
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo "Collection URL is: {$url}\n";
|
2010-12-14 20:33:28 +00:00
|
|
|
|
|
|
|
$collection = new AtomPubClient($url, $user, $pass);
|
2010-12-14 01:48:23 +00:00
|
|
|
|
|
|
|
// confirm the feed has edit links ..... ?
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Posting an empty message (should fail)... ';
|
2010-12-14 21:11:34 +00:00
|
|
|
try {
|
|
|
|
$noticeUrl = $collection->post('');
|
|
|
|
die("FAILED, succeeded!\n");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "ok\n";
|
|
|
|
}
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Posting an invalid XML message (should fail)... ';
|
2010-12-14 21:11:34 +00:00
|
|
|
try {
|
|
|
|
$noticeUrl = $collection->post('<feed<entry>barf</yomomma>');
|
|
|
|
die("FAILED, succeeded!\n");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "ok\n";
|
|
|
|
}
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Posting a valid XML but non-Atom message (should fail)... ';
|
2010-12-14 21:11:34 +00:00
|
|
|
try {
|
|
|
|
$noticeUrl = $collection->post('<feed xmlns="http://notatom.com"><id>arf</id><entry><id>barf</id></entry></feed>');
|
|
|
|
die("FAILED, succeeded!\n");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "ok\n";
|
|
|
|
}
|
2010-12-14 01:48:23 +00:00
|
|
|
|
|
|
|
// post!
|
2010-12-14 21:11:34 +00:00
|
|
|
$rand = mt_rand(0, 99999);
|
|
|
|
$atom = <<<END_ATOM
|
|
|
|
<entry xmlns="http://www.w3.org/2005/Atom">
|
2020-06-24 13:08:11 +01:00
|
|
|
<title>This is an AtomPub test post title ({$rand})</title>
|
|
|
|
<content>This is an AtomPub test post content ({$rand})</content>
|
2010-12-14 21:11:34 +00:00
|
|
|
</entry>
|
|
|
|
END_ATOM;
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Posting a new message... ';
|
2010-12-14 20:33:28 +00:00
|
|
|
$noticeUrl = $collection->post($atom);
|
2020-06-24 13:08:11 +01:00
|
|
|
echo "ok, got {$noticeUrl}\n";
|
2010-12-14 01:48:23 +00:00
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Fetching the new notice... ';
|
2010-12-14 20:33:28 +00:00
|
|
|
$notice = new AtomPubClient($noticeUrl, $user, $pass);
|
|
|
|
$body = $notice->get();
|
|
|
|
AtomPubClient::validateAtomEntry($body);
|
|
|
|
echo "ok\n";
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Getting the notice ID URI... ';
|
2010-12-14 22:07:25 +00:00
|
|
|
$noticeUri = AtomPubClient::entryId($body);
|
2020-06-24 13:08:11 +01:00
|
|
|
echo "ok: {$noticeUri}\n";
|
2010-12-14 22:07:25 +00:00
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Confirming new entry points to itself right... ';
|
2010-12-14 21:52:44 +00:00
|
|
|
$editUrl = AtomPubClient::entryEditURL($body);
|
|
|
|
if ($editUrl != $noticeUrl) {
|
2020-06-24 13:08:11 +01:00
|
|
|
die("Entry lists edit URL as {$editUrl}, no match!\n");
|
2010-12-14 21:52:44 +00:00
|
|
|
}
|
|
|
|
echo "OK\n";
|
2010-12-14 01:48:23 +00:00
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Refetching the collection... ';
|
2010-12-14 20:33:28 +00:00
|
|
|
$feed = $collection->get();
|
|
|
|
echo "ok\n";
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Confirming new entry is in the feed... ';
|
2010-12-14 22:07:25 +00:00
|
|
|
$entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
|
|
|
|
if (!$entry) {
|
|
|
|
die("missing!\n");
|
|
|
|
}
|
2010-12-14 01:48:23 +00:00
|
|
|
// edit URL should match
|
2010-12-14 22:07:25 +00:00
|
|
|
echo "ok\n";
|
2010-12-14 01:48:23 +00:00
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Editing notice (should fail)... ';
|
2010-12-14 01:48:23 +00:00
|
|
|
try {
|
2010-12-14 20:33:28 +00:00
|
|
|
$notice->put($target, $atom2);
|
|
|
|
die("ERROR: editing a notice should have failed.\n");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "ok (failed as expected)\n";
|
2010-12-14 01:48:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Deleting notice... ';
|
2010-12-14 20:33:28 +00:00
|
|
|
$notice->delete();
|
|
|
|
echo "ok\n";
|
2010-12-14 01:48:23 +00:00
|
|
|
|
2010-12-14 20:33:28 +00:00
|
|
|
echo "Refetching deleted notice to confirm it's gone... ";
|
|
|
|
try {
|
|
|
|
$body = $notice->get();
|
2010-12-14 21:23:09 +00:00
|
|
|
var_dump($body);
|
2010-12-14 20:33:28 +00:00
|
|
|
die("ERROR: notice should be gone now.\n");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "ok\n";
|
|
|
|
}
|
2010-12-14 01:48:23 +00:00
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Refetching the collection.. ';
|
2010-12-14 20:33:28 +00:00
|
|
|
$feed = $collection->get();
|
|
|
|
echo "ok\n";
|
2010-12-14 01:48:23 +00:00
|
|
|
|
2020-06-24 13:08:11 +01:00
|
|
|
echo 'Confirming deleted notice is no longer in the feed... ';
|
2010-12-14 22:07:25 +00:00
|
|
|
$entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
|
|
|
|
if ($entry) {
|
|
|
|
die("still there!\n");
|
|
|
|
}
|
|
|
|
echo "ok\n";
|
2010-12-14 01:48:23 +00:00
|
|
|
|
|
|
|
// make subscriptions
|
|
|
|
// make some posts
|
|
|
|
// make sure the posts go through or not depending on the subs
|
|
|
|
// remove subscriptions
|
|
|
|
// test that they don't go through now
|
|
|
|
|
|
|
|
// group memberships too
|
|
|
|
|
|
|
|
// make sure we can't post to someone else's feed!
|
|
|
|
// make sure we can't delete someone else's messages
|
|
|
|
// make sure we can't create/delete someone else's subscriptions
|
|
|
|
// make sure we can't create/delete someone else's group memberships
|
|
|
|
|