From fd41c6979a128b5a0c39f9efe96aa8e7f0d5b8d4 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Tue, 14 Jan 2025 07:38:12 +0900 Subject: [PATCH] Fix tests --- lib/ruby_saml/authrequest.rb | 2 +- lib/ruby_saml/logoutrequest.rb | 2 +- lib/ruby_saml/slo_logoutresponse.rb | 5 ++- test/authrequest_test.rb | 51 ++++++++++++++++++----------- test/logoutrequest_test.rb | 32 ++++++++++-------- test/slo_logoutresponse_test.rb | 43 ++++++++++++++---------- 6 files changed, 80 insertions(+), 55 deletions(-) diff --git a/lib/ruby_saml/authrequest.rb b/lib/ruby_saml/authrequest.rb index ce13a27f..84b81f65 100644 --- a/lib/ruby_saml/authrequest.rb +++ b/lib/ruby_saml/authrequest.rb @@ -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. diff --git a/lib/ruby_saml/logoutrequest.rb b/lib/ruby_saml/logoutrequest.rb index 4f10ff3e..f89ab8d0 100644 --- a/lib/ruby_saml/logoutrequest.rb +++ b/lib/ruby_saml/logoutrequest.rb @@ -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. diff --git a/lib/ruby_saml/slo_logoutresponse.rb b/lib/ruby_saml/slo_logoutresponse.rb index d77faed8..e8fc4680 100644 --- a/lib/ruby_saml/slo_logoutresponse.rb +++ b/lib/ruby_saml/slo_logoutresponse.rb @@ -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" @@ -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 diff --git a/test/authrequest_test.rb b/test/authrequest_test.rb index 45468511..0a8e121c 100644 --- a/test/authrequest_test.rb +++ b/test/authrequest_test.rb @@ -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 @@ -272,17 +294,6 @@ class AuthrequestTest < Minitest::Test assert auth_doc.to_s =~ /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 diff --git a/test/logoutrequest_test.rb b/test/logoutrequest_test.rb index 82828964..05e90767 100644 --- a/test/logoutrequest_test.rb +++ b/test/logoutrequest_test.rb @@ -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 diff --git a/test/slo_logoutresponse_test.rb b/test/slo_logoutresponse_test.rb index 1636c303..9f150b81 100644 --- a/test/slo_logoutresponse_test.rb +++ b/test/slo_logoutresponse_test.rb @@ -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