Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
b143641b
Commit
b143641b
authored
9 years ago
by
Daniel Wagner-Hall
Browse files
Options
Downloads
Plain Diff
Merge pull request #258 from matrix-org/slowtestsmakemesad
Swap out bcrypt for md5 in tests
parents
a7122692
86fac9c9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/handlers/auth.py
+25
-2
25 additions, 2 deletions
synapse/handlers/auth.py
synapse/handlers/register.py
+1
-2
1 addition, 2 deletions
synapse/handlers/register.py
tests/utils.py
+13
-0
13 additions, 0 deletions
tests/utils.py
with
39 additions
and
4 deletions
synapse/handlers/auth.py
+
25
−
2
View file @
b143641b
...
...
@@ -324,7 +324,7 @@ class AuthHandler(BaseHandler):
def
_check_password
(
self
,
user_id
,
password
,
stored_hash
):
"""
Checks that user_id has passed password, raises LoginError if not.
"""
if
not
bcrypt
.
checkpw
(
password
,
stored_hash
):
if
not
self
.
validate_hash
(
password
,
stored_hash
):
logger
.
warn
(
"
Failed password login for user %s
"
,
user_id
)
raise
LoginError
(
403
,
""
,
errcode
=
Codes
.
FORBIDDEN
)
...
...
@@ -369,7 +369,7 @@ class AuthHandler(BaseHandler):
@defer.inlineCallbacks
def
set_password
(
self
,
user_id
,
newpassword
):
password_hash
=
bcrypt
.
hash
pw
(
newpassword
,
bcrypt
.
gensalt
()
)
password_hash
=
self
.
hash
(
newpassword
)
yield
self
.
store
.
user_set_password_hash
(
user_id
,
password_hash
)
yield
self
.
store
.
user_delete_access_tokens
(
user_id
)
...
...
@@ -391,3 +391,26 @@ class AuthHandler(BaseHandler):
def
_remove_session
(
self
,
session
):
logger
.
debug
(
"
Removing session %s
"
,
session
)
del
self
.
sessions
[
session
[
"
id
"
]]
def
hash
(
self
,
password
):
"""
Computes a secure hash of password.
Args:
password (str): Password to hash.
Returns:
Hashed password (str).
"""
return
bcrypt
.
hashpw
(
password
,
bcrypt
.
gensalt
())
def
validate_hash
(
self
,
password
,
stored_hash
):
"""
Validates that self.hash(password) == stored_hash.
Args:
password (str): Password to hash.
stored_hash (str): Expected hash value.
Returns:
Whether self.hash(password) == stored_hash (bool).
"""
return
bcrypt
.
checkpw
(
password
,
stored_hash
)
This diff is collapsed.
Click to expand it.
synapse/handlers/register.py
+
1
−
2
View file @
b143641b
...
...
@@ -25,7 +25,6 @@ import synapse.util.stringutils as stringutils
from
synapse.util.async
import
run_on_reactor
from
synapse.http.client
import
CaptchaServerHttpClient
import
bcrypt
import
logging
import
urllib
...
...
@@ -82,7 +81,7 @@ class RegistrationHandler(BaseHandler):
yield
run_on_reactor
()
password_hash
=
None
if
password
:
password_hash
=
bcrypt
.
hash
pw
(
password
,
bcrypt
.
gensalt
()
)
password_hash
=
self
.
auth_handler
()
.
hash
(
password
)
if
localpart
:
yield
self
.
check_username
(
localpart
)
...
...
This diff is collapsed.
Click to expand it.
tests/utils.py
+
13
−
0
View file @
b143641b
...
...
@@ -27,6 +27,7 @@ from twisted.enterprise.adbapi import ConnectionPool
from
collections
import
namedtuple
from
mock
import
patch
,
Mock
import
hashlib
import
urllib
import
urlparse
...
...
@@ -67,6 +68,18 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
**
kargs
)
# bcrypt is far too slow to be doing in unit tests
def
swap_out_hash_for_testing
(
old_build_handlers
):
def
build_handlers
():
handlers
=
old_build_handlers
()
auth_handler
=
handlers
.
auth_handler
auth_handler
.
hash
=
lambda
p
:
hashlib
.
md5
(
p
).
hexdigest
()
auth_handler
.
validate_hash
=
lambda
p
,
h
:
hashlib
.
md5
(
p
).
hexdigest
()
==
h
return
handlers
return
build_handlers
hs
.
build_handlers
=
swap_out_hash_for_testing
(
hs
.
build_handlers
)
defer
.
returnValue
(
hs
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment