diaspora_federation 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/diaspora_federation.rb +23 -4
- data/lib/diaspora_federation/discovery.rb +14 -0
- data/lib/diaspora_federation/discovery/discovery.rb +94 -0
- data/lib/diaspora_federation/{web_finger → discovery}/exceptions.rb +5 -1
- data/lib/diaspora_federation/{web_finger → discovery}/h_card.rb +29 -25
- data/lib/diaspora_federation/{web_finger → discovery}/host_meta.rb +13 -13
- data/lib/diaspora_federation/{web_finger → discovery}/web_finger.rb +24 -28
- data/lib/diaspora_federation/{web_finger → discovery}/xrd_document.rb +10 -11
- data/lib/diaspora_federation/entities.rb +12 -0
- data/lib/diaspora_federation/entities/person.rb +33 -0
- data/lib/diaspora_federation/entities/profile.rb +54 -0
- data/lib/diaspora_federation/entity.rb +62 -30
- data/lib/diaspora_federation/fetcher.rb +42 -0
- data/lib/diaspora_federation/logging.rb +4 -2
- data/lib/diaspora_federation/properties_dsl.rb +11 -2
- data/lib/diaspora_federation/validators.rb +38 -0
- data/lib/diaspora_federation/validators/h_card_validator.rb +30 -0
- data/lib/diaspora_federation/validators/person_validator.rb +18 -0
- data/lib/diaspora_federation/validators/profile_validator.rb +33 -0
- data/lib/diaspora_federation/validators/rules/birthday.rb +38 -0
- data/lib/diaspora_federation/validators/rules/boolean.rb +38 -0
- data/lib/diaspora_federation/validators/rules/diaspora_id.rb +46 -0
- data/lib/diaspora_federation/validators/rules/guid.rb +28 -0
- data/lib/diaspora_federation/validators/rules/nilable_uri.rb +19 -0
- data/lib/diaspora_federation/validators/rules/not_nil.rb +23 -0
- data/lib/diaspora_federation/validators/rules/public_key.rb +33 -0
- data/lib/diaspora_federation/validators/rules/tag_count.rb +34 -0
- data/lib/diaspora_federation/validators/web_finger_validator.rb +20 -0
- data/lib/diaspora_federation/version.rb +1 -1
- metadata +82 -8
- data/lib/diaspora_federation/web_finger.rb +0 -13
@@ -0,0 +1,18 @@
|
|
1
|
+
module DiasporaFederation
|
2
|
+
module Validators
|
3
|
+
# This validates a {Entities::Person}
|
4
|
+
class PersonValidator < Validation::Validator
|
5
|
+
include Validation
|
6
|
+
|
7
|
+
rule :guid, :guid
|
8
|
+
|
9
|
+
rule :diaspora_id, %i(not_empty diaspora_id)
|
10
|
+
|
11
|
+
rule :url, %i(not_nil nilableURI)
|
12
|
+
|
13
|
+
rule :profile, :not_nil
|
14
|
+
|
15
|
+
rule :exported_key, :public_key
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DiasporaFederation
|
2
|
+
module Validators
|
3
|
+
# This validates a {Entities::Profile}
|
4
|
+
class ProfileValidator < Validation::Validator
|
5
|
+
include Validation
|
6
|
+
|
7
|
+
rule :diaspora_id, :diaspora_id
|
8
|
+
|
9
|
+
# the name must not contain a semicolon because of mentions
|
10
|
+
# @{<full_name> ; <diaspora_id>}
|
11
|
+
rule :first_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
12
|
+
rule :last_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
13
|
+
|
14
|
+
# this urls can be relative
|
15
|
+
rule :image_url, nilableURI: [:path]
|
16
|
+
rule :image_url_medium, nilableURI: [:path]
|
17
|
+
rule :image_url_small, nilableURI: [:path]
|
18
|
+
|
19
|
+
rule :birthday, :birthday
|
20
|
+
|
21
|
+
# TODO: replace regex with "length: {maximum: xxx}" but this rule doesn't allow nil now.
|
22
|
+
rule :gender, regular_expression: {regex: /\A.{,255}\z/}
|
23
|
+
rule :bio, regular_expression: {regex: /\A.{,65535}\z/}
|
24
|
+
rule :location, regular_expression: {regex: /\A.{,255}\z/}
|
25
|
+
|
26
|
+
rule :searchable, :boolean
|
27
|
+
|
28
|
+
rule :nsfw, :boolean
|
29
|
+
|
30
|
+
rule :tag_string, tag_count: {maximum: 5}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "date"
|
2
|
+
|
3
|
+
module Validation
|
4
|
+
module Rule
|
5
|
+
# Birthday validation rule
|
6
|
+
#
|
7
|
+
# Valid is:
|
8
|
+
# * nil or an empty +String+
|
9
|
+
# * a +Date+ object
|
10
|
+
# * a +String+ with the format "yyyy-mm-dd" and is a valid +Date+, example: 2015-07-25
|
11
|
+
class Birthday
|
12
|
+
# The error key for this rule
|
13
|
+
# @return [Symbol] error key
|
14
|
+
def error_key
|
15
|
+
:birthday
|
16
|
+
end
|
17
|
+
|
18
|
+
# Determines if value is a valid birthday date
|
19
|
+
def valid_value?(value)
|
20
|
+
return true if value.nil? || (value.is_a?(String) && value.empty?)
|
21
|
+
return true if value.is_a? Date
|
22
|
+
|
23
|
+
if value =~ /[0-9]{4}\-[0-9]{2}\-[0-9]{2}/
|
24
|
+
date_field = value.split("-").map(&:to_i)
|
25
|
+
return Date.valid_civil?(date_field[0], date_field[1], date_field[2])
|
26
|
+
end
|
27
|
+
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
# This rule has no params
|
32
|
+
# @return [Hash] params
|
33
|
+
def params
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Validation
|
2
|
+
module Rule
|
3
|
+
# Boolean validation rule
|
4
|
+
#
|
5
|
+
# Valid is:
|
6
|
+
# * a +String+: "true", "false", "t", "f", "yes", "no", "y", "n", "1", "0"
|
7
|
+
# * a +Fixnum+: 1 or 0
|
8
|
+
# * a +Boolean+: true or false
|
9
|
+
class Boolean
|
10
|
+
# The error key for this rule
|
11
|
+
# @return [Symbol] error key
|
12
|
+
def error_key
|
13
|
+
:boolean
|
14
|
+
end
|
15
|
+
|
16
|
+
# Determines if value is a valid +boolean+
|
17
|
+
def valid_value?(value)
|
18
|
+
return false if value.nil?
|
19
|
+
|
20
|
+
if value.is_a?(String)
|
21
|
+
true if value =~ /\A(true|false|t|f|yes|no|y|n|1|0)\z/i
|
22
|
+
elsif value.is_a?(Fixnum)
|
23
|
+
true if value == 1 || value == 0
|
24
|
+
elsif [true, false].include? value
|
25
|
+
true
|
26
|
+
else
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# This rule has no params
|
32
|
+
# @return [Hash] params
|
33
|
+
def params
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Validation
|
2
|
+
module Rule
|
3
|
+
# Diaspora ID validation rule
|
4
|
+
#
|
5
|
+
# This rule is based on https://github.com/zombor/Validator/blob/master/lib/validation/rule/email.rb
|
6
|
+
# which was adapted from https://github.com/emmanuel/aequitas/blob/master/lib/aequitas/rule/format/email_address.rb
|
7
|
+
class DiasporaId
|
8
|
+
# The Regex for a valid diaspora ID
|
9
|
+
DIASPORA_ID = begin
|
10
|
+
letter = "a-zA-Z"
|
11
|
+
digit = "0-9"
|
12
|
+
username = "[#{letter}#{digit}\\-\\_\\.]+"
|
13
|
+
atext = "[#{letter}#{digit}+\\=\\-\\_]"
|
14
|
+
dot_atom = "#{atext}+([.]#{atext}*)*"
|
15
|
+
no_ws_ctl = '\x01-\x08\x11\x12\x14-\x1f\x7f'
|
16
|
+
text = '[\x01-\x09\x11\x12\x14-\x7f]'
|
17
|
+
quoted_pair = "(\\x5c#{text})"
|
18
|
+
dtext = "[#{no_ws_ctl}\\x21-\\x5a\\x5e-\\x7e]"
|
19
|
+
dcontent = "(?:#{dtext}|#{quoted_pair})"
|
20
|
+
domain_literal = "\\[#{dcontent}+\\]"
|
21
|
+
domain = "(?:#{dot_atom}|#{domain_literal})"
|
22
|
+
port = "(:[#{digit}]+)?"
|
23
|
+
addr_spec = "(#{username}\\@#{domain}#{port})?"
|
24
|
+
|
25
|
+
/\A#{addr_spec}\z/u
|
26
|
+
end
|
27
|
+
|
28
|
+
# The error key for this rule
|
29
|
+
# @return [Symbol] error key
|
30
|
+
def error_key
|
31
|
+
:diaspora_id
|
32
|
+
end
|
33
|
+
|
34
|
+
# Determines if value is a valid diaspora ID
|
35
|
+
def valid_value?(value)
|
36
|
+
value.nil? || !DIASPORA_ID.match(value).nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
# This rule has no params
|
40
|
+
# @return [Hash] params
|
41
|
+
def params
|
42
|
+
{}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Validation
|
2
|
+
module Rule
|
3
|
+
# GUID validation rule
|
4
|
+
#
|
5
|
+
# Valid is a +String+ that is at least 16 chars long and contains only:
|
6
|
+
# * Letters: a-z
|
7
|
+
# * Numbers: 0-9
|
8
|
+
# * Special chars: '-', '_', '@', '.' and ':'
|
9
|
+
class Guid
|
10
|
+
# The error key for this rule
|
11
|
+
# @return [Symbol] error key
|
12
|
+
def error_key
|
13
|
+
:guid
|
14
|
+
end
|
15
|
+
|
16
|
+
# Determines if value is a valid +GUID+
|
17
|
+
def valid_value?(value)
|
18
|
+
value.is_a?(String) && value.downcase =~ /\A[0-9a-z\-_@.:]{16,}\z/
|
19
|
+
end
|
20
|
+
|
21
|
+
# This rule has no params
|
22
|
+
# @return [Hash] params
|
23
|
+
def params
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Validation
|
2
|
+
module Rule
|
3
|
+
# URI validation rule
|
4
|
+
|
5
|
+
# It allows +nil+, so maybe add an additional {Rule::NotNil} rule.
|
6
|
+
class NilableURI < Validation::Rule::URI
|
7
|
+
# The error key for this rule
|
8
|
+
# @return [Symbol] error key
|
9
|
+
def error_key
|
10
|
+
:nilableURI
|
11
|
+
end
|
12
|
+
|
13
|
+
# Determines if value is a valid URI
|
14
|
+
def valid_value?(uri_string)
|
15
|
+
uri_string.nil? || super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Validation
|
2
|
+
module Rule
|
3
|
+
# Validates that a property is not +nil+
|
4
|
+
class NotNil
|
5
|
+
# The error key for this rule
|
6
|
+
# @return [Symbol] error key
|
7
|
+
def error_key
|
8
|
+
:not_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
# Determines if value is not nil
|
12
|
+
def valid_value?(value)
|
13
|
+
!value.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
# This rule has no params
|
17
|
+
# @return [Hash] params
|
18
|
+
def params
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Validation
|
2
|
+
module Rule
|
3
|
+
# Public key validation rule
|
4
|
+
#
|
5
|
+
# A valid key must:
|
6
|
+
# * start with "-----BEGIN PUBLIC KEY-----" and end with "-----END PUBLIC KEY-----"
|
7
|
+
# or
|
8
|
+
# * start with "-----BEGIN RSA PUBLIC KEY-----" and end with "-----END RSA PUBLIC KEY-----"
|
9
|
+
class PublicKey
|
10
|
+
# The error key for this rule
|
11
|
+
# @return [Symbol] error key
|
12
|
+
def error_key
|
13
|
+
:public_key
|
14
|
+
end
|
15
|
+
|
16
|
+
# Determines if value is a valid public key
|
17
|
+
def valid_value?(value)
|
18
|
+
!value.nil? && (
|
19
|
+
(value.strip.start_with?("-----BEGIN PUBLIC KEY-----") &&
|
20
|
+
value.strip.end_with?("-----END PUBLIC KEY-----")) ||
|
21
|
+
(value.strip.start_with?("-----BEGIN RSA PUBLIC KEY-----") &&
|
22
|
+
value.strip.end_with?("-----END RSA PUBLIC KEY-----"))
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
# This rule has no params
|
27
|
+
# @return [Hash] params
|
28
|
+
def params
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Validation
|
2
|
+
module Rule
|
3
|
+
# Rule for validating the number of tags in a string.
|
4
|
+
# Only the "#" characters will be counted.
|
5
|
+
# The string can be nil.
|
6
|
+
class TagCount
|
7
|
+
# This rule must have a +maximum+ param
|
8
|
+
# @return [Hash] params
|
9
|
+
attr_reader :params
|
10
|
+
|
11
|
+
# create a new rule for a maximum tag count validation
|
12
|
+
# @param [Hash] params
|
13
|
+
# @option params [Fixnum] :maximum maximum allowed tag count
|
14
|
+
def initialize(params)
|
15
|
+
unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
|
16
|
+
raise ArgumentError, "A number has to be specified for :maximum"
|
17
|
+
end
|
18
|
+
|
19
|
+
@params = params
|
20
|
+
end
|
21
|
+
|
22
|
+
# The error key for this rule
|
23
|
+
# @return [Symbol] error key
|
24
|
+
def error_key
|
25
|
+
:tag_count
|
26
|
+
end
|
27
|
+
|
28
|
+
# Determines if value doesn't have more than +maximum+ tags
|
29
|
+
def valid_value?(value)
|
30
|
+
value.nil? || value.count("#") <= params[:maximum]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module DiasporaFederation
|
2
|
+
module Validators
|
3
|
+
# This validates a {Discovery::WebFinger}
|
4
|
+
#
|
5
|
+
# @note it does not validate the guid and public key, because it will be
|
6
|
+
# removed in the webfinger
|
7
|
+
class WebFingerValidator < Validation::Validator
|
8
|
+
include Validation
|
9
|
+
|
10
|
+
rule :acct_uri, :not_empty
|
11
|
+
|
12
|
+
rule :alias_url, [:not_nil, nilableURI: %i(host path)]
|
13
|
+
rule :hcard_url, [:not_nil, nilableURI: %i(host path)]
|
14
|
+
rule :seed_url, %i(not_nil nilableURI)
|
15
|
+
rule :profile_url, [:not_nil, nilableURI: %i(host path)]
|
16
|
+
rule :atom_url, [:not_nil, nilableURI: %i(host path)]
|
17
|
+
rule :salmon_url, [:not_nil, nilableURI: %i(host path)]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Neff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -30,6 +30,62 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.6.6
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.9.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: faraday_middleware
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.10.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.10.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: typhoeus
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.7.0
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.7.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: valid
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.5.0
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.5.0
|
33
89
|
description: This gem provides the functionality for de-/serialization and de-/encryption
|
34
90
|
of Entities in the protocols used for communication among the various installations
|
35
91
|
of Diaspora*
|
@@ -43,16 +99,34 @@ files:
|
|
43
99
|
- README.md
|
44
100
|
- lib/diaspora_federation.rb
|
45
101
|
- lib/diaspora_federation/callbacks.rb
|
102
|
+
- lib/diaspora_federation/discovery.rb
|
103
|
+
- lib/diaspora_federation/discovery/discovery.rb
|
104
|
+
- lib/diaspora_federation/discovery/exceptions.rb
|
105
|
+
- lib/diaspora_federation/discovery/h_card.rb
|
106
|
+
- lib/diaspora_federation/discovery/host_meta.rb
|
107
|
+
- lib/diaspora_federation/discovery/web_finger.rb
|
108
|
+
- lib/diaspora_federation/discovery/xrd_document.rb
|
109
|
+
- lib/diaspora_federation/entities.rb
|
110
|
+
- lib/diaspora_federation/entities/person.rb
|
111
|
+
- lib/diaspora_federation/entities/profile.rb
|
46
112
|
- lib/diaspora_federation/entity.rb
|
113
|
+
- lib/diaspora_federation/fetcher.rb
|
47
114
|
- lib/diaspora_federation/logging.rb
|
48
115
|
- lib/diaspora_federation/properties_dsl.rb
|
116
|
+
- lib/diaspora_federation/validators.rb
|
117
|
+
- lib/diaspora_federation/validators/h_card_validator.rb
|
118
|
+
- lib/diaspora_federation/validators/person_validator.rb
|
119
|
+
- lib/diaspora_federation/validators/profile_validator.rb
|
120
|
+
- lib/diaspora_federation/validators/rules/birthday.rb
|
121
|
+
- lib/diaspora_federation/validators/rules/boolean.rb
|
122
|
+
- lib/diaspora_federation/validators/rules/diaspora_id.rb
|
123
|
+
- lib/diaspora_federation/validators/rules/guid.rb
|
124
|
+
- lib/diaspora_federation/validators/rules/nilable_uri.rb
|
125
|
+
- lib/diaspora_federation/validators/rules/not_nil.rb
|
126
|
+
- lib/diaspora_federation/validators/rules/public_key.rb
|
127
|
+
- lib/diaspora_federation/validators/rules/tag_count.rb
|
128
|
+
- lib/diaspora_federation/validators/web_finger_validator.rb
|
49
129
|
- lib/diaspora_federation/version.rb
|
50
|
-
- lib/diaspora_federation/web_finger.rb
|
51
|
-
- lib/diaspora_federation/web_finger/exceptions.rb
|
52
|
-
- lib/diaspora_federation/web_finger/h_card.rb
|
53
|
-
- lib/diaspora_federation/web_finger/host_meta.rb
|
54
|
-
- lib/diaspora_federation/web_finger/web_finger.rb
|
55
|
-
- lib/diaspora_federation/web_finger/xrd_document.rb
|
56
130
|
- lib/tasks/build.rake
|
57
131
|
- lib/tasks/diaspora_federation_tasks.rake
|
58
132
|
- lib/tasks/tests.rake
|