Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_version_integer_invalid_version(invalid_version):
with pytest.raises(RuntimeError):
util.get_version_integer(invalid_version)
try:
kvp_version_integer = util.get_version_integer(kvp_version)
except Exception as err:
kvp_version_integer = 'invalid_value'
if (request != 'GetCapabilities' and
kvp_version_integer != own_version_integer):
error = 1
locator = 'version'
code = 'InvalidParameterValue'
text = ('Invalid value for version: %s. Value MUST be '
'2.0.2 or 3.0.0' % kvp_version)
# check for GetCapabilities acceptversions
if 'acceptversions' in self.kvp:
for vers in self.kvp['acceptversions'].split(','):
vers_integer = util.get_version_integer(vers)
if vers_integer == own_version_integer:
break
else:
error = 1
locator = 'acceptversions'
code = 'VersionNegotiationFailed'
text = ('Invalid parameter value in '
'acceptversions: %s. Value MUST be '
'2.0.2 or 3.0.0' %
self.kvp['acceptversions'])
# test request
if self.kvp['request'] not in \
self.context.model['operations']:
error = 1
locator = 'request'
# test version
if ('version' in self.kvp and
util.get_version_integer(self.kvp['version']) !=
util.get_version_integer(self.request_version) and
self.kvp['request'] != 'GetCapabilities'):
error = 1
locator = 'version'
code = 'InvalidParameterValue'
text = 'Invalid value for version: %s.\
Value MUST be 2.0.2 or 3.0.0' % self.kvp['version']
# check for GetCapabilities acceptversions
if 'acceptversions' in self.kvp:
for vers in self.kvp['acceptversions'].split(','):
if (util.get_version_integer(vers) ==
util.get_version_integer(self.request_version)):
break
else:
error = 1
locator = 'acceptversions'
code = 'VersionNegotiationFailed'
text = 'Invalid parameter value in acceptversions:\
%s. Value MUST be 2.0.2 or 3.0.0' % \
self.kvp['acceptversions']
# test request
if self.kvp['request'] not in \
self.context.model['operations'].keys():
error = 1
locator = 'request'
if self.kvp['request'] in ['Transaction','Harvest']:
break
# test each of the basic keyword values
if error == 0:
# test service
if self.kvp['service'] != 'CSW':
error = 1
locator = 'service'
code = 'InvalidParameterValue'
text = 'Invalid value for service: %s.\
Value MUST be CSW' % self.kvp['service']
# test version
if ('version' in self.kvp and
util.get_version_integer(self.kvp['version']) !=
util.get_version_integer(self.request_version) and
self.kvp['request'] != 'GetCapabilities'):
error = 1
locator = 'version'
code = 'InvalidParameterValue'
text = 'Invalid value for version: %s.\
Value MUST be 2.0.2 or 3.0.0' % self.kvp['version']
# check for GetCapabilities acceptversions
if 'acceptversions' in self.kvp:
for vers in self.kvp['acceptversions'].split(','):
if (util.get_version_integer(vers) ==
util.get_version_integer(self.request_version)):
break
else:
error = 1
locator = 'acceptversions'
text = 'Missing keyword: %s' % k
break
# test each of the basic keyword values
if error == 0:
# test service
if self.kvp['service'] != 'CSW':
error = 1
locator = 'service'
code = 'InvalidParameterValue'
text = 'Invalid value for service: %s.\
Value MUST be CSW' % self.kvp['service']
# test version
if ('version' in self.kvp and
util.get_version_integer(self.kvp['version']) !=
util.get_version_integer(self.request_version) and
self.kvp['request'] != 'GetCapabilities'):
error = 1
locator = 'version'
code = 'InvalidParameterValue'
text = 'Invalid value for version: %s.\
Value MUST be 2.0.2 or 3.0.0' % self.kvp['version']
# check for GetCapabilities acceptversions
if 'acceptversions' in self.kvp:
for vers in self.kvp['acceptversions'].split(','):
if (util.get_version_integer(vers) ==
util.get_version_integer(self.request_version)):
break
else:
error = 1
# test version
if ('version' in self.kvp and
util.get_version_integer(self.kvp['version']) !=
util.get_version_integer(self.request_version) and
self.kvp['request'] != 'GetCapabilities'):
error = 1
locator = 'version'
code = 'InvalidParameterValue'
text = 'Invalid value for version: %s.\
Value MUST be 2.0.2 or 3.0.0' % self.kvp['version']
# check for GetCapabilities acceptversions
if 'acceptversions' in self.kvp:
for vers in self.kvp['acceptversions'].split(','):
if (util.get_version_integer(vers) ==
util.get_version_integer(self.request_version)):
break
else:
error = 1
locator = 'acceptversions'
code = 'VersionNegotiationFailed'
text = 'Invalid parameter value in acceptversions:\
%s. Value MUST be 2.0.2 or 3.0.0' % \
self.kvp['acceptversions']
# test request
if self.kvp['request'] not in \
self.context.model['operations'].keys():
error = 1
locator = 'request'
if self.kvp['request'] in ['Transaction','Harvest']:
code = 'OperationNotSupported'
break
# test each of the basic keyword values
if error == 0:
# test service
if self.kvp['service'] != 'CSW':
error = 1
locator = 'service'
code = 'InvalidParameterValue'
text = 'Invalid value for service: %s.\
Value MUST be CSW' % self.kvp['service']
# test version
kvp_version = self.kvp.get('version', '')
try:
kvp_version_integer = util.get_version_integer(kvp_version)
except Exception as err:
kvp_version_integer = 'invalid_value'
if (request != 'GetCapabilities' and
kvp_version_integer != own_version_integer):
error = 1
locator = 'version'
code = 'InvalidParameterValue'
text = ('Invalid value for version: %s. Value MUST be '
'2.0.2 or 3.0.0' % kvp_version)
# check for GetCapabilities acceptversions
if 'acceptversions' in self.kvp:
for vers in self.kvp['acceptversions'].split(','):
vers_integer = util.get_version_integer(vers)
if vers_integer == own_version_integer:
break
LOGGER.info('Turning on default csw30:Capabilities for base URL')
self.kvp = {
'service': 'CSW',
'acceptversions': '3.0.0',
'request': 'GetCapabilities'
}
http_accept = self.environ.get('HTTP_ACCEPT', '')
if 'application/opensearchdescription+xml' in http_accept:
self.mode = 'opensearch'
self.kvp['outputschema'] = 'http://www.w3.org/2005/Atom'
if error == 0:
# test for the basic keyword values (service, version, request)
basic_options = ['service', 'request']
request = self.kvp.get('request', '')
own_version_integer = util.get_version_integer(
self.request_version)
if self.request_version == '2.0.2':
basic_options.append('version')
if self.request_version == '3.0.0' and 'version' not in self.kvp and self.requesttype == 'POST':
if 'service' not in self.kvp:
self.kvp['service'] = 'CSW'
basic_options.append('service')
self.kvp['version'] = self.request_version
basic_options.append('version')
for k in basic_options:
if k not in self.kvp:
if (k in ['version', 'acceptversions'] and
request == 'GetCapabilities'):
pass
else: