ruby-saml 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-saml might be problematic. Click here for more details.

data/Gemfile CHANGED
@@ -9,4 +9,5 @@ group :test do
9
9
  gem "rake"
10
10
  gem "mocha"
11
11
  gem "nokogiri"
12
+ gem "timecop"
12
13
  end
@@ -36,16 +36,14 @@ module Onelogin
36
36
  # The value of the user identifier as designated by the initialization request response
37
37
  def name_id
38
38
  @name_id ||= begin
39
- node = REXML::XPath.first(document, "/p:Response/a:Assertion[@ID='#{document.signed_element_id}']/a:Subject/a:NameID", { "p" => PROTOCOL, "a" => ASSERTION })
40
- node ||= REXML::XPath.first(document, "/p:Response[@ID='#{document.signed_element_id}']/a:Assertion/a:Subject/a:NameID", { "p" => PROTOCOL, "a" => ASSERTION })
39
+ node = xpath_first_from_signed_assertion('/a:Subject/a:NameID')
41
40
  node.nil? ? nil : node.text
42
41
  end
43
42
  end
44
43
 
45
44
  def sessionindex
46
45
  @sessionindex ||= begin
47
- node = REXML::XPath.first(document, "/p:Response/a:Assertion[@ID='#{document.signed_element_id}']/a:AuthnStatement", { "p" => PROTOCOL, "a" => ASSERTION })
48
- node ||= REXML::XPath.first(document, "/p:Response[@ID='#{document.signed_element_id}']/a:Assertion/a:AuthnStatement", { "p" => PROTOCOL, "a" => ASSERTION })
46
+ node = xpath_first_from_signed_assertion('/a:AuthnStatement')
49
47
  node.nil? ? nil : node.attributes['SessionIndex']
50
48
  end
51
49
  end
@@ -55,7 +53,7 @@ module Onelogin
55
53
  @attr_statements ||= begin
56
54
  result = {}
57
55
 
58
- stmt_element = REXML::XPath.first(document, "/p:Response/a:Assertion/a:AttributeStatement", { "p" => PROTOCOL, "a" => ASSERTION })
56
+ stmt_element = xpath_first_from_signed_assertion('/a:AttributeStatement')
59
57
  return {} if stmt_element.nil?
60
58
 
61
59
  stmt_element.elements.each do |attr_element|
@@ -76,7 +74,7 @@ module Onelogin
76
74
  # When this user session should expire at latest
77
75
  def session_expires_at
78
76
  @expires_at ||= begin
79
- node = REXML::XPath.first(document, "/p:Response/a:Assertion/a:AuthnStatement", { "p" => PROTOCOL, "a" => ASSERTION })
77
+ node = xpath_first_from_signed_assertion('/a:AuthnStatement')
80
78
  parse_time(node, "SessionNotOnOrAfter")
81
79
  end
82
80
  end
@@ -91,15 +89,13 @@ module Onelogin
91
89
 
92
90
  # Conditions (if any) for the assertion to run
93
91
  def conditions
94
- @conditions ||= begin
95
- REXML::XPath.first(document, "/p:Response/a:Assertion[@ID='#{document.signed_element_id}']/a:Conditions", { "p" => PROTOCOL, "a" => ASSERTION })
96
- end
92
+ @conditions ||= xpath_first_from_signed_assertion('/a:Conditions')
97
93
  end
98
94
 
99
95
  def issuer
100
96
  @issuer ||= begin
101
97
  node = REXML::XPath.first(document, "/p:Response/a:Issuer", { "p" => PROTOCOL, "a" => ASSERTION })
102
- node ||= REXML::XPath.first(document, "/p:Response/a:Assertion/a:Issuer", { "p" => PROTOCOL, "a" => ASSERTION })
98
+ node ||= xpath_first_from_signed_assertion('/a:Issuer')
103
99
  node.nil? ? nil : node.text
104
100
  end
105
101
  end
@@ -126,7 +122,7 @@ module Onelogin
126
122
  if soft
127
123
  @schema.validate(@xml).map{ return false }
128
124
  else
129
- @schema.validate(@xml).map{ |error| raise(Exception.new("#{error.message}\n\n#{@xml.to_s}")) }
125
+ @schema.validate(@xml).map{ |error| validation_error("#{error.message}\n\n#{@xml.to_s}") }
130
126
  end
131
127
  end
132
128
 
@@ -146,6 +142,12 @@ module Onelogin
146
142
  true
147
143
  end
148
144
 
145
+ def xpath_first_from_signed_assertion(subelt=nil)
146
+ node = REXML::XPath.first(document, "/p:Response/a:Assertion[@ID='#{document.signed_element_id}']#{subelt}", { "p" => PROTOCOL, "a" => ASSERTION })
147
+ node ||= REXML::XPath.first(document, "/p:Response[@ID='#{document.signed_element_id}']/a:Assertion#{subelt}", { "p" => PROTOCOL, "a" => ASSERTION })
148
+ node
149
+ end
150
+
149
151
  def get_fingerprint
150
152
  if settings.idp_cert
