示例#1
0
 def test_gpg_key_invalid_base64(self):
     # $ echo -n "hello world" | base64
     # aGVsbG8gd29ybGQ=
     key = 'aGVsbG8gd29ybGQ'
     with self.assertRaises(ValueError) as e:
         gpg.gpg_key_valid(key)
     self.assertEqual(str(e.exception), gpg.ERR_BASE64)
def validate_users_gpg_key(users):
    ok = True
    for user in users:
        public_gpg_key = user.get('public_gpg_key')
        if public_gpg_key:
            try:
                gpg_key_valid(public_gpg_key)
            except ValueError as e:
                msg = \
                    'invalid public gpg key for user {}: {}'.format(
                        user['org_username'], str(e))
                logging.error(msg)
                ok = False

    return ok
def validate_users_gpg_key(users):
    ok = True
    settings = queries.get_app_interface_settings()
    smtp_client = SmtpClient(settings=settings)
    for user in users:
        public_gpg_key = user.get('public_gpg_key')
        if public_gpg_key:
            recipient = smtp_client.get_recipient(user['org_username'])
            try:
                gpg_key_valid(public_gpg_key, recipient)
            except ValueError as e:
                msg = \
                    'invalid public gpg key for user {}: {}'.format(
                        user['org_username'], str(e))
                logging.error(msg)
                ok = False

    return ok
def validate_users_gpg_key(users):
    ok = True
    for user in users:
        public_gpg_key = user.get('public_gpg_key')
        if public_gpg_key:
            gpg_ok, error_message = gpg_key_valid(public_gpg_key)
            if not gpg_ok:
                msg = \
                    'invalid public gpg key for user {}: {}'.format(
                        user['org_username'], error_message)
                logging.error(msg)
                ok = False

    return ok
示例#5
0
 def test_gpg_key_invalid_equal_signs(self):
     key = 'equal=signs=not=at=end=of=key'
     with self.assertRaises(ValueError) as e:
         gpg.gpg_key_valid(key)
     self.assertEqual(str(e.exception), gpg.ERR_EQUAL_SIGNS)
示例#6
0
 def test_gpg_key_invalid_spaces(self):
     key = 'key with spaces'
     with self.assertRaises(ValueError) as e:
         gpg.gpg_key_valid(key)
     self.assertEqual(str(e.exception), gpg.ERR_SPACES)