vishnu 1.2.2 → 2.0.0

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: e3c3ac27d6595188485f30fd8e19b94f4366efa9
4
- data.tar.gz: 6a8e3d5cc7217a1f6e7fbea35941af2ae925f99e
3
+ metadata.gz: 092e4ac774903584fdaa83c58aaa49fdecbb56b6
4
+ data.tar.gz: b5e5768c1a1ff5e604503d01ab969853993593c2
5
5
  SHA512:
6
- metadata.gz: 90d6bcf8cae62e3037b0920826ec39184b6cdbaa64bfb5b5e1bb7f8ae24a2a55356170ba45d1060757d50d050706902e5defc57fb2e7df218f7427e539266c12
7
- data.tar.gz: 9fa0491431764f3fe25aadb020c9d66b0b9a0229b319f33a8f6e09670869c43c40cb16875dd5d9a1044e06810ab8ef8c4fd023abc98420c6bebb3d83b42db49a
6
+ metadata.gz: 364464d050b89d3f61d7d871a6ba991595e373e53c57c4849f5dc69e93d6f1183b009536fdfd395679dfa2c821f876ccbed2b9753939e22cd7ff184cf146a69d
7
+ data.tar.gz: 3e729cb99404c40976dc56b93c1b8af2e891b6fd9a71e072bb0e5bc7f13df2c5c8a54021986a45dd1b1fa42f20516d3e5d31ec31f9cffcb12301a16dfc415f26
@@ -0,0 +1,43 @@
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
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.2.0
3
+ - '2.0.0'
4
+ - '2.1.8'
5
+ - '2.2.4'
6
+ - '2.3.0'
7
+ - rbx
8
+ script: bundle exec rspec
data/Gemfile CHANGED
@@ -1,9 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- group :development do
4
- gem 'jeweler'
5
- gem 'shoulda', '> 1.2.3'
6
- gem 'minitest', '4.7.5'
7
- gem 'test-unit'
8
- end
9
-
3
+ # Specify your gem's dependencies in vishnu.gemspec
4
+ gemspec
@@ -1,6 +1,7 @@
1
1
  The MIT License
2
2
 
3
3
  Copyright (c) 2011 Kang-min Liu
4
+ Copyright (c) 2016 Anton Smirnov
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
20
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
21
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
22
  THE SOFTWARE.
22
-
@@ -0,0 +1,71 @@
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 CHANGED
@@ -1,39 +1 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gem|
6
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
7
- gem.name = "vishnu"
8
- gem.homepage = "http://github.com/sandfoxme/vishnu"
9
- gem.license = "MIT"
10
- gem.summary = %Q{Avatar URL Generation wih libravatar.org}
11
- gem.description = %Q{libravatar.org 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 avatar image URL}
12
- gem.email = "sandfox@sandfox.me"
13
- gem.authors = ['Anton Smirnov', "Kang-min Liu"]
14
- # Include your dependencies below. Runtime dependencies are required when using your gem,
15
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
16
- # gem.add_runtime_dependency 'digest/sha2', '> 0.1'
17
- # gem.add_runtime_dependency 'uri', '> 0.1'
18
- # gem.add_development_dependency 'shoulda', '> 1.2.3'
19
- end
20
- Jeweler::RubygemsDotOrgTasks.new
21
-
22
- require 'rake/testtask'
23
- Rake::TestTask.new(:test) do |test|
24
- test.libs << 'lib' << 'test'
25
- test.pattern = 'test/**/test_*.rb'
26
- test.verbose = true
27
- end
28
-
29
- task :default => :test
30
-
31
- require 'rdoc/task'
32
- Rake::RDocTask.new do |rdoc|
33
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
34
-
35
- rdoc.rdoc_dir = 'rdoc'
36
- rdoc.title = "vishnu #{version}"
37
- rdoc.rdoc_files.include('README*')
38
- rdoc.rdoc_files.include('lib/**/*.rb')
39
- end
1
+ require 'bundler/gem_tasks'
@@ -1,3 +1,5 @@
1
- require 'vishnu'
1
+ # enable compatibility between Vishnu and Libravatar and allow require 'libravatar' to work
2
+
3
+ require_relative 'vishnu'
2
4
 
3
5
  class Libravatar < Vishnu; end
@@ -1,15 +1,18 @@
1
1
  #
