Skip to content

Commit b84b22f

Browse files
authored
Merge pull request #53 from c00kiemon5ter/feature-fix-pykcs11-tests
Do not skip pykcs11 tests
2 parents c553d83 + 4657599 commit b84b22f

4 files changed

Lines changed: 74 additions & 68 deletions

File tree

.travis.yml

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1+
sudo: false
12
language: python
2-
sudo: require
3-
python:
4-
- "2.7"
3+
python:
4+
- 2.7
5+
56
addons:
6-
apt:
7-
packages:
8-
- libxml2-dev
9-
- libxslt-dev
10-
- libsofthsm
11-
- softhsm
12-
- opensc
13-
- libengine-pkcs11-openssl
14-
before_install:
15-
- sudo apt-get -qq update
16-
- sudo apt-get -y install libxml2-dev libxslt-dev libsofthsm softhsm opensc libengine-pkcs11-openssl
17-
- pip install .
18-
- pip install nose
19-
- sh scripts/install-pykcs11.sh
20-
- pip install coveralls
21-
script: "coverage run --source=xmlsec setup.py nosetests"
7+
apt:
8+
sources:
9+
- sourceline: ppa:pkg-opendnssec/ppa
10+
packages:
11+
- xmlsec1
12+
- libxml2-dev
13+
- libxslt-dev
14+
- libsofthsm2
15+
- softhsm2
16+
- opensc
17+
- libengine-pkcs11-openssl
18+
- swig
19+
20+
install:
21+
- pip install pykcs11
22+
- pip install nose
23+
- pip install coveralls
24+
25+
script:
26+
- coverage run --source=xmlsec setup.py nosetests -vv -d
27+
2228
after_success:
23-
coveralls
29+
- coveralls

scripts/install-pykcs11.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/xmlsec/test/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ def run_cmd(args, softhsm_conf=None):
3030
logging.debug(out)
3131
rv = proc.wait()
3232
if rv:
33-
raise RuntimeError("command exited with code != 0: %d" % rv)
33+
with open(softhsm_conf) as f:
34+
conf = f.read()
35+
msg = '[cmd: {cmd}] [code: {code}] [stdout: {out}] [stderr: {err}] [config: {conf}]'
36+
msg = msg.format(
37+
cmd=" ".join(args), code=rv, out=out.strip(), err=err.strip(), conf=conf,
38+
)
39+
raise RuntimeError(msg)

src/xmlsec/test/p11_test.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import shutil
1414
import tempfile
1515

16-
from defusedxml import lxml
1716
from lxml import etree
1817

1918
import xmlsec
@@ -37,27 +36,23 @@
3736

