warden-github 1.3.1 → 1.3.2

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: c67b01bbd594201720d597739d548d7d3cdfa0f1
4
- data.tar.gz: d2579092f8f208ad1595601bd64b9d1a830a3c79
3
+ metadata.gz: 3157cb993681be8dafe7f2a76c0b6c93594dff58
4
+ data.tar.gz: abfe1e6a32e6d7230c6d5c63911b40773fdc71e7
5
5
  SHA512:
6
- metadata.gz: 770c694827a511d2184f716bc2815f841ca0030425069d4ec44cdcfafde8951a0ee1d4e4a4986af7a9f20bc32534346e9e30f5832be0f2bcaaa6c53eabb9e986
7
- data.tar.gz: e4b0dc2d35df3101eb3537dd734a1b6ec29a5b578856ae41eca29613d6dd4a60b5fb12bd8e6fabd3e7a524d590c615978c3abaf9405d99849109cad39f53dafe
6
+ metadata.gz: 5310d52b3c309bbaa4e5879762907a5ce687ba58425c0bc1a73f7a29b6b6453f2799d3ab4b0cfd0ba76680637be243d2cfbe695c16c45cac39f9e2f53cf27124
7
+ data.tar.gz: 6f9bb9279df04d8c2ce3e903537fe9ccfb73f9f250f63789d0c6b0056cc48f2cdc616893d8df1319fe588f5837538fae8778c2c462f584864ce8db470d0f2cf6
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.0
3
+ - 2.4.1
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'debugger', :platforms => :ruby_19, :require => false
4
- gem 'ruby-debug', :platforms => :ruby_18, :require => false
3
+ gem 'byebug', require: false
5
4
 
6
5
  # Specify your gem's dependencies in warden-github.gemspec
7
6
  gemspec
data/README.md CHANGED
@@ -48,11 +48,11 @@ use Warden::Manager do |config|
48
48
  config.failure_app = BadAuthentication
49
49
  config.default_strategies :github
50
50
 
51
- config.scope_defaults :default, :config => { :scope => 'user:email' }
52
- config.scope_defaults :admin, :config => { :client_id => 'foobar',
53
- :client_secret => 'barfoo',
54
- :scope => 'user,repo',
55
- :redirect_uri => '/admin/oauth/callback' }
51
+ config.scope_defaults :default, config: { scope: 'user:email' }
52
+ config.scope_defaults :admin, config: { client_id: 'foobar',
53
+ client_secret: 'barfoo',
54
+ scope: 'user,repo',
55
+ redirect_uri: '/admin/oauth/callback' }
56
56
 
57
57
  config.serialize_from_session { |key| Warden::GitHub::Verifier.load(key) }
58
58
  config.serialize_into_session { |user| Warden::GitHub::Verifier.dump(user) }
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems/specification'
3
3
  require 'date'
4
4
  require 'bundler'
5
5
 
6
- task :default => [:spec]
6
+ task default: [:spec]
7
7
 
8
8
  require 'rspec/core/rake_task'
9
9
  desc "Run specs"
@@ -5,15 +5,15 @@ module Example
5
5
  enable :inline_templates
6
6
 
7
7
  GITHUB_CONFIG = {
8
- :client_id => ENV['GITHUB_CLIENT_ID'] || 'test_client_id',
9
- :client_secret => ENV['GITHUB_CLIENT_SECRET'] || 'test_client_secret'
8
+ client_id: ENV['GITHUB_CLIENT_ID'] || 'test_client_id',
9
+ client_secret: ENV['GITHUB_CLIENT_SECRET'] || 'test_client_secret'
10
10
  }
11
11
 
12
12
  use Warden::Manager do |config|
13
13
  config.failure_app = BadAuthentication
14
14
  config.default_strategies :github
15
- config.scope_defaults :default, :config => GITHUB_CONFIG
16
- config.scope_defaults :admin, :config => GITHUB_CONFIG.merge(:scope => 'user,notifications')
15
+ config.scope_defaults :default, config: GITHUB_CONFIG
16
+ config.scope_defaults :admin, config: GITHUB_CONFIG.merge(scope: 'user,notifications')
17
17
  end
18
18
 
19
19
  get '/' do
@@ -26,7 +26,7 @@ module Example
26
26
  end
27
27
 
28
28
  get '/admin/login' do
29
- env['warden'].authenticate!(:scope => :admin)
29
+ env['warden'].authenticate!(scope: :admin)
30
30
  redirect '/'
31
31
  end
32
32
 
@@ -7,15 +7,15 @@ module Example
7
7
  enable :inline_templates
8
8
 
9
9
  GITHUB_CONFIG = {
10
- :client_id => ENV['GITHUB_CLIENT_ID'] || 'test_client_id',
11
- :client_secret => ENV['GITHUB_CLIENT_SECRET'] || 'test_client_secret',
12
- :scope => 'user'
10
+ client_id: ENV['GITHUB_CLIENT_ID'] || 'test_client_id',
11
+ client_secret: ENV['GITHUB_CLIENT_SECRET'] || 'test_client_secret',
12
+ scope: 'user'
13
13
  }
14
14
 
15
15
  use Warden::Manager do |config|
16
16
  config.failure_app = BadAuthentication
17
17
  config.default_strategies :github
