cassette 1.1.5 → 1.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cassette/authentication/filter.rb +2 -4
- data/lib/cassette/authentication/user.rb +4 -2
- data/lib/cassette/authentication.rb +1 -24
- data/lib/cassette/cache/null_store.rb +34 -0
- data/lib/cassette/cache.rb +8 -2
- data/lib/cassette/errors.rb +9 -11
- data/lib/cassette/http/request.rb +0 -7
- data/lib/cassette/http/ticket_response.rb +23 -40
- data/lib/cassette/http.rb +0 -1
- data/lib/cassette/rubycas/user_factory.rb +0 -2
- data/lib/cassette/version.rb +2 -2
- data/lib/cassette.rb +3 -1
- data/spec/cassette/authentication_spec.rb +3 -3
- metadata +7 -23
- data/lib/cassette/http/parsed_response.rb +0 -20
- data/spec/cassette/http/parsed_response_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36477f617205d04852d5cbfbfecfa50c804979a4
|
4
|
+
data.tar.gz: 25cd9472c3cd2f16896a89330fc7512b6e693afc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97cc8d0ee09138579a8aa99ab4c98938206806c06cf72c685c5cfb9de534203ee77351ab0dca094bd7517dd19a27b45fbe241c74283fa39daf75cda206aa7e84
|
7
|
+
data.tar.gz: 9f7afb92efbb6d7b330a108a9b2cbf1dce9f6839e9e104e91e5f1700288c95dfdab4f59555db34773a4b4d1ea958ee97ec89bb87fea71898fb56ad50a23c3739
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'active_support/concern'
|
4
3
|
require 'cassette/authentication/user'
|
5
4
|
|
6
5
|
module Cassette
|
7
6
|
class Authentication
|
8
7
|
module Filter
|
9
|
-
|
10
|
-
|
11
|
-
included do |controller|
|
8
|
+
def self.included(controller)
|
9
|
+
controller.extend(ClassMethods)
|
12
10
|
controller.before_action(:validate_authentication_ticket)
|
13
11
|
controller.send(:attr_accessor, :current_user)
|
14
12
|
end
|
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
require 'cassette/authentication'
|
4
4
|
require 'cassette/authentication/authorities'
|
5
|
-
require '
|
5
|
+
require 'forwardable'
|
6
6
|
|
7
7
|
module Cassette
|
8
8
|
class Authentication
|
9
9
|
class User
|
10
|
+
extend Forwardable
|
11
|
+
|
10
12
|
attr_accessor :login, :name, :authorities, :email, :ticket, :type
|
11
|
-
|
13
|
+
def_delegators :@authorities, :has_role?, :has_raw_role?
|
12
14
|
|
13
15
|
def initialize(attrs = {})
|
14
16
|
config = attrs[:config]
|
@@ -31,7 +31,7 @@ module Cassette
|
|
31
31
|
begin
|
32
32
|
logger.info("Validating #{ticket} on #{validate_path}")
|
33
33
|
|
34
|
-
response = http.
|
34
|
+
response = http.post(validate_path, ticket: ticket, service: service).body
|
35
35
|
ticket_response = Http::TicketResponse.new(response)
|
36
36
|
|
37
37
|
logger.info("Validation resut: #{response.inspect}")
|
@@ -54,29 +54,6 @@ module Cassette
|
|
54
54
|
|
55
55
|
attr_accessor :cache, :logger, :http, :config
|
56
56
|
|
57
|
-
def try_content(node, *keys)
|
58
|
-
keys.inject(node) do |a, e|
|
59
|
-
a.try(:[], e)
|
60
|
-
end.try(:[], '__content__')
|
61
|
-
end
|
62
|
-
|
63
|
-
def extract_user(xml, ticket)
|
64
|
-
ActiveSupport::XmlMini.with_backend('LibXML') do
|
65
|
-
result = ActiveSupport::XmlMini.parse(xml)
|
66
|
-
|
67
|
-
login = try_content(result, 'serviceResponse', 'authenticationSuccess', 'user')
|
68
|
-
|
69
|
-
if login
|
70
|
-
attributes = result['serviceResponse']['authenticationSuccess']['attributes']
|
71
|
-
name = try_content(attributes, 'cn')
|
72
|
-
authorities = try_content(attributes, 'authorities')
|
73
|
-
|
74
|
-
Cassette::Authentication::User.new(login: login, name: name, authorities: authorities,
|
75
|
-
ticket: ticket, config: config)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
57
|
def validate_path
|
81
58
|
"/serviceValidate"
|
82
59
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Cassette
|
4
|
+
module Cache
|
5
|
+
# You cache nothing, null store
|
6
|
+
#
|
7
|
+
# This is a fallback class when Rails or ActiveSupport cache cannot
|
8
|
+
# be loaded
|
9
|
+
class NullStore
|
10
|
+
def clear
|
11
|
+
end
|
12
|
+
|
13
|
+
def read(_key, _options)
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_matched(_key)
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def write(_key, _value, _options)
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def increment(_key)
|
26
|
+
0
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch(_key, _options, &block)
|
30
|
+
block.call
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/cassette/cache.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
begin
|
4
|
+
require 'active_support/cache'
|
5
|
+
rescue LoadError
|
6
|
+
require 'cassette/cache/null_store'
|
7
|
+
end
|
4
8
|
|
5
9
|
module Cassette
|
6
10
|
module Cache
|
@@ -8,8 +12,10 @@ module Cassette
|
|
8
12
|
@backend ||= begin
|
9
13
|
if defined?(::Rails) && ::Rails.cache
|
10
14
|
::Rails.cache
|
11
|
-
|
15
|
+
elsif defined?(::ActiveSupport::Cache::MemoryStore)
|
12
16
|
ActiveSupport::Cache::MemoryStore.new
|
17
|
+
else
|
18
|
+
NullStore.new
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/cassette/errors.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'active_support/inflector'
|
4
|
-
|
5
3
|
module Cassette
|
6
4
|
module Errors
|
7
5
|
TYPES = {
|
8
|
-
401 => :
|
9
|
-
400 => :
|
10
|
-
403 => :
|
11
|
-
500 => :
|
12
|
-
404 => :
|
13
|
-
412 => :
|
6
|
+
401 => :AuthorizationRequired,
|
7
|
+
400 => :BadRequest,
|
8
|
+
403 => :Forbidden,
|
9
|
+
500 => :InternalServerError,
|
10
|
+
404 => :NotFound,
|
11
|
+
412 => :PreconditionFailed
|
14
12
|
}
|
15
13
|
|
16
14
|
def self.raise_by_code(code)
|
@@ -19,12 +17,12 @@ module Cassette
|
|
19
17
|
if name
|
20
18
|
fail error_class(name)
|
21
19
|
else
|
22
|
-
fail error_class(:
|
20
|
+
fail error_class(:InternalServerError)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
24
|
def self.error_class(name)
|
27
|
-
|
25
|
+
Cassette::Errors.const_get(name)
|
28
26
|
end
|
29
27
|
|
30
28
|
class Base < StandardError
|
@@ -34,7 +32,7 @@ module Cassette
|
|
34
32
|
end
|
35
33
|
|
36
34
|
TYPES.each do |status, name|
|
37
|
-
const_set(name
|
35
|
+
const_set(name, Class.new(Errors::Base))
|
38
36
|
error_class(name).const_set('CODE', status)
|
39
37
|
end
|
40
38
|
end
|
@@ -1,47 +1,30 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'rexml/xpath'
|
3
|
+
|
1
4
|
module Cassette
|
2
5
|
module Http
|
3
6
|
class TicketResponse
|
4
|
-
|
5
|
-
@content = ParsedResponse.new(response)
|
6
|
-
end
|
7
|
-
|
8
|
-
def login
|
9
|
-
fetch_val(
|
10
|
-
content,
|
11
|
-
'serviceResponse',
|
12
|
-
'authenticationSuccess',
|
13
|
-
'user',
|
14
|
-
'__content__'
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
def name
|
19
|
-
fetch_val(attributes, 'cn', '__content__')
|
20
|
-
end
|
21
|
-
|
22
|
-
def authorities
|
23
|
-
fetch_val(attributes, 'authorities', '__content__')
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
attr_reader :content
|
29
|
-
|
30
|
-
def fetch_val(hash, *keys)
|
31
|
-
keys.reduce(hash, &access_key)
|
32
|
-
end
|
33
|
-
|
34
|
-
def access_key
|
35
|
-
lambda { |hash, key| hash.try(:[], key) }
|
36
|
-
end
|
7
|
+
attr_reader :login, :name, :authorities
|
37
8
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
)
|
9
|
+
def initialize(response)
|
10
|
+
namespaces = { "cas" => "http://www.yale.edu/tp/cas" }
|
11
|
+
query = "//cas:serviceResponse/cas:authenticationSuccess/cas:user"
|
12
|
+
|
13
|
+
document = REXML::Document.new(response)
|
14
|
+
element = REXML::XPath.first(document, query, namespaces)
|
15
|
+
@login = element.try(:text)
|
16
|
+
|
17
|
+
if @login
|
18
|
+
attributes_query =
|
19
|
+
"//cas:serviceResponse/cas:authenticationSuccess/cas:attributes"
|
20
|
+
attributes = Hash[REXML::XPath.
|
21
|
+
first(document, attributes_query, namespaces).
|
22
|
+
elements.
|
23
|
+
map { |e| [e.name, e.text] }]
|
24
|
+
|
25
|
+
@name = attributes['cn']
|
26
|
+
@authorities = attributes['authorities']
|
27
|
+
end
|
45
28
|
end
|
46
29
|
end
|
47
30
|
end
|
data/lib/cassette/http.rb
CHANGED
data/lib/cassette/version.rb
CHANGED
data/lib/cassette.rb
CHANGED
@@ -12,9 +12,11 @@ require 'cassette/authentication/cache'
|
|
12
12
|
require 'cassette/authentication/filter'
|
13
13
|
|
14
14
|
require 'faraday'
|
15
|
+
require 'forwardable'
|
15
16
|
require 'logger'
|
16
17
|
|
17
18
|
module Cassette
|
19
|
+
extend Forwardable
|
18
20
|
extend self
|
19
21
|
|
20
22
|
attr_writer :config, :logger
|
@@ -35,5 +37,5 @@ module Cassette
|
|
35
37
|
@config if defined?(@config)
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
def_delegators Http::Request, :post
|
39
41
|
end
|
@@ -45,13 +45,13 @@ describe Cassette::Authentication do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'raises a Forbidden exception on any exceptions' do
|
48
|
-
allow(http).to receive(:
|
48
|
+
allow(http).to receive(:post).with(anything, anything).and_raise(Cassette::Errors::BadRequest)
|
49
49
|
expect { subject.ticket_user('ticket') }.to raise_error(Cassette::Errors::Forbidden)
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'with a failed CAS response' do
|
53
53
|
before do
|
54
|
-
allow(http).to receive(:
|
54
|
+
allow(http).to receive(:post).with(anything, anything)
|
55
55
|
.and_return(OpenStruct.new(body: fixture('cas/fail.xml')))
|
56
56
|
end
|
57
57
|
|
@@ -62,7 +62,7 @@ describe Cassette::Authentication do
|
|
62
62
|
|
63
63
|
context 'with a successful CAS response' do
|
64
64
|
before do
|
65
|
-
allow(http).to receive(:
|
65
|
+
allow(http).to receive(:post).with(anything, anything)
|
66
66
|
.and_return(OpenStruct.new(body: fixture('cas/success.xml')))
|
67
67
|
end
|
68
68
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Hermida Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.9'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: libxml-ruby
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: activesupport
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,7 +31,7 @@ dependencies:
|
|
45
31
|
- - ">"
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: 3.1.0
|
48
|
-
type: :
|
34
|
+
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
@@ -235,13 +221,13 @@ files:
|
|
235
221
|
- lib/cassette/authentication/filter.rb
|
236
222
|
- lib/cassette/authentication/user.rb
|
237
223
|
- lib/cassette/cache.rb
|
224
|
+
- lib/cassette/cache/null_store.rb
|
238
225
|
- lib/cassette/client.rb
|
239
226
|
- lib/cassette/client/cache.rb
|
240
227
|
- lib/cassette/errors.rb
|
241
228
|
- lib/cassette/errors/not_a_customer.rb
|
242
229
|
- lib/cassette/errors/not_an_employee.rb
|
243
230
|
- lib/cassette/http.rb
|
244
|
-
- lib/cassette/http/parsed_response.rb
|
245
231
|
- lib/cassette/http/request.rb
|
246
232
|
- lib/cassette/http/ticket_response.rb
|
247
233
|
- lib/cassette/rubycas.rb
|
@@ -261,7 +247,6 @@ files:
|
|
261
247
|
- spec/cassette/client/cache_spec.rb
|
262
248
|
- spec/cassette/client_spec.rb
|
263
249
|
- spec/cassette/errors_spec.rb
|
264
|
-
- spec/cassette/http/parsed_response_spec.rb
|
265
250
|
- spec/cassette/http/request_spec.rb
|
266
251
|
- spec/cassette/http/ticket_response_spec.rb
|
267
252
|
- spec/cassette/rubycas/routing_constraint_spec.rb
|
@@ -286,12 +271,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
286
271
|
version: '0'
|
287
272
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
273
|
requirements:
|
289
|
-
- - "
|
274
|
+
- - ">"
|
290
275
|
- !ruby/object:Gem::Version
|
291
|
-
version:
|
276
|
+
version: 1.3.1
|
292
277
|
requirements: []
|
293
278
|
rubyforge_project:
|
294
|
-
rubygems_version: 2.5.
|
279
|
+
rubygems_version: 2.4.5.1
|
295
280
|
signing_key:
|
296
281
|
specification_version: 4
|
297
282
|
summary: Generates, validates and caches TGTs and STs
|
@@ -306,7 +291,6 @@ test_files:
|
|
306
291
|
- spec/cassette/client/cache_spec.rb
|
307
292
|
- spec/cassette/client_spec.rb
|
308
293
|
- spec/cassette/errors_spec.rb
|
309
|
-
- spec/cassette/http/parsed_response_spec.rb
|
310
294
|
- spec/cassette/http/request_spec.rb
|
311
295
|
- spec/cassette/http/ticket_response_spec.rb
|
312
296
|
- spec/cassette/rubycas/routing_constraint_spec.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'delegate'
|
2
|
-
require 'active_support/xml_mini'
|
3
|
-
|
4
|
-
module Cassette
|
5
|
-
module Http
|
6
|
-
class ParsedResponse < SimpleDelegator
|
7
|
-
def initialize(raw_content, parser = XMLParser)
|
8
|
-
super(parser.call(raw_content))
|
9
|
-
end
|
10
|
-
|
11
|
-
XMLParser = lambda do |raw_content|
|
12
|
-
ActiveSupport::XmlMini.with_backend('LibXML') do
|
13
|
-
ActiveSupport::XmlMini.parse(raw_content)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
private_constant :XMLParser
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
describe Cassette::Http::ParsedResponse do
|
2
|
-
subject(:parsed_response) { described_class.new(xml_response) }
|
3
|
-
|
4
|
-
let(:xml_response) { fixture('cas/success.xml') }
|
5
|
-
|
6
|
-
let(:hash_response) do
|
7
|
-
{
|
8
|
-
"serviceResponse" => {
|
9
|
-
"authenticationSuccess" => {
|
10
|
-
"user"=> {
|
11
|
-
"__content__" => "test-user"
|
12
|
-
},
|
13
|
-
"attributes" => {
|
14
|
-
"authorities" => {
|
15
|
-
"__content__" => "[CUPOM, AUDITING,]"
|
16
|
-
},
|
17
|
-
"cn" => {
|
18
|
-
"__content__" => "Test System"
|
19
|
-
}
|
20
|
-
}
|
21
|
-
}
|
22
|
-
}
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
it { is_expected.to eq(hash_response) }
|
27
|
-
end
|