Skip to content

Commit 77f1281

Browse files
committed
Update method naming and specs
1 parent ab5029c commit 77f1281

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

lib/onelogin/ruby-saml/response.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def session_expires_at
7878
parse_time(node, "SessionNotOnOrAfter")
7979
end
8080
end
81-
81+
8282
# Checks the status of the response for a "Success" code
8383
def success?
8484
@status_code ||= begin
@@ -118,7 +118,7 @@ def validate(soft = true)
118118
validate_structure(soft) &&
119119
validate_response_state(soft) &&
120120
validate_conditions(soft) &&
121-
document.validate2(get_fingerprint, soft) &&
121+
document.validate_document(get_fingerprint, soft) &&
122122
success?
123123
end
124124

lib/xml_security.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def initialize(response)
4444
extract_signed_element_id
4545
end
4646

47-
def validate2(idp_cert_fingerprint, soft = true)
47+
def validate_document(idp_cert_fingerprint, soft = true)
4848
# get cert from response
4949
cert_element = REXML::XPath.first(self, "//ds:X509Certificate", { "ds"=>DSIG })
5050
raise Onelogin::Saml::ValidationError.new("Certificate element missing in response (ds:X509Certificate)") unless cert_element
@@ -59,10 +59,10 @@ def validate2(idp_cert_fingerprint, soft = true)
5959
return soft ? false : (raise Onelogin::Saml::ValidationError.new("Fingerprint mismatch"))
6060
end
6161

62-
validate_doc2(base64_cert, soft)
62+
validate_signature(base64_cert, soft)
6363
end
6464

65-
def validate_doc2(base64_cert, soft = true)
65+
def validate_signature(base64_cert, soft = true)
6666
# validate references
6767

6868
# check for inclusive namespaces

test/response_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class RubySamlTest < Test::Unit::TestCase
120120
settings = Onelogin::Saml::Settings.new
121121
response.settings = settings
122122
settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA"
123-
XMLSecurity::SignedDocument.any_instance.expects(:validate_doc).returns(true)
123+
XMLSecurity::SignedDocument.any_instance.expects(:validate_signature).returns(true)
124124
assert response.validate!
125125
end
126126

@@ -240,13 +240,13 @@ class RubySamlTest < Test::Unit::TestCase
240240
response = Onelogin::Saml::Response.new(response_document)
241241
assert_equal "https://app.onelogin.com/saml/metadata/13590", response.issuer
242242
end
243-
243+
244244
should "return the issuer inside the response" do
245245
response = Onelogin::Saml::Response.new(response_document_2)
246246
assert_equal "wibble", response.issuer
247247
end
248248
end
249-
249+
250250
context "#success" do
251251
should "find a status code that says success" do
252252
response = Onelogin::Saml::Response.new(response_document)

test/xml_security_test.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ class XmlSecurityTest < Test::Unit::TestCase
1111
end
1212

1313
should "should run validate without throwing NS related exceptions" do
14-
assert !@document.validate_doc(@base64cert, true)
14+
assert !@document.validate_signature(@base64cert, true)
1515
end
1616

1717
should "should run validate with throwing NS related exceptions" do
1818
assert_raise(Onelogin::Saml::ValidationError) do
19-
@document.validate_doc(@base64cert, false)
19+
@document.validate_signature(@base64cert, false)
2020
end
2121
end
22-
22+
2323
should "not raise an error when softly validating the document multiple times" do
2424
assert_nothing_raised do
25-
2.times { @document.validate_doc(@base64cert, true) }
25+
2.times { @document.validate_signature(@base64cert, true) }
2626
end
2727
end
2828

2929
should "should raise Fingerprint mismatch" do
3030
exception = assert_raise(Onelogin::Saml::ValidationError) do
31-
@document.validate("no:fi:ng:er:pr:in:t", false)
31+
@document.validate_document("no:fi:ng:er:pr:in:t", false)
3232
end
3333
assert_equal("Fingerprint mismatch", exception.message)
3434
end
3535