18
- config.scope_defaults :default, :config => GITHUB_CONFIG
18
+ config.scope_defaults :default, config: GITHUB_CONFIG
19
19
  config.serialize_from_session { |key| Warden::GitHub::Verifier.load(key) }
20
20
  config.serialize_into_session { |user| Warden::GitHub::Verifier.dump(user) }
21
21
  end
@@ -43,10 +43,10 @@ module Warden
43
43
  #
44
44
  # # This configures an additional scope that uses the github strategy
45
45
  # # with custom configuration.
46
- # config.scope_defaults :admin, :config => { :client_id => 'foobar',
47
- # :client_secret => 'barfoo',
48
- # :scope => 'user,repo',
49
- # :redirect_uri => '/admin/oauth/callback' }
46
+ # config.scope_defaults :admin, config: { client_id: 'foobar',
47
+ # client_secret: 'barfoo',
48
+ # scope: 'user,repo',
49
+ # redirect_uri: '/admin/oauth/callback' }
50
50
  # end
51
51
  class Config
52
52
  BadConfig = Class.new(StandardError)
@@ -88,10 +88,10 @@ module Warden
88
88
  end
89
89
 
90
90
  def to_hash
91
- { :client_id => client_id,
92
- :client_secret => client_secret,
93
- :redirect_uri => redirect_uri,
94
- :scope => scope }
91
+ { client_id: client_id,
92
+ client_secret: client_secret,
93
+ redirect_uri: redirect_uri,
94
+ scope: scope }
95
95
  end
96
96
 
97
97
  private
@@ -4,3 +4,10 @@ Warden::Manager.after_authentication do |user, auth, opts|
4
4
 
5
5
  strategy.finalize_flow! if strategy.class == Warden::GitHub::Strategy
6
6
  end
7
+
8
+ Warden::Manager.after_set_user do |user, auth, opts|
9
+ if user.is_a?(Warden::GitHub::User)
10
+ session = auth.session(opts.fetch(:scope))
11
+ user.memberships = session[:_memberships] ||= {}
12
+ end
13
+ end
@@ -25,10 +25,10 @@ module Warden
25
25
  def authorize_uri
26
26
  @authorize_uri ||= build_uri(
27
27
  '/login/oauth/authorize',
28
- :client_id => client_id,
29
- :redirect_uri => redirect_uri,
30
- :scope => scope,
31
- :state => state)
28
+ client_id: client_id,
29
+ redirect_uri: redirect_uri,
30
+ scope: scope,
31
+ state: state)
32
32
  end
33
33
 
34
34
  def access_token
@@ -53,9 +53,9 @@ module Warden
53
53
  def access_token_uri
54
54
  @access_token_uri ||= build_uri(
55
55
  '/login/oauth/access_token',
56
- :client_id => client_id,
57
- :client_secret => client_secret,
58
- :code => code)
56
+ client_id: client_id,
57
+ client_secret: client_secret,
58
+ code: code)
59
59
  end
60
60
 
61
61
  def build_uri(path, params)
@@ -92,7 +92,7 @@ module Warden
92
92
 
93
93
  def oauth
94
94
  @oauth ||= OAuth.new(
95
- config.to_hash.merge(:code => params['code'], :state => state))
95
+ config.to_hash.merge(code: params['code'], state: state))
96
96
  end
97
97
 
98
98
  def config
@@ -1,10 +1,12 @@
1
1
  module Warden
2
2
  module GitHub
3
- class User < Struct.new(:attribs, :token, :browser_session_id, :memberships)
3
+ class User < Struct.new(:attribs, :token, :browser_session_id)
4
4
  ATTRIBUTES = %w[id login name gravatar_id avatar_url email company site_admin].freeze
5
5
 
6
+ attr_accessor :memberships
7
+
6
8
  def self.load(access_token, browser_session_id = nil)
7
- api = Octokit::Client.new(:access_token => access_token)
9
+ api = Octokit::Client.new(access_token: access_token)
8
10
  data = { }
9
11
 
10
12
  api.user.to_hash.each do |k,v|
@@ -75,7 +77,7 @@ module Warden
75
77
  def browser_session_valid?(since = 120)
76
78
  return true unless using_single_sign_out?
77
79
  client = api
78
- client.get("/user/sessions/active", :browser_session_id => browser_session_id)
80
+ client.get("/user/sessions/active", browser_session_id: browser_session_id)
79
81
  client.last_response.status == 204
80
82
  rescue Octokit::ServerError # GitHub API unavailable
81
83
  true
@@ -100,7 +102,7 @@ module Warden
100
102
  # Don't cache instance for now because of a ruby marshaling bug present
101
103
  # in MRI 1.9.3 (Bug #7627) that causes instance variables to be
102
104
  # marshaled even when explicitly specifying #marshal_dump.
103
- Octokit::Client.new(:login => login, :access_token => token)
105
+ Octokit::Client.new(login: login, access_token: token)
104
106
  end
105
107
 
106
108
  private
@@ -1,5 +1,5 @@
1
1
  module Warden
2
2
  module GitHub
3
- VERSION = "1.3.1"
3
+ VERSION = "1.3.2"
4
4
  end
5
5
  end
@@ -5,17 +5,17 @@ describe 'OAuth' do
5
5
 
6
6
  def stub_code_for_token_exchange(answer='access_token=the_token')
