Skip to content

Commit

Permalink
fix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
pvizeli committed Feb 26, 2020
1 parent 5b9b4ed commit 4c18312
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ FROM python:3.7
WORKDIR /workspaces

# Install Python dependencies from requirements.txt if it exists
COPY requirements.txt requirements_test.txt ./
RUN pip3 install -r requirements.txt -r requirement_tests.txt \
COPY requirements_test.txt .
RUN pip3 install -r requirement_tests.txt \
&& pip3 install tox \
&& rm -f requirements.txt requirements_test.txt
&& rm -f requirements_test.txt

# Set the default shell to bash instead of sh
ENV SHELL /bin/bash
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.idea/vcs.xml
2 changes: 1 addition & 1 deletion pycognito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def admin_delete_user(self):
)

def admin_reset_password(self, username, client_metadata=None):
response = self.client.admin_reset_user_password(
self.client.admin_reset_user_password(
UserPoolId=self.user_pool_id,
Username=username,
ClientMetatada=client_metadata,
Expand Down
49 changes: 25 additions & 24 deletions pycognito/aws_srp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@
import datetime
import hashlib
import hmac
import os
import re

import boto3
import os
import six

from .exceptions import ForceChangePasswordException

# https://github.com/aws/amazon-cognito-identity-js/blob/master/src/AuthenticationHelper.js#L22
n_hex = (
N_HEX = (
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
+ "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
+ "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
+ "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
+ "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
+ "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
+ "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"
+ "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
+ "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"
+ "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
+ "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"
+ "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF"
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
"83655D23DCA3AD961C62F356208552BB9ED529077096966D"
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"
"43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF"
)
# https://github.com/aws/amazon-cognito-identity-js/blob/master/src/AuthenticationHelper.js#L49
g_hex = "2"
info_bits = bytearray("Caldera Derived Key", "utf-8")
G_HEX = "2"
INFO_BITS = bytearray("Caldera Derived Key", "utf-8")


def hash_sha256(buf):
Expand Down Expand Up @@ -84,8 +84,8 @@ def compute_hkdf(ikm, salt):
@private
"""
prk = hmac.new(salt, ikm, hashlib.sha256).digest()
info_bits_update = info_bits + bytearray(chr(1), "utf-8")
hmac_hash = hmac.new(prk, info_bits_update, hashlib.sha256).digest()
INFO_BITS_update = INFO_BITS + bytearray(chr(1), "utf-8")
hmac_hash = hmac.new(prk, INFO_BITS_update, hashlib.sha256).digest()
return hmac_hash[:16]


Expand Down Expand Up @@ -129,9 +129,9 @@ def __init__(
self.client = (
client if client else boto3.client("cognito-idp", region_name=pool_region)
)
self.big_n = hex_to_long(n_hex)
self.g = hex_to_long(g_hex)
self.k = hex_to_long(hex_hash("00" + n_hex + "0" + g_hex))
self.big_n = hex_to_long(N_HEX)
self.g = hex_to_long(G_HEX)
self.k = hex_to_long(hex_hash("00" + N_HEX + "0" + G_HEX))
self.small_a_value = self.generate_random_small_a()
self.large_a_value = self.calculate_a()

Expand Down Expand Up @@ -224,6 +224,7 @@ def process_challenge(self, challenge_parameters):
+ bytearray(secret_block_bytes)
+ bytearray(timestamp, "utf-8")
)

hmac_obj = hmac.new(hkdf, msg, digestmod=hashlib.sha256)
signature_string = base64.standard_b64encode(hmac_obj.digest())
response = {
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ use_parentheses = true

[flake8]
max-line-length = 88
ignore = E501, E203
ignore = E501, W503, E203
29 changes: 12 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import os
from pathlib import Path

from setuptools import setup, find_packages

try:
from pip._internal.req import parse_requirements
except ImportError:
from pip.req import parse_requirements

install_reqs = parse_requirements("requirements.txt", session=False)
test_reqs = parse_requirements("requirements_test.txt", session=False)

version = "0.6.1"

README = """Python class to integrate Boto3's Cognito client so it is easy to login users. With SRP support."""
VERSION = "0.1.0"

setup(
name="pycognito",
version=version,
description=README,
long_description=README,
version=VERSION,
description="Python class to integrate Boto3's Cognito client so it is easy to login users. With SRP support.",
long_description=Path("README.md").read_text(),
long_description_content_type="text/markdown",
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
Expand All @@ -33,8 +24,12 @@
packages=find_packages(),
url="https://github.com/pvizeli/pycognito",
license="Apache License 2.0",
install_requires=[str(ir.req) for ir in install_reqs],
extras_require={"test": [str(ir.req) for ir in test_reqs]},
install_requires=[
"boto3>=1.10.49",
"envs>=1.3",
"python-jose[cryptography]>=3.1.0",
"requests>=2.22.0",
],
include_package_data=True,
zip_safe=True,
)
6 changes: 3 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_verify_token(self):
self.user.authenticate(self.password)
bad_access_token = "{}wrong".format(self.user.access_token)

with self.assertRaises(TokenVerificationException) as vm:
with self.assertRaises(TokenVerificationException):
self.user.verify_token(bad_access_token, "access_token", "access")

# def test_logout(self):
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_validate_verification(self, cognito_user):
def test_confirm_forgot_password(self, cognito_user):
u = cognito_user(self.cognito_user_pool_id, self.app_id, username=self.username)
u.confirm_forgot_password("4553", "samplepassword")
with self.assertRaises(TypeError) as vm:
with self.assertRaises(TypeError):
u.confirm_forgot_password(self.password)

@patch("warrant.aws_srp.AWSSRP.authenticate_user", _mock_authenticate_user)
Expand All @@ -247,7 +247,7 @@ def test_change_password(self, _):
self.user.change_password(self.password, "crazypassword$45DOG")
stub.assert_no_pending_responses()

with self.assertRaises(ParamValidationError) as vm:
with self.assertRaises(ParamValidationError):
self.user.change_password(self.password, None)

def test_set_attributes(self):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ commands =

[testenv:tests]
commands =
nosetests tests
nosetests tests/

0 comments on commit 4c18312

Please sign in to comment.