omniauth-icalia 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 639cd1645e7cf5c313a531d912ee22f9050ab57dac3cff0badd3042bd55fe249
4
- data.tar.gz: 1925f26f026e334cc4274318f603563d6f1accb95cef046fcbb6e72f5f8299ea
3
+ metadata.gz: 6cad58273fb22cba6b5c8d71664759576620fa2537740fdfccde10cb60f2fff0
4
+ data.tar.gz: 7e276c2f58291e30add46bebb595658afddc43e6b2c7d06f21aa7096b726b68e
5
5
  SHA512:
6
- metadata.gz: f37cf9a8b6572028d3ca09bf2f3d277d5689bf5a240e4cd42787f8f7744f5e9b809292fd7e7a1c475903f73f24cd17c79dbe6131c0cf8a54e75b91b2bbb23a74
7
- data.tar.gz: ea3586542406a86fba4f17dccc6b0cae09a6df54be04b2d44a1e6886ecdf26ef6acf6fabae0a3d0d4c396638693bd900d193d24e93396c7819422b8c65e3c080
6
+ metadata.gz: 0aca0652ac4f348489ad9486182bdb3cee95c926c307865aa0a9d91b2c84287c5fe2b562dc46f76857a542ef0b256d2a433fbdcc4544b2b3c979dd6baef3845d
7
+ data.tar.gz: 469abd58dd314111be50a440e7055d3939c3b1b133b25ebc13e46ea04549dd8aae48d63ed274b299f1993fc9ff246f6d6ac681678257601af3c39475a657f68b
data/README.md CHANGED
@@ -24,6 +24,33 @@ Or install it yourself as:
24
24
 
25
25
  TODO: Write usage instructions here
26
26
 
27
+ ## System Testing on your app
28
+
29
+ You can use the included service stub in your system tests.
30
+
31
+ On your spec_helper, or test setup file:
32
+
33
+ ```ruby
34
+ require 'omniauth-icalia/service_stubs'
35
+ ```
36
+
37
+ Then, in your test setup, call `prepare`:
38
+
39
+ ```ruby
40
+ # For example, in RSpec:
41
+ before { Icalia::StubbedSSOService.prepare }
42
+
43
+ # Use a block if you need to set the data returned by the service:
44
+ before do
45
+ Icalia::StubbedSSOService.prepare do |config|
46
+ # Optionally add example data about the expected token owner:
47
+ config.example_resource_owner_id = SecureRandom.uuid
48
+ config.example_resource_owner_given_name = 'George'
49
+ config.example_resource_owner_family_name = 'Harrison'
50
+ end
51
+ end
52
+ ```
53
+
27
54
  ## Development
28
55
 