151
153
  cert = OpenSSL::X509::Certificate.new(settings.idp_cert)
@@ -1,5 +1,5 @@
1
1
  module Onelogin
2
2
  module Saml
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.1'
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require 'test/unit'
3
3
  require 'shoulda'
4
4
  require 'mocha'
5
5
  require 'ruby-debug'
6
+ require 'timecop'
6
7
 
7
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -119,12 +119,29 @@ class XmlSecurityTest < Test::Unit::TestCase
119
119
  end
120
120
 
121
121
  context "StarfieldTMS" do
122
- should "be able to validate a response" do
123
- response = Onelogin::Saml::Response.new(fixture(:starfield_response))
124
- response.settings = Onelogin::Saml::Settings.new(
125
- :idp_cert_fingerprint => "8D:BA:53:8E:A3:B6:F9:F1:69:6C:BB:D9:D8:BD:41:B3:AC:4F:9D:4D"
126
- )
127
- assert response.validate!
122
+ setup do
123
+ @response = Onelogin::Saml::Response.new(fixture(:starfield_response))
124
+ @response.settings = Onelogin::Saml::Settings.new(
125
+ :idp_cert_fingerprint => "8D:BA:53:8E:A3:B6:F9:F1:69:6C:BB:D9:D8:BD:41:B3:AC:4F:9D:4D"
126
+ )
127
+ end
128
+
129
+ should "be able to validate a good response" do
130
+ Timecop.freeze Time.parse('2012-11-28 17:55:00 UTC') do
131
+ assert @response.validate!
132
+ end
133
+ end
134
+
135
+ should "fail before response is valid" do
136
+ Timecop.freeze Time.parse('2012-11-20 17:55:00 UTC') do
137
+ assert ! @response.is_valid?
138
+ end
139
+ end
140
+
141
+ should "fail after response expires" do
142
+ Timecop.freeze Time.parse('2012-11-30 17:55:00 UTC') do
143
+ assert ! @response.is_valid?
144
+ end
128
145
  end
129
146
  end
130
147
 
metadata CHANGED
@@ -1,72 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-saml
3
- version: !ruby/object:Gem::Version
4
- version: 0.7.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 1
10
+ version: 0.7.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - OneLogin LLC
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-01-23 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: canonix
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - '='
20
- - !ruby/object:Gem::Version
21
- version: 0.1.1
22
- type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
- requirements:
27
- - - '='
28
- - !ruby/object:Gem::Version
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 1
29
34
  version: 0.1.1
30
- - !ruby/object:Gem::Dependency
31
- name: uuid
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '2.3'
38
35
  type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: uuid
39
39
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
- requirements:
42
+ requirements:
43
43
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '2.3'
46
- - !ruby/object:Gem::Dependency
47
- name: nokogiri
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
44
+ - !ruby/object:Gem::Version
45
+ hash: 5
46
+ segments:
47
+ - 2
48
+ - 3
49
+ version: "2.3"
54
50
  type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: nokogiri
55
54
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
57
56
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :runtime
65
+ version_requirements: *id003
62
66
  description: SAML toolkit for Ruby on Rails
63
67
  email: support@onelogin.com
64
68
  executables: []
69
+
65
70
  extensions: []
66
- extra_rdoc_files:
71
+
72
+ extra_rdoc_files:
67
73
  - LICENSE
68
74
  - README.md
69
- files:
75
+ files:
70
76
  - .document
71
77
  - .gitignore
72
78
  - .travis.yml
@@ -115,32 +121,41 @@ files:
115
121
  - test/settings_test.rb
116
122
  - test/test_helper.rb
117
123
  - test/xml_security_test.rb
124
+ has_rdoc: true
118
125
  homepage: http://github.com/onelogin/ruby-saml
119
126
  licenses: []
127
+
120
128
  post_install_message:
121
- rdoc_options:
129
+ rdoc_options:
122
130
  - --charset=UTF-8
123
- require_paths:
131
+ require_paths:
124
132
  - lib
125
- required_ruby_version: !ruby/object:Gem::Requirement
133
+ required_ruby_version: !ruby/object:Gem::Requirement
126
134
  none: false
127
- requirements:
128
- - - ! '>='
129
- - !ruby/object:Gem::Version
130
- version: '0'
131
- required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
143
  none: false
133
- requirements:
134
- - - ! '>='
135
- - !ruby/object:Gem::Version
136
- version: '0'
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
137
151
  requirements: []
152
+
138
153
  rubyforge_project: http://www.rubygems.org/gems/ruby-saml
139
- rubygems_version: 1.8.23
154
+ rubygems_version: 1.6.2
140
155
  signing_key:
141
156
  specification_version: 3
142
157
  summary: SAML Ruby Tookit
143
- test_files:
158
+ test_files:
144
159
  - test/certificates/certificate1
145
160
  - test/logoutrequest_test.rb
146
161
  - test/logoutresponse_test.rb
@@ -166,4 +181,3 @@ test_files:
166
181
  - test/settings_test.rb
167
182
  - test/test_helper.rb
168
183
  - test/xml_security_test.rb
169
- has_rdoc: