# blocks bob_restore, carol_restore is made, and the staff suspend dave_restore, silence mrestore on Mastodon and take
# down a post of alice's. The backup is restored: PrivaPub stops, restores it as it starts again, and nothing protective
# is undone: the deleted post stays gone, the post made since answers as deleted, mastouser still follows her, the block
# holds, carol's name stays taken, and the suspension, the silence and the takedown hold (R6). Every session ends, so the scenario signs in again, and at
staff POST /clientapi/moderator/accounts/moderate -d "{\"accountId\":\"$mr_id\",\"action\":\"unsilence\"}" >/dev/null
[ -n "$dave_id"]&&[ -n "$down_id"]&&[ -n "$mr_id"]&& ok "dave_restore, a post to take down and mrestore on Mastodon"|| ko "the moderation's subjects: $dave_id$down_id$mr_id"
before=$(backups | j "print(' '.join(b['id'] for b in d['backups']))")
["$(curl -s -o /dev/null -w '%{http_code}' -X POST -H "$RH""$P/clientapi/admin/backups")"="202"]&& ok "a backup is asked for"|| ko "the backup was refused"
backup=""
newest(){ backups | j "
ids=[b['id'] for b in d['backups'] if b['id'] not in '$before'.split()]
print(ids[0] if ids and d.get('running') is None else '')";}
-d "{\"password\":\"$ROOT_PASS\",\"host\":\"elsewhere.test\"}")"="422"]&& ok "a restore with the wrong host is refused"|| ko "a restore with the wrong host was taken"
&& ok "PrivaPub came back, and the administrator's session ended"||{ ko "PrivaPub never came back from the restore"; podman logs --tail 30 pasture-privapub;return 1;}
["$(backups | j "print(d['lastRestore']['backup'])")"="$backup"]&& ok "the last restore is $backup"|| ko "the last restore is not $backup"
["$(curl -s -o /dev/null -w '%{http_code}' -H "$AH""$P/api/v1/accounts/verify_credentials")"="401"]&& ok "alice's old token is refused"|| ko "alice's old token still works"
["$(curl -s -o /dev/null -w '%{http_code}' -H "$AH""$P/api/v1/statuses/$regret_id")"="404"]&& ok "the post deleted after the backup stays deleted"|| ko "the deleted post came back"
gone_unsigned "$regret_uri"&& ok "its address answers as gone"|| ko "its address answers $(pstatus "$regret_uri")"
gone_unsigned "$since_uri"&& ok "the post made after the backup answers as gone"|| ko "the post made after the backup answers $(pstatus "$since_uri")"
["$(curl -s -H "$AH""$P/api/v1/accounts/$alice_id/followers"| j "print(any(a['acct']=='mastouser@mastodon.test' for a in d))")"="True"]\
&& ok "mastouser still follows alice"|| ko "the follower gained after the backup was lost"
["$(m_follows)"="True"]&& ok "Mastodon still has the follow"|| ko "Mastodon lost the follow"
-d "{\"userName\":\"$carol\",\"name\":\"carol\",\"biography\":\"again\"}")" !="200"]&& ok "carol's name stays taken"|| ko "carol's name was free again"