Skip to content

Commit

Permalink
Fixed #6 dput check local section is failed.
Browse files Browse the repository at this point in the history
  * This error is using seciont not defined at /etc/dput.cf or ~/.dput.cf.
  * "local" host is defined at /etc/dput.cf in default.
  * Changed using "local" host and raise KeyError when not defined.

Signed-off-by: Kouhei Maeda <mkouhei@palmtb.net>
  • Loading branch information
mkouhei committed May 30, 2014
1 parent 78d9157 commit e459269
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
49 changes: 38 additions & 11 deletions pydebsign/debsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
class Debsign(object):
""" debsign class """
def __init__(self, changes_path, passphrase=None, keyid=None,
gnupghome=None, verbose=False, lintian=True):
gnupghome=None, verbose=False,
lintian=True, dput_host='local'):
"""
:param changes_path: .changes file path
:param passphrase: passphrase of GPG secret key,
using gpg-agent when this is None.
But cannot use execuceded gpg-agent
by another shell session.
:param keyid: id for the key which will be used to do the signing
:param keyid: id for the key which will be used to do the signing
:param gnupghome: path of .gnupg existed directory
:param verbose: `bool` True is verbose message of gnupg
:param lintian: `bool` True is running lintian by dput
:param verbose: `bool` True is verbose message of gnupg
:param lintian: `bool` True is running lintian by dput
:param dput_host: `str` specify host identifier for dput
'local' is defined in /etc/dput.cf in default
cf. you know to print `dput -H`.
"""
self.changes_path = os.path.abspath(changes_path)
self.dsc_path = ''
Expand All @@ -52,6 +56,10 @@ def __init__(self, changes_path, passphrase=None, keyid=None,
else:
self.gpg = gnupg.GPG(use_agent=use_agent, verbose=verbose)
self.lintian = lintian
if check_dput_host(dput_host) is False:
raise KeyError('%s is not defined '
'in /etc/dput.cf or ~/.dput.cf' % dput_host)
self.dput_host = dput_host

def initialize(self):
""" initialize common propeties """
Expand Down Expand Up @@ -232,9 +240,11 @@ def verify_with_dput(self):
Returns: `bool` True is valid, False is invalid.
"""
if self.lintian:
command = 'dput -ol local %s' % self.changes_path
command = '/usr/bin/dput -ol %s %s' % (self.dput_host,
self.changes_path)
else:
command = 'dput -o local %s' % self.changes_path
command = '/usr/bin/dput -o %s %s' % (self.dput_host,
self.changes_path)
args = shlex.split(command)
return subprocess.call(args)

Expand Down Expand Up @@ -264,20 +274,24 @@ def verification(self, dsc_filesize, dsc_checksums, file_list):


def debsign_process(changes_path, passphrase=None, keyid=None,
gnupghome=None, lintian=True):
gnupghome=None, lintian=True, dput_host='local'):
""" debsign process sequence
:param changes_path: .changes file path
:param passphrase: passphrase of GPG secret key,
using gpg-agent when this is None.
But cannot use execuceded gpg-agent
by another shell session.
:param keyid: id for the key which will be used to do the signing
:param keyid: id for the key which will be used to do the signing
:param gnupghome: path of .gnupg existed directory
:param verbose: `bool` True is verbose message of gnupg
:param lintian: `bool` True is running lintian by dput
:param verbose: `bool` True is verbose message of gnupg
:param lintian: `bool` True is running lintian by dput
:param dput_host: `str` specify host identifier for dput
'local' is defined in /etc/dput.cf in default
cf. you know to print `dput -H`.
"""
dbsg = Debsign(changes_path, passphrase=passphrase,
keyid=keyid, gnupghome=gnupghome, lintian=lintian)
keyid=keyid, gnupghome=gnupghome,
lintian=lintian, dput_host=dput_host)
dbsg.initialize()
file_list = dbsg.parse_changes()

Expand Down Expand Up @@ -321,3 +335,16 @@ def check_encode(data):
"""
return (isinstance(data, bytes) and
isinstance(data, str) is False)


def check_dput_host(dput_host):
""" Check spcified host is defined in dput.cf
Returns: `bool`: True is dput_host is defined
:param dput_host: `str` dput host
"""
command = '/usr/bin/dput -H'
args = shlex.split(command)
response = subprocess.check_output(args).decode('utf-8')
return dput_host in [host.split(' => ')[0]
for host in response.split('\n')
if len(host.split(' => ')) > 1]
22 changes: 21 additions & 1 deletion pydebsign/tests/test_pydebsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def test_normal_case(self):
passphrase=self.passphrase,
keyid=self.keyid,
gnupghome=self.gnupghome,
lintian=False))
lintian=False,
dput_host='local'))

def test_invalid_passphrase(self):
""" trying debsign with invalid passphrase """
Expand Down Expand Up @@ -139,3 +140,22 @@ def test_check_encode(self):
else:
self.assertTrue(debsign.check_encode(_byte))
self.assertTrue(debsign.check_encode(_byte2))

def test_invalid_dput_host_case(self):
""" signing .changes and verifying process is as follows;
1. Signing .dsc file with GPG key.
2. Retrieve size and md5, sha1, sha256 finger print from signed .dsc.
3. Rewrite of above values at .changes.
4. Signing .changes file with GPG key.
5. Verify checksums from .changes and retreived checksums
6. Verify signature of .dsc and .changes
7. Fail .changes file with `dput -o .changes` command.
"""
self.assertRaises(KeyError,
debsign.debsign_process,
self.changes_path,
passphrase=self.passphrase,
keyid=self.keyid,
gnupghome=self.gnupghome,
lintian=False,
dput_host='dummy')

0 comments on commit e459269

Please sign in to comment.