-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support free-threaded Python 3.13 #925
base: main
Are you sure you want to change the base?
Changes from all commits
ff6d732
61fe5b6
c72b363
2a0c879
9187561
c65835f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ jobs: | |
PYTHON: | ||
- {VERSION: "3.8", TOXENV: "py38"} | ||
- {VERSION: "3.13", TOXENV: "py313"} | ||
- {VERSION: "3.13t", TOXENV: "py313"} | ||
MACOS: | ||
- macos-13 | ||
- macos-latest | ||
|
@@ -24,7 +25,7 @@ jobs: | |
- uses: actions/[email protected] | ||
- name: Setup python | ||
id: setup-python | ||
uses: actions/[email protected].0 | ||
uses: quansight-labs/[email protected].1 | ||
with: | ||
python-version: ${{ matrix.PYTHON.VERSION }} | ||
- uses: actions/[email protected] | ||
|
@@ -53,12 +54,13 @@ jobs: | |
PYTHON: | ||
- {VERSION: "3.8", TOXENV: "py38"} | ||
- {VERSION: "3.13", TOXENV: "py313"} | ||
- {VERSION: "3.13t", TOXENV: "py313"} | ||
name: "Python ${{ matrix.PYTHON.VERSION }} on ${{ matrix.WINDOWS.WINDOWS }}" | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Setup python | ||
id: setup-python | ||
uses: actions/[email protected].0 | ||
uses: quansight-labs/[email protected].1 | ||
with: | ||
python-version: ${{ matrix.PYTHON.VERSION }} | ||
architecture: ${{ matrix.WINDOWS.ARCH }} | ||
|
@@ -92,19 +94,20 @@ jobs: | |
- {VERSION: "3.11", TOXENV: "py311"} | ||
- {VERSION: "3.12", TOXENV: "py312"} | ||
- {VERSION: "3.13", TOXENV: "py313"} | ||
- {VERSION: "3.13t", TOXENV: "py313"} | ||
- {VERSION: "pypy-3.9", TOXENV: "pypy3"} | ||
- {VERSION: "pypy-3.10", TOXENV: "pypy3"} | ||
|
||
# MSRV | ||
- {VERSION: "3.13", TOXENV: "py313", RUST_VERSION: "1.64.0"} | ||
- {VERSION: "3.13", TOXENV: "py313", RUST_VERSION: "beta"} | ||
- {VERSION: "3.13", TOXENV: "py313", RUST_VERSION: "nightly"} | ||
name: "${{ matrix.PYTHON.TOXENV }} on linux, Rust ${{ matrix.PYTHON.RUST_VERSION || 'stable' }}" | ||
name: "${{ matrix.PYTHON.VERSION }} on linux, Rust ${{ matrix.PYTHON.RUST_VERSION || 'stable' }}" | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Setup python | ||
id: setup-python | ||
uses: actions/[email protected].0 | ||
uses: quansight-labs/[email protected].1 | ||
with: | ||
python-version: ${{ matrix.PYTHON.VERSION }} | ||
- uses: actions/[email protected] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import uuid | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
import pytest | ||
|
||
import bcrypt | ||
|
@@ -171,7 +174,7 @@ | |
] | ||
|
||
|
||
def test_gensalt_basic(monkeypatch): | ||
def test_gensalt_basic(): | ||
salt = bcrypt.gensalt() | ||
assert salt.startswith(b"$2b$12$") | ||
|
||
|
@@ -219,7 +222,7 @@ def test_gensalt_bad_prefix(): | |
bcrypt.gensalt(prefix=b"bad") | ||
|
||
|
||
def test_gensalt_2a_prefix(monkeypatch): | ||
def test_gensalt_2a_prefix(): | ||
salt = bcrypt.gensalt(prefix=b"2a") | ||
assert salt.startswith(b"$2a$12$") | ||
|
||
|
@@ -464,6 +467,7 @@ def test_kdf_no_warn_rounds(): | |
bcrypt.kdf(b"password", b"salt", 10, 10, True) | ||
|
||
|
||
@pytest.mark.thread_unsafe() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this thread unsafe? |
||
def test_kdf_warn_rounds(): | ||
with pytest.warns(UserWarning): | ||
bcrypt.kdf(b"password", b"salt", 10, 10) | ||
|
@@ -494,3 +498,41 @@ def test_2a_wraparound_bug(): | |
) | ||
== b"$2a$04$R1lJ2gkNaoPGdafE.H.16.1MKHPvmKwryeulRe225LKProWYwt9Oi" | ||
) | ||
|
||
|
||
@pytest.mark.thread_unsafe() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this thread unsafe? |
||
def test_multithreading(): | ||
def get_id(): | ||
return uuid.uuid4().bytes | ||
|
||
class User: | ||
def __init__(self, id_, pw): | ||
self.id_ = id_ | ||
self.salt = bcrypt.gensalt(4) | ||
self.hash_ = bcrypt.hashpw(pw, self.salt) | ||
self.key = bcrypt.kdf(pw, self.salt, 32, 50) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose these parameters to make this run in a reasonable time. Still, it's a very slow test compared with the rest of the test suite. |
||
assert self.check(pw) | ||
|
||
def check(self, pw): | ||
return bcrypt.checkpw(pw, self.hash_) | ||
|
||
# use UUIDs as both ID and passwords | ||
num_users = 50 | ||
ids = [get_id() for _ in range(num_users)] | ||
pws = {id_: get_id() for id_, _ in zip(ids, range(num_users))} | ||
|
||
user_creator = ThreadPoolExecutor(max_workers=4) | ||
|
||
def create_user(id_, pw): | ||
return id_, User(id_, pw) | ||
|
||
creator_futures = [ | ||
user_creator.submit(create_user, id_, pw) for id_, pw in pws.items() | ||
] | ||
|
||
users = [future.result() for future in creator_futures] | ||
|
||
Comment on lines
+519
to
+534
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there's way too much going on relative to what we're actually trying to test. At base we're trying to to run all the bcrypt functions concurrently. So I think this can simplify to:
remoe the unused id field from User, and then just use the attributes, rather than the pws dict? |
||
for id_, user in users: | ||
assert bcrypt.hashpw(pws[id_], user.salt) == user.hash_ | ||
assert user.check(pws[id_]) | ||
assert bcrypt.kdf(pws[id_], user.salt, 32, 50) == user.key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to this PR, but I noticed these fixtures weren't being used anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great