7
7
  stub_request(:post, 'https://github.com/login/oauth/access_token').
8
- with(:body => hash_including(:code => code)).
9
- to_return(:status => 200, :body => answer)
8
+ with(body: hash_including(code: code)).
9
+ to_return(status: 200, body: answer)
10
10
  end
11
11
 
12
12
  def stub_user_retrieval
13
13
  stub_request(:get, 'https://api.github.com/user').
14
- with(:headers => { 'Authorization' => 'token the_token' }).
14
+ with(headers: { 'Authorization' => 'token the_token' }).
15
15
  to_return(
16
- :status => 200,
17
- :body => File.read('spec/fixtures/user.json'),
18
- :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
16
+ status: 200,
17
+ body: File.read('spec/fixtures/user.json'),
18
+ headers: { 'Content-Type' => 'application/json; charset=utf-8' })
19
19
  end
20
20
 
21
21
  def redirect_uri(response)
@@ -27,12 +27,12 @@ describe 'OAuth' do
27
27
  unauthenticated_response = get '/profile'
28
28
  github_uri = redirect_uri(unauthenticated_response)
29
29
 
30
- github_uri.scheme.should eq 'https'
31
- github_uri.host.should eq 'github.com'
32
- github_uri.path.should eq '/login/oauth/authorize'
33
- github_uri.query_values['client_id'].should =~ /\w+/
34
- github_uri.query_values['state'].should =~ /\w+/
35
- github_uri.query_values['redirect_uri'].should =~ /^http.*\/profile$/
30
+ expect(github_uri.scheme).to eq 'https'
31
+ expect(github_uri.host).to eq 'github.com'
32
+ expect(github_uri.path).to eq '/login/oauth/authorize'
33
+ expect(github_uri.query_values['client_id']).to match(/\w+/)
34
+ expect(github_uri.query_values['state']).to match(/\w+/)
35
+ expect(github_uri.query_values['redirect_uri']).to match(/^http.*\/profile$/)
36
36
  end
37
37
  end
38
38
 
@@ -53,8 +53,8 @@ describe 'OAuth' do
53
53
  get '/login'
54
54
  response = get "/login?code=#{code}&state=foobar"
55
55
 
56
- response.should_not be_successful
57
- response.body.should include 'State mismatch'
56
+ expect(response).not_to be_successful
57
+ expect(response.body).to include 'State mismatch'
58
58
  end
59
59
  end
60
60
 
@@ -67,8 +67,8 @@ describe 'OAuth' do
67
67
  state = github_uri.query_values['state']
68
68
  response = get "/login?code=#{code}&state=#{state}"
69
69
 
70
- response.should_not be_successful
71
- response.body.should include 'Bad verification code'
70
+ expect(response).not_to be_successful
71
+ expect(response.body).to include 'Bad verification code'
72
72
  end
73
73
  end
74
74
 
@@ -79,8 +79,8 @@ describe 'OAuth' do
79
79
  state = github_uri.query_values['state']
80
80
  response = get "/login?error=access_denied&state=#{state}"
81
81
 
82
- response.should_not be_successful
83
- response.body.should include 'access denied'
82
+ expect(response).not_to be_successful
83
+ expect(response.body).to include 'access denied'
84
84
  end
85
85
  end
86
86
 
@@ -96,8 +96,8 @@ describe 'OAuth' do
96
96
  callback_response = get "/profile?code=#{code}&state=#{state}"
97
97
  authenticated_uri = redirect_uri(callback_response)
98
98
 
99
- authenticated_uri.path.should eq '/profile'
100
- authenticated_uri.query.should eq 'foo=bar'
99
+ expect(authenticated_uri.path).to eq '/profile'
100
+ expect(authenticated_uri.query).to eq 'foo=bar'
101
101
  end
102
102
  end
103
103
 
@@ -113,8 +113,8 @@ describe 'OAuth' do
113
113
  callback_response = get "/profile?code=#{code}&state=#{state}&browser_session_id=abcdefghijklmnop"
114
114
  authenticated_uri = redirect_uri(callback_response)
115
115
 
116
- authenticated_uri.path.should eq '/profile'
117
- authenticated_uri.query.should eq 'foo=bar'
116
+ expect(authenticated_uri.path).to eq '/profile'
117
+ expect(authenticated_uri.query).to eq 'foo=bar'
118
118
  end
119
119
  end
120
120
  end
@@ -123,8 +123,8 @@ describe 'OAuth' do
123
123
  it 'does not recognize a seeming callback url as an actual callback' do
124
124
  response = get '/profile?state=foo&code=bar'
125
125
 
126
- a_request(:post, 'https://github.com/login/oauth/access_token').
127
- should have_not_been_made
126
+ expect(a_request(:post, 'https://github.com/login/oauth/access_token')).
127
+ to have_not_been_made
128
128
  end
129
129
  end
130
130
 
@@ -142,7 +142,7 @@ describe 'OAuth' do
142
142
  get authenticated_uri.path
143
143
  logged_in_response = get '/login'
144
144
 
145
- redirect_uri(logged_in_response).path.should eq '/'
145
+ expect(redirect_uri(logged_in_response).path).to eq '/'
146
146
  end
147
147
  end
148
148
  end
@@ -19,6 +19,6 @@ RSpec.configure do |config|
19
19
 