2
- # The Libravatar class generates the avatar URL provided by the libravatar
3
- # web service at http://www.libravatar.org
2
+ # The Vishnu class generates the avatar URL provided by the libravatar
3
+ # web service at https://www.libravatar.org
4
4
  #
5
5
  # Users may associate their avatar images with multiple OpenIDs and Emails.
6
6
  #
7
- # Author:: Kang-min Liu (http://gugod.org)
7
+ # Original Author:: Kang-min Liu (http://gugod.org/)
8
+ # Fork Author:: Anton Smirnov (https://sandfox.me/)
8
9
  # Copyright:: Copyright (c) 2011 Kang-min Liu
9
10
  # License:: MIT
10
- # Contributors:: https://github.com/gugod/libravatar/contributors
11
+ # Contributors:: https://github.com/sandfoxme/vishnu/graphs/contributors
11
12
  #
12
13
 
14
+ require_relative 'vishnu/version'
15
+
13
16
  require 'digest/md5'
14
17
  require 'digest/sha2'
15
18
  require 'uri'
@@ -20,7 +23,7 @@ class Vishnu
20
23
 
21
24
  # The options should contain :email or :openid values. If both are
22
25
  # given, email will be used. The value of openid and email will be
23
- # normalized by the rule described in http://www.libravatar.org/api
26
+ # normalized by the rule described in https://wiki.libravatar.org/api/
24
27
  #
25
28
  # List of option keys:
26
29
  #
@@ -30,99 +33,116 @@ class Vishnu
30
33
  # - :https Set to true to serve avatars over SSL
31
34
  # - :default URL to redirect missing avatars to, or one of these specials: "404", "mm", "identicon", "monsterid", "wavatar", "retro"
32
35
  #
33
- def initialize(options = {})
34
- @email = options[:email]
35
- @openid = options[:openid]
36
- @size = options[:size]
37
- @default = options[:default]
38
- @https = options[:https]
39
- end
40
-
41
- def get_target_domain
42
- return @email.split('@')[1] if @email
43
- return URI.parse(@openid).host
36
+ def initialize(email: nil, openid: nil, size: nil, default: nil, https: nil)
37
+ @email = email
38
+ @openid = openid
39
+ @size = size
40
+ @default = default
41
+ @https = https
44
42
  end
45
43
 
46
44
  # All the values which are different between HTTP and HTTPS methods.
47
- @@profiles = [
48
- { :scheme => 'http://',
49
- :host => 'cdn.libravatar.org',
50
- :srv => '_avatars._tcp.',
51
- :port => 80 },
52
- { :scheme => 'https://',
53
- :host => 'seccdn.libravatar.org',
54
- :srv => '_avatars-sec._tcp.',
55
- :port => 443 }
56
- ]
57
-
58
- # Grab the DNS SRV records associated with the target domain,
59
- # and choose one according to RFC2782.
60
- def srv_lookup
61
- profile = @@profiles[ @https ? 1 : 0 ]
62
- Resolv::DNS::open do |dns|
63
- rrs = dns.getresources(profile[:srv] + get_target_domain(),
64
- Resolv::DNS::Resource::IN::SRV).to_a
65
- return [nil, nil] unless rrs.any?
66
-
67
-
68
- min_priority = rrs.map{ |r| r.priority }.min
69
- rrs.delete_if{ |r| r.priority != min_priority }
70
-
71
- weight_sum = rrs.inject(0) { |a,r| a+r.weight }.to_f
72
-
73
- r = rrs.max_by { |r| r.weight == 0 ? 0 : rand ** (weight_sum / r.weight) }
74
-
75
- return [r.target, r.port]
76
- end
77
- end
78
-
79
- def get_base_url
80
- profile = @@profiles[ @https ? 1 : 0 ]
81
- target, port = srv_lookup
82
-
83
- if (target && port)
84
- port_fragment = port != profile[:port] ? ':' + port.to_s : ''
85
- return profile[:scheme] + target.to_s + port_fragment
86
- else
87
- return profile[:scheme] + profile[:host]
88
- end
89
- end
45
+ PROFILES = [
46
+ {
47
+ scheme: 'http://',
48
+ host: 'cdn.libravatar.org',
49
+ srv: '_avatars._tcp.',
50
+ port: 80,
51
+ },
52
+ {
53
+ scheme: 'https://',
54
+ host: 'seccdn.libravatar.org',
55
+ srv: '_avatars-sec._tcp.',
56
+ port: 443,
57
+ }
58
+ ]
90
59
 
