omniauth-slack 2.0.1 → 2.1.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: c9192e242fdbc3258a77413bf2ebe036666ff3ed
4
- data.tar.gz: 94178c66fb3f9dab3a3f73cad1511460d10d8806
3
+ metadata.gz: 3e89b915cc602370b6fe4e45701064d3d8e6d815
4
+ data.tar.gz: a7d0bb3eb0f63b4db69e5264129040624d4a18af
5
5
  SHA512:
6
- metadata.gz: c4a5fd83c1403453ec3ca1b644e76490e0d658b9dbf23f4e7376b6bafbbbaf08c32c495d068130afe138f62fcac3b32fbad0e2b564205c9079c09a3f035dd468
7
- data.tar.gz: e4753f6f5ccdce00a01af7f8ed60942f7dd6260a61d0fa1268f2cf72ebd56f8ef318501c842ff52086af8a00f3d4e2b0a8a7e87227034544af589ae2b80de562
6
+ metadata.gz: 506559336073e79071574d5d439bd58deba9338a50140f328598da93fe813188d1655194835086cf2b8e4a8f58caa98cc5bfaa5acd2f32786f9a9144df139499
7
+ data.tar.gz: 260f4fdaa573c204d6e152f3aecf28965ed075e4496d872650940baa918217ae1033fc7a7d159a1cefe4950a0ac8d62a3fd5b83789d44a5352b0160af352e67e
data/README.md CHANGED
@@ -96,3 +96,7 @@ end
96
96
 
97
97
 
