Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/onelogin/ruby-saml/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Utils
(\d+)W # 8: Weeks
)
$)x.freeze
UUID_PREFIX = '_'

# Checks if the x509 cert provided is expired
#
Expand Down Expand Up @@ -333,8 +334,12 @@ def self.retrieve_plaintext(cipher_text, symmetric_key, algorithm)
end
end

def self.set_prefix(value)
UUID_PREFIX.replace value
end

def self.uuid
RUBY_VERSION < '1.9' ? "_#{@@uuid_generator.generate}" : "_#{SecureRandom.uuid}"
"#{UUID_PREFIX}" + (RUBY_VERSION < '1.9' ? "#{@@uuid_generator.generate}" : "#{SecureRandom.uuid}")
end

# Given two strings, attempt to match them as URIs using Rails' parse method. If they can be parsed,
Expand Down
15 changes: 15 additions & 0 deletions test/logoutrequest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ class RequestTest < Minitest::Test
end
end

describe "playgin with preix" do
it "creates request with ID prefixed with default '_'" do
request = OneLogin::RubySaml::Logoutrequest.new

assert_match /^_/, request.uuid
end

it "creates request with ID is prefixed, when :id_prefix is passed" do
OneLogin::RubySaml::Utils::set_prefix("test")
request = OneLogin::RubySaml::Logoutrequest.new
assert_match /^test/, request.uuid
OneLogin::RubySaml::Utils::set_prefix("_")
end
end

describe "signing with HTTP-POST binding" do

before do
Expand Down
13 changes: 13 additions & 0 deletions test/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ class RequestTest < Minitest::Test
assert auth_url.include?('&RelayState=http%3A%2F%2Fexample.com')
end

it "creates request with ID prefixed with default '_'" do
request = OneLogin::RubySaml::Authrequest.new

assert_match /^_/, request.uuid
end

it "creates request with ID is prefixed, when :id_prefix is passed" do
OneLogin::RubySaml::Utils::set_prefix("test")
request = OneLogin::RubySaml::Authrequest.new
assert_match /^test/, request.uuid
OneLogin::RubySaml::Utils::set_prefix("_")
end

describe "when the target url is not set" do
before do
settings.idp_sso_service_url = nil
Expand Down
15 changes: 15 additions & 0 deletions test/slo_logoutresponse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ class SloLogoutresponseTest < Minitest::Test
assert_match /Destination='http:\/\/unauth.com\/logout\/return'/, inflated
end

describe "playgin with preix" do
it "creates request with ID prefixed with default '_'" do
request = OneLogin::RubySaml::SloLogoutresponse.new

assert_match /^_/, request.uuid
end

it "creates request with ID is prefixed, when :id_prefix is passed" do
OneLogin::RubySaml::Utils::set_prefix("test")
request = OneLogin::RubySaml::SloLogoutresponse.new
assert_match /^test/, request.uuid
OneLogin::RubySaml::Utils::set_prefix("_")
end
end

describe "signing with HTTP-POST binding" do

before do
Expand Down