• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / df64ddc8-90c3-487d-9aa2-3b77b7bd21e5

14 Apr 2026 04:41PM UTC coverage: 0.454% (-95.0%) from 95.439%
df64ddc8-90c3-487d-9aa2-3b77b7bd21e5

push

circleci

web-flow
Remove Preservation Conservation work order type check (#5765)

Make sure description and enum is not an empty string

The specific issue appears for items in East Asian with bad data in Alma that fail the eligibility check for the Illiad service.
The problem was only revealed now after the changes in https://github.com/pulibrary/bibdata/pull/3178.

For the East Asian items the enum and description values are empty strings, so the specific  method returns that are present and not nil . The next Illiad eligibility check is the Preservation Conservation which does not exist anymore as a status label.
So the Illiad service eligibility check fails.

related to [#5755]

0 of 7 new or added lines in 4 files covered. (0.0%)

9770 existing lines in 228 files now uncovered.

46 of 10128 relevant lines covered (0.45%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/orangelight/middleware/invalid_parameter_handler.rb
1
# frozen_string_literal: true
2

3
# If the user enters a url that has invalid parameters
4
# this middleware will return a 400 status
5
# and the load balancer will display its own error page
6

UNCOV
7
module Orangelight
×
UNCOV
8
  module Middleware
×
UNCOV
9
    class InvalidParameterHandler
×
UNCOV
10
      def initialize(app)
×
UNCOV
11
        @app = app
×
UNCOV
12
      end
×
13

UNCOV
14
      def call(env)
×
UNCOV
15
        validate_for!(env)
×
UNCOV
16
        @app.call(env)
×
UNCOV
17
      rescue ActionController::BadRequest => bad_request_error
×
UNCOV
18
        raise bad_request_error if raise_error?(bad_request_error.message)
×
19

UNCOV
20
        Rails.logger.error "Invalid parameters passed in the request: #{bad_request_error} within the environment #{@request.inspect}"
×
UNCOV
21
        bad_request_response(env)
×
UNCOV
22
      end
×
23

UNCOV
24
      private
×
25

UNCOV
26
        def bad_request_body
×
UNCOV
27
          'Bad Request'
×
UNCOV
28
        end
×
29

UNCOV
30
        def bad_request_headers(env)
×
UNCOV
31
          {
×
UNCOV
32
            'Content-Type' => "#{request_content_type(env)}; charset=#{default_charset}",
×
UNCOV
33
            'Content-Length' => bad_request_body.bytesize.to_s
×
UNCOV
34
          }
×
UNCOV
35
        end
×
36

UNCOV
37
        def bad_request_response(env)
×
UNCOV
38
          [
×
UNCOV
39
            bad_request_status,
×
UNCOV
40
            bad_request_headers(env),
×
UNCOV
41
            [bad_request_body]
×
UNCOV
42
          ]
×
UNCOV
43
        end
×
44

UNCOV
45
        def bad_request_status
×
UNCOV
46
          400
×
UNCOV
47
        end
×
48

UNCOV
49
        def default_charset
×
UNCOV
50
          ActionDispatch::Response.default_charset
×
UNCOV
51
        end
×
52

UNCOV
53
        def default_content_type
×
54
          'text/html'
×
UNCOV
55
        end
×
56

57
        # Check if facet fields have empty value lists
UNCOV
58
        def facet_fields_values(params)
×
UNCOV
59
          facet_parameter = params.fetch(:f, [])
×
UNCOV
60
          raise ActionController::BadRequest, "Invalid facet parameter passed: #{facet_parameter}" unless facet_parameter.is_a?(Array) || facet_parameter.is_a?(Hash)
×
61

UNCOV
62
          facet_parameter.collect do |facet_field, value_list|
×
UNCOV
63
            raise ActionController::BadRequest, "Facet field #{facet_field} has a scalar value #{value_list}" if value_list.is_a?(String)
×
64

UNCOV
65
            next unless value_list.nil?
×
UNCOV
66
            raise ActionController::BadRequest, "Facet field #{facet_field} has a nil value"
×
UNCOV
67
          end
×
UNCOV
68
        end
×
69

70
        # Check if params have key with leading or trailing whitespaces
UNCOV
71
        def check_for_white_spaces(params)
×
UNCOV
72
          params.each_key do |k|
×
UNCOV
73
            next unless ((k[0].match?(/\s/) || k[-1].match?(/\s/)) && (k.is_a? String)) == true
×
UNCOV
74
            raise ActionController::BadRequest, "Param '#{k}' contains a space"
×
UNCOV
75
          end
×
UNCOV
76
        end
×
77

78
        ##
79
        # Previously, we were rescuing only from exceptions we recognized.
80
        # The problem with that is that there will be exceptions we don't recognize and
81
        # haven't been able to diagnose (see, e.g., https://github.com/pulibrary/orangelight/issues/1455)
82
        # and when those happen we want to provide the user with a graceful way forward,
83
        # not just an error screen. Therefore, we should rescue all errors, log the problem,
84
        # and redirect the user somewhere helpful.
UNCOV
85
        def raise_error?(_message)
×
UNCOV
86
          false
×
UNCOV
87
        end
×
88

UNCOV
89
        def request_content_type(env)
×
UNCOV
90
          request = request_for(env)
×
UNCOV
91
          request.formats.first || default_content_type
×
UNCOV
92
        end
×
93

UNCOV
94
        def request_for(env)
×
UNCOV
95
          ActionDispatch::Request.new(env.dup)
×
UNCOV
96
        end
×
97

UNCOV
98
        def valid_message_patterns
×
99
          [
×
UNCOV
100
            /invalid %-encoding/,
×
UNCOV
101
            /Facet field/,
×
UNCOV
102
            /Invalid facet/,
×
UNCOV
103
            /contains a space/
×
UNCOV
104
          ]
×
UNCOV
105
        end
×
106

UNCOV
107
        def validate_for!(env)
×
108
          # calling request.params is sufficient to trigger an error
109
          # see https://github.com/rack/rack/issues/337#issuecomment-46453404
UNCOV
110
          params = request_for(env).params
×
UNCOV
111
          check_for_white_spaces(params)
×
UNCOV
112
          facet_fields_values(params)
×
UNCOV
113
        end
×
UNCOV
114
    end
×
UNCOV
115
  end
×
UNCOV
116
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc