diaspora_federation 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98960499491bf5fa4f32f9b26b07d251be8feb1e
4
- data.tar.gz: 0769440c0da228ac91ac6129ce7129bb81a144ef
3
+ metadata.gz: ada8efaa115784225786ce35f925e13179f7d5e2
4
+ data.tar.gz: 9ecfc78d096a8f5173ddbcd3665fd22445c9374c
5
5
  SHA512:
6
- metadata.gz: d0237ce04699644b5925a6a80350070305d16addbbd1c032c802dcc527d6fd648668f97834349e43ec1711fac469a571379a0951cb551f39998ded04528ce9de
7
- data.tar.gz: a6a930e63aea294c0a0437cb831a0607de17361e8e00fb7ecc4f25bd76a453cb55a6010eb12e5fed2e3e331f122d1f5b44e31a997c8f76fad4a953628b69e028
6
+ metadata.gz: 1ad31c9c21a5e42e0197ccb51ec14d8e5262b6fc527f9b3b7ba95ff9162d69c8be8783275d576a7051bca3ddfbe0913dd3d1b5d46ad9d32a90c2288b510c6f42
7
+ data.tar.gz: 1b32aa2ff5b1c4d0763f8b97eb1473cc03d143ae3f7bd028a24557e11780d8a2b6d2f14c89ecd67977eae708b33aba868de867e3c92031c583468577f4fd2c4a
data/Changelog.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 0.1.5
2
+
3
+ ## Refactor
4
+
5
+ * Use `head` method instead of `:nothing` option [44f6527](https://github.com/diaspora/diaspora_federation/commit/44f6527d64489c212c0f6b050ad343ea0e53e964)
6
+ * Add `sender` parameter to `:receive_entity` callback [fb60f83](https://github.com/diaspora/diaspora_federation/commit/fb60f8392698f49b9291f3461e7a68ec84def9e2)
7
+
8
+ ## Bug fixes
9
+
10
+ * HydraWrapper: Validate hostname after redirect [d18e623](https://github.com/diaspora/diaspora_federation/commit/d18e623082ac620a89e0542ceb97a9f2501c16bf)
11
+
1
12
  # 0.1.4
2
13
 
3
14
  ## Refactor
@@ -232,8 +232,8 @@ module DiasporaFederation
232
232
  private
233
233
 
234
234
  def validate_http_config
235
- configuration_error "http_concurrency: please configure a number" unless @http_concurrency.is_a?(Fixnum)
236
- configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Fixnum)
235
+ configuration_error "http_concurrency: please configure a number" unless @http_concurrency.is_a?(Integer)
236
+ configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Integer)
237
237
 
238
238
  return unless !@http_verbose.is_a?(TrueClass) && !@http_verbose.is_a?(FalseClass)
239
239
  configuration_error "http_verbose: please configure a boolean"
@@ -44,13 +44,13 @@ module DiasporaFederation
44
44
  raise "Failed to fetch #{url}: #{response.status}" unless response.success?
45
45
  response.body
46
46
  rescue => e
47
- if http_fallback && url.start_with?("https://")
48
- logger.warn "Retry with http: #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
49
- url.sub!("https://", "http://")
50
- retry
51
- else
47
+ unless http_fallback && url.start_with?("https://")
52
48
  raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
53
49
  end
50
+
51
+ logger.warn "Retry with http: #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
52
+ url.sub!("https://", "http://")
53
+ retry
54
54
  end
55
55
 
56
56
  def host_meta_url
@@ -131,10 +131,10 @@ module DiasporaFederation
131
131
  # @return [String] A Base64 encoded signature of #signature_data with key
132
132
  def sign_with_parent_author_if_available
133
133
  privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, parent.author)
134
- if privkey
135
- sign_with_key(privkey).tap do
136
- logger.info "event=sign status=complete signature=parent_author_signature obj=#{self}"
137
- end
134
+ return unless privkey
135
+
136
+ sign_with_key(privkey).tap do
137
+ logger.info "event=sign status=complete signature=parent_author_signature obj=#{self}"
138
138
  end
139
139
  end
140
140
 
@@ -209,11 +209,9 @@ module DiasporaFederation
209
209
 
210
210
  def fetch_parent(data)
211
211
  type = data.fetch(:parent_type) {
212
- if const_defined?(:PARENT_TYPE)
213
- self::PARENT_TYPE
214
- else
215
- raise DiasporaFederation::Entity::ValidationError, "invalid #{self}! missing 'parent_type'."
216
- end
212
+ break self::PARENT_TYPE if const_defined?(:PARENT_TYPE)
213
+
214
+ raise DiasporaFederation::Entity::ValidationError, "invalid #{self}! missing 'parent_type'."
217
215
  }
