From 2cff617e3c1a5f33e36c763b7458c3229f42ff7e Mon Sep 17 00:00:00 2001 From: Javier Torres Date: Tue, 10 Jan 2017 11:23:50 +0100 Subject: [PATCH] Add tests for SAML metadata controller --- Makefile | 1 + app/controllers/carto/saml_controller.rb | 6 ++++- spec/requests/carto/saml_controller_spec.rb | 27 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 spec/requests/carto/saml_controller_spec.rb diff --git a/Makefile b/Makefile index 80d122de66..15f867739f 100644 --- a/Makefile +++ b/Makefile @@ -265,6 +265,7 @@ SPEC_HELPER_MIN_SPECS = \ spec/requests/carto/superadmin/users_controller_spec.rb \ spec/requests/carto/superadmin/user_migration_imports_spec.rb \ spec/requests/carto/superadmin/user_migration_exports_spec.rb \ + spec/requests/carto/saml_controller_spec.rb \ spec/requests/admin/users_controller_spec.rb \ spec/services/carto/user_table_index_service_spec.rb \ spec/lib/carto/strong_password_validator_spec.rb \ diff --git a/app/controllers/carto/saml_controller.rb b/app/controllers/carto/saml_controller.rb index 9290cbfa59..a130c1d5fe 100644 --- a/app/controllers/carto/saml_controller.rb +++ b/app/controllers/carto/saml_controller.rb @@ -4,8 +4,12 @@ require_dependency 'carto/controller_helper' module Carto class SamlController < ApplicationController + include Carto::ControllerHelper + ssl_required :metadata - before_filter :load_organization + before_filter :load_organization, :ensure_saml_enabled + + rescue_from LoadError, UnauthorizedError, with: :rescue_from_carto_error # Callback from Github Oauth def metadata diff --git a/spec/requests/carto/saml_controller_spec.rb b/spec/requests/carto/saml_controller_spec.rb new file mode 100644 index 0000000000..cb5c249743 --- /dev/null +++ b/spec/requests/carto/saml_controller_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper_min' + +describe Carto::SamlController do + before(:all) do + @organization = FactoryGirl.create(:saml_organization) + end + + after(:all) do + @organization.destroy + end + + it 'shows SAML metadata' do + get saml_metadata_url(user_domain: @organization.name) + response.status.should eq 200 + end + + it 'returns an error for non-existing organizations' do + get saml_metadata_url(user_domain: 'wadus') + response.status.should eq 404 + end + + it 'returns an error for non-configured organizations' do + Carto::Organization.any_instance.stubs(:auth_saml_enabled?).returns(false) + get saml_metadata_url(user_domain: @organization.name) + response.status.should eq 403 + end +end