Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Jan 13, 2025
1 parent ada54de commit fd41c69
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lib/ruby_saml/authrequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module RubySaml
class Authrequest < SamlMessage

# AuthNRequest ID
attr_reader :uuid
attr_accessor :uuid
alias_method :request_id, :uuid

# Creates the AuthNRequest string.
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_saml/logoutrequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module RubySaml
class Logoutrequest < SamlMessage

# Logout Request ID
attr_reader :uuid
attr_accessor :uuid
alias_method :request_id, :uuid

# Creates the Logout Request string.
Expand Down
5 changes: 2 additions & 3 deletions lib/ruby_saml/slo_logoutresponse.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "ruby_saml/logging"

require "ruby_saml/saml_message"
require "ruby_saml/utils"
require "ruby_saml/setting_error"
Expand All @@ -14,8 +13,8 @@ module RubySaml
class SloLogoutresponse < SamlMessage

# Logout Response ID
attr_reader :uuid
alias_method :request_id, :uuid
attr_accessor :uuid
alias_method :response_id, :uuid

# Creates the Logout Response string.
# @param settings [RubySaml::Settings|nil] Toolkit settings
Expand Down
51 changes: 31 additions & 20 deletions test/authrequest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,39 @@ class AuthrequestTest < Minitest::Test
assert auth_url.include?('&RelayState=http%3A%2F%2Fexample.com')
end

it "creates request with ID prefixed with default '_'" do
request = RubySaml::Authrequest.new
describe "uuid" do
it "uuid is initialized to nil" do
request = RubySaml::Authrequest.new

assert_match(/^_/, request.uuid)
end
assert_nil(request.uuid)
assert_equal request.request_id, request.uuid
end

it "creates request with ID prefixed with default '_'" do
request = RubySaml::Authrequest.new
request.create(settings)

assert_match(/^_/, request.uuid)
assert_equal request.request_id, request.uuid
end

it "creates request with ID prefixed by Settings#sp_uuid_prefix" do
settings.sp_uuid_prefix = 'test'
request = RubySaml::Authrequest.new
request.create(settings)

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

it "can mutate the uuid" do
request = RubySaml::Authrequest.new
request_id = request.request_id
assert_equal request_id, request.uuid
request.uuid = "new_uuid"
assert_equal "new_uuid", request.uuid
assert_equal request.request_id, request.uuid
end
end

describe "when the target url is not set" do
Expand Down Expand Up @@ -272,17 +294,6 @@ class AuthrequestTest < Minitest::Test
assert auth_doc.to_s =~ /<saml:AuthnContextDeclRef>example\/decl\/ref<\/saml:AuthnContextDeclRef>/
end

describe "#manipulate request_id" do
it "be able to modify the request id" do
authnrequest = RubySaml::Authrequest.new
request_id = authnrequest.request_id
assert_equal request_id, authnrequest.uuid
authnrequest.uuid = "new_uuid"
assert_equal authnrequest.request_id, authnrequest.uuid
assert_equal "new_uuid", authnrequest.request_id
end
end

each_signature_algorithm do |sp_key_algo, sp_hash_algo|
describe "#create_params signing with HTTP-POST binding" do
before do
Expand Down
32 changes: 19 additions & 13 deletions test/logoutrequest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,35 @@ class RequestTest < Minitest::Test
end
end

describe "playgin with preix" do
describe "uuid" do
it "uuid is initialized to nil" do
request = RubySaml::Logoutrequest.new

assert_nil(request.uuid)
end

it "creates request with ID prefixed with default '_'" do
request = RubySaml::Logoutrequest.new
request.create(settings)

assert_match(/^_/, request.uuid)
end

it "creates request with ID is prefixed, when :id_prefix is passed" do
RubySaml::Utils::set_prefix("test")
it "creates request with ID prefixed by Settings#sp_uuid_prefix" do
settings.sp_uuid_prefix = 'test'
request = RubySaml::Logoutrequest.new
request.create(settings)

assert_match(/^test/, request.uuid)
RubySaml::Utils::set_prefix("_")
end
end

describe "#manipulate request_id" do
it "be able to modify the request id" do
logoutrequest = RubySaml::Logoutrequest.new
request_id = logoutrequest.request_id
assert_equal request_id, logoutrequest.uuid
logoutrequest.uuid = "new_uuid"
assert_equal logoutrequest.request_id, logoutrequest.uuid
assert_equal "new_uuid", logoutrequest.request_id
it "can mutate the uuid" do
request = RubySaml::Logoutrequest.new
request_id = request.request_id
assert_equal request_id, request.uuid
request.uuid = "new_uuid"
assert_equal "new_uuid", request.uuid
assert_equal request.request_id, request.uuid
end
end

Expand Down
43 changes: 26 additions & 17 deletions test/slo_logoutresponse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,38 @@ 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 = RubySaml::SloLogoutresponse.new
describe "uuid" do
it "uuid is initialized to nil" do
response = RubySaml::SloLogoutresponse.new

assert_match(/^_/, request.uuid)
assert_nil(response.uuid)
assert_equal response.response_id, response.uuid
end

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

assert_match(/^_/, response.uuid)
assert_equal response.response_id, response.uuid
end

it "creates response with ID prefixed by Settings#sp_uuid_prefix" do
settings.sp_uuid_prefix = 'test'
response = RubySaml::SloLogoutresponse.new
response.create(settings)

assert_match(/^test/, response.uuid)
assert_equal response.response_id, response.uuid
end
end

describe "#manipulate response_id" do
it "be able to modify the response id" do
logoutresponse = RubySaml::SloLogoutresponse.new
response_id = logoutresponse.response_id
assert_equal response_id, logoutresponse.uuid
logoutresponse.uuid = "new_uuid"
assert_equal logoutresponse.response_id, logoutresponse.uuid
assert_equal "new_uuid", logoutresponse.response_id
response = RubySaml::SloLogoutresponse.new
response_id = response.response_id
assert_equal response_id, response.uuid
response.uuid = "new_uuid"
assert_equal "new_uuid", response.uuid
assert_equal response.response_id, response.uuid
end
end

Expand Down

0 comments on commit fd41c69

Please sign in to comment.