91
60
  # Generate the libravatar URL
92
- def to_s
61
+ def url
93
62
  if @email
94
- @email.downcase!
95
- id = Digest::MD5.hexdigest(@email)
63
+ id = Digest::MD5.hexdigest(normalize_email(@email))
96
64
  else
97
65
  id = Digest::SHA2.hexdigest(normalize_openid(@openid))
98
66
  end
99
- s = @size ? "s=#{@size}" : nil
100
- d = @default ? "d=#{@default}" : nil
101
67
 
102
- query = [s,d].reject{|x|!x}.join("&")
103
- query = "?#{query}" unless query == ""
104
- baseurl = get_base_url() + '/avatar/'
105
- return baseurl + id + query
68
+ size = @size ? "s=#{@size}" : nil
69
+ default = @default ? "d=#{@default}" : nil
70
+
71
+ query = [ size, default ].reject{ |x| !x }.join('&')
72
+ query = "?#{query}" unless query == ''
73
+
74
+ baseurl = get_base_url + '/avatar/'
75
+
76
+ baseurl + id + query
106
77
  end
107
78
 
79
+ alias_method :to_s, :url
80
+
108
81
  private
109
82
 
110
- def sanitize_srv_lookup(hostname, port)
111
- unless hostname.match(/^[0-9a-zA-Z\-.]+$/) && 1 <= port && port <= 65535
112
- return [nil, nil]
83
+ def get_target_domain
84
+ if @email
85
+ @email.split('@')[1]
86
+ else
87
+ URI.parse(@openid).host
88
+ end
113
89
  end
114
90
 
115
- return [hostname, port]
116
- end
91
+ # Grab the DNS SRV records associated with the target domain,
92
+ # and choose one according to RFC2782.
93
+ def srv_lookup
94
+ profile = PROFILES[ @https ? 1 : 0 ]
95
+ Resolv::DNS::open do |dns|
96
+ resources = dns.getresources(profile[:srv] + get_target_domain,
97
+ Resolv::DNS::Resource::IN::SRV).to_a
98
+ return [nil, nil] unless resources.any?
99
+
117
100
 
118
- # Normalize an openid URL following the description on libravatar.org
119
- def normalize_openid(s)
120
- x = URI.parse(s)
121
- x.host.downcase!
122
- x.scheme = x.scheme.downcase
123
- if (x.path == "" && x.fragment == nil)
124
- x.path = "/"
101
+ min_priority = resources.map{ |r| r.priority }.min
102
+ resources.delete_if{ |r| r.priority != min_priority }
103
+
104
+ weight_sum = resources.inject(0) { |sum, r| sum + r.weight }.to_f
105
+
106
+ r = resources.max_by { |r| r.weight == 0 ? 0 : rand ** (weight_sum / r.weight) }
107
+
108
+ return sanitize_srv_lookup(r.target.to_s, r.port)
109
+ end
125
110
  end
126
- return x.to_s
127
- end
111
+
112
+ def get_base_url
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
122
+ end
123
+
124
+ def sanitize_srv_lookup(hostname, port)
125
+ unless hostname.match(/^[0-9a-zA-Z\-.]+$/) && 1 <= port && port <= 65535
126
+ return [nil, nil]
127
+ end
128
+
129
+ [hostname, port]
130
+ end
131
+
132
+ def normalize_email(email)
133
+ email.downcase
134
+ end
135
+
136
+ # Normalize an openid URL following the description on libravatar.org
137
+ def normalize_openid(url)
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
+
145
+ parsed_url.to_s
146
+ end
147
+
128
148
  end
@@ -0,0 +1,3 @@
1
+ class Vishnu
2
+ VERSION = '2.0.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require_relative '../lib/vishnu'
@@ -0,0 +1,97 @@
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
@@ -1,61 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: vishnu 1.2.2 ruby lib
1
+ require_relative 'lib/vishnu/version'
6
2
 
