diaspora_federation 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +14 -2
  3. data/lib/diaspora_federation/callbacks.rb +2 -0
  4. data/lib/diaspora_federation/discovery/discovery.rb +11 -20
  5. data/lib/diaspora_federation/discovery/exceptions.rb +2 -0
  6. data/lib/diaspora_federation/discovery/h_card.rb +3 -12
  7. data/lib/diaspora_federation/discovery/web_finger.rb +33 -36
  8. data/lib/diaspora_federation/discovery/xrd_document.rb +15 -13
  9. data/lib/diaspora_federation/discovery.rb +2 -1
  10. data/lib/diaspora_federation/entities/account_deletion.rb +3 -1
  11. data/lib/diaspora_federation/entities/account_migration/signable.rb +2 -0
  12. data/lib/diaspora_federation/entities/account_migration.rb +5 -1
  13. data/lib/diaspora_federation/entities/comment.rb +3 -1
  14. data/lib/diaspora_federation/entities/contact.rb +2 -0
  15. data/lib/diaspora_federation/entities/conversation.rb +4 -2
  16. data/lib/diaspora_federation/entities/embed.rb +2 -0
  17. data/lib/diaspora_federation/entities/event.rb +2 -0
  18. data/lib/diaspora_federation/entities/event_participation.rb +3 -1
  19. data/lib/diaspora_federation/entities/like.rb +3 -1
  20. data/lib/diaspora_federation/entities/location.rb +2 -0
  21. data/lib/diaspora_federation/entities/message.rb +3 -1
  22. data/lib/diaspora_federation/entities/participation.rb +5 -3
  23. data/lib/diaspora_federation/entities/person.rb +3 -1
  24. data/lib/diaspora_federation/entities/photo.rb +3 -1
  25. data/lib/diaspora_federation/entities/poll.rb +2 -0
  26. data/lib/diaspora_federation/entities/poll_answer.rb +2 -0
  27. data/lib/diaspora_federation/entities/poll_participation.rb +3 -1
  28. data/lib/diaspora_federation/entities/post.rb +3 -1
  29. data/lib/diaspora_federation/entities/profile.rb +3 -1
  30. data/lib/diaspora_federation/entities/related_entity.rb +3 -1
  31. data/lib/diaspora_federation/entities/relayable.rb +17 -30
  32. data/lib/diaspora_federation/entities/reshare.rb +4 -2
  33. data/lib/diaspora_federation/entities/retraction.rb +6 -4
  34. data/lib/diaspora_federation/entities/signable.rb +3 -1
  35. data/lib/diaspora_federation/entities/status_message.rb +3 -1
  36. data/lib/diaspora_federation/entities.rb +2 -5
  37. data/lib/diaspora_federation/entity.rb +12 -8
  38. data/lib/diaspora_federation/federation/diaspora_url_parser.rb +4 -1
  39. data/lib/diaspora_federation/federation/fetcher.rb +3 -0
  40. data/lib/diaspora_federation/federation/receiver/abstract_receiver.rb +2 -0
  41. data/lib/diaspora_federation/federation/receiver/exceptions.rb +2 -0
  42. data/lib/diaspora_federation/federation/receiver/private.rb +3 -0
  43. data/lib/diaspora_federation/federation/receiver/public.rb +2 -0
  44. data/lib/diaspora_federation/federation/receiver.rb +9 -16
  45. data/lib/diaspora_federation/federation/sender/hydra_wrapper.rb +2 -0
  46. data/lib/diaspora_federation/federation/sender.rb +2 -0
  47. data/lib/diaspora_federation/federation.rb +2 -0
  48. data/lib/diaspora_federation/http_client.rb +4 -2
  49. data/lib/diaspora_federation/logging.rb +8 -6
  50. data/lib/diaspora_federation/parsers/base_parser.rb +4 -0
  51. data/lib/diaspora_federation/parsers/json_parser.rb +6 -1
  52. data/lib/diaspora_federation/parsers/relayable_json_parser.rb +3 -0
  53. data/lib/diaspora_federation/parsers/relayable_xml_parser.rb +2 -0
  54. data/lib/diaspora_federation/parsers/xml_parser.rb +18 -6
  55. data/lib/diaspora_federation/parsers.rb +2 -0
  56. data/lib/diaspora_federation/properties_dsl.rb +6 -39
  57. data/lib/diaspora_federation/salmon/aes.rb +5 -3
  58. data/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb +4 -2
  59. data/lib/diaspora_federation/salmon/exceptions.rb +2 -20
  60. data/lib/diaspora_federation/salmon/magic_envelope.rb +13 -10
  61. data/lib/diaspora_federation/salmon.rb +3 -4
  62. data/lib/diaspora_federation/validators/account_deletion_validator.rb +2 -0
  63. data/lib/diaspora_federation/validators/account_migration_validator.rb +2 -0
  64. data/lib/diaspora_federation/validators/comment_validator.rb +2 -0
  65. data/lib/diaspora_federation/validators/contact_validator.rb +2 -0
  66. data/lib/diaspora_federation/validators/conversation_validator.rb +2 -0
  67. data/lib/diaspora_federation/validators/embed_validator.rb +2 -0
  68. data/lib/diaspora_federation/validators/event_participation_validator.rb +2 -0
  69. data/lib/diaspora_federation/validators/event_validator.rb +2 -0
  70. data/lib/diaspora_federation/validators/h_card_validator.rb +2 -0
  71. data/lib/diaspora_federation/validators/like_validator.rb +2 -0
  72. data/lib/diaspora_federation/validators/location_validator.rb +2 -0
  73. data/lib/diaspora_federation/validators/message_validator.rb +2 -0
  74. data/lib/diaspora_federation/validators/optional_aware_validator.rb +3 -0
  75. data/lib/diaspora_federation/validators/participation_validator.rb +2 -0
  76. data/lib/diaspora_federation/validators/person_validator.rb +2 -0
  77. data/lib/diaspora_federation/validators/photo_validator.rb +2 -0
  78. data/lib/diaspora_federation/validators/poll_answer_validator.rb +2 -0
  79. data/lib/diaspora_federation/validators/poll_participation_validator.rb +2 -0
  80. data/lib/diaspora_federation/validators/poll_validator.rb +2 -0
  81. data/lib/diaspora_federation/validators/profile_validator.rb +2 -0
  82. data/lib/diaspora_federation/validators/related_entity_validator.rb +2 -0
  83. data/lib/diaspora_federation/validators/relayable_validator.rb +2 -0
  84. data/lib/diaspora_federation/validators/reshare_validator.rb +2 -0
  85. data/lib/diaspora_federation/validators/retraction_validator.rb +2 -0
  86. data/lib/diaspora_federation/validators/rules/birthday.rb +3 -1
  87. data/lib/diaspora_federation/validators/rules/boolean.rb +6 -5
  88. data/lib/diaspora_federation/validators/rules/diaspora_id.rb +3 -1
  89. data/lib/diaspora_federation/validators/rules/diaspora_id_list.rb +3 -0
  90. data/lib/diaspora_federation/validators/rules/guid.rb +3 -1
  91. data/lib/diaspora_federation/validators/rules/not_nil.rb +2 -0
  92. data/lib/diaspora_federation/validators/rules/public_key.rb +2 -0
  93. data/lib/diaspora_federation/validators/rules/tag_count.rb +2 -0
  94. data/lib/diaspora_federation/validators/status_message_validator.rb +2 -0
  95. data/lib/diaspora_federation/validators/web_finger_validator.rb +2 -0
  96. data/lib/diaspora_federation/validators.rb +2 -0
  97. data/lib/diaspora_federation/version.rb +3 -1
  98. data/lib/diaspora_federation.rb +3 -2
  99. metadata +9 -28
  100. data/lib/diaspora_federation/discovery/host_meta.rb +0 -90
  101. data/lib/diaspora_federation/entities/relayable_retraction.rb +0 -66
  102. data/lib/diaspora_federation/entities/request.rb +0 -31
  103. data/lib/diaspora_federation/entities/signed_retraction.rb +0 -43
  104. data/lib/diaspora_federation/salmon/encrypted_slap.rb +0 -109
  105. data/lib/diaspora_federation/salmon/slap.rb +0 -55
  106. data/lib/diaspora_federation/salmon/xml_payload.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 799e373a0f8e153d52d0dcb671ae0599563a621367664bf4dd992268da1b8344
