From c53851347611c5bd8d551297c3e950aa4c214723 Mon Sep 17 00:00:00 2001 From: Brian Kelly Date: Tue, 3 Sep 2024 11:46:52 -0500 Subject: [PATCH] Strip out proxy from Rails-based WMS requests (#370) --- app/controllers/wms_controller.rb | 18 ++++++++++++++++++ lib/nyugeoblacklight/wms_layer.rb | 12 ++++++++++++ spec/lib/nyu_geoblacklight/wms_layer_spec.rb | 11 +++++++++++ 3 files changed, 41 insertions(+) create mode 100644 app/controllers/wms_controller.rb create mode 100644 lib/nyugeoblacklight/wms_layer.rb create mode 100644 spec/lib/nyu_geoblacklight/wms_layer_spec.rb diff --git a/app/controllers/wms_controller.rb b/app/controllers/wms_controller.rb new file mode 100644 index 00000000..abb695d6 --- /dev/null +++ b/app/controllers/wms_controller.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class WmsController < ApplicationController + def handle + # Overriding to use NYU Specific WMS Layer class + response = NyuGeoblacklight::WmsLayer.new(wms_params).feature_info + + respond_to do |format| + format.json { render json: response } + end + end + + private + + def wms_params + params.permit(Settings.GBL_PARAMS) + end +end diff --git a/lib/nyugeoblacklight/wms_layer.rb b/lib/nyugeoblacklight/wms_layer.rb new file mode 100644 index 00000000..b8581542 --- /dev/null +++ b/lib/nyugeoblacklight/wms_layer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module NyuGeoblacklight + class WmsLayer < Geoblacklight::WmsLayer + def initialize(params) + # Overriding to strip proxy from WMS requests made by Rails app + params['URL'].gsub!('http://proxy.library.nyu.edu/login?url=', '') + + super(params) + end + end +end diff --git a/spec/lib/nyu_geoblacklight/wms_layer_spec.rb b/spec/lib/nyu_geoblacklight/wms_layer_spec.rb new file mode 100644 index 00000000..dd4c2d7b --- /dev/null +++ b/spec/lib/nyu_geoblacklight/wms_layer_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +RSpec.describe NyuGeoblacklight::WmsLayer do + context 'when the URL param contains the NYU proxy' do + it 'strips out the NYU proxy' do + wms_layer = described_class.new({ 'URL' => 'http://proxy.library.nyu.edu/login?url=http://example.com' }) + + expect(wms_layer.url).to eq('http://example.com') + end + end +end