test/utils_test.rb in ruby-saml-1.4.1 vs test/utils_test.rb in ruby-saml-1.4.2

- old
+ new

@@ -1,6 +1,6 @@ -require "test_helper" +require File.expand_path(File.join(File.dirname(__FILE__), "test_helper")) class UtilsTest < Minitest::Test describe ".format_cert" do let(:formatted_certificate) do read_certificate("formatted_certificate") @@ -11,11 +11,11 @@ assert_equal "", OneLogin::RubySaml::Utils.format_cert(cert) end it "returns nil when the cert is nil" do cert = nil - assert_equal nil, OneLogin::RubySaml::Utils.format_cert(cert) + assert_nil OneLogin::RubySaml::Utils.format_cert(cert) end it "returns the certificate when it is valid" do assert_equal formatted_certificate, OneLogin::RubySaml::Utils.format_cert(formatted_certificate) end @@ -46,11 +46,11 @@ assert_equal "", OneLogin::RubySaml::Utils.format_private_key(private_key) end it "returns nil when the private key is nil" do private_key = nil - assert_equal nil, OneLogin::RubySaml::Utils.format_private_key(private_key) + assert_nil OneLogin::RubySaml::Utils.format_private_key(private_key) end it "returns the private key when it is valid" do assert_equal formatted_private_key, OneLogin::RubySaml::Utils.format_private_key(formatted_private_key) end @@ -150,9 +150,59 @@ assert_match /^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/, OneLogin::RubySaml::Utils.uuid end it "doesn't return the same value twice" do refute_equal OneLogin::RubySaml::Utils.uuid, OneLogin::RubySaml::Utils.uuid + end + end + + describe 'uri_match' do + it 'matches two urls' do + destination = 'http://www.example.com/test?var=stuff' + settings = 'http://www.example.com/test?var=stuff' + assert OneLogin::RubySaml::Utils.uri_match?(destination, settings) + end + + it 'fails to match two urls' do + destination = 'http://www.example.com/test?var=stuff' + settings = 'http://www.example.com/othertest?var=stuff' + assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings) + end + + it "matches two URLs if the scheme case doesn't match" do + destination = 'http://www.example.com/test?var=stuff' + settings = 'HTTP://www.example.com/test?var=stuff' + assert OneLogin::RubySaml::Utils.uri_match?(destination, settings) + end + + it "matches two URLs if the host case doesn't match" do + destination = 'http://www.EXAMPLE.com/test?var=stuff' + settings = 'http://www.example.com/test?var=stuff' + assert OneLogin::RubySaml::Utils.uri_match?(destination, settings) + end + + it "fails to match two URLs if the path case doesn't match" do + destination = 'http://www.example.com/TEST?var=stuff' + settings = 'http://www.example.com/test?var=stuff' + assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings) + end + + it "fails to match two URLs if the query case doesn't match" do + destination = 'http://www.example.com/test?var=stuff' + settings = 'http://www.example.com/test?var=STUFF' + assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings) + end + + it 'matches two non urls' do + destination = 'stuff' + settings = 'stuff' + assert OneLogin::RubySaml::Utils.uri_match?(destination, settings) + end + + it "fails to match two non urls" do + destination = 'stuff' + settings = 'not stuff' + assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings) end end end end