3837
component_default_paths = {
3938
'P11_MODULE': [
40-
'/usr/lib/libsofthsm.so',
41-
'/usr/lib/softhsm/libsofthsm.so',
4239
'/usr/lib/softhsm/libsofthsm2.so',
40+
'/usr/lib/softhsm/libsofthsm.so',
4341
],
4442
'P11_ENGINE': [
4543
'/usr/lib/ssl/engines/libpkcs11.so',
4644
'/usr/lib/engines/engine_pkcs11.so',
4745
'/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so',
4846
],
49-
'P11_SPY': [
50-
'/usr/lib/pkcs11/pkcs11-spy.so',
51-
],
5247
'PKCS11_TOOL': [
5348
'/usr/bin/pkcs11-tool',
5449
],
5550
'OPENSC_TOOL': [
5651
'/usr/bin/opensc-tool',
5752
],
5853
'SOFTHSM': [
59-
'/usr/bin/softhsm',
6054
'/usr/bin/softhsm2-util',
55+
'/usr/bin/softhsm',
6156
],
6257
'OPENSSL': [
6358
'/usr/bin/openssl',
@@ -80,9 +75,13 @@
8075
raise unittest.SkipTest("Required components missing: {}".format(missing))
8176

8277
softhsm_version = 1
83-
if component_path['SOFTHSM'] == '/usr/bin/softhsm2-util':
78+
if component_path['SOFTHSM'].endswith('softhsm2-util'):
8479
softhsm_version = 2
8580

81+
openssl_version = subprocess.check_output([component_path['OPENSSL'],
82+
'version']
83+
)[8:11]
84+
8685
p11_test_files = []
8786
softhsm_conf = None
8887
server_cert_pem = None
@@ -117,11 +116,18 @@ def setup():
117116
with open(softhsm_conf, "w") as f:
118117
if softhsm_version == 2:
119118
softhsm_db = _td()
120-
f.write("#Generated by pyXMLSecurity test\ndirectories.tokendir = %s\nobjectstore.backend = file\nlog.level = DEBUG\n"%softhsm_db)
121-
119+
f.write("""
120+
# Generated by pyXMLSecurity test
121+
directories.tokendir = %s
122+
objectstore.backend = file
123+
log.level = DEBUG
124+
""" % softhsm_db)
122125
else:
123126
softhsm_db = _tf()
124-
f.write("#Generated by pyXMLSecurity test\n0:%s\n" % softhsm_db)
127+
f.write("""
128+
# Generated by pyXMLSecurity test
129+
0:%s
130+
""" % softhsm_db)
125131

126132
logging.debug("Initializing the token")
127133
run_cmd([component_path['SOFTHSM'],
@@ -150,27 +156,27 @@ def setup():
150156
openssl_conf = _tf()
151157
logging.debug("Generating OpenSSL config")
152158
with open(openssl_conf, "w") as f:
153-
f.write("""
154-
openssl_conf = openssl_def
155-
156-
[openssl_def]
157-
engines = engine_section
158-
159-
[engine_section]
160-
pkcs11 = pkcs11_section
161-
162-
[pkcs11_section]
163-
engine_id = pkcs11
164-
dynamic_path = %s
165-
MODULE_PATH = %s
166-
PIN = secret1
167-
init = 0
168-
169-
[req]
170-
distinguished_name = req_distinguished_name
171-
172-
[req_distinguished_name]
173-
""" % (component_path['P11_ENGINE'], component_path['P11_MODULE']))
159+
dynamic_path = (
160+
"dynamic_path = %s" % component_path['P11_ENGINE']
161+
if openssl_version == "1.0"
162+
else ""
163+
)
164+
f.write("\n".join([
165+
"openssl_conf = openssl_def",
166+
"[openssl_def]",
167+
"engines = engine_section",
168+
"[engine_section]",
169+
"pkcs11 = pkcs11_section",
170+
"[req]",
171+
"distinguished_name = req_distinguished_name",
172+
"[req_distinguished_name]",
173+
"[pkcs11_section]",
174+
"engine_id = pkcs11",
175+
dynamic_path,
176+
"MODULE_PATH = %s" % component_path['P11_MODULE'],
177+
"PIN = secret1",
178+
"init = 0",
179+
]))
174180

175181
signer_cert_der = _tf()
176182

@@ -182,7 +188,7 @@ def setup():
182188
'-engine', 'pkcs11',
183189
'-config', openssl_conf,
184190
'-keyform', 'engine',
185-
'-key', 'pkcs11:token=test',
191+
'-key', 'label_test',
186192
'-passin', 'pass:secret1',
187193
'-out', signer_cert_pem], softhsm_conf=softhsm_conf)
188194

@@ -269,7 +275,8 @@ def test_open_session_no_pin(self):
269275
if session is not None:
270276
pk11._close_session(session)
271277

272-
@unittest.skipIf(component_path['P11_MODULE'] is None, "SoftHSM PKCS11 module not installed")
278+
# @unittest.skipIf(component_path['P11_MODULE'] is None, "SoftHSM PKCS11 module not installed")
279+
@unittest.skip("SoftHSM PKCS11 module does not support 2 sessions")
273280
def test_two_sessions(self):
274281
session1 = None
275282
session2 = None

0 commit comments

Comments
 (0)