7
- Gem::Specification.new do |s|
8
- s.name = "vishnu"
9
- s.version = "1.2.2"
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'vishnu'
5
+ spec.version = Vishnu::VERSION
10
6
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Anton Smirnov", "Kang-min Liu"]
14
- s.date = "2016-06-20"
15
- s.description = "libravatar.org 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 avatar image URL"
16
- s.email = "sandfox@sandfox.me"
17
- s.extra_rdoc_files = [
18
- "LICENSE.txt",
19
- "README.rdoc"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".travis.yml",
24
- "Gemfile",
25
- "LICENSE.txt",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "lib/libravatar.rb",
30
- "lib/vishnu.rb",
31
- "test/helper.rb",
32
- "test/test_libravatar.rb",
33
- "vishnu.gemspec"
34
- ]
35
- s.homepage = "http://github.com/sandfoxme/vishnu"
36
- s.licenses = ["MIT"]
37
- s.rubygems_version = "2.5.1"
38
- s.summary = "Avatar URL Generation wih libravatar.org"
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'
39
13
 
40
- if s.respond_to? :specification_version then
41
- s.specification_version = 4
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']
42
17
 
43
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_development_dependency(%q<jeweler>, [">= 0"])
45
- s.add_development_dependency(%q<shoulda>, ["> 1.2.3"])
46
- s.add_development_dependency(%q<minitest>, ["= 4.7.5"])
47
- s.add_development_dependency(%q<test-unit>, [">= 0"])
48
- else
49
- s.add_dependency(%q<jeweler>, [">= 0"])
50
- s.add_dependency(%q<shoulda>, ["> 1.2.3"])
51
- s.add_dependency(%q<minitest>, ["= 4.7.5"])
52
- s.add_dependency(%q<test-unit>, [">= 0"])
53
- end
54
- else
55
- s.add_dependency(%q<jeweler>, [">= 0"])
56
- s.add_dependency(%q<shoulda>, ["> 1.2.3"])
57
- s.add_dependency(%q<minitest>, ["= 4.7.5"])
58
- s.add_dependency(%q<test-unit>, [">= 0"])
59
- end
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'
60
24
  end
61
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vishnu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Smirnov
@@ -9,52 +9,52 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-20 00:00:00.000000000 Z
12
+ date: 2016-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: jeweler
15
+ name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '1.6'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '1.6'
28
28
  - !ruby/object:Gem::Dependency
29
- name: shoulda
29
+ name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 1.2.3
34
+ version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 1.2.3
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: minitest
43
+ name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '='
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 4.7.5
48
+ version: '3.4'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '='
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 4.7.5
55
+ version: '3.4'
56
56
  - !ruby/object:Gem::Dependency
57
- name: test-unit
57
+ name: simplecov
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -67,29 +67,27 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- description: libravatar.org provides avatar image hosting (like gravatar.com). Their
71
- users may associate avatar images with email or openid. This rubygem can be used
72
- to generate libravatar avatar image URL
70
+ description: Libravatar provides avatar image hosting (like gravatar.com). Their users
71
+ may associate avatar images with email or openid. This rubygem can be used to generate
72
+ Libravatar image URL
73
73
  email: sandfox@sandfox.me
74
74
  executables: []
75
75
  extensions: []
76
- extra_rdoc_files:
77
- - LICENSE.txt
78
- - README.rdoc
76
+ extra_rdoc_files: []
79
77
  files:
80
- - ".document"
78
+ - ".gitignore"
81
79
  - ".travis.yml"
82
80
  - Gemfile
83
81
  - LICENSE.txt
84
- - README.rdoc
82
+ - README.md
85
83
  - Rakefile
86
- - VERSION
87
84
  - lib/libravatar.rb
88
85
  - lib/vishnu.rb
89
- - test/helper.rb
90
- - test/test_libravatar.rb
86
+ - lib/vishnu/version.rb
87
+ - spec/spec_helper.rb
88
+ - spec/vishnu_spec.rb
91
89
  - vishnu.gemspec
92
- homepage: http://github.com/sandfoxme/vishnu
90
+ homepage: https://github.com/sandfoxme/vishnu
93
91
  licenses:
94
92
  - MIT
95
93
  metadata: {}
@@ -101,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
99
  requirements:
102
100
  - - ">="
103
101
  - !ruby/object:Gem::Version
104
- version: '0'
102
+ version: 2.0.0
105
103
  required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  requirements:
107
105
  - - ">="
@@ -109,8 +107,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
107
  version: '0'
110
108
  requirements: []
111
109
  rubyforge_project:
