Skip to content

Commit b157df0

Browse files
committed
Same code as authnrequest, logoutrequest for logoutresponse
1 parent 926b149 commit b157df0

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

lib/onelogin/ruby-saml/slo_logoutresponse.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def create_params(settings, request_id = nil, logout_message = nil, params = {})
9797
# @return [String] The SAMLResponse String.
9898
#
9999
def create_logout_response_xml_doc(settings, request_id = nil, logout_message = nil)
100+
document = create_xml_document(settings, request_id, logout_message)
101+
sign_document(document, settings)
102+
end
103+
104+
def create_xml_document(settings, request_id = nil, logout_message = nil)
100105
time = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
101106

102107
response_doc = XMLSecurity::Document.new
@@ -126,14 +131,18 @@ def create_logout_response_xml_doc(settings, request_id = nil, logout_message =
126131
status_message = status.add_element 'samlp:StatusMessage'
127132
status_message.text = logout_message
128133

134+
response_doc
135+
end
136+
137+
def sign_document(document, settings)
129138
# embed signature
130139
if settings.security[:logout_responses_signed] && settings.private_key && settings.certificate && settings.security[:embed_sign]
131140
private_key = settings.get_sp_key
132141
cert = settings.get_sp_cert
133-
response_doc.sign_document(private_key, cert, settings.security[:signature_method], settings.security[:digest_method])
142+
document.sign_document(private_key, cert, settings.security[:signature_method], settings.security[:digest_method])
134143
end
135144

136-
response_doc
145+
document
137146
end
138147

139148
end

test/logoutrequest_test.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class RequestTest < Minitest::Test
104104
settings.private_key = ruby_saml_key_text
105105
end
106106

107-
it "doens't sign through create_xml_document" do
107+
it "doesn't sign through create_xml_document" do
108108
unauth_req = OneLogin::RubySaml::Logoutrequest.new
109109
inflated = unauth_req.create_xml_document(settings).to_s
110110

@@ -113,6 +113,22 @@ class RequestTest < Minitest::Test
113113
refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
114114
end
115115

116+
it "sign unsigned request" do
117+
unauth_req = OneLogin::RubySaml::Logoutrequest.new
118+
unauth_req_doc = unauth_req.create_xml_document(settings)
119+
inflated = unauth_req_doc.to_s
120+
121+
refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
122+
refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
123+
refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
124+
125+
inflated = unauth_req.sign_document(unauth_req_doc, settings).to_s
126+
127+
assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
128+
assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
129+
assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
130+
end
131+
116132
it "signs through create_logout_request_xml_doc" do
117133
unauth_req = OneLogin::RubySaml::Logoutrequest.new
118134
inflated = unauth_req.create_logout_request_xml_doc(settings).to_s

test/slo_logoutresponse_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,40 @@ class SloLogoutresponseTest < Minitest::Test
7373
settings.security[:embed_sign] = true
7474
end
7575

76+
it "doesn't sign through create_xml_document" do
77+
unauth_res = OneLogin::RubySaml::SloLogoutresponse.new
78+
inflated = unauth_res.create_xml_document(settings).to_s
79+
80+
refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
81+
refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
82+
refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
83+
end
84+
85+
it "sign unsigned request" do
86+
unauth_res = OneLogin::RubySaml::SloLogoutresponse.new
87+
unauth_res_doc = unauth_res.create_xml_document(settings)
88+
inflated = unauth_res_doc.to_s
89+
90+
refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
91+
refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
92+
refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
93+
94+
inflated = unauth_res.sign_document(unauth_res_doc, settings).to_s
95+
96+
assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
97+
assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
98+
assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
99+
end
100+
101+
it "signs through create_logout_response_xml_doc" do
102+
unauth_res = OneLogin::RubySaml::SloLogoutresponse.new
103+
inflated = unauth_res.create_logout_response_xml_doc(settings).to_s
104+
105+
assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
106+
assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
107+
assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
108+
end
109+
76110
it "create a signed logout response" do
77111
logout_request.settings = settings
78112
params = OneLogin::RubySaml::SloLogoutresponse.new.create_params(settings, logout_request.id, "Custom Logout Message")

0 commit comments

Comments
 (0)