diff --git a/lib/onelogin/ruby-saml/authrequest.rb b/lib/onelogin/ruby-saml/authrequest.rb index 870219a56..443750f90 100644 --- a/lib/onelogin/ruby-saml/authrequest.rb +++ b/lib/onelogin/ruby-saml/authrequest.rb @@ -36,6 +36,7 @@ def create(settings, params = {}) params.each_pair do |key, value| request_params << "&#{key.to_s}=#{CGI.escape(value.to_s)}" end + raise "Invalid settings, idp_sso_target_url is not set!" if settings.idp_sso_target_url.nil? @login_url = settings.idp_sso_target_url + request_params end diff --git a/test/request_test.rb b/test/request_test.rb index 379a11033..239e73737 100644 --- a/test/request_test.rb +++ b/test/request_test.rb @@ -129,6 +129,19 @@ class RequestTest < Minitest::Test assert_match /&hello=$/, auth_url end + describe "when the target url is not set" do + before do + settings.idp_sso_target_url = nil + end + + it "raises an error with a descriptive message" do + err = assert_raises RuntimeError do + OneLogin::RubySaml::Authrequest.new.create(settings) + end + assert_match /idp_sso_target_url is not set/, err.message + end + end + describe "when the target url doesn't contain a query string" do it "create the SAMLRequest parameter correctly" do