ginjo-omniauth-slack 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ ### JSON response from v2 OAUTH2 user_scope request ###
2
+
3
+ {
4
+ "enterprise" : null,
5
+ "ok" : true,
6
+ "team" : {
7
+ "id" : "T0BXXXXXX"
8
+ },
9
+ "authed_user" : {
10
+ "scope" : "identity.basic,identity.email,identity.avatar,identity.team",
11
+ "id" : "U0BXXXXXX",
12
+ "token_type" : "user",
13
+ "access_token" : "xoxp-111111111111-22222222222-3333333333333-fa39d45841fa1daab3a98f945a133d02"
14
+ },
15
+ "app_id" : "A0XXXXXXXXX"
16
+ }
@@ -0,0 +1,25 @@
1
+ ---
2
+ !ruby/hash:OmniAuth::AuthHash
3
+ app_home: !ruby/array:Hashie::Array
4
+ - chat:write
5
+ - im:history
6
+ - im:read
7
+ team: !ruby/array:Hashie::Array []
8
+ channel: !ruby/array:Hashie::Array
9
+ - channels:history
10
+ - channels:read
11
+ - chat:write
12
+ group: !ruby/array:Hashie::Array
13
+ - chat:write
14
+ mpim: !ruby/array:Hashie::Array
15
+ - chat:write
16
+ im: !ruby/array:Hashie::Array
17
+ - chat:write
18
+ identity: !ruby/array:Hashie::Array
19
+ - identity.avatar:read:user
20
+ - identity.email:read:user
21
+ - identity.team:read:user
22
+ - identity:read:user
23
+ classic: !ruby/array:Hashie::Array
24
+ - identify
25
+ - channels:read
@@ -16,16 +16,6 @@ module OAuth2StrategyTests
16
16
  @options = { :client_options => { "authorize_url" => "https://example.com" } }
17
17
  assert_equal "https://example.com", strategy.client.options[:authorize_url]
18
18
  end
19
-
20
- test "should transfer team_domain from options to client.site uri" do
21
- @options = { :team_domain => 'subdomain' }
22
- assert_equal "https://subdomain.slack.com", strategy.client.site
23
- end
24
-
25
- test "should transfer team_domain from request.params to client.site uri" do
26
- @request.stubs(:params).returns({ 'team_domain' => 'subdomain2' })
27
- assert_equal "https://subdomain2.slack.com", strategy.client.site
28
- end
29
19
  end
30
20
 
31
21
  module AuthorizeParamsTests
@@ -1,250 +1,2 @@
1
- require 'helper'
2
- require 'omniauth-slack'
1
+ Dir[File.expand_path("../**/*_test.rb", __FILE__)].each(&method(:require))
3
2
 
