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.

activitypub_validator.rs 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. use activitypub::activity::Object;
  2. use activitypub::validator as validator;
  3. #[test]
  4. fn validate_object()
  5. {
  6. match validator::validate_object(serde_json::to_value(valid_dummy_object()).unwrap())
  7. {
  8. Ok(_) => assert!(true),
  9. Err(_) => assert!(false, "Valid object should pass the validator")
  10. }
  11. match validator::validate_object(serde_json::to_value(invalid_dummy_object()).unwrap())
  12. {
  13. Ok(_) => assert!(false, "Invalid object should not pass the validator"),
  14. Err(_) => assert!(true)
  15. }
  16. }
  17. fn valid_dummy_object() -> Object
  18. {
  19. Object
  20. {
  21. _type: String::from("Note"),
  22. id: String::from("https://example.tld/objects/afb1c173-2ecd-4250-9bca-5e90d4340e06"),
  23. published: String::from("2015-02-10T15:04:55Z"),
  24. attributedTo: String::from("https://example.tld/users/alyssa"),
  25. inReplyTo: None,
  26. summary: None,
  27. content: String::from("Haha it's me Alyssa!"),
  28. to: vec![],
  29. cc: vec![String::from("https://example.tld/users/alyssa/followers"), String::from("https://www.w3.org/ns/activitystreams#Public")],
  30. tag: vec![]
  31. }
  32. }
  33. fn invalid_dummy_object() -> Object
  34. {
  35. Object
  36. {
  37. _type: String::from("Notice"),
  38. id: String::from("https://example.tld/objects/93254c3a-dd02-4987-adc7-abfb815799da"),
  39. published: String::from("2015-02-10T15:04:55Z"),
  40. attributedTo: String::from("https://example.tld/users/alyssa"),
  41. inReplyTo: None,
  42. summary: None,
  43. content: String::from("Listening to Pink Floyd right now"),
  44. to: vec![],
  45. cc: vec![String::from("https://example.tld/users/alyssa/followers"), String::from("https://www.w3.org/ns/activitystreams#Public")],
  46. tag: vec![]
  47. }
  48. }