def test_atomic_no_merge_base(): assert merge_dict( {1: atomic([5])}, {1: [6, 7]}, ) == { 1: [6, 7] }
def test_atomic_no_merge_update(): assert merge_dict( {1: [5]}, {1: atomic([6, 7])}, ) == { 1: [6, 7] }
def test_invalid_atomic(self): with self.assertRaises(ValueError): metadata.atomic(1) with self.assertRaises(ValueError): metadata.atomic(None) with self.assertRaises(ValueError): metadata.atomic("str")
def test_dictmap(): assert set( dictionary_key_map( { "key1": 1, "key2": {"key3": [3, 3, 3], "key4": atomic([4, 4, 4]), "key5": {"key6": "6"}, "key7": set((7, 7, 7))}, } ) ) == set( [ ("key1",), ("key2",), ("key2", "key3"), ("key2", "key4"), ("key2", "key5"), ("key2", "key5", "key6"), ("key2", "key7"), ] )
def test_dictmap(): assert set(map_dict_keys({ 'key1': 1, 'key2': { 'key3': [3, 3, 3], 'key4': atomic([4, 4, 4]), 'key5': { 'key6': "6", }, 'key7': set((7, 7, 7)), }, })) == set([ ("key1",), ("key2",), ("key2", "key3"), ("key2", "key4"), ("key2", "key5"), ("key2", "key5", "key6"), ("key2", "key7"), ])
def test_atomic_in_layer(): stack = Metastack({'list': [1, 2, 3]}) stack._set_layer('identifier', {'list': atomic([4])}) assert 1 not in stack.get('list', None) assert 2 not in stack.get('list', None) assert 3 not in stack.get('list', None)
def test_atomic_in_base(): stack = Metastack({'list': atomic([1, 2, 3])}) stack._set_layer('identifier', {'list': [4]}) assert 4 not in stack.get('list', None)
def test_atomic_in_layer(): stack = Metastack() stack.set_layer(0, 'base', {'list': [1, 2, 3]}) stack.set_layer(0, 'overlay', {'list': atomic([4])}) assert list(stack.get(('list', ))) == [4]
def test_atomic_no_merge_base(): assert merge_dict( {1: atomic([5])}, {1: [6, 7]}, ) == {1: [6, 7]}
def test_atomic_no_merge_update(): assert merge_dict( {1: [5]}, {1: atomic([6, 7])}, ) == {1: [6, 7]}
def test_valid_atomic(self): self.assertTrue(isinstance(metadata.atomic([]), _Atomic)) self.assertTrue(isinstance(metadata.atomic(tuple()), _Atomic)) self.assertTrue(isinstance(metadata.atomic(set()), _Atomic)) self.assertTrue(isinstance(metadata.atomic({}), _Atomic))
def add_greylistd_config(metadata): if metadata.get('exim/greylist/enabled', False): if 'exim4-config_check_rcpt' not in metadata.get('exim/acl', {}) \ or 'exim4-config_check_data' not in metadata.get('exim/acl', {}): return {} # patch greylist into config check_rcpt = [] check_data = [] for line in metadata.get('exim/acl/exim4-config_check_rcpt/content'): if line == 'acl_check_rcpt:': check_rcpt += [ 'acl_check_rcpt:', ' # greylistd(8) configuration follows.', ' # This statement has been added by "greylistd-setup-exim4",', ' # and can be removed by running "greylistd-setup-exim4 remove".', ' # Any changes you make here will then be lost.', ' #', ' # Perform greylisting on incoming messages from remote hosts.', ' # We do NOT greylist messages with no envelope sender, because that', ' # would conflict with remote hosts doing callback verifications, and we', ' # might not be able to send mail to such hosts for a while (until the', ' # callback attempt is no longer greylisted, and then some).', ' #', ' # We also check the local whitelist to avoid greylisting mail from', ' # hosts that are expected to forward mail here (such as backup MX hosts,', ' # list servers, etc).', ' #', ' # Because the recipient address has not yet been verified, we do so', ' # now and skip this statement for non-existing recipients. This is', ' # in order to allow for a 550 (reject) response below. If the delivery', ' # happens over a remote transport (such as "smtp"), recipient callout', ' # verification is performed, with the original sender intact.', ' #', ' defer', ' message = $sender_host_address is not yet authorized to deliver \\', ' mail from <$sender_address> to <$local_part@$domain>. \\', ' Please try later.', ' log_message = greylisted.', ' !senders = :', ' !hosts = : +relay_from_hosts : \\', ' ${if exists {/etc/greylistd/whitelist-hosts}\\', ' {/etc/greylistd/whitelist-hosts}{}} : \\', ' ${if exists {/var/lib/greylistd/whitelist-hosts}\\', ' {/var/lib/greylistd/whitelist-hosts}{}}', ' !authenticated = *', ' !acl = acl_local_deny_exceptions', ' !dnslists = ${if exists {/etc/greylistd/dnswl-known-good-sender}\\', ' {${readfile{/etc/greylistd/dnswl-known-good-sender}}}{}}', ' domains = +local_domains : +relay_to_domains', ' verify = recipient', ' condition = ${readsocket{/var/run/greylistd/socket}\\', ' {--grey \\', ' $sender_host_address \\', ' $sender_address \\', ' $local_part@$domain}\\', ' {5s}{}{false}}', '', ' # Deny if blacklisted by greylist', ' deny', ' message = $sender_host_address is blacklisted from delivering \\', ' mail from <$sender_address> to <$local_part@$domain>.', ' log_message = blacklisted.', ' !senders = :', ' !authenticated = *', ' domains = +local_domains : +relay_to_domains', ' verify = recipient', ' condition = ${readsocket{/var/run/greylistd/socket}\\', ' {--black \\', ' $sender_host_address \\', ' $sender_address \\', ' $local_part@$domain}\\', ' {5s}{}{false}}', '', '', '', ] else: check_rcpt.append(line) for line in metadata.get('exim/acl/exim4-config_check_data/content'): if line == 'acl_check_data:': check_data += [ 'acl_check_data:', ' # greylistd(8) configuration follows.', ' # This statement has been added by "greylistd-setup-exim4",', ' # and can be removed by running "greylistd-setup-exim4 remove".', ' # Any changes you make here will then be lost.', ' #', ' # Perform greylisting on incoming messages with no envelope sender here.', ' # We did not subject these to greylisting after RCPT TO:, because that', ' # would interfere with remote hosts doing sender callout verifications.', ' #', ' # Because there is no sender address, we supply only two data items:', ' # - The remote host address', ' # - The recipient address (normally, bounces have only one recipient)', ' #', ' # We also check the local whitelist to avoid greylisting mail from', ' # hosts that are expected to forward mail here (such as backup MX hosts,', ' # list servers, etc).', ' #', ' defer', ' message = $sender_host_address is not yet authorized to deliver \\', ' mail from <$sender_address> to <$recipients>. \\', ' Please try later.', ' log_message = greylisted.', ' senders = :', ' !hosts = : +relay_from_hosts : \\', ' ${if exists {/etc/greylistd/whitelist-hosts}\\', ' {/etc/greylistd/whitelist-hosts}{}} : \\', ' ${if exists {/var/lib/greylistd/whitelist-hosts}\\', ' {/var/lib/greylistd/whitelist-hosts}{}}', ' !authenticated = *', ' !acl = acl_local_deny_exceptions', ' condition = ${readsocket{/var/run/greylistd/socket}\\', ' {--grey \\', ' $sender_host_address \\', ' $recipients}\\', ' {5s}{}{false}}', '', ' # Deny if blacklisted by greylist', ' deny', ' message = $sender_host_address is blacklisted from delivering \\', ' mail from <$sender_address> to <$recipients>.', ' log_message = blacklisted.', ' !senders = :', ' !authenticated = *', ' condition = ${readsocket{/var/run/greylistd/socket}\\', ' {--black \\', ' $sender_host_address \\', ' $recipients}\\', ' {5s}{}{false}}', '', '', ] else: check_data.append(line) return { 'exim': { 'acl': { 'exim4-config_check_rcpt': { 'content': atomic(check_rcpt), }, 'exim4-config_check_data': { 'content': atomic(check_data), } }, } } return {}