4
- OmniAuth.logger.level = 1
5
-
6
- class StrategyTest < StrategyTestCase
7
- include OAuth2StrategyTests
8
- end
9
-
10
- class ClientTest < StrategyTestCase
11
- test "has correct Slack site" do
12
- assert_equal "https://slack.com", strategy.client.site
13
- end
14
-
15
- test "has correct authorize url" do
16
- assert_equal "/oauth/authorize", strategy.client.options[:authorize_url]
17
- end
18
-
19
- test "has correct token url" do
20
- assert_equal "/api/oauth.access", strategy.client.options[:token_url]
21
- end
22
-
23
- test "has correct auth_scheme" do
24
- assert_equal :basic_auth, strategy.client.options[:auth_scheme]
25
- end
26
-
27
- test 'request logs api call' do
28
- OAuth2::Client.class_eval do
29
- def request(*args)
30
- {simple: 'hash'}
31
- end
32
- end
33
- @client = strategy.client
34
- OmniAuth.logger.expects(:send).with(){|*params| assert_equal :debug, params[0]}
35
- @client.request(:get, 'http://test-url')
36
- end
37
-
38
- test 'request adds api response to raw_info hash' do
39
- OAuth2::Client.class_eval do
40
- def request(*args)
41
- {simple: 'hash'}
42
- end
43
- end
44
- @client = strategy.client
45
- @client.request(:get, 'http://test-url')
46
- assert_equal( {'test-url' => {simple: 'hash'}}, strategy.send(:raw_info) )
47
- end
48
- end
49
-
50
- class CallbackUrlTest < StrategyTestCase
51
- test "returns the default callback url" do
52
- url_base = "http://auth.request.com"
53
- @request.stubs(:url).returns("#{url_base}/some/page")
54
- strategy.stubs(:script_name).returns("") # as not to depend on Rack env
55
- assert_equal "#{url_base}/auth/slack/callback", strategy.callback_url
56
- end
57
-
58
- test "returns path from callback_path option" do
59
- @options = { :callback_path => "/auth/slack/done"}
60
- url_base = "http://auth.request.com"
61
- @request.stubs(:url).returns("#{url_base}/page/path")
62
- strategy.stubs(:script_name).returns("") # as not to depend on Rack env
63
- assert_equal "#{url_base}/auth/slack/done", strategy.callback_url
64
- end
65
- end
66
-
67
- class UidTest < StrategyTestCase
68
- def setup
69
- super
70
- #strategy.stubs(:identity).returns("user" => {"id" => "U123"}, "team" => {"id" => "T456"})
71
- strategy.stubs(:auth).returns("user" => {"id" => "U123"}, "team" => {"id" => "T456"})
72
- end
73
-
74
- test "returns the user ID from user_identity" do
75
- assert_equal "U123-T456", strategy.uid
76
- end
77
- end
78
-
79
- class CredentialsTest < StrategyTestCase
80
- def setup
81
- super
82
- @access_token = stub("OAuth2::AccessToken")
83
- @access_token.stubs(:token)
84
- @access_token.stubs(:expires?)
85
- @access_token.stubs(:expires_at)
86
- @access_token.stubs(:refresh_token)
87
- @access_token.stubs(:[])
88
- @access_token.stubs(:params)
89
- strategy.stubs(:access_token).returns(@access_token)
90
- end
91
-
92
- test "returns a Hash" do
93
- assert_kind_of Hash, strategy.credentials
94
- end
95
-
96
- test "returns the token" do
97
- @access_token.stubs(:token).returns("123")
98
- assert_equal "123", strategy.credentials["token"]
99
- end
100
-
101
- test "returns the expiry status" do
102
- @access_token.stubs(:expires?).returns(true)
103
- assert strategy.credentials["expires"]
104
-
105
- @access_token.stubs(:expires?).returns(false)
106
- refute strategy.credentials["expires"]
107
- end
108
-
109
- test "returns the refresh token and expiry time when expiring" do
110
- ten_mins_from_now = (Time.now + 600).to_i
111
- @access_token.stubs(:expires?).returns(true)
112
- @access_token.stubs(:refresh_token).returns("321")
113
- @access_token.stubs(:expires_at).returns(ten_mins_from_now)
114
- assert_equal "321", strategy.credentials["refresh_token"]
115
- assert_equal ten_mins_from_now, strategy.credentials["expires_at"]
116
- end
117
-
118
- test "does not return the refresh token when test is nil and expiring" do
119
- @access_token.stubs(:expires?).returns(true)
120
- @access_token.stubs(:refresh_token).returns(nil)
121
- assert_nil strategy.credentials["refresh_token"]
122
- refute_has_key "refresh_token", strategy.credentials
123
- end
124
-
125
- test "does not return the refresh token when not expiring" do
126
- @access_token.stubs(:expires?).returns(false)
127
- @access_token.stubs(:refresh_token).returns("XXX")
128
- assert_nil strategy.credentials["refresh_token"]
129
- refute_has_key "refresh_token", strategy.credentials
130
- end
131
- end
132
-
133
- class IdentityTest < StrategyTestCase
134
-
135
- def setup
136
- super
137
- @access_token = stub("OAuth2::AccessToken")
138
- @access_token.stubs(:[])
139
- @access_token.stubs(:params)
140
- @access_token.stubs(:token)
141
- strategy.stubs(:access_token).returns(@access_token)
142
- strategy.stubs(:has_scope?).returns true
143
- end
144
-
145
- test "performs a GET to https://slack.com/api/users.identity" do
146
- @access_token.expects(:get).with("/api/users.identity", {:headers => {"X-Slack-User" => nil}})
147
- .returns(stub_everything("OAuth2::Response"))
148
- strategy.identity
149
- end
150
-
151
- end
152
-
153
- class SkipInfoTest < StrategyTestCase
154
-
155
- test 'info should not include extended info when skip_info is specified' do
156
- @options = { skip_info: true }
157
- #strategy.stubs(:identity).returns({})
158
- strategy.stubs(:auth).returns({})
159
- assert_equal %w(name email user_id team_name team_id image), strategy.info.keys.map(&:to_s)
160
- end
161
-
162
- end
163
-
164
- class AuthorizeParamsTest < StrategyTestCase
165
-
166
- test 'returns OmniAuth::Strategy::Options hash' do
167
- assert_kind_of OmniAuth::Strategy::Options, strategy.authorize_params
168
- end
169
-
170
- test 'forwards request params (scope, team, redirect_uri) to slack' do
171
- strategy.request.params['scope'] = 'test-scope'
172
- strategy.request.params['team'] = 'test-team'
173
- strategy.request.params['redirect_uri'] = 'http://my-test-uri/auth/callback'
174
- assert_equal 'test-scope', strategy.authorize_params['scope']
175
- assert_equal 'test-team', strategy.authorize_params['team']
176
- assert_equal 'http://my-test-uri/auth/callback', strategy.authorize_params['redirect_uri']
177
- end
178
-
179
- end
180
-
181
- class InitializeTest < StrategyTestCase
182
-
183
- test 'sets @main_semaphore with a new Mutex' do
184
- assert_kind_of Mutex, strategy.instance_variable_get(:@main_semaphore)
185
- end
186
-
187
- test 'sets @semaphores with empty hash' do
188
- assert_equal( {}, strategy.instance_variable_get(:@semaphores) )
189
- end
190
-
191
- end
192
-
193
- class SemaphoreTest < StrategyTestCase
194
-
195
- def setup
196
- super
197
-
198
- def strategy.test_method
199
- send :semaphore
200
- end
201
- end
202
-
203
- test 'synchronized management of method-specific mutexes' do
204
- strategy.test_method
205
- assert_kind_of Mutex, strategy.instance_variable_get(:@semaphores)['test_method']
206
- end
207
-
208
- end
209
-
210
- class ActiveMethodsTest < StrategyTestCase
211
-
212
- test 'with no settings, returns all defined api methods' do
213
- assert_equal %w(apps_permissions_users_list identity user_info user_profile team_info bot_info),
214
- strategy.send(:active_methods)
215
- end
216
-
217
- test 'with :include_data, returns only included methods' do
218
- strategy.options[:include_data] = %w(identity team_info)
219
- assert_equal %w(identity team_info),
220
- strategy.send(:active_methods)
221
- end
222
-
223
- test 'with :exclude_data, returns all but excluded methods' do
224
- strategy.options[:exclude_data] = %w(identity team_info)
225
- assert_equal %w(apps_permissions_users_list user_info user_profile bot_info),
226
- strategy.send(:active_methods)
227
- end
228
-
229
- end
230
-
231
- class IsNotExcluded < StrategyTestCase
232
-
233
- def setup
234
- super
235
-
236
- def identity
237
- strategy.send 'is_not_excluded?'
238
- end
239
- end
240
-
241
- test 'returns true if calling method is in active-methods' do
242
- assert_equal true, identity
243
- end
244
-
245
- test 'returns false if calling method is not in active-methods' do
246
- strategy.options[:exclude_data] = 'identity'
247
- assert_equal false, identity
248
- end
249
-
250
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ginjo-omniauth-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kimura
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-19 00:00:00.000000000 Z
12
+ date: 2020-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth2
@@ -90,16 +90,29 @@ extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
92
  - ".gitignore"
