vishnu 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/libravatar.rb +4 -3
- data/lib/vishnu/version.rb +3 -1
- data/lib/vishnu.rb +88 -74
- metadata +18 -43
- data/.gitignore +0 -43
- data/.travis.yml +0 -8
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -71
- data/Rakefile +0 -1
- data/spec/spec_helper.rb +0 -4
- data/spec/vishnu_spec.rb +0 -97
- data/vishnu.gemspec +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 39c384bc0a95bcbf579da3f0b6b67c0c2373f7ab22131e11c22411201eff6e97
|
4
|
+
data.tar.gz: 48582e1db8a8fce83385ad8df1dedd84857dbc6003d4d4ca8de056fbe5503209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75b4cc8561a2cb4b11f8c1d33c20fba40cb987bb9424d2bb9146005a175306bb4f9d6cb212c6659137e388b67228f1dcee8945be05afb6096f8224a5fe459624
|
7
|
+
data.tar.gz: f3ac061ca1e38ab6013b87db04f2c7f09d18cc0ecd9210e998b7aaf46634fe4e52ec83b96797cc04f6bc732925fc9f6e7fc4715191423db6e3daa5956646a3a8
|
data/lib/libravatar.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
# enable compatibility between Vishnu and Libravatar
|
1
|
+
# enable compatibility between Vishnu and Libravatar
|
2
|
+
# and allow require 'libravatar' to work
|
2
3
|
|
3
|
-
|
4
|
+
require 'vishnu'
|
4
5
|
|
5
|
-
|
6
|
+
Libravatar = Vishnu
|
data/lib/vishnu/version.rb
CHANGED
data/lib/vishnu.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# The Vishnu class generates the avatar URL provided by the libravatar
|
3
4
|
# web service at https://www.libravatar.org
|
4
5
|
#
|
5
6
|
# Users may associate their avatar images with multiple OpenIDs and Emails.
|
6
|
-
#
|
7
|
+
#
|
7
8
|
# Original Author:: Kang-min Liu (http://gugod.org/)
|
8
9
|
# Fork Author:: Anton Smirnov (https://sandfox.me/)
|
9
10
|
# Copyright:: Copyright (c) 2011 Kang-min Liu
|
@@ -11,7 +12,7 @@
|
|
11
12
|
# Contributors:: https://github.com/sandfoxme/vishnu/graphs/contributors
|
12
13
|
#
|
13
14
|
|
14
|
-
|
15
|
+
require 'vishnu/version'
|
15
16
|
|
16
17
|
require 'digest/md5'
|
17
18
|
require 'digest/sha2'
|
@@ -31,7 +32,8 @@ class Vishnu
|
|
31
32
|
# - :openid
|
32
33
|
# - :size An integer ranged 1 - 512, default is 80.
|
33
34
|
# - :https Set to true to serve avatars over SSL
|
34
|
-
# - :default URL to redirect missing avatars to, or one of these specials:
|
35
|
+
# - :default URL to redirect missing avatars to, or one of these specials:
|
36
|
+
# "404", "mm", "identicon", "monsterid", "wavatar", "retro"
|
35
37
|
#
|
36
38
|
def initialize(email: nil, openid: nil, size: nil, default: nil, https: nil)
|
37
39
|
@email = email
|
@@ -42,107 +44,119 @@ class Vishnu
|
|
42
44
|
end
|
43
45
|
|
44
46
|
# All the values which are different between HTTP and HTTPS methods.
|
45
|
-
PROFILES =
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
PROFILES = {
|
48
|
+
http: {
|
49
|
+
scheme: 'http://',
|
50
|
+
host: 'cdn.libravatar.org',
|
51
|
+
srv: '_avatars._tcp.',
|
52
|
+
port: 80,
|
53
|
+
}.freeze,
|
54
|
+
https: {
|
55
|
+
scheme: 'https://',
|
56
|
+
host: 'seccdn.libravatar.org',
|
57
|
+
srv: '_avatars-sec._tcp.',
|
58
|
+
port: 443,
|
59
|
+
}.freeze
|
60
|
+
}.freeze
|
59
61
|
|
60
62
|
# Generate the libravatar URL
|
61
63
|
def url
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
id =
|
65
|
+
if @email
|
66
|
+
Digest::MD5.hexdigest(normalize_email(@email))
|
67
|
+
else
|
68
|
+
Digest::SHA2.hexdigest(normalize_openid(@openid))
|
69
|
+
end
|
67
70
|
|
68
|
-
size =
|
69
|
-
default =
|
71
|
+
size = "s=#{@size}" if @size
|
72
|
+
default = "d=#{@default}" if @default
|
70
73
|
|
71
|
-
|
74
|
+
# noinspection RubyScope
|
75
|
+
# ok for them to be nil
|
76
|
+
query = [size, default].reject(&:!).join('&')
|
72
77
|
query = "?#{query}" unless query == ''
|
73
78
|
|
74
|
-
|
79
|
+
base_url = get_base_url + '/avatar/'
|
75
80
|
|
76
|
-
|
81
|
+
base_url + id + query
|
77
82
|
end
|
78
83
|
|
79
84
|
alias_method :to_s, :url
|
80
85
|
|
81
86
|
private
|
82
87
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
else
|
87
|
-
URI.parse(@openid).host
|
88
|
-
end
|
89
|
-
end
|
88
|
+
def profile
|
89
|
+
PROFILES[@https ? :https : :http]
|
90
|
+
end
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
return [nil, nil] unless resources.any?
|
92
|
+
def get_target_domain
|
93
|
+
if @email
|
94
|
+
@email.split('@')[1]
|
95
|
+
else
|
96
|
+
URI.parse(@openid).host
|
97
|
+
end
|
98
|
+
end
|
99
99
|
|
100
|
+
# Grab the DNS SRV records associated with the target domain,
|
101
|
+
# and choose one according to RFC2782.
|
102
|
+
def srv_lookup
|
103
|
+
Resolv::DNS.open do |dns|
|
104
|
+
resources = dns.getresources(
|
105
|
+
profile[:srv] + get_target_domain,
|
106
|
+
Resolv::DNS::Resource::IN::SRV
|
107
|
+
).to_a
|
100
108
|
|
101
|
-
|
102
|
-
resources.delete_if{ |r| r.priority != min_priority }
|
109
|
+
return [nil, nil] unless resources.any?
|
103
110
|
|
104
|
-
|
111
|
+
min_priority = resources.map(&:priority).min
|
112
|
+
resources.delete_if { |r| r.priority != min_priority }
|
105
113
|
|
106
|
-
|
114
|
+
weight_sum = resources.inject(0) { |sum, r| sum + r.weight }.to_f
|
107
115
|
|
108
|
-
|
116
|
+
resource = resources.max_by do |r|
|
117
|
+
if r.weight == 0
|
118
|
+
0
|
119
|
+
else
|
120
|
+
rand**(weight_sum / r.weight)
|
121
|
+
end
|
109
122
|
end
|
110
|
-
end
|
111
123
|
|
112
|
-
|
113
|
-
profile = PROFILES[ @https ? 1 : 0 ]
|
114
|
-
target, port = srv_lookup
|
115
|
-
|
116
|
-
if target && port
|
117
|
-
port_fragment = port != profile[:port] ? ':' + port.to_s : ''
|
118
|
-
profile[:scheme] + target.to_s + port_fragment
|
119
|
-
else
|
120
|
-
profile[:scheme] + profile[:host]
|
121
|
-
end
|
124
|
+
return sanitize_srv_lookup(resource.target.to_s, resource.port)
|
122
125
|
end
|
126
|
+
end
|
123
127
|
|
124
|
-
|
125
|
-
|
126
|
-
return [nil, nil]
|
127
|
-
end
|
128
|
+
def get_base_url
|
129
|
+
target, port = srv_lookup
|
128
130
|
|
129
|
-
|
131
|
+
if target && port
|
132
|
+
port_fragment = port != profile[:port] ? ':' + port.to_s : ''
|
133
|
+
profile[:scheme] + target.to_s + port_fragment
|
134
|
+
else
|
135
|
+
profile[:scheme] + profile[:host]
|
130
136
|
end
|
137
|
+
end
|
131
138
|
|
132
|
-
|
133
|
-
|
139
|
+
def sanitize_srv_lookup(hostname, port)
|
140
|
+
unless hostname.match(/^[0-9a-zA-Z\-.]+$/) && 1 <= port && port <= 65_535
|
141
|
+
return [nil, nil]
|
134
142
|
end
|
135
143
|
|
136
|
-
|
137
|
-
|
138
|
-
parsed_url = URI.parse(url)
|
139
|
-
parsed_url.host = parsed_url.host.downcase
|
140
|
-
parsed_url.scheme = parsed_url.scheme.downcase
|
141
|
-
if parsed_url.path == '' && parsed_url.fragment == nil
|
142
|
-
parsed_url.path = '/'
|
143
|
-
end
|
144
|
+
[hostname, port]
|
145
|
+
end
|
144
146
|
|
145
|
-
|
147
|
+
def normalize_email(email)
|
148
|
+
email.downcase
|
149
|
+
end
|
150
|
+
|
151
|
+
# Normalize an openid URL following the description on libravatar.org
|
152
|
+
def normalize_openid(url)
|
153
|
+
parsed_url = URI.parse(url)
|
154
|
+
parsed_url.host = parsed_url.host.downcase
|
155
|
+
parsed_url.scheme = parsed_url.scheme.downcase
|
156
|
+
if parsed_url.path == '' && parsed_url.fragment.nil?
|
157
|
+
parsed_url.path = '/'
|
146
158
|
end
|
147
159
|
|
160
|
+
parsed_url.to_s
|
161
|
+
end
|
148
162
|
end
|
metadata
CHANGED
@@ -1,32 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vishnu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Smirnov
|
8
8
|
- Kang-min Liu
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.6'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.6'
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: rake
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
31
17
|
requirements:
|
32
18
|
- - ">="
|
@@ -43,18 +29,18 @@ dependencies:
|
|
43
29
|
name: rspec
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
45
31
|
requirements:
|
46
|
-
- - "
|
32
|
+
- - ">="
|
47
33
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
34
|
+
version: '0'
|
49
35
|
type: :development
|
50
36
|
prerelease: false
|
51
37
|
version_requirements: !ruby/object:Gem::Requirement
|
52
38
|
requirements:
|
53
|
-
- - "
|
39
|
+
- - ">="
|
54
40
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
41
|
+
version: '0'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
43
|
+
name: rake
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
59
45
|
requirements:
|
60
46
|
- - ">="
|
@@ -67,31 +53,23 @@ dependencies:
|
|
67
53
|
- - ">="
|
68
54
|
- !ruby/object:Gem::Version
|
69
55
|
version: '0'
|
70
|
-
description:
|
71
|
-
|
72
|
-
|
73
|
-
|
56
|
+
description: |
|
57
|
+
Libravatar provides avatar image hosting (like gravatar.com).
|
58
|
+
Their users may associate avatar images with email or openid.
|
59
|
+
This rubygem can be used to generate Libravatar image URL
|
60
|
+
email: sandfox+gem@sandfox.me
|
74
61
|
executables: []
|
75
62
|
extensions: []
|
76
63
|
extra_rdoc_files: []
|
77
64
|
files:
|
78
|
-
- ".gitignore"
|
79
|
-
- ".travis.yml"
|
80
|
-
- Gemfile
|
81
|
-
- LICENSE.txt
|
82
|
-
- README.md
|
83
|
-
- Rakefile
|
84
65
|
- lib/libravatar.rb
|
85
66
|
- lib/vishnu.rb
|
86
67
|
- lib/vishnu/version.rb
|
87
|
-
|
88
|
-
- spec/vishnu_spec.rb
|
89
|
-
- vishnu.gemspec
|
90
|
-
homepage: https://github.com/sandfoxme/vishnu
|
68
|
+
homepage: https://sandfox.dev/ruby/vishnu.html
|
91
69
|
licenses:
|
92
70
|
- MIT
|
93
71
|
metadata: {}
|
94
|
-
post_install_message:
|
72
|
+
post_install_message:
|
95
73
|
rdoc_options: []
|
96
74
|
require_paths:
|
97
75
|
- lib
|
@@ -106,11 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
84
|
- !ruby/object:Gem::Version
|
107
85
|
version: '0'
|
108
86
|
requirements: []
|
109
|
-
|
110
|
-
|
111
|
-
signing_key:
|
87
|
+
rubygems_version: 3.4.10
|
88
|
+
signing_key:
|
112
89
|
specification_version: 4
|
113
90
|
summary: Avatar URL Generation with libravatar.org
|
114
|
-
test_files:
|
115
|
-
- spec/spec_helper.rb
|
116
|
-
- spec/vishnu_spec.rb
|
91
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# rcov generated
|
2
|
-
coverage
|
3
|
-
|
4
|
-
# rdoc generated
|
5
|
-
rdoc
|
6
|
-
|
7
|
-
# yard generated
|
8
|
-
doc
|
9
|
-
.yardoc
|
10
|
-
|
11
|
-
# bundler
|
12
|
-
.bundle
|
13
|
-
Gemfile.lock
|
14
|
-
|
15
|
-
# jeweler generated
|
16
|
-
pkg
|
17
|
-
|
18
|
-
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
-
#
|
20
|
-
# * Create a file at ~/.gitignore
|
21
|
-
# * Include files you want ignored
|
22
|
-
# * Run: git config --global core.excludesfile ~/.gitignore
|
23
|
-
#
|
24
|
-
# After doing this, these files will be ignored in all your git projects,
|
25
|
-
# saving you from having to 'pollute' every project you touch with them
|
26
|
-
#
|
27
|
-
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
28
|
-
#
|
29
|
-
# For MacOS:
|
30
|
-
#
|
31
|
-
#.DS_Store
|
32
|
-
#
|
33
|
-
# For TextMate
|
34
|
-
#*.tmproj
|
35
|
-
#tmtags
|
36
|
-
#
|
37
|
-
# For emacs:
|
38
|
-
#*~
|
39
|
-
#\#*
|
40
|
-
#.\#*
|
41
|
-
#
|
42
|
-
# For vim:
|
43
|
-
#*.swp
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2011 Kang-min Liu
|
4
|
-
Copyright (c) 2016 Anton Smirnov
|
5
|
-
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
8
|
-
in the Software without restriction, including without limitation the rights
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
11
|
-
furnished to do so, subject to the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be included in
|
14
|
-
all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# Vishnu
|
2
|
-
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/vishnu.svg)](http://badge.fury.io/rb/vishnu)
|
4
|
-
[![Reference Status](https://www.versioneye.com/ruby/vishnu/reference_badge.svg)](https://www.versioneye.com/ruby/vishnu/references)
|
5
|
-
[![Build Status](https://travis-ci.org/sandfoxme/vishnu.svg?branch=master)](https://travis-ci.org/sandfoxme/vishnu)
|
6
|
-
|
7
|
-
Vishnu is a simple library to use Libravatar avatars in your ruby app.
|
8
|
-
|
9
|
-
[Libravatar](https://libravatar.org/) is an avatar service to let their
|
10
|
-
users associate avatar images with their emails or openids. This rubygem
|
11
|
-
generates their avatar URL.
|
12
|
-
|
13
|
-
## Installation
|
14
|
-
|
15
|
-
Add the following line to your ```Gemfile```:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
gem 'vishnu'
|
19
|
-
```
|
20
|
-
|
21
|
-
Or if you want to register ```Libravatar``` alias, then:
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
gem 'vishnu', require: 'libravatar'
|
25
|
-
```
|
26
|
-
|
27
|
-
## Usage
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
Vishnu.new(email: 'someone@example.com').url # get avatar for email
|
31
|
-
Vishnu.new(openid: 'https://example.com').url # get avatar for OpenID URL
|
32
|
-
Vishnu.new(email: 'someone@example.com').to_s # use to_s alias
|
33
|
-
|
34
|
-
# use all options
|
35
|
-
avatar = Vishnu.new(
|
36
|
-
email: 'someone@example.com', # email
|
37
|
-
openid: 'https://example.com/', # OpenID URL. If both email and url are set,
|
38
|
-
# you will get avatar for the email
|
39
|
-
size: 150, # avatar size, 1-512; default is 80
|
40
|
-
default: 'identicon', # '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'
|
41
|
-
# or url to your default
|
42
|
-
https: true, # use secure url or not; default is false
|
43
|
-
)
|
44
|
-
|
45
|
-
avatar.size = 40 # all params are also available as attributes
|
46
|
-
|
47
|
-
avatar.url # get avatar url new style
|
48
|
-
avatar.to_s # and old style
|
49
|
-
# => "https://seccdn.libravatar.org/avatar/16d113840f999444259f73bac9ab8b10?s=40&d=identicon"
|
50
|
-
|
51
|
-
require 'libravatar' # register an alias if you didn't add require: 'libravatar' to your Gemfile
|
52
|
-
Libravatar.new(email: 'someone@example.com').to_s # libravatar gem style
|
53
|
-
```
|
54
|
-
|
55
|
-
## libravatar gem compatibility
|
56
|
-
|
57
|
-
As a fork, vishnu is mostly compatible to the [libravatar](https://rubygems.org/gems/libravatar) v1.2.0 gem.
|
58
|
-
|
59
|
-
Major differences in 2.0 are:
|
60
|
-
|
61
|
-
* ruby < 2.0.0 is no longer supported
|
62
|
-
* methods ```get_target_domain```, ```srv_lookup```, ```get_base_url```
|
63
|
-
(basically everything except `to_s` and attribute setters / getters)
|
64
|
-
are now private
|
65
|
-
|
66
|
-
If you for some reason depend on these features, use ```vishnu 1.2.1```
|
67
|
-
which is basically rebranded bugfix for ```libravatar 1.2.0```.
|
68
|
-
|
69
|
-
## License
|
70
|
-
|
71
|
-
Licensed under the MIT License. See ```LICENSE.txt``` for further details.
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
data/spec/spec_helper.rb
DELETED
data/spec/vishnu_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Vishnu do
|
4
|
-
describe 'Gets urls' do
|
5
|
-
before(:each) do
|
6
|
-
dns = double('Resolv::DNS')
|
7
|
-
allow(Resolv::DNS).to receive(:open).and_yield(dns)
|
8
|
-
allow(dns).to receive(:getresources) do |host, type|
|
9
|
-
expect(type).to eq(Resolv::DNS::Resource::IN::SRV)
|
10
|
-
|
11
|
-
case host.downcase
|
12
|
-
when '_avatars._tcp.federated.com'
|
13
|
-
[
|
14
|
-
Resolv::DNS::Resource::IN::SRV.new(0, 5, 80, 'avatars.federated.com'),
|
15
|
-
Resolv::DNS::Resource::IN::SRV.new(5, 5, 80, 'not-in-priority.federated.com'),
|
16
|
-
]
|
17
|
-
when '_avatars-sec._tcp.federated.com'
|
18
|
-
[
|
19
|
-
Resolv::DNS::Resource::IN::SRV.new(5, 5, 443, 'not-in-priority.federated.com'),
|
20
|
-
Resolv::DNS::Resource::IN::SRV.new(0, 5, 443, 'avatars.federated.com'),
|
21
|
-
]
|
22
|
-
when '_avatars._tcp.custom-federated.com'
|
23
|
-
[Resolv::DNS::Resource::IN::SRV.new(0, 5, 8080, 'avatars.custom-federated.com')]
|
24
|
-
when '_avatars-sec._tcp.custom-federated.com'
|
25
|
-
[Resolv::DNS::Resource::IN::SRV.new(0, 5, 8043, 'avatars.custom-federated.com')]
|
26
|
-
else
|
27
|
-
[]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'gets url for email' do
|
33
|
-
# non-federated
|
34
|
-
expect(Vishnu.new(email: 'user@example.com').url).to eq('http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af')
|
35
|
-
expect(Vishnu.new(email: 'user@example.com').to_s).to eq('http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af')
|
36
|
-
expect(Vishnu.new(email: 'USER@ExAmPlE.CoM').url).to eq('http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af')
|
37
|
-
expect(Vishnu.new(email: 'user@example.com', https: true).url).to eq('https://seccdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af')
|
38
|
-
expect(Vishnu.new(email: 'user@example.com', https: false).url).to eq('http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af')
|
39
|
-
expect(Vishnu.new(email: 'USER@ExAmPlE.CoM', default: 'http://example.com/avatar.png').url).to eq('http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af?d=http://example.com/avatar.png')
|
40
|
-
expect(Vishnu.new(email: 'USER@ExAmPlE.CoM', size: 512, default: 'mm').url).to eq('http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af?s=512&d=mm')
|
41
|
-
|
42
|
-
# federated
|
43
|
-
expect(Vishnu.new(email: 'user@federated.com').url).to eq('http://avatars.federated.com/avatar/d69b469ded547b3ddef720a70c186322')
|
44
|
-
expect(Vishnu.new(email: 'user@feDeRaTed.cOm', https: true).url).to eq('https://avatars.federated.com/avatar/d69b469ded547b3ddef720a70c186322')
|
45
|
-
expect(Vishnu.new(email: 'USER@cuStOm-feDerated.COM').url).to eq('http://avatars.custom-federated.com:8080/avatar/8df8704e4b556e0684f7c38accdaf517')
|
46
|
-
expect(Vishnu.new(email: 'user@custom-federated.com', https: true).url).to eq('https://avatars.custom-federated.com:8043/avatar/8df8704e4b556e0684f7c38accdaf517')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'gets url for openid' do
|
50
|
-
avatar = Vishnu.new(openid: 'http://example.com/id/Bob')
|
51
|
-
expect(avatar.url).to eq('http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd')
|
52
|
-
|
53
|
-
avatar = Vishnu.new(openid: 'https://example.com/id/Bob')
|
54
|
-
expect(avatar.url).to eq('http://cdn.libravatar.org/avatar/82be86d8b10f6492d0eb3d6475c388044529b9d4ddf7269dec2483601b22d2e1')
|
55
|
-
|
56
|
-
avatar = Vishnu.new(openid: 'hTTp://EXAMPLE.COM/id/Bob')
|
57
|
-
expect(avatar.url).to eq('http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd')
|
58
|
-
|
59
|
-
avatar = Vishnu.new(openid: 'hTTp://EXAMPLE.COM/id/Bob', size: 512)
|
60
|
-
expect(avatar.url).to eq('http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd?s=512')
|
61
|
-
|
62
|
-
avatar = Vishnu.new(openid: 'http://example.com/id/bob')
|
63
|
-
expect(avatar.url).to eq('http://cdn.libravatar.org/avatar/84106b275be9a7c69f3b0f77d1d504a794e6d0e4e0a068fa529d869b721f4261')
|
64
|
-
|
65
|
-
avatar = Vishnu.new(openid: 'hTTp://EXAMPLE.COM/ID/BOB')
|
66
|
-
expect(avatar.url).to eq('http://cdn.libravatar.org/avatar/10e678f0db6ead293f21fae8adb1407ab039cffc46f39783152770e4628d9c6c')
|
67
|
-
|
68
|
-
avatar = Vishnu.new(openid: 'http://example.com')
|
69
|
-
expect(avatar.url).to eq('http://cdn.libravatar.org/avatar/2a1b402420ef46577471cdc7409b0fa2c6a204db316e59ade2d805435489a067')
|
70
|
-
|
71
|
-
avatar = Vishnu.new(openid: 'http://federated.com/id/user')
|
72
|
-
expect(avatar.url).to eq('http://avatars.federated.com/avatar/50ef67971fecacf62abe7f9a002aaf6a26ff5882229a51899439dd4c7ccb9ddd')
|
73
|
-
|
74
|
-
avatar = Vishnu.new(openid: 'http://custom-federated.com/id/user')
|
75
|
-
expect(avatar.url).to eq('http://avatars.custom-federated.com:8080/avatar/e2014cf33d71fbf29f6976eab7f9569e7c9eae358cca0ac5b4aa536400a1c9fe')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe 'Works correctly inside' do
|
80
|
-
it 'sanitizes openid' do
|
81
|
-
avatar = Vishnu.new
|
82
|
-
|
83
|
-
expect(avatar.send(:normalize_openid, 'HTTP://EXAMPLE.COM/id/Bob')).to eq('http://example.com/id/Bob')
|
84
|
-
expect(avatar.send(:normalize_openid, 'HTTP://EXAMPLE.COM')).to eq('http://example.com/')
|
85
|
-
expect(avatar.send(:normalize_openid, 'https://example.com/id/bob')).to eq('https://example.com/id/bob')
|
86
|
-
expect(avatar.send(:normalize_openid, 'https://eXamPlE.cOm/ID/BOB/')).to eq('https://example.com/ID/BOB/')
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'sanitizes SRV lookup result' do
|
90
|
-
avatar = Vishnu.new
|
91
|
-
expect(avatar.send(:sanitize_srv_lookup, 'hosntame.abcde.fghi.com', 12345)).to eq(['hosntame.abcde.fghi.com', 12345])
|
92
|
-
expect(avatar.send(:sanitize_srv_lookup, 'hosntame.abcde.fghi.com', 65348283)).to eq([nil, nil])
|
93
|
-
expect(avatar.send(:sanitize_srv_lookup, 'FNORD IMPUNTK *#(*$#&', 12345)).to eq([nil, nil])
|
94
|
-
expect(avatar.send(:sanitize_srv_lookup, 'FNORD IMPUNTK *#(*$#&', 65348283)).to eq([nil, nil])
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
data/vishnu.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative 'lib/vishnu/version'
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'vishnu'
|
5
|
-
spec.version = Vishnu::VERSION
|
6
|
-
|
7
|
-
spec.authors = ['Anton Smirnov', 'Kang-min Liu']
|
8
|
-
spec.email = 'sandfox@sandfox.me'
|
9
|
-
spec.summary = 'Avatar URL Generation with libravatar.org'
|
10
|
-
spec.description = 'Libravatar provides avatar image hosting (like gravatar.com). Their users may associate avatar images with email or openid. This rubygem can be used to generate Libravatar image URL'
|
11
|
-
spec.homepage = 'https://github.com/sandfoxme/vishnu'
|
12
|
-
spec.license = 'MIT'
|
13
|
-
|
14
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
-
spec.require_paths = ['lib']
|
17
|
-
|
18
|
-
spec.required_ruby_version = '>= 2.0.0'
|
19
|
-
|
20
|
-
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
-
spec.add_development_dependency 'rake'
|
22
|
-
spec.add_development_dependency 'rspec', '~> 3.4'
|
23
|
-
spec.add_development_dependency 'simplecov'
|
24
|
-
end
|
25
|
-
|