owl-blogs/e2e_tests/mock_masto/main.py

215 lines
10 KiB
Python
Raw Permalink Normal View History

2024-05-14 19:23:37 +00:00
import json
from flask import Flask, request
app = Flask(__name__)
PRIV_KEY_PEM = """-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCni8P4bvkC/3Sx
NTrDw1qw0vWtJKZMsyJ3Mcs4+1apoVqOQhujUqGqFSiRT7Vmc7OEhB0vikdiTkCk
1PcoTd/rOa/0WbG8385JcLzaJfTIG+rrRtHwZ1TwxwBju43jpGEZjpbA0dqoXMkr
J1MyD7aPLoAiVe0ikw2czSZumv4ncemOtk0VG3b2TnIxo3CMKtUOWu8xT08MMIuo
3cZRnpI6Xr/ULzvjv8e3EjIpwRJqMPECtGsfdcjFmR0yFIrjrlmkZTiW31z/Dk7i
xRGD0ADy3WEQ3lA4l3mNZeyG4S0Wi4iYe9/wegESMZcakLoME7ks+KNS388Mdbcd
DKy9NmWvAgMBAAECggEABLQAA0hHhdWv6+Lc9xkpFuTvxTV4fuyvCf4u1eGlnstg
ZF/nW1/6w8XQ8WCgbJ4mKuZz1J14FYKxfoRaj8S9MA2Ff+wd+M77gRpAuDWajRzO
LQk8OW2yd7POXKkAzvln9F9eofkCFKR4zSpPGTenCJaQkuYrQEOKfUf7oofdRzQi
w9kmp3wAxM/EseHZpknYDCgDQV7MDQAaMD7kbynL2WfXPxebktwpRlKUwgtGrevj
gagQL8J/GX6wO3ymw9sln4BhlI2+3LuiMXQdQc1tamkXFCguCuOZCu/2VRdCHmiS
nnpu+FMspBHbvxO+RXo3Cu/S6jjJgoQxD2WZTE0gqQKBgQDM6AQdqBYjISdkI9Gl
6ZLLjwZRJSYpopujtX7pun61l9kUwQevaR2Z39rMWxX62DD6arazi/ygIUBw6Kgp
s/qBEb29ec+0cESdC8aJYb3dGvDzh/8C05p7ozxj8JZQcxq5W5jql/BELlSsUONO
jfqQv8RGZNSkD9uy6TxOr4eWIwKBgQD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4lt9c/w5O4sURg9AA
8t1hEN5QOJd5jWXshuEtFouImHvf8HoBEjGXGpC6DBO5LPijUt/PDHW3HQysvTZl
rwIDAQAB
-----END PUBLIC KEY-----"""
INBOX = []
@app.route("/.well-known/webfinger")
def webfinger():
return json.dumps(
{
"subject": "acct:h4kor@mock_masto",
"aliases": [
2024-05-16 19:11:02 +00:00
"http://mock_masto:8000/@h4kor",
"http://mock_masto:8000/users/h4kor",
2024-05-14 19:23:37 +00:00
],
"links": [
{
"rel": "http://webfinger.net/rel/profile-page",
"type": "text/html",
2024-05-16 19:11:02 +00:00
"href": "http://mock_masto:8000/@h4kor",
2024-05-14 19:23:37 +00:00
},
{
"rel": "self",
"type": "application/activity+json",
2024-05-16 19:11:02 +00:00
"href": "http://mock_masto:8000/users/h4kor",
2024-05-14 19:23:37 +00:00
},
{
"rel": "http://ostatus.org/schema/1.0/subscribe",
2024-05-16 19:11:02 +00:00
"template": "http://mock_masto:8000/authorize_interaction?uri={uri}",
2024-05-14 19:23:37 +00:00
},
{
"rel": "http://webfinger.net/rel/avatar",
"type": "image/png",
"href": "http://assets.mock_masto/accounts/avatars/000/082/056/original/a4be9944e3b03229.png",
},
],
}
)
@app.route("/users/h4kor")
def actor():
2024-05-16 18:27:06 +00:00
print("request to actor")
2024-05-14 19:23:37 +00:00
return json.dumps(
{
"@context": [
"http://www.w3.org/ns/activitystreams",
"http://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"toot": "http://joinmastodon.org/ns#",
"featured": {"@id": "toot:featured", "@type": "@id"},
"featuredTags": {"@id": "toot:featuredTags", "@type": "@id"},
"alsoKnownAs": {"@id": "as:alsoKnownAs", "@type": "@id"},
"movedTo": {"@id": "as:movedTo", "@type": "@id"},
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value",
"discoverable": "toot:discoverable",
"Device": "toot:Device",
"Ed25519Signature": "toot:Ed25519Signature",
"Ed25519Key": "toot:Ed25519Key",
"Curve25519Key": "toot:Curve25519Key",
"EncryptedMessage": "toot:EncryptedMessage",
"publicKeyBase64": "toot:publicKeyBase64",
"deviceId": "toot:deviceId",
"claim": {"@type": "@id", "@id": "toot:claim"},
"fingerprintKey": {"@type": "@id", "@id": "toot:fingerprintKey"},
"identityKey": {"@type": "@id", "@id": "toot:identityKey"},
"devices": {"@type": "@id", "@id": "toot:devices"},
"messageFranking": "toot:messageFranking",
"messageType": "toot:messageType",
"cipherText": "toot:cipherText",
"suspended": "toot:suspended",
"memorial": "toot:memorial",
"indexable": "toot:indexable",
"Hashtag": "as:Hashtag",
"focalPoint": {"@container": "@list", "@id": "toot:focalPoint"},
},
],
2024-05-16 19:11:02 +00:00
"id": "http://mock_masto:8000/users/h4kor",
2024-05-14 19:23:37 +00:00
"type": "Person",
2024-05-16 19:11:02 +00:00
"following": "http://mock_masto:8000/users/h4kor/following",
"followers": "http://mock_masto:8000/users/h4kor/followers",
"inbox": "http://mock_masto:8000/users/h4kor/inbox",
"outbox": "http://mock_masto:8000/users/h4kor/outbox",
"featured": "http://mock_masto:8000/users/h4kor/collections/featured",
"featuredTags": "http://mock_masto:8000/users/h4kor/collections/tags",
2024-05-14 19:23:37 +00:00
"preferredUsername": "h4kor",
"name": "Niko",
2024-05-16 19:11:02 +00:00
"summary": '<p>Teaching computers to do things with arguable efficiency.</p><p>he/him</p><p><a href="http://mock_masto:8000/tags/vegan" class="mention hashtag" rel="tag">#<span>vegan</span></a> <a href="http://mock_masto:8000/tags/cooking" class="mention hashtag" rel="tag">#<span>cooking</span></a> <a href="http://mock_masto:8000/tags/programming" class="mention hashtag" rel="tag">#<span>programming</span></a> <a href="http://mock_masto:8000/tags/politics" class="mention hashtag" rel="tag">#<span>politics</span></a> <a href="http://mock_masto:8000/tags/climate" class="mention hashtag" rel="tag">#<span>climate</span></a></p>',
"url": "http://mock_masto:8000/@h4kor",
2024-05-14 19:23:37 +00:00
"manuallyApprovesFollowers": False,
"discoverable": True,
"indexable": False,
"published": "2018-08-16T00:00:00Z",
"memorial": False,
2024-05-16 19:11:02 +00:00
"devices": "http://mock_masto:8000/users/h4kor/collections/devices",
2024-05-14 19:23:37 +00:00
"publicKey": {
2024-05-16 19:11:02 +00:00
"id": "http://mock_masto:8000/users/h4kor#main-key",
"owner": "http://mock_masto:8000/users/h4kor",
2024-05-14 19:23:37 +00:00
"publicKeyPem": PUB_KEY_PEM,
},
"tag": [
{
"type": "Hashtag",
2024-05-16 19:11:02 +00:00
"href": "http://mock_masto:8000/tags/politics",
2024-05-14 19:23:37 +00:00
"name": "#politics",
},
{
"type": "Hashtag",
2024-05-16 19:11:02 +00:00
"href": "http://mock_masto:8000/tags/climate",
2024-05-14 19:23:37 +00:00
"name": "#climate",
},
{
"type": "Hashtag",
2024-05-16 19:11:02 +00:00
"href": "http://mock_masto:8000/tags/vegan",
2024-05-14 19:23:37 +00:00
"name": "#vegan",
},
{
"type": "Hashtag",
2024-05-16 19:11:02 +00:00
"href": "http://mock_masto:8000/tags/programming",
2024-05-14 19:23:37 +00:00
"name": "#programming",
},
{
"type": "Hashtag",
2024-05-16 19:11:02 +00:00
"href": "http://mock_masto:8000/tags/cooking",
2024-05-14 19:23:37 +00:00
"name": "#cooking",
},
],
"attachment": [
{
"type": "PropertyValue",
"name": "Me",
"value": '<a href="http://rerere.org" target="_blank" rel="nofollow noopener noreferrer me" translate="no"><span class="invisible">http://</span><span class="">rerere.org</span><span class="invisible"></span></a>',
},
{
"type": "PropertyValue",
"name": "Blog",
"value": '<a href="http://blog.libove.org" target="_blank" rel="nofollow noopener noreferrer me" translate="no"><span class="invisible">http://</span><span class="">blog.libove.org</span><span class="invisible"></span></a>',
},
{"type": "PropertyValue", "name": "Location", "value": "Münster"},
{
"type": "PropertyValue",
"name": "Current Project",
"value": '<a href="http://git.libove.org/h4kor/owl-blogs" target="_blank" rel="nofollow noopener noreferrer me" translate="no"><span class="invisible">http://</span><span class="">git.libove.org/h4kor/owl-blogs</span><span class="invisible"></span></a>',
},
],
2024-05-16 19:11:02 +00:00
"endpoints": {"sharedInbox": "http://mock_masto:8000/inbox"},
2024-05-14 19:23:37 +00:00
"icon": {
"type": "Image",
"mediaType": "image/png",
"url": "http://assets.mock_masto/accounts/avatars/000/082/056/original/a4be9944e3b03229.png",
},
}
)
2024-05-16 19:11:02 +00:00
@app.route("/users/h4kor/inbox", methods=["POST"])
2024-05-14 19:23:37 +00:00
def inbox():
if request.method == "POST":
2024-05-16 19:11:02 +00:00
INBOX.append(json.loads(request.get_data()))
2024-05-14 19:23:37 +00:00
return ""
2024-05-16 19:11:02 +00:00
@app.route("/msgs")
def msgs():
return json.dumps(INBOX)
2024-05-14 19:23:37 +00:00
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port="8000")