98
98
  [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/kmrshntr/omniauth-slack/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
99
+
100
+
101
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/kmrshntr/omniauth-slack/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
102
+
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |task|
5
+ task.libs << "test"
6
+ end
7
+
8
+ task :default => :test
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Slack
3
- VERSION = "2.0.1"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -34,6 +34,7 @@ module OmniAuth
34
34
  team: raw_info['team'],
35
35
  user: raw_info['user'],
36
36
  team_id: raw_info['team_id'],
37
+ team_domain: team_info['team']['domain'],
37
38
  user_id: raw_info['user_id'],
38
39
  is_admin: user_info['user']['is_admin'],
39
40
  is_owner: user_info['user']['is_owner'],
@@ -42,17 +43,20 @@ module OmniAuth
42
43
  end
43
44
 
44
45
  extra do
45
- {:raw_info => raw_info, :user_info => user_info}
46
+ {:raw_info => raw_info, :user_info => user_info, :team_info => team_info}
46
47
  end
47
48
 
48
49
  def user_info
49
50
  @user_info ||= access_token.get("/api/users.info?user=#{raw_info['user_id']}").parsed
50
51
  end
51
52
 
53
+ def team_info
54
+ @team_info ||= access_token.get("/api/team.info").parsed
55
+ end
56
+
52
57
  def raw_info
53
58
  @raw_info ||= access_token.get("/api/auth.test").parsed
54
59
  end
55
-
56
60
  end
57
61
  end
58
62
  end
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency "mocha"
23
25
  end
@@ -0,0 +1,56 @@
1
+ require "bundler/setup"
2
+ require "minitest/autorun"
3
+ require "mocha/setup"
4
+ require "omniauth/strategies/slack"
5
+
6
+ OmniAuth.config.test_mode = true
7
+
8
+ module BlockTestHelper
9
+ def test(name, &blk)
10
+ method_name = "test_#{name.gsub(/\s+/, "_")}"
11
+ raise "Method already defined: #{method_name}" if instance_methods.include?(method_name.to_sym)
12
+ define_method method_name, &blk
13
+ end
14
+ end
15
+
16
+ module CustomAssertions
17
+ def assert_has_key(key, hash, msg = nil)
18
+ msg = message(msg) { "Expected #{hash.inspect} to have key #{key.inspect}" }
19
+ assert hash.has_key?(key), msg
20
+ end
21
+
22
+ def refute_has_key(key, hash, msg = nil)
23
+ msg = message(msg) { "Expected #{hash.inspect} not to have key #{key.inspect}" }
24
+ refute hash.has_key?(key), msg
25
+ end
26
+ end
27
+
28
+ class TestCase < Minitest::Test
29
+ extend BlockTestHelper
30
+ include CustomAssertions
31
+ end
32
+
33
+ class StrategyTestCase < TestCase
34
+ def setup
35
+ @request = stub("Request")
36
+ @request.stubs(:params).returns({})
37
+ @request.stubs(:cookies).returns({})
38
+ @request.stubs(:env).returns({})
39
+ @request.stubs(:scheme).returns({})
40
+ @request.stubs(:ssl?).returns(false)
41
+
42
+ @client_id = "123"
43
+ @client_secret = "53cr3tz"
44
+ end
45
+
46
+ def strategy
47
+ @strategy ||= begin
48
+ args = [@client_id, @client_secret, @options].compact
49
+ OmniAuth::Strategies::Slack.new(nil, *args).tap do |strategy|
50
+ strategy.stubs(:request).returns(@request)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ Dir[File.expand_path("../support/**/*", __FILE__)].each &method(:require)
@@ -0,0 +1,85 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ module OAuth2StrategyTests
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include ClientTests
6
+ include AuthorizeParamsTests
7
+ include CSRFAuthorizeParamsTests
8
+ include TokenParamsTests
9
+ end
10
+ end
11
+
12
+ module ClientTests
13
+ extend BlockTestHelper
14
+
15
+ test "should be initialized with symbolized client_options" do
16
+ @options = { :client_options => { "authorize_url" => "https://example.com" } }
17
+ assert_equal "https://example.com", strategy.client.options[:authorize_url]
18
+ end
19
+ end
20
+
21
+ module AuthorizeParamsTests
22
+ extend BlockTestHelper
23
+
24
+ test "should include any authorize params passed in the :authorize_params option" do
25
+ @options = { :authorize_params => { :foo => "bar", :baz => "zip" } }
26
+ assert_equal "bar", strategy.authorize_params["foo"]
27
+ assert_equal "zip", strategy.authorize_params["baz"]
28
+ end
29
+
30
+ test "should include top-level options that are marked as :authorize_options" do
31
+ @options = { :authorize_options => [:scope, :foo], :scope => "bar", :foo => "baz" }
32
+ assert_equal "bar", strategy.authorize_params["scope"]
33
+ assert_equal "baz", strategy.authorize_params["foo"]
34
+ end
35
+
36
+ test "should exclude top-level options that are not passed" do
37
+ @options = { :authorize_options => [:bar] }
38
+ refute_has_key :bar, strategy.authorize_params
39
+ refute_has_key "bar", strategy.authorize_params
40
+ end
41
+ end
42
+
43
+ module CSRFAuthorizeParamsTests
44
+ extend BlockTestHelper
45
+
46
+ test "should store random state in the session when none is present in authorize or request params" do
47
+ assert_includes strategy.authorize_params.keys, "state"
48
+ refute_empty strategy.authorize_params["state"]
49
+ refute_empty strategy.session["omniauth.state"]
50
+ assert_equal strategy.authorize_params["state"], strategy.session["omniauth.state"]
51
+ end
52
+
53
+ test "should not store state in the session when present in authorize params vs. a random one" do
54
+ @options = { :authorize_params => { :state => "bar" } }
55
+ refute_empty strategy.authorize_params["state"]
56
+ refute_equal "bar", strategy.authorize_params[:state]
57
+ refute_empty strategy.session["omniauth.state"]
58
+ refute_equal "bar", strategy.session["omniauth.state"]
59
+ end
60
+
61
+ test "should not store state in the session when present in request params vs. a random one" do
62
+ @request.stubs(:params).returns({ "state" => "foo" })
63
+ refute_empty strategy.authorize_params["state"]
64
+ refute_equal "foo", strategy.authorize_params[:state]
65
+ refute_empty strategy.session["omniauth.state"]
66
+ refute_equal "foo", strategy.session["omniauth.state"]
67
+ end
68
+ end
69
+
70
+ module TokenParamsTests
71
+ extend BlockTestHelper
72
+
73
+ test "should include any authorize params passed in the :token_params option" do
74
+ @options = { :token_params => { :foo => "bar", :baz => "zip" } }
75
+ assert_equal "bar", strategy.token_params["foo"]
76
+ assert_equal "zip", strategy.token_params["baz"]
77
+ end
78
+
79
+ test "should include top-level options that are marked as :token_options" do
80
+ @options = { :token_options => [:scope, :foo], :scope => "bar", :foo => "baz" }
81
+ assert_equal "bar", strategy.token_params["scope"]
82
+ assert_equal "baz", strategy.token_params["foo"]
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,100 @@
1
+ require "helper"
2
+ require "omniauth-slack"
3
+
4
+ class StrategyTest < StrategyTestCase
5
+ include OAuth2StrategyTests
6
+ end
7
+
8
+ class ClientTest < StrategyTestCase
9
+ test "has correct Slack site" do
10
+ assert_equal "https://slack.com", strategy.client.site
11
+ end
12
+
13
+ test "has correct authorize url" do
14
+ assert_equal "/oauth/authorize", strategy.client.options[:authorize_url]
15
+ end
16
+
17
+ test "has correct token url" do
18
+ assert_equal "/api/oauth.access", strategy.client.options[:token_url]
19
+ end
20
+ end
21
+
22
+ class CallbackUrlTest < StrategyTestCase
23
+ test "returns the default callback url" do
24
+ url_base = "http://auth.request.com"
25
+ @request.stubs(:url).returns("#{url_base}/some/page")
26
+ strategy.stubs(:script_name).returns("") # as not to depend on Rack env
27
+ assert_equal "#{url_base}/auth/slack/callback", strategy.callback_url
28
+ end
29
+
30
+ test "returns path from callback_path option" do
31
+ @options = { :callback_path => "/auth/slack/done"}
32
+ url_base = "http://auth.request.com"
33
+ @request.stubs(:url).returns("#{url_base}/page/path")
34
+ strategy.stubs(:script_name).returns("") # as not to depend on Rack env
35
+ assert_equal "#{url_base}/auth/slack/done", strategy.callback_url
36
+ end
37
+ end
38
+
39
+ class UidTest < StrategyTestCase
40
+ def setup
41
+ super
42
+ strategy.stubs(:raw_info).returns("user_id" => "U123")
43
+ end
44
+
45
+ test "returns the user ID from raw_info" do
46
+ assert_equal "U123", strategy.uid
47
+ end
48
+ end
49
+
50
+ class CredentialsTest < StrategyTestCase
51
+ def setup
52
+ super
53
+ @access_token = stub("OAuth2::AccessToken")
54
+ @access_token.stubs(:token)
55
+ @access_token.stubs(:expires?)
56
+ @access_token.stubs(:expires_at)
57
+ @access_token.stubs(:refresh_token)
58
+ strategy.stubs(:access_token).returns(@access_token)
59
+ end
60
+
61
+ test "returns a Hash" do
62
+ assert_kind_of Hash, strategy.credentials
63
+ end
64
+
65
+ test "returns the token" do
66
+ @access_token.stubs(:token).returns("123")
67
+ assert_equal "123", strategy.credentials["token"]
68
+ end
69
+
70
+ test "returns the expiry status" do
71
+ @access_token.stubs(:expires?).returns(true)
72
+ assert strategy.credentials["expires"]
73
+
74
+ @access_token.stubs(:expires?).returns(false)
75
+ refute strategy.credentials["expires"]
76
+ end
77
+
78
+ test "returns the refresh token and expiry time when expiring" do
79
+ ten_mins_from_now = (Time.now + 600).to_i
80
+ @access_token.stubs(:expires?).returns(true)
81
+ @access_token.stubs(:refresh_token).returns("321")
82
+ @access_token.stubs(:expires_at).returns(ten_mins_from_now)
83
+ assert_equal "321", strategy.credentials["refresh_token"]
84
+ assert_equal ten_mins_from_now, strategy.credentials["expires_at"]
85
+ end
86
+
87
+ test "does not return the refresh token when test is nil and expiring" do
88
+ @access_token.stubs(:expires?).returns(true)
89
+ @access_token.stubs(:refresh_token).returns(nil)
90
+ assert_nil strategy.credentials["refresh_token"]
91
+ refute_has_key "refresh_token", strategy.credentials
92
+ end
93
+
94
+ test "does not return the refresh token when not expiring" do
95
+ @access_token.stubs(:expires?).returns(false)
96
+ @access_token.stubs(:refresh_token).returns("XXX")
97
+ assert_nil strategy.credentials["refresh_token"]
98
+ refute_has_key "refresh_token", strategy.credentials
99
+ end
100
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kimura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: OmniAuth strategy for Slack
56
84
  email:
57
85
  - kimura@enigmo.co.jp
@@ -68,6 +96,9 @@ files:
68
96
  - lib/omniauth-slack/version.rb
69
97
  - lib/omniauth/strategies/slack.rb
70
98
  - omniauth-slack.gemspec
99
+ - test/helper.rb
100
+ - test/support/shared_examples.rb
101
+ - test/test.rb
71
102
  homepage: https://github.com/kmrshntr/omniauth-slack.git
72
103
  licenses:
73
104
  - MIT
@@ -92,4 +123,7 @@ rubygems_version: 2.4.3
92
123
  signing_key:
93
124
  specification_version: 4
94
125
  summary: OmniAuth strategy for Slack
95
- test_files: []
126
+ test_files:
127
+ - test/helper.rb
128
+ - test/support/shared_examples.rb
129
+ - test/test.rb