20
20
  def stub_user_session_request
21
21
  stub_request(:get, "https://api.github.com/user/sessions/active?browser_session_id=abcdefghijklmnop").
22
- with(:headers => {'Accept'=>'application/vnd.github.v3+json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'token the_token', 'Content-Type'=>'application/json', 'User-Agent'=>"Octokit Ruby Gem #{Octokit::VERSION}"})
22
+ with(headers: {'Accept'=>'application/vnd.github.v3+json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'token the_token', 'Content-Type'=>'application/json', 'User-Agent'=>"Octokit Ruby Gem #{Octokit::VERSION}"})
23
23
  end
24
24
  end
@@ -4,11 +4,11 @@ describe Warden::GitHub::Config do
4
4
  let(:warden_scope) { :test_scope }
5
5
 
6
6
  let(:env) do
7
- { 'warden' => double(:config => warden_config) }
7
+ { 'warden' => double(config: warden_config) }
8
8
  end
9
9
 
10
10
  let(:warden_config) do
11
- { :scope_defaults => { warden_scope => { :config => scope_config } } }
11
+ { scope_defaults: { warden_scope => { config: scope_config } } }
12
12
  end
13
13
 
14
14
  let(:scope_config) do
@@ -16,7 +16,7 @@ describe Warden::GitHub::Config do
16
16
  end
17
17
 
18
18
  let(:request) do
19
- double(:url => 'http://example.com/the/path', :path => '/the/path')
19
+ double(url: 'http://example.com/the/path', path: '/the/path')
20
20
  end
21
21
 
22
22
  subject(:config) do
@@ -24,7 +24,7 @@ describe Warden::GitHub::Config do
24
24
  end
25
25
 
26
26
  before do
27
- config.stub(:request => request)
27
+ allow(config).to receive_messages(request: request)
28
28
  end
29
29
 
30
30
  def silence_warnings
@@ -38,7 +38,7 @@ describe Warden::GitHub::Config do
38
38
  context 'when specified in scope config' do
39
39
  it 'returns the client id' do
40
40
  scope_config[:client_id] = 'foobar'
41
- config.client_id.should eq 'foobar'
41
+ expect(config.client_id).to eq 'foobar'
42
42
  end
43
43
  end
44
44
 
@@ -46,15 +46,15 @@ describe Warden::GitHub::Config do
46
46
  it 'returns the client id' do
47
47
  warden_config[:github_client_id] = 'foobar'
48
48
  silence_warnings do
49
- config.client_id.should eq 'foobar'
49
+ expect(config.client_id).to eq 'foobar'
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  context 'when specified in ENV' do
55
55
  it 'returns the client id' do
56
- ENV.stub(:[]).with('GITHUB_CLIENT_ID').and_return('foobar')
57
- config.client_id.should eq 'foobar'
56
+ allow(ENV).to receive(:[]).with('GITHUB_CLIENT_ID').and_return('foobar')
57
+ expect(config.client_id).to eq 'foobar'
58
58
  end
59
59
  end
60
60
 
@@ -69,7 +69,7 @@ describe Warden::GitHub::Config do
69
69
  context 'when specified in scope config' do
70
70
  it 'returns the client secret' do
71
71
  scope_config[:client_secret] = 'foobar'
72
- config.client_secret.should eq 'foobar'
72
+ expect(config.client_secret).to eq 'foobar'
73
73
  end
74
74
  end
75
75
 
@@ -77,16 +77,16 @@ describe Warden::GitHub::Config do
77
77
  it 'returns the client secret' do
78
78
  warden_config[:github_secret] = 'foobar'
79
79
  silence_warnings do
80
- config.client_secret.should eq 'foobar'
80
+ expect(config.client_secret).to eq 'foobar'
81
81
  end
82
82
  end
83
83
  end
84
84
 
85
85
  context 'when specified in ENV' do
86
86
  it 'returns the client secret' do
87
- ENV.stub(:[]).with('GITHUB_CLIENT_SECRET').and_return('foobar')
87
+ allow(ENV).to receive(:[]).with('GITHUB_CLIENT_SECRET').and_return('foobar')
88
88
  silence_warnings do
89
- config.client_secret.should eq 'foobar'
89
+ expect(config.client_secret).to eq 'foobar'
90
90
  end
91
91
  end
92
92
  end
@@ -102,14 +102,14 @@ describe Warden::GitHub::Config do
102
102
  context 'when specified in scope config' do
103
103
  it 'returns the expanded redirect uri' do
104
104
  scope_config[:redirect_uri] = '/callback'
105
- config.redirect_uri.should eq 'http://example.com/callback'
105
+ expect(config.redirect_uri).to eq 'http://example.com/callback'
106
106
  end
107
107
  end
108
108
 
109
109
  context 'when specified path lacks leading slash' do
110
110
  it 'corrects the path and returns the expanded uri' do
111
111
  scope_config[:redirect_uri] = 'callback'
112
- config.redirect_uri.should eq 'http://example.com/callback'
112
+ expect(config.redirect_uri).to eq 'http://example.com/callback'
113
113
  end
114
114
  end
115
115
 
@@ -117,40 +117,40 @@ describe Warden::GitHub::Config do
117
117
  it 'returns the expanded redirect uri' do
118
118
  warden_config[:github_callback_url] = '/callback'
119
119
  silence_warnings do
120
- config.redirect_uri.should eq 'http://example.com/callback'
120
+ expect(config.redirect_uri).to eq 'http://example.com/callback'
121
121
  end
122
122
  end
123
123
  end
124
124
 
125
125
  context 'when not specified' do
126
126
  it 'returns the expanded redirect uri with the current path' do
127
- config.redirect_uri.should eq 'http://example.com/the/path'
127
+ expect(config.redirect_uri).to eq 'http://example.com/the/path'
128
128
  end
129
129
  end
130
130
 
131
131
  context 'when HTTP_X_FORWARDED_PROTO is set to https' do
132
132
  it 'returns the expanded redirect uri(with port) with adjusted scheme' do
133
133
  env['HTTP_X_FORWARDED_PROTO'] = 'https'
134
- request.stub(:url => 'http://example.com:443/the/path')
135
- config.redirect_uri.should eq 'https://example.com/the/path'
134
+ allow(request).to receive_messages(url: 'http://example.com:443/the/path')
135
+ expect(config.redirect_uri).to eq 'https://example.com/the/path'
136
136
  end
137
137
 
138
138
  it 'returns the expanded redirect uri with adjusted scheme including port 80' do
139
139
  env['HTTP_X_FORWARDED_PROTO'] = 'https'
140
- request.stub(:url => 'http://example.com:80/the/path')
141
- config.redirect_uri.should eq 'https://example.com/the/path'
140
+ allow(request).to receive_messages(url: 'http://example.com:80/the/path')
141
+ expect(config.redirect_uri).to eq 'https://example.com/the/path'
142
142
  end
143
143
 
144
144
  it 'returns the expanded redirect uri with adjusted scheme including port 80 with multiple forwarded protocols' do
145
145
  env['HTTP_X_FORWARDED_PROTO'] = 'https,https'
146
- request.stub(:url => 'https://example.com:80/the/path')
147
- config.redirect_uri.should eq 'https://example.com/the/path'
146
+ allow(request).to receive_messages(url: 'https://example.com:80/the/path')
147
+ expect(config.redirect_uri).to eq 'https://example.com/the/path'
148
148
  end
149
149
 
150
150
  it 'returns the expanded redirect uri(without port) with adjusted scheme' do
151
151
  env['HTTP_X_FORWARDED_PROTO'] = 'https'
152
- request.stub(:url => 'http://example.com/the/path')
153
- config.redirect_uri.should eq 'https://example.com/the/path'
152
+ allow(request).to receive_messages(url: 'http://example.com/the/path')
153
+ expect(config.redirect_uri).to eq 'https://example.com/the/path'
154
154
  end
155
155
  end
156
156
  end
@@ -159,7 +159,7 @@ describe Warden::GitHub::Config do
159
159
  context 'when specified in scope config' do
160
160
  it 'returns the client secret' do
161
161
  scope_config[:scope] = 'user'
162
- config.scope.should eq 'user'
162
+ expect(config.scope).to eq 'user'
163
163
  end
164
164
  end
165
165
 
@@ -167,14 +167,14 @@ describe Warden::GitHub::Config do
167
167
  it 'returns the client secret' do
168
168
  warden_config[:github_scopes] = 'user'
169
169
  silence_warnings do
170
- config.scope.should eq 'user'
170
+ expect(config.scope).to eq 'user'
171
171
  end
172
172
  end
173
173
  end
174
174
 
175
175
  context 'when not specified' do
176
176
  it 'returns nil' do
177
- config.scope.should be_nil
177
+ expect(config.scope).to be_nil
178
178
  end
179
179
  end
180
180
  end
@@ -182,13 +182,13 @@ describe Warden::GitHub::Config do
182
182
  describe '#to_hash' do
183
183
  it 'includes all configs' do
184
184
  scope_config.merge!(
185
- :scope => 'user',
186
- :client_id => 'abc',
187
- :client_secret => '123',
188
- :redirect_uri => '/foo')
185
+ scope: 'user',
186
+ client_id: 'abc',
187
+ client_secret: '123',
188
+ redirect_uri: '/foo')
189
189
 
190
- config.to_hash.keys.
191
- should =~ [:scope, :client_id, :client_secret, :redirect_uri]
190
+ expect(config.to_hash.keys).
191
+ to match_array([:scope, :client_id, :client_secret, :redirect_uri])
192
192
  end
193
193
  end
194
194
  end
@@ -4,7 +4,7 @@ describe Warden::GitHub::MembershipCache do
4
4
  describe '#fetch_membership' do
5
5
  it 'returns false by default' do
6
6
  cache = described_class.new({})
7
- cache.fetch_membership('foo', 'bar').should be_falsey
7
+ expect(cache.fetch_membership('foo', 'bar')).to be_falsey
8
8
  end
9
9
 
10
10
  context 'when cache valid' do
@@ -15,7 +15,7 @@ describe Warden::GitHub::MembershipCache do
15
15
  end
16
16
 
17
17
  it 'returns true' do
18
- cache.fetch_membership('foo', 'bar').should be_truthy
18
+ expect(cache.fetch_membership('foo', 'bar')).to be_truthy
19
19
  end
20
20
 
21
21
  it 'does not invoke the block' do
@@ -24,7 +24,7 @@ describe Warden::GitHub::MembershipCache do
24
24
  end
25
25
 
26
26
  it 'converts type and id to strings' do
27
- cache.fetch_membership(:foo, :bar).should be_truthy
27
+ expect(cache.fetch_membership(:foo, :bar)).to be_truthy
28
28
  end
29
29
  end
30
30
 
@@ -37,7 +37,7 @@ describe Warden::GitHub::MembershipCache do
37
37
 
38
38
  context 'when no block given' do
39
39
  it 'returns false' do
40
- cache.fetch_membership('foo', 'bar').should be_falsey
40
+ expect(cache.fetch_membership('foo', 'bar')).to be_falsey
41
41
  end
42
42
  end
43
43
 
@@ -50,13 +50,13 @@ describe Warden::GitHub::MembershipCache do
50
50
  it 'caches the value when block returns true' do
51
51
  cache = described_class.new({})
52
52
  cache.fetch_membership('foo', 'bar') { true }
53
- cache.fetch_membership('foo', 'bar').should be_truthy
53
+ expect(cache.fetch_membership('foo', 'bar')).to be_truthy
54
54
  end
55
55
 
56
56
  it 'does not cache the value when block returns false' do
57
57
  cache = described_class.new({})
58
58
  cache.fetch_membership('foo', 'bar') { false }
59
- cache.fetch_membership('foo', 'bar').should be_falsey
59
+ expect(cache.fetch_membership('foo', 'bar')).to be_falsey
60
60
  end
61
61
  end
62
62
 
@@ -71,8 +71,8 @@ describe Warden::GitHub::MembershipCache do
71
71
  cache = described_class.new(hash)
72
72
 
73
73
  # Verify that existing data in the hash is used:
74
- expect(cache.fetch_membership('foo', 'valid')).to be_true
75
- expect(cache.fetch_membership('foo', 'timedout')).to be_false
74
+ expect(cache.fetch_membership('foo', 'valid')).to be(true)
75
+ expect(cache.fetch_membership('foo', 'timedout')).to be(false)
76
76
 
77
77
  # Add new data to the hash:
78
78
  cache.fetch_membership('foo', 'new') { true }
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Warden::GitHub::OAuth do
4
4
  let(:default_attrs) do
5
- { :state => 'abc',
6
- :client_id => 'foo',
7
- :client_secret => 'bar',
8
- :redirect_uri => 'http://example.com/callback' }
5
+ { state: 'abc',
6
+ client_id: 'foo',
7
+ client_secret: 'bar',
8
+ redirect_uri: 'http://example.com/callback' }
9
9
  end
10
10
 
11
11
  def oauth(attrs=default_attrs)
@@ -14,7 +14,7 @@ describe Warden::GitHub::OAuth do
14
14
 
15
15
  describe '#authorize_uri' do
16
16
  it 'contains the base uri' do
17
- oauth.authorize_uri.to_s.should \
17
+ expect(oauth.authorize_uri.to_s).to \
18
18
  include Octokit.web_endpoint
19
19
  end
20
20
 
@@ -22,15 +22,15 @@ describe Warden::GitHub::OAuth do
22
22
  it "contains the correct #{name} param" do
23
23
  uri = Addressable::URI.parse(oauth.authorize_uri)
24
24
 
25
- uri.query_values[name].should eq default_attrs[name.to_sym]
25
+ expect(uri.query_values[name]).to eq default_attrs[name.to_sym]
26
26
  end
27
27
  end
28
28
 
29
- { :nil => nil, :empty => '' }.each do |desc, value|
29
+ { nil: nil, empty: '' }.each do |desc, value|
30
30
  it "does not contain the scope param if #{desc}" do
31
- uri = oauth(default_attrs.merge(:scope => value)).authorize_uri
31
+ uri = oauth(default_attrs.merge(scope: value)).authorize_uri
32
32
 
33
- uri.to_s.should_not include 'scope'
33
+ expect(uri.to_s).not_to include 'scope'
34
34
  end
35
35
  end
36
36
  end
@@ -38,19 +38,19 @@ describe Warden::GitHub::OAuth do
38
38
  describe '#access_token' do
39
39
  def expect_request(attrs={})
40
40
  stub_request(:post, %r{\/login\/oauth\/access_token$}).
41
- with(:body => hash_including(attrs.fetch(:params, {}))).
42
- to_return(:status => 200,
43
- :body => attrs.fetch(:answer, 'access_token=foobar'))
41
+ with(body: hash_including(attrs.fetch(:params, {}))).
42
+ to_return(status: 200,
43
+ body: attrs.fetch(:answer, 'access_token=foobar'))
44
44
  end
45
45
 
46
46
  it 'exchanges the code for an access token' do
47
- expect_request(:answer => 'access_token=the_token&token_type=bearer')
47
+ expect_request(answer: 'access_token=the_token&token_type=bearer')
48
48
 
49
- oauth.access_token.should eq 'the_token'
49
+ expect(oauth.access_token).to eq 'the_token'
50
50
  end
51
51
 
52
52
  it 'raises BadVerificationCode if no access token is returned' do
53
- expect_request(:answer => 'error=bad_verification_code')
53
+ expect_request(answer: 'error=bad_verification_code')
54
54
 
55
55
  expect { oauth.access_token }.
56
56
  to raise_error(described_class::BadVerificationCode)
@@ -58,8 +58,8 @@ describe Warden::GitHub::OAuth do
58
58
 
59
59
  %w[ client_id client_secret code ].each do |name|
60
60
  it "performs a request containing the correct #{name} param" do
61
- oauth(default_attrs.merge(:code => 'the_code')).tap do |o|
62
- expect_request(:params => { name => o.send(name) })
61
+ oauth(default_attrs.merge(code: 'the_code')).tap do |o|
62
+ expect_request(params: { name => o.send(name) })
63
63
  o.access_token
64
64
  end
65
65
  end
@@ -28,15 +28,15 @@ describe Warden::GitHub::SSO do
28
28
  describe "warden_github_sso_session_valid?" do
29
29
  it "identifies when browsers need to be reverified" do
30
30
  subject.session[:warden_github_sso_session_verified_at] = Time.now.utc.to_i - 10
31
- subject.should be_warden_github_sso_session_valid(user)
31
+ expect(subject).to be_warden_github_sso_session_valid(user)
32
32
 
33
33
  subject.session[:warden_github_sso_session_verified_at] = Time.now.utc.to_i - 300
34
- stub_user_session_request.to_return(:status => 204, :body => "", :headers => {})
35
- subject.should be_warden_github_sso_session_valid(user)
34
+ stub_user_session_request.to_return(status: 204, body: "", headers: {})
35
+ expect(subject).to be_warden_github_sso_session_valid(user)
36
36
 
37
37
  subject.session[:warden_github_sso_session_verified_at] = Time.now.utc.to_i - 300
38
- stub_user_session_request.to_return(:status => 404, :body => "", :headers => {})
39
- subject.should_not be_warden_github_sso_session_valid(user)
38
+ stub_user_session_request.to_return(status: 404, body: "", headers: {})
39
+ expect(subject).not_to be_warden_github_sso_session_valid(user)
40
40
  end
41
41
  end
42
42
  end
@@ -21,14 +21,14 @@ describe Warden::GitHub::User do
21
21
 
22
22
  describe '#token' do
23
23
  it 'returns the token' do
24
- user.token.should eq token
24
+ expect(user.token).to eq token
25
25
  end
26
26
  end
27
27
 
28
28
  %w[login name gravatar_id avatar_url email company].each do |name|
29
29
  describe "##{name}" do
30
30
  it "returns the #{name}" do
31
- user.send(name).should eq default_attrs[name]
31
+ expect(user.send(name)).to eq default_attrs[name]
32
32
  end
33
33
  end
34
34
  end
@@ -37,16 +37,16 @@ describe Warden::GitHub::User do
37
37
  it 'returns a preconfigured Octokit client for the user' do
38
38
  api = user.api
39
39
 
40
- api.should be_an Octokit::Client
41
- api.login.should eq user.login
42
- api.access_token.should eq user.token
40
+ expect(api).to be_an Octokit::Client
41
+ expect(api.login).to eq user.login
42
+ expect(api.access_token).to eq user.token
43
43
  end
44
44
  end
45
45
 
46
46
  def stub_api(user, method, args, ret)
47
47
  api = double
48
- user.stub(:api => api)
49
- api.should_receive(method).with(*args).and_return(ret)
48
+ allow(user).to receive_messages(api: api)
49
+ expect(api).to receive(method).with(*args).and_return(ret)
50
50
  end
51
51
 
52
52
  [:organization_public_member?, :organization_member?].each do |method|
@@ -54,14 +54,14 @@ describe Warden::GitHub::User do
54
54
  context 'when user is not member' do
55
55
  it 'returns false' do
56
56
  stub_api(user, method, ['rails', user.login], false)
57
- user.send(method, 'rails').should be_falsey
57
+ expect(user.send(method, 'rails')).to be_falsey
58
58
  end
59
59
  end
60
60
 
61
61
  context 'when user is member' do
62
62
  it 'returns true' do
63
63
  stub_api(user, method, ['rails', user.login], true)
64
- user.send(method, 'rails').should be_truthy
64
+ expect(user.send(method, 'rails')).to be_truthy
65
65
  end
66
66
  end
67
67
  end
@@ -71,21 +71,21 @@ describe Warden::GitHub::User do
71
71
  context 'when user is not member' do
72
72
  it 'returns false' do
73
73
  api = double()
74
- user.stub(:api => api)
74
+ allow(user).to receive_messages(api: api)
75
75
 
76
- api.stub(:team_member?).with(123, user.login).and_return(false)
76
+ allow(api).to receive(:team_member?).with(123, user.login).and_return(false)
77
77
 
78
- user.should_not be_team_member(123)
78
+ expect(user).not_to be_team_member(123)
79
79
  end
80
80
  end
81
81
 
82
82
  context 'when user is member' do
83
83
  it 'returns true' do
84
84
  api = double()
85
- user.stub(:api => api)
86
- api.stub(:team_member?).with(123, user.login).and_return(true)
85
+ allow(user).to receive_messages(api: api)
86
+ allow(api).to receive(:team_member?).with(123, user.login).and_return(true)
87
87
 
88
- user.should be_team_member(123)
88
+ expect(user).to be_team_member(123)
89
89
  end
90
90
  end
91
91
  end
@@ -95,49 +95,49 @@ describe Warden::GitHub::User do
95
95
  client = double
96
96
  attrs = {}
97
97
 
98
- Octokit::Client.
99
- should_receive(:new).
100
- with(:access_token => token).
98
+ expect(Octokit::Client).
99
+ to receive(:new).
100
+ with(access_token: token).
101
101
  and_return(client)
102
- client.should_receive(:user).and_return(attrs)
102
+ expect(client).to receive(:user).and_return(attrs)
103
103
 
104
104
  user = described_class.load(token)
105
105
 
106
- user.attribs.should eq attrs
107
- user.token.should eq token
106
+ expect(user.attribs).to eq attrs
107
+ expect(user.token).to eq token
108
108
  end
109
109
  end
110
110
 
111
111
  # NOTE: This always passes on MRI 1.9.3 because of ruby bug #7627.
112
112
  it 'marshals correctly' do
113
- Marshal.load(Marshal.dump(user)).should eq user
113
+ expect(Marshal.load(Marshal.dump(user))).to eq user
114
114
  end
115
115
 
116
116
  describe 'single sign out' do
117
117
  it "knows if the user is using single sign out" do
118
- user.should_not be_using_single_sign_out
119
- sso_user.should be_using_single_sign_out
118
+ expect(user).not_to be_using_single_sign_out
119
+ expect(sso_user).to be_using_single_sign_out
120
120
  end
121
121
 
122
122
  context "browser reverification" do
123
123
  it "handles success" do
124
- stub_user_session_request.to_return(:status => 204, :body => "", :headers => {})
125
- sso_user.should be_browser_session_valid
124
+ stub_user_session_request.to_return(status: 204, body: "", headers: {})
125
+ expect(sso_user).to be_browser_session_valid
126
126
  end
127
127
 
128
128
  it "handles failure" do
129
- stub_user_session_request.to_return(:status => 404, :body => "", :headers => {})
130
- sso_user.should_not be_browser_session_valid
129
+ stub_user_session_request.to_return(status: 404, body: "", headers: {})
130
+ expect(sso_user).not_to be_browser_session_valid
131
131
  end
132
132
 
133
133
  it "handles GitHub being unavailable" do
134
134
  stub_user_session_request.to_raise(Octokit::ServerError.new)
135
- sso_user.should be_browser_session_valid
135
+ expect(sso_user).to be_browser_session_valid
136
136
  end
137
137
 
138
138
  it "handles authentication failures" do
139
- stub_user_session_request.to_return(:status => 403, :body => "", :headers => {})
140
- sso_user.should_not be_browser_session_valid
139
+ stub_user_session_request.to_return(status: 403, body: "", headers: {})
140
+ expect(sso_user).not_to be_browser_session_valid
141
141
  end
142
142
  end
143
143
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_development_dependency "rack", "~>1.4.1"
22
22
  s.add_development_dependency "rake"
23
- s.add_development_dependency "rspec", "~>2.8"
23
+ s.add_development_dependency "rspec", "~>3.6"
24
24
  s.add_development_dependency "simplecov"
25
25
  s.add_development_dependency "webmock", "~>1.9"
26
26
  s.add_development_dependency "sinatra"
metadata CHANGED
@@ -1,195 +1,195 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Donohoe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-16 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: warden
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">"
17
+ - - '>'
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">"
24
+ - - '>'
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: octokit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">"
31
+ - - '>'
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">"
38
+ - - '>'
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">"
45
+ - - '>'
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">"
52
+ - - '>'
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.4.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.4.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '2.8'
89
+ version: '3.6'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '2.8'
96
+ version: '3.6'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: webmock
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
117
  version: '1.9'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.9'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: sinatra
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: shotgun
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: addressable
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">"
157
+ - - '>'
158
158
  - !ruby/object:Gem::Version
159
159
  version: 2.2.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">"
164
+ - - '>'
165
165
  - !ruby/object:Gem::Version
166
166
  version: 2.2.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rack-test
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - "~>"
171
+ - - ~>
172
172
  - !ruby/object:Gem::Version
173
173
  version: 0.5.3
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - "~>"
178
+ - - ~>
179
179
  - !ruby/object:Gem::Version
180
180
  version: 0.5.3
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: yajl-ruby
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ">="
185
+ - - '>='
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ">="
192
+ - - '>='
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  description: A warden strategy for easy oauth integration with github
@@ -199,9 +199,9 @@ executables: []
199
199
  extensions: []
200
200
  extra_rdoc_files: []
201
201
  files:
202
- - ".gitignore"
203
- - ".rspec"
204
- - ".travis.yml"
202
+ - .gitignore
203
+ - .rspec
204
+ - .travis.yml
205
205
  - CHANGELOG.md
206
206
  - Gemfile
207
207
  - LICENSE.md
@@ -240,17 +240,17 @@ require_paths:
240
240
  - lib
241
241
  required_ruby_version: !ruby/object:Gem::Requirement
242
242
  requirements:
243
- - - ">="
243
+ - - '>='
244
244
  - !ruby/object:Gem::Version
245
245
  version: '0'
246
246
  required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - ">="
248
+ - - '>='
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
251
  requirements: []
252
252
  rubyforge_project: warden-github
253
- rubygems_version: 2.5.1
253
+ rubygems_version: 2.0.14.1
254
254
  signing_key:
255
255
  specification_version: 4
256
256
  summary: A warden strategy for easy oauth integration with github