4
- data.tar.gz: 9ee5e27b118036f4bb840e090bfe0e44654da4610a503c5f3b50f69532ce0457
3
+ metadata.gz: 202b522935a3c394944b6578a45868370beff4748994f9bf8fa5cded6dd436b0
4
+ data.tar.gz: 761667ad6330ccb2088751a0bde704e914b0e590f347938577c19002d0aaf4a4
5
5
  SHA512:
6
- metadata.gz: 5eb7cca4e379ae813a08511c3af2716b325b477b1d0f93a3d012e2ae03c66545ddf97151e5c0be8e8c4b463f3fbb49ed8560ab9db62b4baaed1949eb71261b99
7
- data.tar.gz: 16274964f8727afd81f7b7bfb6c9d7acf19cd705a0401759bbbfbf30d7f1177702be83be40dec6fb8acddb7e984339bc26ab4cd9dedb7e4527303016bb5b1832
6
+ metadata.gz: 1adda0e8a5d0f789a31a589b24775ea2b09e06d3d24116ea29f0a8057680783a8dd79094c7f4c0047c1c064b18d92c2d40b6c9506ab813284c826589f714b9c3
7
+ data.tar.gz: dcd14ec61c90371f4153094b02d0341838b92d37401cb1354c1845d81cbeaf6b3d32fc883809a88ad35dc6974a5b4d2d6a5f3ed844ab2ddb658c292ca070c6be
data/Changelog.md CHANGED
@@ -1,6 +1,18 @@
1
- # 0.2.8
1
+ # 0.3.0
2
2
 