29
56
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,176 @@
1
+ require 'sinatra/base'
2
+
3
+ require 'capybara'
4
+ require 'capybara/server'
5
+
6
+ require 'socket'
7
+
8
+ module Icalia
9
+ class StubbedSSOService < Sinatra::Base
10
+ FIND_AVAILABLE_PORT = 0
11
+ CODE = 'icalia_oauth_authorization_code'.freeze
12
+
13
+ post '/oauth/token' do
14
+ if params[:code] == CODE
15
+ response.headers['Content-Type'] = 'application/json'
16
+ flow = oauth_flows.last
17
+ data = flow.slice('state').merge(
18
+ access_token: 'ACCESS_TOKEN',
19
+ token_type: 'Bearer',
20
+ created_at: DateTime.now.to_i
21
+ )
22
+ flow[:granted_access_data] = data
23
+ data.to_json
24
+ else
25
+ status 400
26
+ {
27
+ error: 'invalid_grant',
28
+ error_description: "Authorization code does not exist: #{code}",
29
+ }.to_json
30
+ end
31
+ end
32
+
33
+ get '/oauth/authorize' do
34
+ store_oauth_flow_data params
35
+ uri = URI(params[:redirect_uri])
36
+ uri.query = URI.encode_www_form(state: params[:state], code: CODE)
37
+ redirect uri
38
+ end
39
+
40
+ get '/oauth/token/info' do
41
+ flow = oauth_flows.last
42
+ data = {
43
+ data: {
44
+ id: SecureRandom.uuid,
45
+ type: 'oauth-access-token',
46
+ attributes: {
47
+ scopes: [],
48
+ 'expires-at': nil,
49
+ 'created-at': Time.at(flow.dig(:granted_access_data, :created_at))
50
+ },
51
+ relationships: {
52
+ 'resource-owner': {
53
+ data: { type: 'person', id: example_resource_owner_id }
54
+ }
55
+ }
56
+ },
57
+ included: [
58
+ {
59
+ type: 'person',
60
+ id: example_resource_owner_id,
61
+ attributes: {
62
+ 'full-name': example_resource_owner_full_name,
63
+ 'given-name': example_resource_owner_given_name,
64
+ 'family-name': example_resource_owner_family_name,
65
+ 'gender-type': example_resource_owner_gender_type,
66
+ 'custom-gender': example_resource_owner_custom_gender
67
+ }
68
+ }
69
+ ]
70
+ }
71
+ response.headers['Content-Type'] = 'application/vnd.api+json'
72
+ data.to_json
73
+ end
74
+
75
+ %i[example_resource_owner_id example_resource_owner_given_name
76
+ example_resource_owner_family_name example_resource_owner_gender_type
77
+ example_resource_owner_custom_gender].each do |method_name|
78
+ define_singleton_method method_name do
79
+ class_variable_get("@@#{method_name}")
80
+ end
81
+
82
+ define_singleton_method "#{method_name}=".to_sym do |value|
83
+ class_variable_set("@@#{method_name}", value)
84
+ end
85
+ end
86
+
87
+ %i[oauth_flows store_oauth_flow_data example_resource_owner_id
88
+ example_resource_owner_given_name example_resource_owner_family_name
89
+ example_resource_owner_gender_type example_resource_owner_full_name
90
+ example_resource_owner_custom_gender].each do |method_name|
91
+ define_method method_name do |*args|
92
+ self.class.public_send method_name, *args
93
+ end
94
+ end
95
+
96
+ class << self
97
+ def oauth_flows
98
+ @oauth_flows ||= []
99
+ end
100
+
101
+ def reset
102
+ oauth_flows.clear
103
+
104
+ self.example_resource_owner_id = SecureRandom.uuid
105
+ self.example_resource_owner_given_name = 'Example Person'
106
+ self.example_resource_owner_family_name = 'From Artanis'
107
+ self.example_resource_owner_gender_type = 'male'
108
+ self.example_resource_owner_custom_gender = nil
109
+ end
110
+
111
+ def example_resource_owner_full_name
112
+ [example_resource_owner_given_name, example_resource_owner_family_name]
113
+ .compact.join(' ').strip
114
+ end
115
+
116
+ def store_oauth_flow_data(data)
117
+ oauth_flows << data
118
+ end
119
+
120
+ # Taken from FakeStripe.stub_stripe at fake_stripe gem:
121
+ def prepare
122
+ reset
123
+
124
+ yield self if block_given?
125
+
126
+ # Since the OAuth flow is performed by the browser, we'll need to boot
127
+ # the Sinatra app instead of just stubbing the app with WebMock...
128
+ boot_once
129
+
130
+ oauth_host = "http://localhost:#{server_port}"
131
+
132
+ OmniAuth::Strategies::Icalia.instances.each do |options|
133
+ client_options = options.client_options
134
+ client_options.site = oauth_host
135
+ client_options.token_url = "#{oauth_host}/oauth/token"
136
+ client_options.authorize_url = "#{oauth_host}/oauth/authorize"
137
+ end
138
+ end
139
+
140
+ def teardown
141
+ default_client_options = OmniAuth::Strategies::Icalia
142
+ .default_options
143
+ .client_options
144
+
145
+ OmniAuth::Strategies::Icalia.instances.each do |options|
146
+ client_options = options.client_options
147
+ client_options.site = default_client_options.site
148
+ client_options.token_url = default_client_options.token_url
149
+ client_options.authorize_url = default_client_options.authorize_url
150
+ end
151
+ end
152
+
153
+ # Taken from FakeStripe::Utils at fake_stripe gem: =======================
154
+ def find_available_port
155
+ server = TCPServer.new(FIND_AVAILABLE_PORT)
156
+ server.addr[1]
157
+ ensure
158
+ server.close if server
159
+ end
160
+
161
+ # Taken from Bootable at fake_stripe gem: ================================
162
+ def boot(port = find_available_port)
163
+ instance = new
164
+ Capybara::Server.new(instance, port: port).tap(&:boot)
165
+ end
166
+
167
+ def boot_once
168
+ @boot_once ||= boot(server_port)
169
+ end
170
+
171
+ def server_port
172
+ @server_port ||= find_available_port
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1 @@
1
+ require 'icalia/stubbed_sso_service'
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Icalia
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
@@ -12,6 +12,18 @@ module OmniAuth
12
12
  authorize_url: 'https://artanis.icalialabs.com/oauth/authorize'
