Skip to content

Commit 5f7f7fb

Browse files
authored
Merge pull request #85 from dlindahl/chore/fix-some-offenses
Chore/fix some offenses
2 parents c47a0e9 + fa932f9 commit 5f7f7fb

File tree

5 files changed

+56
-83
lines changed

5 files changed

+56
-83
lines changed

.rubocop_todo.yml

+1-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# OmniAuth CAS Strategy [![Gem Version][version_badge]][version] [![Build Status][github_actions_status]][github_actions]
2-
3-
[version_badge]: https://badge.fury.io/rb/omniauth-cas.svg
4-
[version]: https://badge.fury.io/rb/omniauth-cas
5-
[github_actions]: https://github.com/dlindahl/omniauth-cas/actions
6-
[github_actions_status]: https://github.com/dlindahl/omniauth-cas/actions/workflows/ci.yml/badge.svg
7-
[releases]: https://github.com/dlindahl/omniauth-cas/releases
1+
# OmniAuth CAS Strategy [![Gem Version][version_badge]][version] [![Build Status][github_actions_ci_status]][github_actions_ci] [![RuboCop][github_actions_rubocop_status]][github_actions_rubocop]
82

93
This is a [OmniAuth][omniauth] 2.1+ compatible port of the previously available
104
[OmniAuth CAS strategy][old_omniauth_cas] that was bundled with OmniAuth 0.3.
@@ -122,8 +116,15 @@ Special thanks go out to the following people
122116
* Elber Ribeiro (@dynaum) for Ubuntu SSL configuration support
123117
* @rbq for README updates and OmniAuth 0.3 migration guide
124118
125-
[omniauth]: https://github.com/omniauth/omniauth
126-
[old_omniauth_cas]: https://github.com/intridea/omniauth/blob/0-3-stable/oa-enterprise/lib/omniauth/strategies/cas.rb
127119
[document_up]: https://dlindahl.github.io/omniauth-cas/
120+
[github_actions_ci]: https://github.com/dlindahl/omniauth-cas/actions/workflows/ci.yml
121+
[github_actions_ci_status]: https://github.com/dlindahl/omniauth-cas/actions/workflows/ci.yml/badge.svg
122+
[github_actions_rubocop]: https://github.com/dlindahl/omniauth-cas/actions/workflows/rubocop.yml
123+
[github_actions_rubocop_status]: https://github.com/dlindahl/omniauth-cas/actions/workflows/rubocop.yml/badge.svg
128124
[net_http]: https://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html
125+
[old_omniauth_cas]: https://github.com/intridea/omniauth/blob/0-3-stable/oa-enterprise/lib/omniauth/strategies/cas.rb
126+
[omniauth]: https://github.com/omniauth/omniauth
127+
[releases]: https://github.com/dlindahl/omniauth-cas/releases
129128
[sso]: https://wiki.jasig.org/display/CASUM/Single+Sign+Out
129+
[version]: https://badge.fury.io/rb/omniauth-cas
130+
[version_badge]: https://badge.fury.io/rb/omniauth-cas.svg

spec/omniauth/strategies/cas/logout_request_spec.rb

+20-20
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
require 'spec_helper'
44

55
RSpec.describe OmniAuth::Strategies::CAS::LogoutRequest do
6-
subject { described_class.new(strategy, request).call(options) }
6+
subject(:call) { described_class.new(strategy, request).call(options) }
77

88
let(:strategy) { double('strategy') }
99
let(:env) do
1010
{ 'rack.input' => StringIO.new('', 'r') }
1111
end
1212
let(:request) { double('request', params: params, env: env) }
13-
let(:params) { { 'url' => url, 'logoutRequest' => logoutRequest } }
13+
let(:params) { { 'url' => url, 'logoutRequest' => logout_request_xml } }
1414
let(:url) { 'http://example.org/signed_in' }
15-
let(:logoutRequest) do
16-
%(
15+
let(:logout_request_xml) do
16+
<<~XML
1717
<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="123abc-1234-ab12-cd34-1234abcd" Version="2.0" IssueInstant="#{Time.now}">
1818
<saml:NameID>@NOT_USED@</saml:NameID>
1919
<samlp:SessionIndex>ST-123456-123abc456def</samlp:SessionIndex>
2020
</samlp:LogoutRequest>
21-
)
21+
XML
2222
end
2323