3
- * Re-release which allows rails 6 to be used
3
+ ## Breaking changes
4
+
5
+ * Drop support for rails 5.1 and older [4b4375c](https://github.com/diaspora/diaspora_federation/commit/4b4375cf787e09537f53aff92b054a0386681747) [ecfe0ea](https://github.com/diaspora/diaspora_federation/commit/ecfe0ea850d203e8144adab744c4b43263200902)
6
+ * Drop support for ruby 2.6 and older [68df3cf](https://github.com/diaspora/diaspora_federation/commit/68df3cf555efafc72942cfec2c8fb3e8852ddec1) [#121](https://github.com/diaspora/diaspora_federation/pull/121)
7
+ * Drop support for faraday 0.x [#116](https://github.com/diaspora/diaspora_federation/pull/116)
8
+ * Remove support to receive old federation protocol [#114](https://github.com/diaspora/diaspora_federation/pull/114)
9
+ * Remove support for old non-RFC WebFinger [#122](https://github.com/diaspora/diaspora_federation/pull/122)
10
+
11
+ ## Features
12
+
13
+ * Add rails 6 support [afee784](https://github.com/diaspora/diaspora_federation/commit/afee78476b1715ba32e2b97d7cbf2584d57718dd)
14
+ * Add faraday 1.x support [#116](https://github.com/diaspora/diaspora_federation/pull/116)
15
+ * Add support for up to ruby 3.1 [#121](https://github.com/diaspora/diaspora_federation/pull/121)
4
16
 
5
17
  # 0.2.7
6
18
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  # Callbacks are used to communicate with the application. They are called to
3
5
  # fetch data and after data is received.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Discovery
3
5
  # This class contains the logic to fetch all data for the given diaspora* ID.
@@ -22,7 +24,7 @@ module DiasporaFederation
22
24
  validate_diaspora_id
23
25
 
24
26
  DiasporaFederation.callbacks.trigger(:save_person_after_webfinger, person)
25
- logger.info "successfully webfingered #{diaspora_id}"
27
+ logger.info "Successfully webfingered #{diaspora_id}"
26
28
  person
27
29
  rescue DiscoveryError
28
30
  raise # simply re-raise DiscoveryError
@@ -35,6 +37,7 @@ module DiasporaFederation
35
37
  def validate_diaspora_id
36
38
  # Validates if the diaspora* ID matches the diaspora* ID in the webfinger response
37
39
  return if diaspora_id == clean_diaspora_id(webfinger.acct_uri)
40
+
38
41
  raise DiscoveryError, "diaspora* ID does not match: Wanted #{diaspora_id} but got" \
39
42
  " #{clean_diaspora_id(webfinger.acct_uri)}"
40
43
  end
@@ -43,19 +46,17 @@ module DiasporaFederation
43
46
  diaspora_id.strip.sub("acct:", "").to_s.downcase
44
47
  end
45
48
 
46
- def get(url, http_fallback=false)
49
+ def get(url, http_fallback: false)
47
50
  logger.info "Fetching #{url} for #{diaspora_id}"
48
51
  response = HttpClient.get(url)
49
52
  raise "Failed to fetch #{url}: #{response.status}" unless response.success?
53
+
50
54
  response.body
51
55
  rescue => e # rubocop:disable Style/RescueStandardError
52
- unless http_fallback && url.start_with?("https://")
53
- raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
54
- end
56
+ raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}" unless http_fallback
55
57
 
56
58
  logger.warn "Retry with http: #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
57
- url.sub!("https://", "http://")
58
- retry
59
+ get(url.sub("https://", "http://"))
59
60
  end
60
61
 
61
62
  def domain
@@ -66,21 +67,11 @@ module DiasporaFederation
66
67
  "acct:#{diaspora_id}"
67
68
  end
68
69
 
69
- def legacy_webfinger_url_from_host_meta
70
- # This tries the xrd url with https first, then falls back to http.
71
- host_meta = HostMeta.from_xml(get("https://#{domain}/.well-known/host-meta", true))
72
- host_meta.webfinger_template_url.gsub("{uri}", acct_parameter)
73
- end
74
-
75
70
  def webfinger
76
- return @webfinger if @webfinger
77
- webfinger_url = "https://#{domain}/.well-known/webfinger?resource=#{acct_parameter}"
78
-
79
71
  # This tries the WebFinger URL with https first, then falls back to http if webfinger_http_fallback is enabled.
80
- @webfinger = WebFinger.from_json(get(webfinger_url, DiasporaFederation.webfinger_http_fallback))
81
- rescue => e # rubocop:disable Style/RescueStandardError
82
- logger.warn "WebFinger failed, retrying with legacy WebFinger for #{diaspora_id}: #{e.class}: #{e.message}"
83
- @webfinger = WebFinger.from_xml(get(legacy_webfinger_url_from_host_meta))
72
+ @webfinger ||=
73
+ WebFinger.from_json(get("https://#{domain}/.well-known/webfinger?resource=#{acct_parameter}",
74
+ http_fallback: DiasporaFederation.webfinger_http_fallback))
84
75
  end
85
76
 
86
77
  def hcard
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Discovery
3
5
  # Raised, if there is an error while discover a new person
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Discovery
3
5
  # This class provides the means of generating and parsing account data to and
@@ -54,14 +56,6 @@ module DiasporaFederation
54
56
  # @return [String] display name of the user
55
57
  property :full_name, :string
56
58
 
57
- # @!attribute [r] url
58
- # @deprecated should be changed to the profile url. The pod url is in
59
- # the WebFinger (see {WebFinger#seed_url}, will affect older diaspora*
60
- # installations).
61
- #
62
- # @return [String] link to the pod
63
- property :url, :string, optional: true
64
-
65
59
  # @!attribute [r] public_key
66
60
  # When a user is created on the pod, the pod MUST generate a pgp keypair
67
61
  # for them. This key is used for signing messages. The format is a
@@ -143,10 +137,6 @@ module DiasporaFederation
143
137
  add_simple_property(content, :family_name, "family_name", @last_name)
144
138
  #######################################
145
139
 
146
- add_property(content, :url) do |html|
147
- html.a(@url.to_s, id: "pod_location", class: "url", rel: "me", href: @url.to_s)
148
- end
149
-
150
140
  add_photos(content)
151
141
 
152
142
  builder.doc.to_xhtml(indent: 2, indent_text: " ")
@@ -260,6 +250,7 @@ module DiasporaFederation
260
250
 
261
251
  doc = Nokogiri::HTML::Document.parse(html_string)
262
252
  raise InvalidData, "hcard html incomplete" unless html_document_complete?(doc)
253
+
263
254
  doc
264
255
  end
265
256
 
@@ -1,10 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Discovery
3
5
  # The WebFinger document used for diaspora* user discovery is based on an
4
- # {http://tools.ietf.org/html/draft-jones-appsawg-webfinger older draft of the specification}.
5
- #
6
- # In the meantime an actual RFC draft has been in development, which should
7
- # serve as a base for all future changes of this implementation.
6
+ # {https://datatracker.ietf.org/doc/html/rfc7033 RFC 7033}.
8
7
  #
9
8
  # @example Creating a WebFinger document from a person hash
10
9
  # wf = WebFinger.new(
@@ -15,22 +14,20 @@ module DiasporaFederation
15
14
  # atom_url: "https://server.example/public/user.atom",
16
15
  # salmon_url: "https://server.example/receive/users/0123456789abcdef"
17
16
  # )
18
- # xml_string = wf.to_xml
17
+ # json_string = wf.to_json
19
18
  #
20
- # @example Creating a WebFinger instance from an xml document
21
- # wf = WebFinger.from_xml(xml_string)
19
+ # @example Creating a WebFinger instance from an JSON document
20
+ # wf = WebFinger.from_json(json_string)
22
21
  # ...
23
22
  # hcard_url = wf.hcard_url
24
23
  # ...
25
24
  #
26
- # @see http://tools.ietf.org/html/draft-jones-appsawg-webfinger "WebFinger" -
27
- # current draft
28
25
  # @see http://www.iana.org/assignments/link-relations/link-relations.xhtml
29
26
  # official list of IANA link relations
30
27
  class WebFinger < Entity
31
28
  # @!attribute [r] acct_uri
32
- # The Subject element should contain the webfinger address that was asked
33
- # for. If it does not, then this webfinger profile MUST be ignored.
29
+ # The Subject element should contain the WebFinger address that was asked
30
+ # for. If it does not, then this WebFinger profile MUST be ignored.
34
31
  # @return [String]
35
32
  property :acct_uri, :string
36
33
 
@@ -65,27 +62,27 @@ module DiasporaFederation
65
62
  property :salmon_url, :string, optional: true
66
63
 
67
64
  # @!attribute [r] subscribe_url
68
- # This url is used to find another user on the home-pod of the user in the webfinger.
65
+ # This url is used to find another user on the home-pod of the user in the WebFinger.
69
66
  property :subscribe_url, :string, optional: true
70
67
 
71
68
  # +hcard_url+ link relation
72
- REL_HCARD = "http://microformats.org/profile/hcard".freeze
69
+ REL_HCARD = "http://microformats.org/profile/hcard"
73
70
 
74
71
  # +seed_url+ link relation
75
- REL_SEED = "http://joindiaspora.com/seed_location".freeze
72
+ REL_SEED = "http://joindiaspora.com/seed_location"
76
73
 
77
74
  # +profile_url+ link relation.
78
75
  # @note This might just as well be an +Alias+ instead of a +Link+.
79
- REL_PROFILE = "http://webfinger.net/rel/profile-page".freeze
76
+ REL_PROFILE = "http://webfinger.net/rel/profile-page"
80
77
 
81
78
  # +atom_url+ link relation
82
- REL_ATOM = "http://schemas.google.com/g/2010#updates-from".freeze
79
+ REL_ATOM = "http://schemas.google.com/g/2010#updates-from"
83
80
 
84
81
  # +salmon_url+ link relation
85
- REL_SALMON = "salmon".freeze
82
+ REL_SALMON = "salmon"
86
83
 
87
84
  # +subscribe_url+ link relation
88
- REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe".freeze
85
+ REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe"
89
86
 
90
87
  # Additional WebFinger data
91
88
  # @return [Hash] additional elements
@@ -104,29 +101,29 @@ module DiasporaFederation
104
101
  super(data)
105
102
  end
106
103
 
107
- # Creates the XML string from the current WebFinger instance
108
- # @return [String] XML string
104
+ # @!visibility private
105
+ # Generating WebFinger to XML is not supported anymore, use {#to_json} instead.
109
106
  def to_xml
110
- to_xrd.to_xml
107
+ raise "Generating WebFinger to XML is not supported anymore, use 'to_json' instead."
111
108
  end
112
109
 
113
- def to_json
110
+ # Creates the JSON string from the current WebFinger instance
111
+ # @return [String] JSON string
112
+ def to_json(*_args)
114
113
  to_xrd.to_json
115
114
  end
116
115
 
117
- # Creates a WebFinger instance from the given XML string
118
- # @param [String] webfinger_xml WebFinger XML string
119
- # @return [WebFinger] WebFinger instance
120
- # @raise [InvalidData] if the given XML string is invalid or incomplete
121
- def self.from_xml(webfinger_xml)
122
- from_hash(parse_xml_and_validate(webfinger_xml))
116
+ # @!visibility private
117
+ # Parsing WebFinger as XML is not supported anymore, use {from_json} instead.
118
+ def self.from_xml(_webfinger_xml)
119
+ raise "Parsing WebFinger as XML is not supported anymore, use 'from_json' instead."
123
120
  end
124
121
 
125
122
  # Creates a WebFinger instance from the given JSON string
126
123
  # @param [String] webfinger_json WebFinger JSON string
127
124
  # @return [WebFinger] WebFinger instance
128
125
  def self.from_json(webfinger_json)
129
- from_hash(XrdDocument.json_data(webfinger_json))
126
+ from_hash(parse_json_and_validate(webfinger_json))
130
127
  end
131
128
 
132
129
  # Creates a WebFinger instance from the given data
@@ -155,15 +152,15 @@ module DiasporaFederation
155
152
 
156
153
  private
157
154
 
158
- # Parses the XML string to a Hash and does some rudimentary checking on
155
+ # Parses the JSON string to a Hash and does some rudimentary checking on
159
156
  # the data Hash.
160
- # @param [String] webfinger_xml WebFinger XML string
161
- # @return [Hash] data XML data
162
- # @raise [InvalidData] if the given XML string is invalid or incomplete
163
- private_class_method def self.parse_xml_and_validate(webfinger_xml)
164
- XrdDocument.xml_data(webfinger_xml).tap do |data|
157
+ # @param [String] webfinger_json WebFinger JSON string
158
+ # @return [Hash] data JSON data
159
+ # @raise [InvalidData] if the given JSON string is invalid or incomplete
160
+ private_class_method def self.parse_json_and_validate(webfinger_json)
161
+ XrdDocument.json_data(webfinger_json).tap do |data|
165
162
  valid = data.key?(:subject) && data.key?(:links)
166
- raise InvalidData, "webfinger xml is incomplete" unless valid
163
+ raise InvalidData, "Webfinger JSON is incomplete" unless valid
167
164
  end
168
165
  end
169
166
 
@@ -1,15 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Discovery
3
5
  # This class implements basic handling of XRD documents as far as it is
4
6
  # necessary in the context of the protocols used with diaspora* federation.
5
7
  #
6
- # @note {http://tools.ietf.org/html/rfc6415 RFC 6415} recommends that servers
7
- # should also offer the JRD format in addition to the XRD representation.
8
- # Implementing +XrdDocument#to_json+ and +XrdDocument.json_data+ should
9
- # be almost trivial due to the simplicity of the format and the way the data
10
- # is stored internally already. See
11
- # {http://tools.ietf.org/html/rfc6415#appendix-A RFC 6415, Appendix A}
12
- # for a description of the JSON format.
8
+ # It also implements handling of the JRD format, see
9
+ # {https://datatracker.ietf.org/doc/html/rfc6415#appendix-A RFC 6415, Appendix A}
10
+ # for a description of the JSON format.
13
11
  #
14
12
  # @example Creating a XrdDocument
15
13
  # doc = XrdDocument.new
@@ -29,13 +27,13 @@ module DiasporaFederation
29
27
  # @see http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html Extensible Resource Descriptor (XRD) Version 1.0
30
28
  class XrdDocument
31
29
  # xml namespace url
32
- XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0".freeze
30
+ XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0"
33
31
 
34
32
  # +Link+ element attributes
35
33
  LINK_ATTRS = %i[rel type href template].freeze
36
34
 
37
35
  # format string for datetime (+Expires+ element)
38
- DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ".freeze
36
+ DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
39
37
 
40
38
  # The <Expires> element contains a time value which specifies the instant at
41
39
  # and after which the document has expired and SHOULD NOT be used.
@@ -80,14 +78,14 @@ module DiasporaFederation
80
78
  }.to_xml
81
79
  end
82
80
 
83
- def to_json
81
+ def to_json(*_args)
84
82
  {
85
83
  subject: subject,
86
84
  expires: (expires.strftime(DATETIME_FORMAT) if expires.instance_of?(DateTime)),
87
85
  aliases: (aliases if aliases.any?),
88
86
  properties: (properties if properties.any?),
89
87
  links: (links if links.any?)
90
- }.reject {|_, v| v.nil? }
88
+ }.compact
91
89
  end
92
90
 
93
91
  # Parse the XRD document from the given string and create a hash containing
@@ -130,7 +128,7 @@ module DiasporaFederation
130
128
  aliases: json_hash["aliases"],
131
129
  properties: json_hash["properties"],
132
130
  links: symbolize_keys_for_links(json_hash["links"])
133
- }.reject {|_, v| v.nil? }
131
+ }.compact
134
132
  rescue JSON::JSONError => e
135
133
  raise InvalidDocument,
136
134
  "Not a JRD document: #{e.class}: #{e.message[0..255].encode(Encoding.default_external, undef: :replace)}"
@@ -138,14 +136,17 @@ module DiasporaFederation
138
136
 
139
137
  private
140
138
 
139
+ # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor Style/AccessorGrouping
141
140
  attr_reader :expires
142
141
  attr_reader :subject
142
+ # rubocop:enable Layout/EmptyLinesAroundAttributeAccessor Style/AccessorGrouping
143
143
 
144
144
  NS = {xrd: XMLNS}.freeze
145
145
 
146
146
  def add_aliases_to(xml)
147
147
  aliases.each do |a|
148
148
  next if !a.instance_of?(String) || a.empty?
149
+
149
150
  xml.Alias(a.to_s)
150
151
  end
151
152
  end
@@ -171,6 +172,7 @@ module DiasporaFederation
171
172
 
172
173
  doc = Nokogiri::XML(xrd_doc)
173
174
  raise InvalidDocument, "Not an XRD document" if !doc.root || doc.root.name != "XRD"
175
+
174
176
  doc
175
177
  end
176
178
 
@@ -204,7 +206,7 @@ module DiasporaFederation
204
206
 
205
207
  # symbolize link keys from JSON hash, but only convert known keys
206
208
  private_class_method def self.symbolize_keys_for_links(links)
207
- links.map do |link|
209
+ links&.map do |link|
208
210
  {}.tap do |hash|
209
211
  LINK_ATTRS.each do |attr|
210
212
  hash[attr] = link[attr.to_s] if link.key?(attr.to_s)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  # This module provides the namespace for the various classes implementing
3
5
  # WebFinger and other protocols used for metadata discovery on remote servers
@@ -8,7 +10,6 @@ end
8
10
 
9
11
  require "diaspora_federation/discovery/exceptions"
10
12
  require "diaspora_federation/discovery/xrd_document"
11
- require "diaspora_federation/discovery/host_meta"
12
13
  require "diaspora_federation/discovery/web_finger"
13
14
  require "diaspora_federation/discovery/h_card"
14
15
  require "diaspora_federation/discovery/discovery"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity is sent when an account was deleted on a remote pod.
@@ -12,7 +14,7 @@ module DiasporaFederation
12
14
  # Alias for author
13
15
  # @see AccountDeletion#author
14
16
  # @return [String] diaspora* ID
15
- property :author, :string, alias: :diaspora_id, xml_name: :diaspora_handle
17
+ property :author, :string, alias: :diaspora_id
16
18
 
17
19
  # @return [String] string representation of this object
18
20
  def to_s
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  class AccountMigration < Entity
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity is sent when a person changes their diaspora* ID (e.g. when a user migration
@@ -42,13 +44,14 @@ module DiasporaFederation
42
44
  # @return [String] diaspora* ID of the old person identity
43
45
  def old_identity
44
46
  return @old_identity if author_is_new_id?
47
+
45
48
  author
46
49
  end
47
50
 
48
51
  # Returns diaspora* ID of the new person identity.
49
52
  # @return [String] diaspora* ID of the new person identity
50
53
  def new_identity
51
- profile.author if profile
54
+ profile&.author
52
55
  end
53
56
 
54
57
  # @return [String] string representation of this object
@@ -90,6 +93,7 @@ module DiasporaFederation
90
93
  def sign_with_respective_key
91
94
  privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, signer_id)
92
95
  raise PrivateKeyNotFound, "signer=#{signer_id} obj=#{self}" if privkey.nil?
96
+
93
97
  sign_with_key(privkey).tap do
94
98
  logger.info "event=sign status=complete signature=signature signer=#{signer_id} obj=#{self}"
95
99
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a comment to some kind of post (e.g. status message).
@@ -5,7 +7,7 @@ module DiasporaFederation
5
7
  # @see Validators::CommentValidator
6
8
  class Comment < Entity
7
9
  # The {Comment} parent is a {Post}
8
- PARENT_TYPE = "Post".freeze
10
+ PARENT_TYPE = "Post"
9
11
 
10
12
  include Relayable
11
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a contact with another person. A user issues it
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a private conversation between users.
@@ -8,7 +10,7 @@ module DiasporaFederation
8
10
  # The diaspora* ID of the person initiated the conversation
9
11
  # @see Person#author
10
12
  # @return [String] diaspora* ID
11
- property :author, :string, xml_name: :diaspora_handle
13
+ property :author, :string
12
14
 
13
15
  # @!attribute [r] guid
14
16
  # A random string of at least 16 chars
@@ -27,7 +29,7 @@ module DiasporaFederation
27
29
  # @!attribute [r] participants
28
30
  # The diaspora* IDs of the persons participating the conversation separated by ";"
29
31
  # @return [String] participants diaspora* IDs
30
- property :participants, :string, xml_name: :participant_handles
32
+ property :participants, :string
31
33
 
32
34
  # @!attribute [r] messages
33
35
  # @return [[Entities::Message]] Messages of this conversation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity is used to specify embed information about an URL that should be embedded.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents an event and it is federated as a part of a status message.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a participation in an event, i.e. it is issued when a user responds to en event.
@@ -5,7 +7,7 @@ module DiasporaFederation
5
7
  # @see Validators::EventParticipationValidator
6
8
  class EventParticipation < Entity
7
9
  # The {EventParticipation} parent is an {Event}
8
- PARENT_TYPE = "Event".freeze
10
+ PARENT_TYPE = "Event"
9
11
 
10
12
  include Relayable
11
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a like to some kind of post (e.g. status message).
@@ -11,7 +13,7 @@ module DiasporaFederation
11
13
  # Can be "Post" or "Comment" (Comments are currently not implemented in the
12
14
  # diaspora* frontend).
13
15
  # @return [String] parent type
14
- property :parent_type, :string, xml_name: :target_type
16
+ property :parent_type, :string
15
17
 
16
18
  # @!attribute [r] positive
17
19
  # If +true+ set a like, if +false+, set a dislike (dislikes are currently not
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity is used to specify location data and used embedded in a status message.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a private message exchanged in private conversation.
@@ -8,7 +10,7 @@ module DiasporaFederation
8
10
  # The diaspora* ID of the author
9
11
  # @see Person#author
10
12
  # @return [String] diaspora* ID
11
- property :author, :string, xml_name: :diaspora_handle
13
+ property :author, :string
12
14
 
13
15
  # @!attribute [r] guid
14
16
  # A random string of at least 16 chars
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # Participation is sent to subscribe a user on updates for some post.
@@ -8,7 +10,7 @@ module DiasporaFederation
8
10
  # The diaspora* ID of the author
9
11
  # @see Person#author
10
12
  # @return [String] diaspora* ID
11
- property :author, :string, xml_name: :diaspora_handle
13
+ property :author, :string
12
14
 
13
15
  # @!attribute [r] guid
14
16
  # A random string of at least 16 chars
@@ -25,7 +27,7 @@ module DiasporaFederation
25
27
  # A string describing a type of the target to subscribe on
26
28
  # Currently only "Post" is supported.
27
29
  # @return [String] parent type
28
- property :parent_type, :string, xml_name: :target_type
30
+ property :parent_type, :string
29
31
 
30
32
  # @return [String] string representation of this object
31
33
  def to_s
@@ -35,7 +37,7 @@ module DiasporaFederation
35
37
  # Validates that the parent exists and the parent author is local
36
38
  def validate_parent
37
39
  parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, parent_type, parent_guid)
38
- raise ParentNotLocal, "obj=#{self}" unless parent && parent.local
40
+ raise ParentNotLocal, "obj=#{self}" unless parent&.local
39
41
  end
40
42
 
41
43
  # Validate that the parent is local.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity contains the base data of a person.
@@ -19,7 +21,7 @@ module DiasporaFederation
19
21
  # alias for author
20
22
  # @see Person#author
21
23
  # @return [String] diaspora* ID
22
- property :author, :string, alias: :diaspora_id, xml_name: :diaspora_handle
24
+ property :author, :string, alias: :diaspora_id
23
25
 
24
26
  # @!attribute [r] url
25
27
  # @see Discovery::WebFinger#seed_url
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a photo and it is federated as a part of a status message.
@@ -14,7 +16,7 @@ module DiasporaFederation
14
16
  # The diaspora* ID of the person who uploaded the photo
15
17
  # @see Person#author
16
18
  # @return [String] author diaspora* ID
17
- property :author, :string, xml_name: :diaspora_handle
19
+ property :author, :string
18
20
 
19
21
  # @!attribute [r] public
20
22
  # Points if the photo is visible to everyone or only to some aspects
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a poll and it is federated as an optional part of a status message.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DiasporaFederation
2
4
  module Entities
3
5
  # This entity represents a poll answer and is federated as a part of the Poll entity.