Kibou is a federated social networking server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.rs 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. use actor;
  2. use chrono::Utc;
  3. use database;
  4. pub fn create_local_test_actor(username: &str) -> actor::Actor {
  5. let database = database::establish_connection();
  6. let mut test_actor = actor::Actor {
  7. id: 0,
  8. email: Some(format!("{}@example.tld", &username)),
  9. password: Some(String::from("Cy72MZfbfvDk7vnj")),
  10. actor_uri: format!("https://example.tld/{}", &username),
  11. username: Some(String::from("Alyssa P. Hacker")),
  12. preferred_username: String::from(username),
  13. summary: Some(String::from("Hey it's me, Alyssa!")),
  14. inbox: None,
  15. icon: Some(String::from("https://i.imgur.com/NXOJzr3.png")),
  16. keys: serde_json::json!({}),
  17. local: true,
  18. followers: serde_json::json!({"activitypub": []}),
  19. created: Utc::now().naive_utc(),
  20. modified: Utc::now().naive_utc(),
  21. };
  22. actor::create_actor(&database, &mut test_actor);
  23. test_actor.id = actor::get_actor_by_uri(&database, &test_actor.actor_uri)
  24. .unwrap()
  25. .id;
  26. test_actor
  27. }
  28. pub fn delete_test_actor(mut actor: actor::Actor) {
  29. let database = database::establish_connection();
  30. actor::delete(&database, actor);
  31. }
  32. pub fn create_remote_test_actor(username: &str) -> actor::Actor {
  33. let database = database::establish_connection();
  34. let mut test_actor = actor::Actor {
  35. id: 0,
  36. email: None,
  37. password: None,
  38. actor_uri: format!("https://remote.tld/{}", username),
  39. username: Some(String::from("Ben Bitdiddle")),
  40. preferred_username: String::from(username),
  41. summary: Some(String::from("A hardware expert")),
  42. inbox: Some(String::from("https://remote.tld/inbox")),
  43. icon: Some(String::from("https://i.imgur.com/NXOJzr3.png")),
  44. keys: serde_json::json!({}),
  45. local: false,
  46. followers: serde_json::json!({"activitypub": []}),
  47. created: Utc::now().naive_utc(),
  48. modified: Utc::now().naive_utc(),
  49. };
  50. actor::create_actor(&database, &mut test_actor);
  51. test_actor.id = actor::get_actor_by_uri(&database, &test_actor.actor_uri)
  52. .unwrap()
  53. .id;
  54. test_actor
  55. }
  56. pub fn valid_local_dummy_create_activity(
  57. object_id: String,
  58. in_reply_to: Option<String>,
  59. ) -> serde_json::Value {
  60. serde_json::json!({
  61. "context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
  62. "type": "Create",
  63. "id": "https://example.tld/activities/82ea9f28-ae53-4cbf-925e-5e5c37fd12f1",
  64. "actor": "https://example.tld/alyssa",
  65. "object": {
  66. "type": "Note",
  67. "id": object_id,
  68. "attributedTo": "https://example.tld/alyssa",
  69. "inReplyTo": in_reply_to,
  70. "content": "Hello!",
  71. "published": "2015-02-10T15:04:55Z",
  72. "to": ["https://remote.tld/ben"],
  73. "cc": ["https://www.w3.org/ns/activitystreams#Public"]
  74. },
  75. "published": "2015-02-10T15:04:55Z",
  76. "to": ["https://remote.tld/ben"],
  77. "cc": ["https://www.w3.org/ns/activitystreams#Public"]
  78. })
  79. }
  80. pub fn valid_remote_dummy_create_activity(
  81. object_id: String,
  82. in_reply_to: Option<String>,
  83. ) -> serde_json::Value {
  84. serde_json::json!({
  85. "context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
  86. "type": "Create",
  87. "id": "https://remote.tld/activities/10202",
  88. "actor": "https://remote.tld/ben",
  89. "object": {
  90. "type": "Note",
  91. "id": object_id,
  92. "attributedTo": "https://remote.tld/ben",
  93. "inReplyTo": in_reply_to,
  94. "content": "Listening to Pink Floyd right now!",
  95. "published": "2015-02-10T15:04:55Z",
  96. "to": ["https://example.tld/alyssa"],
  97. "cc": ["https://remote.tld/ben/followers", "https://www.w3.org/ns/activitystreams#Public"]
  98. },
  99. "published": "2015-02-10T15:04:55Z",
  100. "to": ["https://example.tld/alyssa"],
  101. "cc": ["https://remote.tld/ben/followers", "https://www.w3.org/ns/activitystreams#Public"]
  102. })
  103. }