93
+ - ".rdoc_options"
94
+ - ".yardopts"
93
95
  - CHANGELOG.md
94
96
  - Gemfile
95
97
  - LICENSE.txt
96
98
  - README.md
97
99
  - Rakefile
98
100
  - lib/omniauth-slack.rb
101
+ - lib/omniauth-slack/debug.rb
102
+ - lib/omniauth-slack/oauth2/access_token.rb
103
+ - lib/omniauth-slack/oauth2/client.rb
104
+ - lib/omniauth-slack/omniauth/auth_hash.rb
105
+ - lib/omniauth-slack/refinements.rb
106
+ - lib/omniauth-slack/slack.rb
99
107
  - lib/omniauth-slack/version.rb
100
108
  - lib/omniauth/strategies/slack.rb
101
109
  - omniauth-slack.gemspec
110
+ - test/access_token_test.rb
102
111
  - test/helper.rb
112
+ - test/refinements_test.rb
113
+ - test/strategy_test.rb
114
+ - test/support/oauth_user_token_response_v2.json
115
+ - test/support/scope_base.yml
103
116
  - test/support/shared_examples.rb
104
117
  - test/test.rb
105
118
  homepage: https://github.com/ginjo/omniauth-slack.git
@@ -127,6 +140,11 @@ signing_key:
127
140
  specification_version: 4
128
141
  summary: OmniAuth strategy for Slack, based on OAuth2 and OmniAuth
129
142
  test_files:
143
+ - test/access_token_test.rb
130
144
  - test/helper.rb
145
+ - test/refinements_test.rb
146
+ - test/strategy_test.rb
147
+ - test/support/oauth_user_token_response_v2.json
148
+ - test/support/scope_base.yml
131
149
  - test/support/shared_examples.rb
132
150
  - test/test.rb