13
13
  }
14
14
 
15
+ @@instances = []
16
+
17
+ def self.instances
18
+ class_variable_get('@@instances')
19
+ end
20
+
21
+ def initialize(*args)
22
+ instance = super(*args)
23
+ @@instances << instance
24
+ instance
25
+ end
26
+
15
27
  def request_phase
16
28
  super
17
29
  end
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'icalia-sdk-event-core', '~> 0.3', '>= 0.3.5'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.17'
26
- spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'capybara', '~> 3.0', '>= 3.0.0'
27
+ spec.add_development_dependency 'sinatra', '~> 2.0', '>= 2.0.0'
28
+ spec.add_development_dependency 'rake', '~> 13.0'
27
29
  spec.add_development_dependency 'rspec', '~> 3.0'
28
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-icalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-16 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -78,20 +78,60 @@ dependencies:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '1.17'
81
+ - !ruby/object:Gem::Dependency
82
+ name: capybara
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.0.0
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 3.0.0
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '3.0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: sinatra
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.0.0
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.0
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '2.0'
81
121
  - !ruby/object:Gem::Dependency
82
122
  name: rake
83
123
  requirement: !ruby/object:Gem::Requirement
84
124
  requirements:
85
125
  - - "~>"
86
126
  - !ruby/object:Gem::Version
87
- version: '10.0'
127
+ version: '13.0'
88
128
  type: :development
89
129
  prerelease: false
90
130
  version_requirements: !ruby/object:Gem::Requirement
91
131
  requirements:
92
132
  - - "~>"
93
133
  - !ruby/object:Gem::Version
94
- version: '10.0'
134
+ version: '13.0'
95
135
  - !ruby/object:Gem::Dependency
96
136
  name: rspec
97
137
  requirement: !ruby/object:Gem::Requirement
@@ -121,12 +161,12 @@ files:
121
161
  - Rakefile
122
162
  - bin/console
123
163
  - bin/setup
164
+ - lib/icalia/stubbed_sso_service.rb
124
165
  - lib/omniauth-icalia.rb
166
+ - lib/omniauth-icalia/service_stubs.rb
125
167
  - lib/omniauth-icalia/version.rb
126
168
  - lib/omniauth/strategies/icalia.rb
127
169
  - omniauth-icalia.gemspec
128
- - spec/omniauth/strategies/icalia_spec.rb
129
- - spec/spec_helper.rb
130
170
  homepage: https://github.com/IcaliaLabs/omniauth-icalia
131
171
  licenses:
132
172
  - MIT
@@ -150,6 +190,4 @@ rubygems_version: 3.0.3
150
190
  signing_key:
151
191
  specification_version: 4
152
192
  summary: Official Omniauth Strategy for Icalia.
