ginjo-omniauth-slack 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test.rb ADDED
@@ -0,0 +1,246 @@
1
+ require 'helper'
2
+ require 'omniauth-slack'
3
+
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 'request logs api call' do
24
+ OAuth2::Client.class_eval do
25
+ def request(*args)
26
+ {simple: 'hash'}
27
+ end
28
+ end
29
+ @client = strategy.client
30
+ OmniAuth.logger.expects(:send).with(){|*params| assert_equal :debug, params[0]}
31
+ @client.request(:get, 'http://test-url')
32
+ end
33
+
34
+ test 'request adds api response to raw_info hash' do
35
+ OAuth2::Client.class_eval do
36
+ def request(*args)
37
+ {simple: 'hash'}
38
+ end
39
+ end
40
+ @client = strategy.client
41
+ @client.request(:get, 'http://test-url')
42
+ assert_equal( {'test-url' => {simple: 'hash'}}, strategy.send(:raw_info) )
43
+ end
44
+ end
45
+
46
+ class CallbackUrlTest < StrategyTestCase
47
+ test "returns the default callback url" do
48
+ url_base = "http://auth.request.com"
49
+ @request.stubs(:url).returns("#{url_base}/some/page")
50
+ strategy.stubs(:script_name).returns("") # as not to depend on Rack env
51
+ assert_equal "#{url_base}/auth/slack/callback", strategy.callback_url
52
+ end
53
+
54
+ test "returns path from callback_path option" do
55
+ @options = { :callback_path => "/auth/slack/done"}
56
+ url_base = "http://auth.request.com"
57
+ @request.stubs(:url).returns("#{url_base}/page/path")
58
+ strategy.stubs(:script_name).returns("") # as not to depend on Rack env
59
+ assert_equal "#{url_base}/auth/slack/done", strategy.callback_url
60
+ end
61
+ end
62
+
63
+ class UidTest < StrategyTestCase
64
+ def setup
65
+ super
66
+ #strategy.stubs(:identity).returns("user" => {"id" => "U123"}, "team" => {"id" => "T456"})
67
+ strategy.stubs(:auth).returns("user" => {"id" => "U123"}, "team" => {"id" => "T456"})
68
+ end
69
+
70
+ test "returns the user ID from user_identity" do
71
+ assert_equal "U123-T456", strategy.uid
72
+ end
73
+ end
74
+
75
+ class CredentialsTest < StrategyTestCase
76
+ def setup
77
+ super
78
+ @access_token = stub("OAuth2::AccessToken")
79
+ @access_token.stubs(:token)
80
+ @access_token.stubs(:expires?)
81
+ @access_token.stubs(:expires_at)
82
+ @access_token.stubs(:refresh_token)
83
+ @access_token.stubs(:[])
84
+ @access_token.stubs(:params)
85
+ strategy.stubs(:access_token).returns(@access_token)
86
+ end
87
+
88
+ test "returns a Hash" do
89
+ assert_kind_of Hash, strategy.credentials
90
+ end
91
+
92
+ test "returns the token" do
93
+ @access_token.stubs(:token).returns("123")
94
+ assert_equal "123", strategy.credentials["token"]
95
+ end
96
+
97
+ test "returns the expiry status" do
98
+ @access_token.stubs(:expires?).returns(true)
99
+ assert strategy.credentials["expires"]
100
+
101
+ @access_token.stubs(:expires?).returns(false)
102
+ refute strategy.credentials["expires"]
103
+ end
104
+
105
+ test "returns the refresh token and expiry time when expiring" do
106
+ ten_mins_from_now = (Time.now + 600).to_i
107
+ @access_token.stubs(:expires?).returns(true)
108
+ @access_token.stubs(:refresh_token).returns("321")
109
+ @access_token.stubs(:expires_at).returns(ten_mins_from_now)
110
+ assert_equal "321", strategy.credentials["refresh_token"]
111
+ assert_equal ten_mins_from_now, strategy.credentials["expires_at"]
112
+ end
113
+
114
+ test "does not return the refresh token when test is nil and expiring" do
115
+ @access_token.stubs(:expires?).returns(true)
116
+ @access_token.stubs(:refresh_token).returns(nil)
117
+ assert_nil strategy.credentials["refresh_token"]
118
+ refute_has_key "refresh_token", strategy.credentials
119
+ end
120
+
121
+ test "does not return the refresh token when not expiring" do
122
+ @access_token.stubs(:expires?).returns(false)
123
+ @access_token.stubs(:refresh_token).returns("XXX")
124
+ assert_nil strategy.credentials["refresh_token"]
125
+ refute_has_key "refresh_token", strategy.credentials
126
+ end
127
+ end
128
+
129
+ class IdentityTest < StrategyTestCase
130
+
131
+ def setup
132
+ super
133
+ @access_token = stub("OAuth2::AccessToken")
134
+ @access_token.stubs(:[])
135
+ @access_token.stubs(:params)
136
+ @access_token.stubs(:token)
137
+ strategy.stubs(:access_token).returns(@access_token)
138
+ strategy.stubs(:has_scope?).returns true
139
+ end
140
+
141
+ test "performs a GET to https://slack.com/api/users.identity" do
142
+ @access_token.expects(:get).with("/api/users.identity", {:headers => {"X-Slack-User" => nil}})
143
+ .returns(stub_everything("OAuth2::Response"))
144
+ strategy.identity
145
+ end
146
+
147
+ end
148
+
149
+ class SkipInfoTest < StrategyTestCase
150
+
151
+ test 'info should not include extended info when skip_info is specified' do
152
+ @options = { skip_info: true }
153
+ #strategy.stubs(:identity).returns({})
154
+ strategy.stubs(:auth).returns({})
155
+ assert_equal %w(name email user_id team_name team_id image), strategy.info.keys.map(&:to_s)
156
+ end
157
+
158
+ end
159
+
160
+ class AuthorizeParamsTest < StrategyTestCase
161
+
162
+ test 'returns OmniAuth::Strategy::Options hash' do
163
+ assert_kind_of OmniAuth::Strategy::Options, strategy.authorize_params
164
+ end
165
+
166
+ test 'forwards request params (scope, team, redirect_uri) to slack' do
167
+ strategy.request.params['scope'] = 'test-scope'
168
+ strategy.request.params['team'] = 'test-team'
169
+ strategy.request.params['redirect_uri'] = 'http://my-test-uri/auth/callback'
170
+ assert_equal 'test-scope', strategy.authorize_params['scope']
171
+ assert_equal 'test-team', strategy.authorize_params['team']
172
+ assert_equal 'http://my-test-uri/auth/callback', strategy.authorize_params['redirect_uri']
173
+ end
174
+
175
+ end
176
+
177
+ class InitializeTest < StrategyTestCase
178
+
179
+ test 'sets @main_semaphore with a new Mutex' do
180
+ assert_kind_of Mutex, strategy.instance_variable_get(:@main_semaphore)
181
+ end
182
+
183
+ test 'sets @semaphores with empty hash' do
184
+ assert_equal( {}, strategy.instance_variable_get(:@semaphores) )
185
+ end
186
+
187
+ end
188
+
189
+ class SemaphoreTest < StrategyTestCase
190
+
191
+ def setup
192
+ super
193
+
194
+ def strategy.test_method
195
+ send :semaphore
196
+ end
197
+ end
198
+
199
+ test 'synchronized management of method-specific mutexes' do
200
+ strategy.test_method
201
+ assert_kind_of Mutex, strategy.instance_variable_get(:@semaphores)['test_method']
202
+ end
203
+
204
+ end
205
+
206
+ class ActiveMethodsTest < StrategyTestCase
207
+
208
+ test 'with no settings, returns all defined api methods' do
209
+ assert_equal %w(apps_permissions_users_list identity user_info user_profile team_info bot_info),
210
+ strategy.send(:active_methods)
211
+ end
212
+
213
+ test 'with :include_data, returns only included methods' do
214
+ strategy.options[:include_data] = %w(identity team_info)
215
+ assert_equal %w(identity team_info),
216
+ strategy.send(:active_methods)
217
+ end
218
+
219
+ test 'with :exclude_data, returns all but excluded methods' do
220
+ strategy.options[:exclude_data] = %w(identity team_info)
221
+ assert_equal %w(apps_permissions_users_list user_info user_profile bot_info),
222
+ strategy.send(:active_methods)
223
+ end
224
+
225
+ end
226
+
227
+ class IsNotExcluded < StrategyTestCase
228
+
229
+ def setup
230
+ super
231
+
232
+ def identity
233
+ strategy.send 'is_not_excluded?'
234
+ end
235
+ end
236
+
237
+ test 'returns true if calling method is in active-methods' do
238
+ assert_equal true, identity
239
+ end
240
+
241
+ test 'returns false if calling method is not in active-methods' do
242
+ strategy.options[:exclude_data] = 'identity'
243
+ assert_equal false, identity
244
+ end
245
+
246
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ginjo-omniauth-slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.4.0
5
+ platform: ruby
6
+ authors:
7
+ - kimura
8
+ - ginjo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.4'
21
+ - - "~>"
22
+ - !ruby/object:Gem::Version
23
+ version: '1.5'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '1.4'
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.11.2
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.11.2
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: mocha
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: OmniAuth strategy for Slack
91
+ email:
92
+ - kimura@enigmo.co.jp
93
+ - wbr@mac.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - CHANGELOG.md
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - lib/omniauth-slack.rb
105
+ - lib/omniauth-slack/version.rb
106
+ - lib/omniauth/strategies/slack.rb
107
+ - omniauth-slack.gemspec
108
+ - test/helper.rb
109
+ - test/support/shared_examples.rb
110
+ - test/test.rb
111
+ homepage: https://github.com/kmrshntr/omniauth-slack.git
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.7.6
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: OmniAuth strategy for Slack, based on the oauth2 and omniauth-oauth2 gems
135
+ test_files:
136
+ - test/helper.rb
137
+ - test/support/shared_examples.rb
138
+ - test/test.rb