Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
5e9b3825
Unverified
Commit
5e9b3825
authored
3 years ago
by
David Robertson
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Pull out encrypted_by_default tests from user_directory tests (#10752)
parent
2ca0d648
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
changelog.d/10752.misc
+1
-0
1 addition, 0 deletions
changelog.d/10752.misc
mypy.ini
+1
-0
1 addition, 0 deletions
mypy.ini
tests/handlers/test_room.py
+108
-0
108 additions, 0 deletions
tests/handlers/test_room.py
tests/handlers/test_user_directory.py
+1
-95
1 addition, 95 deletions
tests/handlers/test_user_directory.py
with
111 additions
and
95 deletions
changelog.d/10752.misc
0 → 100644
+
1
−
0
View file @
5e9b3825
Move tests relating to rooms having encryption out of the user_directory tests.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mypy.ini
+
1
−
0
View file @
5e9b3825
...
...
@@ -90,6 +90,7 @@ files =
tests/test_event_auth.py,
tests/test_utils,
tests/handlers/test_password_providers.py,
tests/handlers/test_room.py,
tests/handlers/test_room_summary.py,
tests/handlers/test_send_email.py,
tests/handlers/test_sync.py,
...
...
This diff is collapsed.
Click to expand it.
tests/handlers/test_room.py
0 → 100644
+
108
−
0
View file @
5e9b3825
import
synapse
from
synapse.api.constants
import
EventTypes
,
RoomEncryptionAlgorithms
from
synapse.rest.client
import
login
,
room
from
tests
import
unittest
from
tests.unittest
import
override_config
class
EncryptedByDefaultTestCase
(
unittest
.
HomeserverTestCase
):
servlets
=
[
login
.
register_servlets
,
synapse
.
rest
.
admin
.
register_servlets_for_client_rest_resource
,
room
.
register_servlets
,
]
@override_config
({
"
encryption_enabled_by_default_for_room_type
"
:
"
all
"
})
def
test_encrypted_by_default_config_option_all
(
self
):
"""
Tests that invite-only and non-invite-only rooms have encryption enabled by
default when the config option encryption_enabled_by_default_for_room_type is
"
all
"
.
"""
# Create a user
user
=
self
.
register_user
(
"
user
"
,
"
pass
"
)
user_token
=
self
.
login
(
user
,
"
pass
"
)
# Create an invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
False
,
tok
=
user_token
)
# Check that the room has an encryption state event
event_content
=
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
)
self
.
assertEqual
(
event_content
,
{
"
algorithm
"
:
RoomEncryptionAlgorithms
.
DEFAULT
})
# Create a non invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
True
,
tok
=
user_token
)
# Check that the room has an encryption state event
event_content
=
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
)
self
.
assertEqual
(
event_content
,
{
"
algorithm
"
:
RoomEncryptionAlgorithms
.
DEFAULT
})
@override_config
({
"
encryption_enabled_by_default_for_room_type
"
:
"
invite
"
})
def
test_encrypted_by_default_config_option_invite
(
self
):
"""
Tests that only new, invite-only rooms have encryption enabled by default when
the config option encryption_enabled_by_default_for_room_type is
"
invite
"
.
"""
# Create a user
user
=
self
.
register_user
(
"
user
"
,
"
pass
"
)
user_token
=
self
.
login
(
user
,
"
pass
"
)
# Create an invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
False
,
tok
=
user_token
)
# Check that the room has an encryption state event
event_content
=
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
)
self
.
assertEqual
(
event_content
,
{
"
algorithm
"
:
RoomEncryptionAlgorithms
.
DEFAULT
})
# Create a non invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
True
,
tok
=
user_token
)
# Check that the room does not have an encryption state event
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
expect_code
=
404
,
)
@override_config
({
"
encryption_enabled_by_default_for_room_type
"
:
"
off
"
})
def
test_encrypted_by_default_config_option_off
(
self
):
"""
Tests that neither new invite-only nor non-invite-only rooms have encryption
enabled by default when the config option
encryption_enabled_by_default_for_room_type is
"
off
"
.
"""
# Create a user
user
=
self
.
register_user
(
"
user
"
,
"
pass
"
)
user_token
=
self
.
login
(
user
,
"
pass
"
)
# Create an invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
False
,
tok
=
user_token
)
# Check that the room does not have an encryption state event
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
expect_code
=
404
,
)
# Create a non invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
True
,
tok
=
user_token
)
# Check that the room does not have an encryption state event
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
expect_code
=
404
,
)
This diff is collapsed.
Click to expand it.
tests/handlers/test_user_directory.py
+
1
−
95
View file @
5e9b3825
...
...
@@ -16,7 +16,7 @@ from unittest.mock import Mock
from
twisted.internet
import
defer
import
synapse.rest.admin
from
synapse.api.constants
import
EventTypes
,
RoomEncryptionAlgorithms
,
UserTypes
from
synapse.api.constants
import
UserTypes
from
synapse.api.room_versions
import
RoomVersion
,
RoomVersions
from
synapse.rest.client
import
login
,
room
,
user_directory
from
synapse.storage.roommember
import
ProfileInfo
...
...
@@ -187,100 +187,6 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
s
=
self
.
get_success
(
self
.
handler
.
search_users
(
u1
,
"
user3
"
,
10
))
self
.
assertEqual
(
len
(
s
[
"
results
"
]),
0
)
@override_config
({
"
encryption_enabled_by_default_for_room_type
"
:
"
all
"
})
def
test_encrypted_by_default_config_option_all
(
self
):
"""
Tests that invite-only and non-invite-only rooms have encryption enabled by
default when the config option encryption_enabled_by_default_for_room_type is
"
all
"
.
"""
# Create a user
user
=
self
.
register_user
(
"
user
"
,
"
pass
"
)
user_token
=
self
.
login
(
user
,
"
pass
"
)
# Create an invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
False
,
tok
=
user_token
)
# Check that the room has an encryption state event
event_content
=
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
)
self
.
assertEqual
(
event_content
,
{
"
algorithm
"
:
RoomEncryptionAlgorithms
.
DEFAULT
})
# Create a non invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
True
,
tok
=
user_token
)
# Check that the room has an encryption state event
event_content
=
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
)
self
.
assertEqual
(
event_content
,
{
"
algorithm
"
:
RoomEncryptionAlgorithms
.
DEFAULT
})
@override_config
({
"
encryption_enabled_by_default_for_room_type
"
:
"
invite
"
})
def
test_encrypted_by_default_config_option_invite
(
self
):
"""
Tests that only new, invite-only rooms have encryption enabled by default when
the config option encryption_enabled_by_default_for_room_type is
"
invite
"
.
"""
# Create a user
user
=
self
.
register_user
(
"
user
"
,
"
pass
"
)
user_token
=
self
.
login
(
user
,
"
pass
"
)
# Create an invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
False
,
tok
=
user_token
)
# Check that the room has an encryption state event
event_content
=
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
)
self
.
assertEqual
(
event_content
,
{
"
algorithm
"
:
RoomEncryptionAlgorithms
.
DEFAULT
})
# Create a non invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
True
,
tok
=
user_token
)
# Check that the room does not have an encryption state event
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
expect_code
=
404
,
)
@override_config
({
"
encryption_enabled_by_default_for_room_type
"
:
"
off
"
})
def
test_encrypted_by_default_config_option_off
(
self
):
"""
Tests that neither new invite-only nor non-invite-only rooms have encryption
enabled by default when the config option
encryption_enabled_by_default_for_room_type is
"
off
"
.
"""
# Create a user
user
=
self
.
register_user
(
"
user
"
,
"
pass
"
)
user_token
=
self
.
login
(
user
,
"
pass
"
)
# Create an invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
False
,
tok
=
user_token
)
# Check that the room does not have an encryption state event
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
expect_code
=
404
,
)
# Create a non invite-only room as that user
room_id
=
self
.
helper
.
create_room_as
(
user
,
is_public
=
True
,
tok
=
user_token
)
# Check that the room does not have an encryption state event
self
.
helper
.
get_state
(
room_id
=
room_id
,
event_type
=
EventTypes
.
RoomEncryption
,
tok
=
user_token
,
expect_code
=
404
,
)
def
test_spam_checker
(
self
):
"""
A user which fails the spam checks will not appear in search results.
...
...
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