153
- test_files:
154
- - spec/omniauth/strategies/icalia_spec.rb
155
- - spec/spec_helper.rb
193
+ test_files: []
@@ -1,109 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe OmniAuth::Strategies::Icalia do
4
- let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
5
- let(:parsed_response) { instance_double('ParsedResponse') }
6
- let(:response) { instance_double('Response', :parsed => parsed_response) }
7
-
8
- let(:example_overridden_site) { 'https://example.com' }
9
- let(:example_overridden_token_url) { 'https://example.com/oauth/token' }
10
- let(:example_overridden_authorize_url) { 'https://example.com/oauth/authorize' }
11
-
12
- let(:example_options) { {} }
13
-
14
- subject do
15
- OmniAuth::Strategies::Icalia.new 'ICALIA_CLIENT_KEY',
16
- 'ICALIA_CLIENT_SECRET',
17
- example_options
18
- end
19
-
20
- before :each do
21
- allow(subject).to receive(:access_token).and_return(access_token)
22
- end
23
-
24
- describe 'client options' do
25
- context 'defaults' do
26
- it 'site is artanis' do
27
- expect(subject.options.client_options.site).to eq 'https://artanis.icalialabs.com'
28
- end
29
-
30
- it 'authorize url is artanis authorize url' do
31
- expect(subject.options.client_options.authorize_url).to eq 'https://artanis.icalialabs.com/oauth/authorize'
32
- end
33
-
34
- it 'token url is artanis token url' do
35
- expect(subject.options.client_options.token_url).to eq 'https://artanis.icalialabs.com/oauth/token'
36
- end
37
- end
38
-
39
- context 'overrides' do
40
- let :example_options do
41
- {
42
- client_options: {
43
- site: example_overridden_site,
44
- token_url: example_overridden_token_url,
45
- authorize_url: example_overridden_authorize_url,
46
- }
47
- }
48
- end
49
-
50
- it 'allows overriding the site' do
51
- expect(subject.options.client_options.site)
52
- .to eq example_overridden_site
53
- end
54
-
55
- it 'allows overriding the authorize url' do
56
- expect(subject.options.client_options.authorize_url)
57
- .to eq example_overridden_authorize_url
58
- end
59
-
60
- it 'allows overriding the token url' do
61
- expect(subject.options.client_options.token_url)
62
- .to eq example_overridden_token_url
63
- end
64
- end
65
- end
66
-
67
- describe '#raw_info', skip: true do
68
- it 'should use relative paths' do
69
- expect(access_token).to receive(:get).with('/oauth/token/info?include=resource-owner.email-accounts').and_return(response)
70
- expect(subject.raw_info).to eq(parsed_response)
71
- end
72
-
73
- it 'should use the header auth mode' do
74
- expect(access_token).to receive(:get).with('user').and_return(response)
75
- subject.raw_info
76
- expect(access_token.options[:mode]).to eq(:header)
77
- end
78
- end
79
-
80
- describe '#info.email', skip: true do
81
- it 'should use any available email' do
82
- allow(subject).to receive(:raw_info).and_return({})
83
- allow(subject).to receive(:email).and_return('you@example.com')
84
- expect(subject.info['email']).to eq('you@example.com')
85
- end
86
- end
87
-
88
- context '#info.urls', skip: true do
89
- it 'should use html_url from raw_info' do
90
- allow(subject).to receive(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' })
91
- expect(subject.info['urls']['icalia']).to eq('http://enterprise/me')
92
- end
93
- end
94
-
95
- context '#extra.scope' do
96
- it 'returns the scope on the returned access_token' do
97
- expect(subject.scope).to eq('user')
98
- end
99
- end
100
-
101
- describe '#callback_url' do
102
- it 'is a combination of host, script name, and callback path' do
103
- allow(subject).to receive(:full_host).and_return('https://example.com')
104
- allow(subject).to receive(:script_name).and_return('/sub_uri')
105
-
106
- expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/icalia/callback')
107
- end
108
- end
109
- end
@@ -1,14 +0,0 @@
1
- require 'bundler/setup'
2
- require 'omniauth-icalia'
3
-
4
- RSpec.configure do |config|
5
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = 'examples.txt'
7
-
8
- # Disable RSpec exposing methods globally on `Module` and `main`
9
- config.disable_monkey_patching!
10
-
11
- config.expect_with :rspec do |c|
12
- c.syntax = :expect
13
- end
14
- end