rack-cas 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,26 @@
1
1
  module RackCAS
2
2
  class ServiceValidationResponse
3
- REQUEST_HEADERS = { 'Accept' => '*/*' }
3
+ class AuthenticationFailure < StandardError; end
4
4
 
5
+ REQUEST_HEADERS = { 'Accept' => '*/*' }
6
+
5
7
  def initialize(url)
6
8
  @url = URL.parse(url)
7
9
  end
8
10
 
9
11
  def user
10
- xml.xpath('/cas:serviceResponse/cas:authenticationSuccess/cas:user').text
12
+ if success?
13
+ xml.xpath('/cas:serviceResponse/cas:authenticationSuccess/cas:user').text
14
+ else
15
+ raise AuthenticationFailure, failure_message
16
+ end
11
17
  end
12
18
 
13
19
  def extra_attributes
14
20
  attrs = {}
15
21
 
22
+ raise AuthenticationFailure, failure_message unless success?
23
+
16
24
  # Jasig style
17
25
  if attr_node = xml.at('/cas:serviceResponse/cas:authenticationSuccess/cas:attributes')
18
26
  attr_node.children.each do |node|
@@ -38,7 +46,18 @@ module RackCAS
38
46
 
39
47
  protected
40
48
 
49
+ def success?
50
+ @success ||= !!xml.at('/cas:serviceResponse/cas:authenticationSuccess')
51
+ end
52
+
53
+ def failure_message
54
+ if node = xml.at('/cas:serviceResponse/cas:authenticationFailure')
55
+ node.text.strip
56
+ end
57
+ end
58
+
41
59
  def response
60
+ require 'net/http'
42
61
  return @response unless @response.nil?
43
62
 
44
63
  http = Net::HTTP.new(@url.host, @url.inferred_port)
data/lib/rack-cas/url.rb CHANGED
@@ -34,17 +34,7 @@ module RackCAS
34
34
  end
35
35
 
36
36
  def dup
37
- duplicated_uri = RackCAS::URL.new(
38
- :scheme => self.scheme ? self.scheme.dup : nil,
39
- :user => self.user ? self.user.dup : nil,
40
- :password => self.password ? self.password.dup : nil,
41
- :host => self.host ? self.host.dup : nil,
42
- :port => self.port,
43
- :path => self.path ? self.path.dup : nil,
44
- :query => self.query ? self.query.dup : nil,
45
- :fragment => self.fragment ? self.fragment.dup : nil
46
- )
47
- return duplicated_uri
37
+ RackCAS::URL.new(super.to_hash)
48
38
  end
49
39
  end
50
40
  end
@@ -1,3 +1,3 @@
1
1
  module RackCAS
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -59,6 +59,54 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.11.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.11.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack-test
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
62
110
  description: Simple CAS authentication for Rails, Sinatra or any Rack-based site
63
111
  email: adam.crownoble@biola.edu
64
112
  executables: []