-
Notifications
You must be signed in to change notification settings - Fork 170
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
Open
ngoldbaum
wants to merge
6
commits into
pyca:main
Choose a base branch
from
ngoldbaum:support-free-threading
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff6d732
Support free-threaded Python 3.13
ngoldbaum 61fe5b6
fix issues with tox.ini
ngoldbaum c72b363
add multithreading test
ngoldbaum 2a0c879
fix pep8
ngoldbaum 9187561
fix ruff format
ngoldbaum c65835f
name linux CI run based on python VERSION
ngoldbaum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
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() | ||
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] | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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