24-
describe 'SAML attributes' do
24+
context 'when parsing SAML attributes' do
2525
let(:callback) { proc {} }
2626
let(:options) do
2727
{ on_single_sign_out: callback }
@@ -33,19 +33,19 @@
3333
@rack_input = req.env['rack.input'].read
3434
true
3535
end
36-
subject
36+
call
3737
end
3838

39-
it 'are parsed and injected into the Rack Request parameters' do
39+
it 'injects them into the Rack Request parameters' do
4040
expect(@rack_input).to eq 'name_id=%40NOT_USED%40&session_index=ST-123456-123abc456def'
4141
end
4242

43-
context 'that raise when parsed' do
43+
context 'when an error is raised' do
4444
let(:env) { { 'rack.input' => nil } }
4545

4646
before do
4747
allow(strategy).to receive(:fail!)
48-
subject
48+
call
4949
end
5050

5151
it 'responds with an error' do
@@ -54,47 +54,47 @@
5454
end
5555
end
5656

57-
describe 'with a configured callback' do
57+
context 'with a configured callback' do
5858
let(:options) do
5959
{ on_single_sign_out: callback }
6060
end
6161

62-
let(:response_body) { subject[2].respond_to?(:body) ? subject[2].body : subject[2] }
62+
let(:response_body) { call[2].respond_to?(:body) ? call[2].body : call[2] }
6363

64-
context 'that returns TRUE' do
64+
context 'when callback returns `true`' do
6565
let(:callback) { proc { true } }
6666

6767
it 'responds with OK' do
68-
expect(subject[0]).to eq 200
68+
expect(call[0]).to eq 200
6969
expect(response_body).to eq ['OK']
7070
end
7171
end
7272

73-
context 'that returns Nil' do
73+
context 'when callback returns `nil`' do
7474
let(:callback) { proc {} }
7575

7676
it 'responds with OK' do
77-
expect(subject[0]).to eq 200
77+
expect(call[0]).to eq 200
7878
expect(response_body).to eq ['OK']
7979
end
8080
end
8181

82-
context 'that returns a tuple' do
82+
context 'when callback returns a tuple' do
8383
let(:callback) { proc { [400, {}, 'Bad Request'] } }
8484

8585
it 'responds with OK' do
86-
expect(subject[0]).to eq 400
86+
expect(call[0]).to eq 400
8787
expect(response_body).to eq ['Bad Request']
8888
end
8989
end
9090

91-
context 'that raises an error' do
91+
context 'when callback raises an error' do
9292
let(:exception) { RuntimeError.new('error') }
9393
let(:callback) { proc { raise exception } }
9494

9595
before do
9696
allow(strategy).to receive(:fail!)
97-
subject
97+
call
9898
end
9999

100100
it 'responds with an error' do

spec/omniauth/strategies/cas/service_ticket_validator_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
end
1919

2020
describe '#call' do
21-
subject { validator.call }
21+
subject(:call) { validator.call }
2222

2323
before do
2424
stub_request(:get, 'https://example.org/serviceValidate?')
2525
.to_return(status: 200, body: '')
2626
end
2727

2828
it 'returns itself' do
29-
expect(subject).to eq validator
29+
expect(call).to eq validator
3030
end
3131

3232
it 'uses the configured CA path' do
33-
subject
33+
call
3434
expect(provider_options).to have_received :ca_path
3535
end
3636
end
3737

3838
describe '#user_info' do
39-
subject { validator.user_info }
39+
subject(:user_info) { validator.user_info }
4040

4141
let(:ok_fixture) do
4242
File.expand_path(File.join(File.dirname(__FILE__), '../../../fixtures/cas_success.xml'))
@@ -51,8 +51,8 @@
5151

5252
context 'with default settings' do
5353
it 'parses user info from the response' do
54-
expect(subject).to include 'user' => 'psegel'
55-
expect(subject).to include 'roles' => 'financier'
54+
expect(user_info).to include 'user' => 'psegel'
55+
expect(user_info).to include 'roles' => 'financier'
5656
end
5757
end
5858

@@ -65,8 +65,8 @@
6565
end
6666

6767
it 'parses multivalued user info from the response' do
68-
expect(subject).to include 'user' => 'psegel'
69-
expect(subject).to include 'roles' => %w[senator lobbyist financier]
68+
expect(user_info).to include 'user' => 'psegel'
69+
expect(user_info).to include 'roles' => %w[senator lobbyist financier]
7070
end
7171
end
7272
end

spec/omniauth/strategies/cas_spec.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@
4848
end
4949

