Skip to content

Commit ab19e64

Browse files
committed
Create Makefile. Adapt github workflow. pep8
1 parent aec7517 commit ab19e64

File tree

6 files changed

+73
-19
lines changed

6 files changed

+73
-19
lines changed

.github/workflows/python-package.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name: Python package
66
on: [push, pull_request]
77

88
jobs:
9-
build:
9+
test:
1010
runs-on: ubuntu-latest
1111

1212
steps:
@@ -15,17 +15,31 @@ jobs:
1515
uses: actions/setup-python@v2
1616
with:
1717
python-version: 2.7
18-
18+
1919
- name: Install dependencies
2020
run: |
2121
sudo apt-get update -qq
2222
sudo apt-get install -qq swig python-dev libxml2-dev libxmlsec1-dev
2323
pip install .
2424
pip install -e ".[test]"
25-
25+
2626
- name: Test
2727
run: |
28-
coverage run --source=src/onelogin/saml2 --rcfile=tests/coverage.rc setup.py test
29-
coverage report -m --rcfile=tests/coverage.rc
30-
pycodestyle tests/src/OneLogin/saml2_tests/*.py demo-flask/*.py demo-django/*.py src/onelogin/saml2/*.py --config=tests/pep8.rc
31-
pyflakes src/onelogin/saml2 demo-django demo-flask tests/src/OneLogin/saml2_tests
28+
make pytest
29+
make pycodestyle
30+
make flake8
31+
32+
- name: Coveralls
33+
uses: AndreMiras/coveralls-python-action@develop
34+
with:
35+
parallel: true
36+
flag-name: Test
37+
38+
coveralls_finish:
39+
needs: test
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Coveralls Finished
43+
uses: AndreMiras/coveralls-python-action@develop
44+
with:
45+
parallel-finished: true

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
VIRTUAL_ENV ?= venv
2+
PYTHON_MAJOR_VERSION=2
3+
PYTHON_MINOR_VERSION=7
4+
PYTHON_VERSION=$(PYTHON_MAJOR_VERSION).$(PYTHON_MINOR_VERSION)
5+
PYTHON_WITH_VERSION=python$(PYTHON_VERSION)
6+
PYTHON=$(VIRTUAL_ENV)/bin/python
7+
PIP=$(VIRTUAL_ENV)/bin/pip
8+
FLAKE8=$(VIRTUAL_ENV)/bin/flake8
9+
PYTEST=$(VIRTUAL_ENV)/bin/pytest
10+
PYCODESTYLE=$(VIRTUAL_ENV)/bin/pycodestyle
11+
COVERAGE=$(VIRTUAL_ENV)/bin/coverage
12+
COVERAGE_CONFIG=tests/coverage.rc
13+
PEP8_CONFIG=tests/pep8.rc
14+
MAIN_SOURCE=src/onelogin/saml2
15+
DEMOS=demo-django demo-flask
16+
TESTS=tests/src/OneLogin/saml2_test
17+
SOURCES=$(MAIN_SOURCE) $(DEMO) $(TESTS)
18+
19+
$(VIRTUAL_ENV):
20+
$(PYTHON_WITH_VERSION) -m venv $(VIRTUAL_ENV)
21+
$(PIP) install .
22+
$(PIP) install -e ".[test]"
23+
24+
virtualenv: $(VIRTUAL_ENV)
25+
26+
pytest: virtualenv
27+
$(COVERAGE) run --source $(MAIN_SOURCE) --rcfile=$(COVERAGE_CONFIG) -m pytest
28+
$(COVERAGE) report -m --rcfile=$(COVERAGE_CONFIG)
29+
30+
pycodestyle: virtualenv
31+
$(PYCODESTYLE) $(SOURCES) --config=$(PEP8_CONFIG)
32+
33+
flake8: virtualenv
34+
$(FLAKE8) --ignore=E501,E731 $(SOURCES)
35+
36+
clean:
37+
rm -rf .pytest_cache/
38+
rm -rf .eggs/
39+
find . -type d -name "__pycache__" -exec rm -r {} +
40+
find . -type d -name "*.egg-info" -exec rm -r {} +
41+
rm .coverage
42+

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
],
4040
extras_require={
4141
'test': (
42+
'pytest>=4.6',
4243
'coverage>=3.6, <5.0',
4344
'freezegun==0.3.5',
4445
'flake8==3.6.0',
45-
'coveralls==1.1',
46+
'coveralls==1.11.1',
4647
),
4748
},
4849
keywords='saml saml2 xmlsec django flask',

src/onelogin/saml2/idp_metadata_parser.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,10 @@ def parse(
193193
data['idp']['singleLogoutService']['binding'] = required_slo_binding
194194

195195
if certs is not None:
196-
if (len(certs) == 1 and
197-
(('signing' in certs and len(certs['signing']) == 1) or
198-
('encryption' in certs and len(certs['encryption']) == 1))) or \
199-
(('signing' in certs and len(certs['signing']) == 1) and
200-
('encryption' in certs and len(certs['encryption']) == 1 and
201-
certs['signing'][0] == certs['encryption'][0])):
196+
signing_cond = 'signing' in certs and len(certs['signing']) == 1
197+
encryption_cond = 'encryption' in certs and len(certs['encryption']) == 1
198+
if (len(certs) == 1 and (signing_cond or encryption_cond)) or \
199+
(signing_cond and encryption_cond and certs['signing'][0] == certs['encryption'][0]):
202200
if 'signing' in certs:
203201
data['idp']['x509cert'] = certs['signing'][0]
204202
else:

src/onelogin/saml2/response.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
266266
continue
267267
else:
268268
irt = sc_data.get('InResponseTo', None)
269-
if (in_response_to is None and irt is not None and
270-
security.get('rejectUnsolicitedResponsesWithInResponseTo', False)) or \
271-
in_response_to and irt and irt != in_response_to:
269+
rurwir = security.get('rejectUnsolicitedResponsesWithInResponseTo', False)
270+
if (in_response_to is None and irt is not None and rurwir) or in_response_to and in_response_to and irt and irt != in_response_to:
272271
continue
273272
recipient = sc_data.get('Recipient', None)
274273
if recipient and current_url not in recipient:

src/onelogin/saml2/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ def get_sp_metadata(self):
697697
)
698698
else:
699699
# Use a custom key to sign the metadata:
700-
if ('keyFileName' not in self.__security['signMetadata'] or
701-
'certFileName' not in self.__security['signMetadata']):
700+
if 'keyFileName' not in self.__security['signMetadata'] or \
701+
'certFileName' not in self.__security['signMetadata']:
702702
raise OneLogin_Saml2_Error(
703703
'Invalid Setting: signMetadata value of the sp is not valid',
704704
OneLogin_Saml2_Error.SETTINGS_INVALID_SYNTAX

0 commit comments

Comments
 (0)