112
- rubygems_version: 2.5.1
110
+ rubygems_version: 2.4.8
113
111
  signing_key:
114
112
  specification_version: 4
115
- summary: Avatar URL Generation wih libravatar.org
116
- test_files: []
113
+ summary: Avatar URL Generation with libravatar.org
114
+ test_files:
115
+ - spec/spec_helper.rb
116
+ - spec/vishnu_spec.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
@@ -1,20 +0,0 @@
1
- = libravatar
2
-
3
- http://libravatar.org is an avatar service to let their users associate avatar images
4
- with their emails or openids. This rubygem generates their avatar URL.
5
-
6
- == Contributing to libravatar
7
-
8
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
9
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
10
- * Fork the project
11
- * Start a feature/bugfix branch
12
- * Commit and push until you are happy with your contribution
13
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
14
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
15
-
16
- == Copyright
17
-
18
- Copyright (c) 2011 Kang-min Liu. See LICENSE.txt for
19
- further details.
20
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.2.2
@@ -1,11 +0,0 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'test/unit'
4
- require 'shoulda'
5
-
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- $LOAD_PATH.unshift(File.dirname(__FILE__))
8
- require 'libravatar'
9
-
10
- class Test::Unit::TestCase
11
- end
@@ -1,50 +0,0 @@
1
- require 'helper'
2
-
3
- class TestLibravatar < Test::Unit::TestCase
4
- should "Generate url from email" do
5
- # echo -n "user@example.com"|md5sum
6
- # => b58996c504c5638798eb6b511e6f49af
7
- avatar = Libravatar.new(:email => "user@example.com")
8
-
9
- re = /http:\/\/.+\/avatar\/b58996c504c5638798eb6b511e6f49af$/
10
- assert avatar.to_s.match(re)
11
- assert Libravatar.new(:email => "USER@ExAmPlE.CoM").to_s.match(re)
12
-
13
- assert_equal Libravatar.new(:email => "user@example.com", :https => true).to_s[0,8], "https://"
14
- assert_equal Libravatar.new(:email => "user@example.com", :https => false).to_s[0,7], "http://"
15
-
16
- assert Libravatar.new(:email => "USER@ExAmPlE.CoM", :default => "http://example.com/avatar.png").to_s.match(/http:\/\/.+\/avatar\/b58996c504c5638798eb6b511e6f49af\?d=http:\/\/example\.com\/avatar\.png/)
17
-
18
- assert_equal Libravatar.new(:email => "USER@ExAmPlE.CoM", :size => 512, :default => "mm").to_s[-43,43], "b58996c504c5638798eb6b511e6f49af?s=512&d=mm"
19
- end
20
-
21
- should "Generate url from openid" do
22
- # echo -n "http://example.com/id/Bob"|shasum -a 256
23
- # => 80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd
24
- avatar = Libravatar.new(:openid => "http://example.com/id/Bob")
25
- assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd"
26
-
27
- avatar = Libravatar.new(:openid => "hTTp://EXAMPLE.COM/id/Bob")
28
- assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd"
29
-
30
- avatar = Libravatar.new(:openid => "hTTp://EXAMPLE.COM/id/Bob", :size => 512)
31
- assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd?s=512"
32
- end
33
-
34
- should "Normalize OpenID" do
35
- x = Libravatar.new
36
- assert_equal x.send(:normalize_openid, "HTTP://EXAMPLE.COM/id/Bob"), "http://example.com/id/Bob"
37
- assert_equal x.send(:normalize_openid, "HTTP://EXAMPLE.COM"), "http://example.com/"
38
- end
39
-
40
- should "Return the federated URI" do
41
- avatar = Libravatar.new(:email => 'invalid@catalyst.net.nz')
42
- assert avatar.to_s.match(/http:\/\/.+\/avatar\/f924d1e9f2c10ee9efa7acdd16484c2f$/)
43
- end
44
-
45
- should "Sanitize the SRV lookup result" do
46
- avatar = Libravatar.new
47
- assert_equal ["hosntame.abcde.fghi.com", 12345], avatar.send(:sanitize_srv_lookup, "hosntame.abcde.fghi.com", 12345)
48
- assert_equal [nil, nil], avatar.send(:sanitize_srv_lookup, "FNORD IMPUNTK *#(*$#&", 65348283)
49
- end
50
- end