218
216
  guid = data.fetch(:parent_guid) {
219
217
  raise DiasporaFederation::Entity::ValidationError, "invalid #{self}! missing 'parent_guid'."
@@ -221,11 +219,11 @@ module DiasporaFederation
221
219
 
222
220
  data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
223
221
 
224
- unless data[:parent]
225
- # Fetch and receive parent from remote, if not available locally
226
- Federation::Fetcher.fetch_public(data[:author], type, guid)
227
- data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
228
- end
222
+ return if data[:parent]
223
+
224
+ # Fetch and receive parent from remote, if not available locally
225
+ Federation::Fetcher.fetch_public(data[:author], type, guid)
226
+ data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
229
227
  end
230
228
  end
231
229
 
@@ -28,7 +28,7 @@ module DiasporaFederation
28
28
 
29
29
  def validate_and_receive
30
30
  validate
31
- DiasporaFederation.callbacks.trigger(:receive_entity, entity, recipient_id)
31
+ DiasporaFederation.callbacks.trigger(:receive_entity, entity, sender, recipient_id)
32
32
  logger.info "successfully received #{entity} from person #{sender}#{" for #{recipient_id}" if recipient_id}"
33
33
  end
34
34
 
@@ -11,13 +11,14 @@ module DiasporaFederation
11
11
  # @return [Hash] hydra opts
12
12
  def self.hydra_opts
13
13
  @hydra_opts ||= {
14
- maxredirs: DiasporaFederation.http_redirect_limit,
15
- timeout: DiasporaFederation.http_timeout,
16
- method: :post,
17
- verbose: DiasporaFederation.http_verbose,
18
- cainfo: DiasporaFederation.certificate_authorities,
19
- forbid_reuse: true,
20
- headers: {
14
+ followlocation: true,
15
+ maxredirs: DiasporaFederation.http_redirect_limit,
16
+ timeout: DiasporaFederation.http_timeout,
17
+ method: :post,
18
+ verbose: DiasporaFederation.http_verbose,
19
+ cainfo: DiasporaFederation.certificate_authorities,
20
+ forbid_reuse: true,
21
+ headers: {
21
22
  "Expect" => "",
22
23
  "Transfer-Encoding" => "",
23
24
  "User-Agent" => DiasporaFederation.http_user_agent
@@ -62,9 +63,7 @@ module DiasporaFederation
62
63
  # @param [Typhoeus::Request] request
63
64
  def prepare_request(request)
64
65
  request.on_complete do |response|
65
- DiasporaFederation.callbacks.trigger(:update_pod, pod_url(response.effective_url), status(response))
66
-
67
- success = response.success?
66
+ success = validate_response_and_update_pod(request, response)
68
67
  log_line = "success=#{success} sender=#{@sender_id} obj=#{@obj_str} url=#{response.effective_url} " \
69
68
  "message=#{response.return_code} code=#{response.response_code} time=#{response.total_time}"
70
69
  if success
@@ -77,15 +76,20 @@ module DiasporaFederation
77
76
  end
78
77
  end
79
78
 
80
- # Get the pod root-url from the send-url
81
- # @param [String] url
82
- # @return [String] pod root-url
83
- def pod_url(url)
84
- URI.parse(url).tap {|uri| uri.path = "/" }.to_s
79
+ def validate_response_and_update_pod(request, response)
80
+ url = URI.parse(request.url)
81
+ effective_url = URI.parse(response.effective_url)
82
+ same_host = url.host == effective_url.host
83
+
84
+ (response.success? && same_host).tap do |success|
85
+ pod_url = (success ? effective_url : url).tap {|uri| uri.path = "/" }.to_s
86
+ status = same_host ? status_from_response(response) : :redirected_to_other_hostname
87
+ DiasporaFederation.callbacks.trigger(:update_pod, pod_url, status)
88
+ end
85
89
  end
86
90
 
87
- def status(res)
88
- res.return_code == :ok ? res.response_code : res.return_code
91
+ def status_from_response(response)
92
+ response.return_code == :ok ? response.response_code : response.return_code
89
93
  end
90
94
  end
91
95
  end
@@ -4,7 +4,7 @@ module Validation
4
4
  #
5
5
  # Valid is:
6
6
  # * a +String+: "true", "false", "t", "f", "yes", "no", "y", "n", "1", "0"
7
- # * a +Fixnum+: 1 or 0
7
+ # * a +Integer+: 1 or 0
8
8
  # * a +Boolean+: true or false
9
9
  class Boolean
10
10
  # The error key for this rule
@@ -19,7 +19,7 @@ module Validation
19
19
 
20
20
  if value.is_a?(String)
21
21
  true if value =~ /\A(true|false|t|f|yes|no|y|n|1|0)\z/i
22
- elsif value.is_a?(Fixnum)
22
+ elsif value.is_a?(Integer)
23
23
  true if value == 1 || value == 0
24
24
  elsif [true, false].include? value
25
25
  true
@@ -9,9 +9,9 @@ module Validation
9
9
 
10
10
  # Creates a new rule for a maximum diaspora* ID count validation
11
11
  # @param [Hash] params
12
- # @option params [Fixnum] :maximum maximum allowed id count
12
+ # @option params [Integer] :maximum maximum allowed id count
13
13
  def initialize(params)
14
- unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
14
+ unless params.include?(:maximum) && params[:maximum].is_a?(Integer)
15
15
  raise ArgumentError, "A number has to be specified for :maximum"
16
16
  end
17
17
 
@@ -10,9 +10,9 @@ module Validation
10
10
 
11
11
  # Creates a new rule for a maximum tag count validation
12
12
  # @param [Hash] params
13
- # @option params [Fixnum] :maximum maximum allowed tag count
13
+ # @option params [Integer] :maximum maximum allowed tag count
14
14
  def initialize(params)
15
- unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
15
+ unless params.include?(:maximum) && params[:maximum].is_a?(Integer)
16
16
  raise ArgumentError, "A number has to be specified for :maximum"
17
17
  end
18
18
 
@@ -1,4 +1,4 @@
1
1
  module DiasporaFederation
2
2
  # the gem version
3
- VERSION = "0.1.4".freeze
3
+ VERSION = "0.1.5".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diaspora_federation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Neff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-21 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri