Skip to content

Commit

Permalink
Merge pull request #1 from dhinesh03/feature/unit-tests
Browse files Browse the repository at this point in the history
Feature/unit tests
  • Loading branch information
dhinesh03 authored Oct 10, 2024
2 parents fa55cf8 + 2f2d500 commit 20afc7a
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[run]
branch = True
omit =
tests/*
*/__init__.py
*/migrations/*
.*/*
build/*
dist/*
[report]
show_missing = True
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Python tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.9, 3.10, 3.11]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies and package
run: |
python -m pip install --upgrade pip
pip install .
- name: Run tests
run: python setup.py test
6 changes: 3 additions & 3 deletions cognito_token_validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def decorator(*args, **kwargs) -> Tuple[str, int, dict]:
auth_header = self.get_auth_header()
if not auth_header or not auth_header.startswith('Bearer '):
return json.dumps({'status': 'error', 'message': 'Token not provided or malformed'}), 400
token = auth_header.split()[1]

if not token:
try:
token = auth_header.split()[1]
except IndexError:
return json.dumps({'status': 'error', 'message': 'Token is missing!'}), 403

# do some basic validation of the token structure
Expand Down
8 changes: 6 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[metadata]
name = cognito_token_validator
version = 0.1.1
version = 0.1.2
author = Dhinesh Kumar Sundaram
author_email = [email protected]
description = A package for validating AWS Cognito tokens and using them as decorators in Flask routes or standalone Python functions
license = MIT
home-page = https://github.com/dhinesh03/cognito-token-validator
home-page = https://github.com/dhinesh03/cognito-token-validator
[aliases]
test=pytest
[flake8]
max-line-length=120
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

setup(
name='cognito_token_validator',
version='0.1.1',
version='0.1.2',
packages=find_packages(),
install_requires=[
'requests',
'cachetools',
'python-jose',
],
tests_require=[
"pytest",
"pytest-mock",
"pytest-cov",
],
setup_requires=["pytest-runner"],
test_suite="tests",
author='Dhinesh Kumar Sundaram',
author_email='[email protected]',
description='A package for validating AWS Cognito tokens and using them as decorators in Flask routes or standalone Python functions',
Expand All @@ -20,5 +27,5 @@
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
python_requires='>=3.6',
python_requires='>=3.9',
)
File renamed without changes.
Loading

0 comments on commit 20afc7a

Please sign in to comment.