5050
describe '#cas_url' do
51-
subject { provider.cas_url }
51+
subject(:cas_url) { provider.cas_url }
5252

5353
let(:params) { {} }
5454
let(:provider) { MyCasProvider.new(nil, params) }
5555

5656
it 'raises an ArgumentError' do
57-
expect { subject }.to raise_error ArgumentError, /:host and :login_url MUST be provided/
57+
expect { cas_url }.to raise_error ArgumentError, /:host and :login_url MUST be provided/
5858
end
5959

6060
context 'with an explicit :url option' do
6161
let(:url) { 'https://example.org:8080/my_cas' }
6262
let(:params) { super().merge url: url }
6363

64-
before { subject }
64+
before { cas_url }
6565

6666
it { is_expected.to eq url }
6767

@@ -76,7 +76,7 @@
7676
context 'with explicit URL component' do
7777
let(:params) { super().merge host: 'example.org', port: 1234, ssl: true, path: '/a/path' }
7878

79-
before { subject }
79+
before { cas_url }
8080

8181
it { is_expected.to eq 'https://example.org:1234/a/path' }
8282

@@ -124,7 +124,7 @@
124124
it { is_expected.to be_redirect }
125125

126126
it 'redirects with a failure message' do
127-
expect(subject.headers).to include 'Location' => '/auth/failure?message=no_ticket&strategy=cas'
127+
expect(last_response.headers).to include 'Location' => '/auth/failure?message=no_ticket&strategy=cas'
128128
end
129129
end
130130

@@ -140,11 +140,11 @@
140140
it { is_expected.to be_redirect }
141141

142142
it 'redirects with a failure message' do
143-
expect(subject.headers).to include 'Location' => '/auth/failure?message=invalid_ticket&strategy=cas'
143+
expect(last_response.headers).to include 'Location' => '/auth/failure?message=invalid_ticket&strategy=cas'
144144
end
145145
end
146146

147-
describe 'with a valid ticket' do
147+
context 'with a valid ticket' do
148148
shared_examples 'successful validation' do
149149
before do
150150
stub_request(:get, %r{^http://cas.example.org:8080?/serviceValidate\?([^&]+&)?ticket=593af})
@@ -166,7 +166,7 @@
166166
})
167167
end
168168

169-
context "request.env['omniauth.auth']" do
169+
describe "request.env['omniauth.auth']" do
170170
subject { last_request.env['omniauth.auth'] }
171171

172172
it { is_expected.to be_a Hash }
@@ -179,7 +179,7 @@
179179
expect(subject.uid).to eq '54'
180180
end
181181

182-
context 'the info hash' do
182+
describe "['info']" do
183183
subject { last_request.env['omniauth.auth']['info'] }
184184

185185
it 'includes user info attributes' do
@@ -194,7 +194,7 @@
194194
end
195195
end
196196

197-
context 'the extra hash' do
197+
describe "['extra']" do
198198
subject { last_request.env['omniauth.auth']['extra'] }
199199

200200
it 'includes additional user attributes' do
@@ -225,7 +225,7 @@
225225
end
226226
end
227227

228-
context 'the credentials hash' do
228+
describe "['credentials']" do
229229
subject { last_request.env['omniauth.auth']['credentials'] }
230230

231231
it 'has a ticket value' do
@@ -255,17 +255,17 @@
255255
end
256256

257257
describe 'with a Single Sign-Out logoutRequest' do
258-
subject do
259-
post 'auth/cas/callback', logoutRequest: logoutRequest
258+
subject(:sso_logout_request) do
259+
post 'auth/cas/callback', logoutRequest: logout_request_xml
260260
end
261261

262-
let(:logoutRequest) do
263-
%(
262+
let(:logout_request_xml) do
263+
<<~XML
264264
<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="123abc-1234-ab12-cd34-1234abcd" Version="2.0" IssueInstant="#{Time.now}">
265265
<saml:NameID>@NOT_USED@</saml:NameID>
266266
<samlp:SessionIndex>ST-123456-123abc456def</samlp:SessionIndex>
267267
</samlp:LogoutRequest>
268-
)
268+
XML
269269
end
270270

271271
let(:logout_request) { double('logout_request', call: [200, {}, 'OK']) }
@@ -275,7 +275,7 @@
275275
.to receive(:logout_request_service)
276276
.and_return double('LogoutRequest', new: logout_request)
277277

278-
subject
278+
sso_logout_request
279279
end
280280

281281
it 'initializes a LogoutRequest' do

0 commit comments

Comments
 (0)