postgresql_pg_hba: Exception when two lines with same weight are compared (#59198)

This commit is contained in:
Sebastiaan Mannem 2019-07-18 07:20:19 +02:00 committed by Abhijeet Kasurde
parent 8a13b41823
commit d0538c0d7a
3 changed files with 7 additions and 6 deletions

View file

@ -573,11 +573,11 @@ class PgHbaRule(dict):
return myweight < hisweight
try:
return self['src'] < other['src']
except (TypeError, KeyError):
except TypeError:
return self.source_type_weight() < other.source_type_weight()
errormessage = 'We have two rules ({1}, {2})'.format(self, other)
errormessage += ' with exact same weight. Please file a bug.'
raise PgHbaValueError(errormessage)
except Exception:
# When all else fails, just compare the exact line.
return self.line() < other.line()
def source_weight(self):
"""Report the weight of this source net.

View file

@ -12,7 +12,7 @@ db_session_role2: 'session_role2'
pg_hba_test_ips:
- contype: local
users: 'all,postgres'
users: 'all,postgres,test'
- source: '0000:ffff::'
netmask: 'ffff:fff0::'
- source: '192.168.0.0/24'

View file

@ -143,8 +143,9 @@
- assert:
that:
- 'pg_hba.pg_hba == [
{ "db": "all", "method": "md5", "type": "local", "usr": "postgres" },
{ "db": "all", "method": "ldap", "type": "local", "usr": "+some", "options": "ldapserver=example.com ldapport=389 ldapprefix=\"cn=\"" },
{ "db": "all", "method": "md5", "type": "local", "usr": "postgres" },
{ "db": "all", "method": "md5", "type": "local", "usr": "test" },
{ "db": "all", "method": "md5", "type": "local", "usr": "all" },
{ "db": "all", "method": "cert", "src": "blue", "type": "hostssl", "usr": "+some", "options": "clientcert=1 map=mymap" },
{ "db": "all", "method": "cert", "src": "red", "type": "hostssl", "usr": "+some", "options": "clientcert=1 map=mymap" },