# vulnerabilties. Validation is on by default.
pgwui.validate_hmac = False
+# Take uploaded column headings literally?
+# The available choices are:
+# on The file's column headings, as typed, are the table's column names.
+# off The file's column headings are case-insensitive.
+# ask Put a "Take Column Headings Literally" checkbox on the upload screen.
+# Optional setting. The default is "off".
+#
+# Caution: Non-ASCII column names, particularly in the Turkish locale,
+# are not guaranteed to be case-insensitive.
+pgwui.literal_column_headings = off
+
#
# Pyramid configuration
# vulnerabilties. Validation is on by default.
# pgwui.validate_hmac = True
+# Take uploaded column headings literally?
+# The available choices are:
+# on The file's column headings, as typed, are the table's column names.
+# off The file's column headings are case-insensitive.
+# ask Put a "Take Column Headings Literally" checkbox on the upload screen.
+# Optional setting. The default is "off".
+#
+# Caution: Non-ASCII column names, particularly in the Turkish locale,
+# are not guaranteed to be case-insensitive.
+pgwui.literal_column_headings = off
+
#
# Pyramid configuration
'route_prefix',
'routes',
'validate_hmac',
+ 'literal_column_headings',
])
# Required length of HMAC value
.format(key))
+class BadLiteralColumnHeadingsError(Error):
+ def __init__(self, value):
+ super().__init__(
+ 'The "pgwui.literal_column_headings" PGWUI setting must be'
+ '"on", "off", "ask", or not present')
+
+
class BadHMACError(Error):
pass
# validate_hmac
boolean_setting('pgwui.validate_hmac', settings)
+ # literal_column_headings
+ validate_literal_column_headings(settings)
+
def do_validate_hmac(settings):
'''True unless the user has specificly rejected hmac validation
raise HMACLengthError()
+def validate_literal_column_headings(settings):
+ '''Make sure the values are those allowed
+ '''
+ value = settings.get('pgwui.literal_column_headings')
+ if value is None:
+ return
+ if value not in ('on', 'off', 'ask'):
+ raise BadLiteralColumnHeadingsError(value)
+
+
def validate_settings(settings):
'''Be sure all settings validate
'''
pgwui_server_init.validate_hmac({'session.secret': ''})
+# validate_literal_column_headings()
+
+def test_validate_literal_column_headings_nosetting():
+ '''No error is raised when there's no setting'''
+ pgwui_server_init.validate_literal_column_headings({})
+
+
+def test_validate_literal_column_headings_on():
+ '''No error is raised when the setting is "on"'''
+ pgwui_server_init.validate_literal_column_headings(
+ {'pgwui.literal_column_headings': 'on'})
+
+
+def test_validate_literal_column_headings_off():
+ '''No error is raised when the setting is "off"'''
+ pgwui_server_init.validate_literal_column_headings(
+ {'pgwui.literal_column_headings': 'off'})
+
+
+def test_validate_literal_column_headings_ask():
+ '''No error is raised when the setting is "ask"'''
+ pgwui_server_init.validate_literal_column_headings(
+ {'pgwui.literal_column_headings': 'ask'})
+
+
+def test_validate_literal_column_headings_bad():
+ '''Raises an error when given a bad value'''
+ with pytest.raises(pgwui_server_init.BadLiteralColumnHeadingsError):
+ pgwui_server_init.validate_literal_column_headings(
+ {'pgwui.literal_column_headings': 'bad'})
+
+
# validate_settings()
def test_validate_settings(monkeypatch):