Skip to content

Commit 1033942

Browse files
committed
Support ability to change ID prefix. See #630
1 parent 5a450a2 commit 1033942

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

lib/onelogin/ruby-saml/utils.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Utils
3232
(\d+)W # 8: Weeks
3333
)
3434
$)x.freeze
35+
UUID_PREFIX = '_'
3536

3637
# Checks if the x509 cert provided is expired
3738
#
@@ -333,8 +334,12 @@ def self.retrieve_plaintext(cipher_text, symmetric_key, algorithm)
333334
end
334335
end
335336

337+
def self.set_prefix(value)
338+
UUID_PREFIX.replace value
339+
end
340+
336341
def self.uuid
337-
RUBY_VERSION < '1.9' ? "_#{@@uuid_generator.generate}" : "_#{SecureRandom.uuid}"
342+
"#{UUID_PREFIX}" + (RUBY_VERSION < '1.9' ? "#{@@uuid_generator.generate}" : "#{SecureRandom.uuid}")
338343
end
339344

340345
# Given two strings, attempt to match them as URIs using Rails' parse method. If they can be parsed,

test/logoutrequest_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ class RequestTest < Minitest::Test
9494
end
9595
end
9696

97+
describe "playgin with preix" do
98+
it "creates request with ID prefixed with default '_'" do
99+
request = OneLogin::RubySaml::Logoutrequest.new
100+
101+
assert_match /^_/, request.uuid
102+
end
103+
104+
it "creates request with ID is prefixed, when :id_prefix is passed" do
105+
OneLogin::RubySaml::Utils::set_prefix("test")
106+
request = OneLogin::RubySaml::Logoutrequest.new
107+
assert_match /^test/, request.uuid
108+
OneLogin::RubySaml::Utils::set_prefix("_")
109+
end
110+
end
111+
97112
describe "signing with HTTP-POST binding" do
98113

99114
before do

test/request_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ class RequestTest < Minitest::Test
161161
assert auth_url.include?('&RelayState=http%3A%2F%2Fexample.com')
162162
end
163163

164+
it "creates request with ID prefixed with default '_'" do
165+
request = OneLogin::RubySaml::Authrequest.new
166+
167+
assert_match /^_/, request.uuid
168+
end
169+
170+
it "creates request with ID is prefixed, when :id_prefix is passed" do
171+
OneLogin::RubySaml::Utils::set_prefix("test")
172+
request = OneLogin::RubySaml::Authrequest.new
173+
assert_match /^test/, request.uuid
174+
OneLogin::RubySaml::Utils::set_prefix("_")
175+
end
176+
164177
describe "when the target url is not set" do
165178
before do
166179
settings.idp_sso_service_url = nil

test/slo_logoutresponse_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ class SloLogoutresponseTest < Minitest::Test
8383
assert_match /Destination='http:\/\/unauth.com\/logout\/return'/, inflated
8484
end
8585

86+
describe "playgin with preix" do
87+
it "creates request with ID prefixed with default '_'" do
88+
request = OneLogin::RubySaml::SloLogoutresponse.new
89+
90+
assert_match /^_/, request.uuid
91+
end
92+
93+
it "creates request with ID is prefixed, when :id_prefix is passed" do
94+
OneLogin::RubySaml::Utils::set_prefix("test")
95+
request = OneLogin::RubySaml::SloLogoutresponse.new
96+
assert_match /^test/, request.uuid
97+
OneLogin::RubySaml::Utils::set_prefix("_")
98+
end
99+
end
100+
86101
describe "signing with HTTP-POST binding" do
87102

88103
before do

0 commit comments

Comments
 (0)