3636
should "should raise Digest mismatch" do
3737
exception = assert_raise(Onelogin::Saml::ValidationError) do
38-
@document.validate_doc(@base64cert, false)
38+
@document.validate_signature(@base64cert, false)
3939
end
4040
assert_equal("Digest mismatch", exception.message)
4141
end
@@ -47,7 +47,7 @@ class XmlSecurityTest < Test::Unit::TestCase
4747
document = XMLSecurity::SignedDocument.new(response)
4848
base64cert = document.elements["//ds:X509Certificate"].text
4949
exception = assert_raise(Onelogin::Saml::ValidationError) do
50-
document.validate_doc(base64cert, false)
50+
document.validate_signature(base64cert, false)
5151
end
5252
assert_equal("Key validation error", exception.message)
5353
end
@@ -57,7 +57,7 @@ class XmlSecurityTest < Test::Unit::TestCase
5757
response.sub!(/<ds:X509Certificate>.*<\/ds:X509Certificate>/, "")
5858
document = XMLSecurity::SignedDocument.new(response)
5959
exception = assert_raise(Onelogin::Saml::ValidationError) do
60-
document.validate("a fingerprint", false) # The fingerprint isn't relevant to this test
60+
document.validate_document("a fingerprint", false) # The fingerprint isn't relevant to this test
6161
end
6262
assert_equal("Certificate element missing in response (ds:X509Certificate)", exception.message)
6363
end
@@ -66,41 +66,41 @@ class XmlSecurityTest < Test::Unit::TestCase
6666
context "Algorithms" do
6767
should "validate using SHA1" do
6868
@document = XMLSecurity::SignedDocument.new(fixture(:adfs_response_sha1, false))
69-
assert @document.validate("F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72")
69+
assert @document.validate_document("F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72")
7070
end
7171

7272
should "validate using SHA256" do
7373
@document = XMLSecurity::SignedDocument.new(fixture(:adfs_response_sha256, false))
74-
assert @document.validate("28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA")
74+
assert @document.validate_document("28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA")
7575
end
7676

7777
should "validate using SHA384" do
7878
@document = XMLSecurity::SignedDocument.new(fixture(:adfs_response_sha384, false))
79-
assert @document.validate("F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72")
79+
assert @document.validate_document("F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72")
8080
end
8181

8282
should "validate using SHA512" do
8383
@document = XMLSecurity::SignedDocument.new(fixture(:adfs_response_sha512, false))
84-
assert @document.validate("F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72")
84+
assert @document.validate_document("F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72")
8585
end
8686
end
87-
87+
8888
context "XmlSecurity::SignedDocument" do
89-
89+
9090
context "#extract_inclusive_namespaces" do
9191
should "support explicit namespace resolution for exclusive canonicalization" do
9292
response = fixture(:open_saml_response, false)
9393
document = XMLSecurity::SignedDocument.new(response)
9494
inclusive_namespaces = document.send(:extract_inclusive_namespaces)
95-
95+
9696
assert_equal %w[ xs ], inclusive_namespaces
9797
end
98-
98+
9999
should "support implicit namespace resolution for exclusive canonicalization" do
100100
response = fixture(:no_signature_ns, false)
101101
document = XMLSecurity::SignedDocument.new(response)
102102
inclusive_namespaces = document.send(:extract_inclusive_namespaces)
103-
103+
104104
assert_equal %w[ #default saml ds xs xsi ], inclusive_namespaces
105105
end
106106

@@ -120,10 +120,10 @@ class XmlSecurityTest < Test::Unit::TestCase
120120
should "return an empty list when inclusive namespace element is missing" do
121121
response = fixture(:no_signature_ns, false)
122122
response.slice! %r{<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="#default saml ds xs xsi"/>}
123-
123+
124124
document = XMLSecurity::SignedDocument.new(response)
125125
inclusive_namespaces = document.send(:extract_inclusive_namespaces)
126-
126+
127127
assert inclusive_namespaces.empty?
128128
end
129129
end
@@ -156,5 +156,5 @@ class XmlSecurityTest < Test::Unit::TestCase
156156
end
157157

158158
end
159-
159+
160160
end

0 commit comments

Comments
 (0)