Route Manager
Route Manager is the core app, and it handles adding and removing routes that will be blocked.
admin
Register models in the Admin site.
ActionTypeAdmin
Bases: SimpleHistoryAdmin
Configure the ActionType and how it shows up in the Admin site.
Source code in scram/route_manager/admin.py
34 35 36 37 38 39 |
|
EntryAdmin
Bases: SimpleHistoryAdmin
Configure how Entries show up in the Admin site.
Source code in scram/route_manager/admin.py
42 43 44 45 46 47 48 49 50 51 52 |
|
WhoFilter
Bases: SimpleListFilter
Only display users who have added entries in the list_filter.
Source code in scram/route_manager/admin.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
lookups(request, model_admin)
Return list of users who have added entries.
Source code in scram/route_manager/admin.py
16 17 18 19 20 21 22 23 24 25 |
|
queryset(request, queryset)
Queryset for users.
Source code in scram/route_manager/admin.py
27 28 29 30 31 |
|
api
The API, which leverages Django Request Framework.
exceptions
Custom exceptions for the API.
ActiontypeNotAllowed
Bases: APIException
An operation attempted to perform an action on behalf of a client that is unauthorized to perform that type.
Source code in scram/route_manager/api/exceptions.py
25 26 27 28 29 30 |
|
IgnoredRoute
Bases: APIException
An operation attempted to add a route that overlaps with a route on the ignore list.
Source code in scram/route_manager/api/exceptions.py
17 18 19 20 21 22 |
|
PrefixTooLarge
Bases: APIException
The CIDR prefix that was specified is larger than the prefix allowed in the settings.
Source code in scram/route_manager/api/exceptions.py
7 8 9 10 11 12 13 14 |
|
serializers
Serializers provide mappings between the API and the underlying model.
ActionTypeSerializer
Bases: ModelSerializer
Map the serializer to the model via Meta.
Source code in scram/route_manager/api/serializers.py
21 22 23 24 25 26 27 28 |
|
Meta
Maps to the ActionType model, and specifies the fields exposed by the API.
Source code in scram/route_manager/api/serializers.py
24 25 26 27 28 |
|
ClientSerializer
Bases: ModelSerializer
Map the serializer to the model via Meta.
Source code in scram/route_manager/api/serializers.py
45 46 47 48 49 50 51 52 |
|
Meta
Maps to the Client model, and specifies the fields exposed by the API.
Source code in scram/route_manager/api/serializers.py
48 49 50 51 52 |
|
CustomCidrAddressField
Bases: CidrAddressField
Define a wrapper field so swagger can properly handle the inherited field.
Source code in scram/route_manager/api/serializers.py
16 17 18 |
|
EntrySerializer
Bases: HyperlinkedModelSerializer
Due to the use of ForeignKeys, this follows some relationships to make sense via the API.
Source code in scram/route_manager/api/serializers.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
Meta
Maps to the Entry model, and specifies the fields exposed by the API.
Source code in scram/route_manager/api/serializers.py
72 73 74 75 76 |
|
create(validated_data)
staticmethod
Implement custom logic and validates creating a new route.
Source code in scram/route_manager/api/serializers.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
get_comment(obj)
staticmethod
Provide a nicer name for change reason.
Returns:
Name | Type | Description |
---|---|---|
string |
The change reason that modified the Entry. |
Source code in scram/route_manager/api/serializers.py
78 79 80 81 82 83 84 85 |
|
IgnoreEntrySerializer
Bases: ModelSerializer
Map the route to the right field type.
Source code in scram/route_manager/api/serializers.py
104 105 106 107 108 109 110 111 112 113 |
|
Meta
Maps to the IgnoreEntry model, and specifies the fields exposed by the API.
Source code in scram/route_manager/api/serializers.py
109 110 111 112 113 |
|
RouteSerializer
Bases: ModelSerializer
Exposes route as a CIDR field.
Source code in scram/route_manager/api/serializers.py
31 32 33 34 35 36 37 38 39 40 41 42 |
|
Meta
Maps to the Route model, and specifies the fields exposed by the API.
Source code in scram/route_manager/api/serializers.py
36 37 38 39 40 41 42 |
|
views
Views provide mappings between the underlying model and how they're listed in the API.
ActionTypeViewSet
Bases: ReadOnlyModelViewSet
Lookup ActionTypes by name when authenticated, and bind to the serializer.
Source code in scram/route_manager/api/views.py
26 27 28 29 30 31 32 33 34 35 36 |
|
ClientViewSet
Bases: ModelViewSet
Lookup Client by hostname on POSTs regardless of authentication, and bind to the serializer.
Source code in scram/route_manager/api/views.py
52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
EntryViewSet
Bases: ModelViewSet
Lookup Entry when authenticated, and bind to the serializer.
Source code in scram/route_manager/api/views.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
check_client_authorization(actiontype)
Ensure that a given client is authorized to use a given actiontype.
Source code in scram/route_manager/api/views.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
check_ignore_list(route)
staticmethod
Ensure that we're not trying to block something from the ignore list.
Source code in scram/route_manager/api/views.py
106 107 108 109 110 111 112 113 |
|
destroy(request, pk=None, *args, **kwargs)
Only delete active (e.g. announced) entries.
Source code in scram/route_manager/api/views.py
200 201 202 203 204 205 |
|
find_entries(arg, active_filter=None)
staticmethod
Query entries either by pk or overlapping route.
Source code in scram/route_manager/api/views.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
get_permissions()
Override the permissions classes for POST method since we want to accept Entry creates from any client.
Note: We make authorization decisions on whether to actually create the object in the perform_create method later.
Source code in scram/route_manager/api/views.py
80 81 82 83 84 85 86 87 88 |
|
perform_create(serializer)
Create a new Entry, causing that route to receive the actiontype (i.e. block).
Source code in scram/route_manager/api/views.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
retrieve(request, pk=None, **kwargs)
Retrieve a single route.
Source code in scram/route_manager/api/views.py
191 192 193 194 195 196 197 198 |
|
IgnoreEntryViewSet
Bases: ModelViewSet
Lookup IgnoreEntries by route when authenticated, and bind to the serializer.
Source code in scram/route_manager/api/views.py
39 40 41 42 43 44 45 46 47 48 49 |
|
apps
Register ourselves with Django.
RouteManagerConfig
Bases: AppConfig
Define the name of the module that's the main app.
Source code in scram/route_manager/apps.py
6 7 8 9 |
|
authentication_backends
Define one or more custom auth backends.
ESnetAuthBackend
Bases: OIDCAuthenticationBackend
Extend the OIDC backend with a custom permission model.
Source code in scram/route_manager/authentication_backends.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
create_user(claims)
Wrap the superclass's user creation.
Source code in scram/route_manager/authentication_backends.py
40 41 42 43 |
|
update_groups(user, claims)
staticmethod
Set the user's group(s) to whatever is in the claims.
Source code in scram/route_manager/authentication_backends.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
update_user(user, claims)
Determine the user name from the claims and update said user's groups.
Source code in scram/route_manager/authentication_backends.py
45 46 47 48 49 50 51 52 53 54 |
|
groups_overlap(a, b)
Helper function to see if a and b have any overlap.
Returns:
Name | Type | Description |
---|---|---|
bool |
True if there's any overlap between a and b. |
Source code in scram/route_manager/authentication_backends.py
8 9 10 11 12 13 14 |
|
context_processors
Define custom functions that take a request and add to the context before template rendering.
active_count(request)
Grab the active count of blocks.
Returns:
Name | Type | Description |
---|---|---|
dict |
active count of blocks |
Source code in scram/route_manager/context_processors.py
20 21 22 23 24 25 26 27 28 29 30 |
|
login_logout(request)
Pass through the relevant URLs from the settings.
Returns:
Name | Type | Description |
---|---|---|
dict |
login and logout URLs |
Source code in scram/route_manager/context_processors.py
9 10 11 12 13 14 15 16 17 |
|
models
Define the models used in the route_manager app.
ActionType
Bases: Model
Define a type of action that can be done with a given route. e.g. Block, shunt, redirect, etc.
Source code in scram/route_manager/models.py
33 34 35 36 37 38 39 40 41 42 43 44 |
|
__str__()
Display clearly whether the action is currently available.
Source code in scram/route_manager/models.py
40 41 42 43 44 |
|
Client
Bases: Model
Any client that would like to hit the API to add entries (e.g. Zeek).
Source code in scram/route_manager/models.py
169 170 171 172 173 174 175 176 177 178 179 180 |
|
__str__()
Only display the hostname.
Source code in scram/route_manager/models.py
178 179 180 |
|
Entry
Bases: Model
An instance of an action taken on a route.
Source code in scram/route_manager/models.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
Meta
Ensure that multiple routes can be added as long as they have different action types.
Source code in scram/route_manager/models.py
110 111 112 113 114 |
|
__str__()
Summarize the most important fields to something easily readable.
Source code in scram/route_manager/models.py
116 117 118 119 120 121 |
|
delete(*args, **kwargs)
Set inactive instead of deleting, as we want to ensure a history of entries.
Source code in scram/route_manager/models.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
get_change_reason()
Traverse some complex relationships to determine the most recent change reason.
Returns:
Name | Type | Description |
---|---|---|
str |
The most recent change reason |
Source code in scram/route_manager/models.py
142 143 144 145 146 147 148 149 |
|
IgnoreEntry
Bases: Model
Define CIDRs you NEVER want to block (i.e. the "don't shoot yourself in the foot" list).
Source code in scram/route_manager/models.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
Meta
Ensure the plural is grammatically correct.
Source code in scram/route_manager/models.py
159 160 161 162 |
|
__str__()
Only display the route.
Source code in scram/route_manager/models.py
164 165 166 |
|
Route
Bases: Model
Define a route as a CIDR route and a UUID.
Source code in scram/route_manager/models.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
__str__()
Don't display the UUID, only the route.
Source code in scram/route_manager/models.py
23 24 25 |
|
get_absolute_url()
staticmethod
Ensure we use UUID on the API side instead.
Source code in scram/route_manager/models.py
27 28 29 30 |
|
WebSocketMessage
Bases: Model
Define a single message sent to downstream translators via WebSocket.
Source code in scram/route_manager/models.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
__str__()
Display clearly what the fields are used for.
Source code in scram/route_manager/models.py
58 59 60 |
|
WebSocketSequenceElement
Bases: Model
In a sequence of messages, define a single element.
Source code in scram/route_manager/models.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
__str__()
Summarize the fields into something short and readable.
Source code in scram/route_manager/models.py
82 83 84 85 86 87 |
|
tests
Define tests executed by pytest.
functional_tests
Use the Django web client to perform end-to-end, WebUI-based testing.
HomePageTest
Bases: TestCase
Ensure the home page works.
Source code in scram/route_manager/tests/functional_tests.py
6 7 |
|
test_admin
Test the WhoFilter functionality of our admin site.
WhoFilterTest
Bases: TestCase
Test that the WhoFilter only shows users who have made entries.
Source code in scram/route_manager/tests/test_admin.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
setUp()
Set up the test environment.
Source code in scram/route_manager/tests/test_admin.py
14 15 16 17 18 19 20 21 |
|
test_who_filter_lookups()
Test that the WhoFilter returns the correct users who have made entries.
Source code in scram/route_manager/tests/test_admin.py
23 24 25 26 27 28 29 30 31 32 33 34 |
|
test_who_filter_queryset_with_value()
Test that the queryset is filtered correctly when a user is selected.
Source code in scram/route_manager/tests/test_admin.py
36 37 38 39 40 41 42 43 44 |
|
test_api
Use pytest to unit test the API.
TestAddRemoveIP
Bases: APITestCase
Ensure that we can block IPs, and that duplicate blocks don't generate an error.
Source code in scram/route_manager/tests/test_api.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
setUp()
Set up the environment for our tests.
Source code in scram/route_manager/tests/test_api.py
14 15 16 17 18 19 20 21 22 23 24 |
|
test_block_duplicate_ipv4()
Block an existing v4 IP and ensure we don't get an error.
Source code in scram/route_manager/tests/test_api.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
test_block_duplicate_ipv6()
Block an existing v6 IP and ensure we don't get an error.
Source code in scram/route_manager/tests/test_api.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
test_block_ipv4()
Block a v4 IP.
Source code in scram/route_manager/tests/test_api.py
26 27 28 29 30 31 32 33 34 35 36 37 |
|
test_block_ipv6()
Block a v6 IP.
Source code in scram/route_manager/tests/test_api.py
61 62 63 64 65 66 67 68 69 70 71 72 |
|
TestUnauthenticatedAccess
Bases: APITestCase
Ensure that an unathenticated client can't do anything.
Source code in scram/route_manager/tests/test_api.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
setUp()
Define some helper variables.
Source code in scram/route_manager/tests/test_api.py
100 101 102 103 |
|
test_unauthenticated_users_have_no_create_access()
Ensure an unauthenticated client can't add an Entry.
Source code in scram/route_manager/tests/test_api.py
105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
test_unauthenticated_users_have_no_ignore_create_access()
Ensure an unauthenticated client can't add an IgnoreEntry.
Source code in scram/route_manager/tests/test_api.py
119 120 121 122 |
|
test_unauthenticated_users_have_no_list_access()
Ensure an unauthenticated client can't list Entries.
Source code in scram/route_manager/tests/test_api.py
124 125 126 127 |
|
test_authorization
Define tests for authorization and permissions.
AuthzTest
Bases: TestCase
Define tests using the built-in authentication.
Source code in scram/route_manager/tests/test_authorization.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
create_entry()
Ensure the admin user can create an Entry.
Source code in scram/route_manager/tests/test_authorization.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
setUp()
Define several users for our tests.
Source code in scram/route_manager/tests/test_authorization.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
test_authorized_add_entry()
Test authorized users with various permissions to ensure they can add an Entry.
Source code in scram/route_manager/tests/test_authorization.py
86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
test_authorized_detail_view()
Test authorized users with various permissions to ensure they can view block details.
Source code in scram/route_manager/tests/test_authorization.py
110 111 112 113 114 115 116 117 |
|
test_unauthorized_add_entry()
Unauthorized users should not be able to add an Entry.
Source code in scram/route_manager/tests/test_authorization.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
test_unauthorized_after_group_removal()
The user has r/w access, then when we remove them from the r/w group, they no longer do.
Source code in scram/route_manager/tests/test_authorization.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
test_unauthorized_detail_view()
Ensure that unauthorized users can't view the blocked IPs.
Source code in scram/route_manager/tests/test_authorization.py
100 101 102 103 104 105 106 107 108 |
|
ESnetAuthBackendTest
Bases: TestCase
Define tests using OIDC authentication with our ESnetAuthBackend.
Source code in scram/route_manager/tests/test_authorization.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
setUp()
Create a sample OIDC user.
Source code in scram/route_manager/tests/test_authorization.py
138 139 140 141 142 143 144 145 146 |
|
test_admin()
Test admin_groups.
Source code in scram/route_manager/tests/test_authorization.py
180 181 182 183 184 185 186 187 188 189 |
|
test_authorized_removal()
Have an authorized user, then downgrade them and make sure they're unauthorized.
Source code in scram/route_manager/tests/test_authorization.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
test_disabled()
Pass all the groups, user should be disabled as it takes precedence.
Source code in scram/route_manager/tests/test_authorization.py
236 237 238 239 240 241 242 243 244 245 |
|
test_readonly()
Test r/o groups.
Source code in scram/route_manager/tests/test_authorization.py
157 158 159 160 161 162 163 164 165 166 |
|
test_readwrite()
Test r/w groups.
Source code in scram/route_manager/tests/test_authorization.py
168 169 170 171 172 173 174 175 176 177 178 |
|
test_unauthorized()
A user with no groups should have no access.
Source code in scram/route_manager/tests/test_authorization.py
148 149 150 151 152 153 154 155 |
|
test_autocreate_admin
Test the auto-creation of an admin user.
test_autocreate_admin(settings)
Test that an admin user is auto-created when AUTOCREATE_ADMIN is True.
Source code in scram/route_manager/tests/test_autocreate_admin.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
test_autocreate_admin_disabled(settings)
Test that an admin user is not auto-created when AUTOCREATE_ADMIN is False.
Source code in scram/route_manager/tests/test_autocreate_admin.py
31 32 33 34 35 36 37 38 |
|
test_autocreate_admin_existing_user(settings)
Test that an admin user is not auto-created when an existing user is present.
Source code in scram/route_manager/tests/test_autocreate_admin.py
41 42 43 44 45 46 47 48 49 50 |
|
test_history
Define tests for the history feature.
TestActiontypeHistory
Bases: TestCase
Test the history on an action type.
Source code in scram/route_manager/tests/test_history.py
9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
setUp()
Set up the test environment.
Source code in scram/route_manager/tests/test_history.py
12 13 14 |
|
test_comments()
Ensure we can go back and set a reason.
Source code in scram/route_manager/tests/test_history.py
16 17 18 19 20 21 |
|
TestEntryHistory
Bases: TestCase
Test the history on an Entry.
Source code in scram/route_manager/tests/test_history.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
setUp()
Set up the test environment.
Source code in scram/route_manager/tests/test_history.py
29 30 31 32 33 34 35 36 37 |
|
test_comments()
Ensure we can update the reason.
Source code in scram/route_manager/tests/test_history.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
test_pagination
Define simple tests for pagination.
TestEntriesListView
Bases: TestCase
Test to make sure our pagination and related scaffolding work.
Source code in scram/route_manager/tests/test_pagination.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
setUp()
Set up the test environment.
Source code in scram/route_manager/tests/test_pagination.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
test_context()
Test that the context structure is correctly filled out.
Source code in scram/route_manager/tests/test_pagination.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
test_filtering_entries_by_action_type()
Test that our paginated output has entries for all available actiontypes in our paginated output.
Source code in scram/route_manager/tests/test_pagination.py
76 77 78 79 80 81 82 83 84 85 86 |
|
test_invalid_page_handling()
Test handling of invalid page numbers.
Source code in scram/route_manager/tests/test_pagination.py
113 114 115 116 117 118 119 120 121 122 123 124 |
|
test_multiple_page_parameters()
Test that we can have separate pages when we have more than one actiontype.
Source code in scram/route_manager/tests/test_pagination.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
test_pagination()
Test pagination when there's multiple action types.
Source code in scram/route_manager/tests/test_pagination.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
test_performance
Tests for performance (load time, DB queries, etc.).
TestViewNumQueries
Bases: TestCase
Viewing an entry should only require one query.
Source code in scram/route_manager/tests/test_performance.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
setUp()
Set up the test environment.
Source code in scram/route_manager/tests/test_performance.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
test_admin_entry_page()
Admin entry list page requires 8 queries.
- create transaction
- lookup session
- lookup user
- lookup distinct users for our WhoFilter
- count entries
- count entries
- get first 100 entries
- query entries (a single query, with select_related)
- release transaction
Source code in scram/route_manager/tests/test_performance.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
test_entry_view()
Viewing an entry requires 8 queries.
- create transaction savepoint
- lookup session
- lookup user
- get entry
- rollback to savepoint
- release transaction savepoint
- context processor active_count active blocks
- context processor active_count all blocks
Source code in scram/route_manager/tests/test_performance.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
test_home_page()
Home page requires 11 queries.
- create transaction
- lookup session
- lookup user
- filter available actiontypes
- count entries with actiontype=1 and is_active
- count by user
- context processor active_count active blocks
- context processor active_count all blocks
- first page for actiontype=1
- close transaction
Source code in scram/route_manager/tests/test_performance.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
test_process_updates()
Process expired requires 6 queries.
- create transaction
- get entries_start active entry count
- find and delete expired entries
- get entries_end active entry count
- get new_entries from DB
- release transaction
Source code in scram/route_manager/tests/test_performance.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
test_swagger
Test the swagger API endpoints.
test_redoc_api(client)
Test that the Redoc API endpoint returns a successful response.
Source code in scram/route_manager/tests/test_swagger.py
15 16 17 18 19 20 |
|
test_schema_api(client)
Test that the Schema API endpoint returns a successful response.
Source code in scram/route_manager/tests/test_swagger.py
23 24 25 26 27 28 29 30 |
|
test_swagger_api(client)
Test that the Swagger API endpoint returns a successful response.
Source code in scram/route_manager/tests/test_swagger.py
7 8 9 10 11 12 |
|
test_views
Define simple tests for the template-based Views.
HomePageFirstVisitTest
Bases: TestCase
Test how the home page renders the first time we view it.
Source code in scram/route_manager/tests/test_views.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
setUp()
Get the home page.
Source code in scram/route_manager/tests/test_views.py
22 23 24 |
|
test_first_homepage_view_has_userinfo()
The first time we view the home page, a user was created for us.
Source code in scram/route_manager/tests/test_views.py
26 27 28 |
|
test_first_homepage_view_is_logged_in()
The first time we view the home page, we're logged in.
Source code in scram/route_manager/tests/test_views.py
30 31 32 |
|
HomePageLogoutTest
Bases: TestCase
Verify that once logged out, we can't view anything.
Source code in scram/route_manager/tests/test_views.py
35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
test_homepage_logout_links_missing()
After logout, we can't see anything.
Source code in scram/route_manager/tests/test_views.py
38 39 40 41 42 43 44 45 46 47 |
|
HomePageTest
Bases: TestCase
Test how the home page renders.
Source code in scram/route_manager/tests/test_views.py
10 11 12 13 14 15 16 |
|
test_root_url_resolves_to_home_page_view()
Ensure we can find the home page.
Source code in scram/route_manager/tests/test_views.py
13 14 15 16 |
|
NotFoundTest
Bases: TestCase
Verify that our custom 404 page is being served up.
Source code in scram/route_manager/tests/test_views.py
50 51 52 53 54 55 56 57 58 |
|
test_404()
Grab a bad URL.
Source code in scram/route_manager/tests/test_views.py
53 54 55 56 57 58 |
|
test_websockets
Define unit tests for the websockets-based communication.
TestTranslatorBaseCase
Bases: TestCase
Base case that other test cases build on top of. Three translators in one group, test one v4 and one v6.
Source code in scram/route_manager/tests/test_websockets.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
add_ip(ip, mask)
async
Ensure we can add an IP to block.
Source code in scram/route_manager/tests/test_websockets.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
api_create_entry(route)
Ensure we can create an Entry via the API.
Source code in scram/route_manager/tests/test_websockets.py
124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
ensure_no_more_msgs(communicators)
async
Run through all communicators and ensure they have no messages waiting.
Source code in scram/route_manager/tests/test_websockets.py
116 117 118 119 120 121 |
|
get_messages(communicator, messages, should_match)
async
Receive a number of messages from the WebSocket and validate them.
Source code in scram/route_manager/tests/test_websockets.py
89 90 91 92 93 94 |
|
get_nothings(communicator)
async
Check there are no more messages waiting.
Source code in scram/route_manager/tests/test_websockets.py
96 97 98 |
|
local_setup()
Allow child classes to override this if desired.
Source code in scram/route_manager/tests/test_websockets.py
85 86 87 |
|
setUp()
Set up our test environment.
Source code in scram/route_manager/tests/test_websockets.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
test_add_v4()
async
Test adding a few v4 routes.
Source code in scram/route_manager/tests/test_websockets.py
138 139 140 141 142 143 |
|
test_add_v6()
async
Test adding a few v6 routes.
Source code in scram/route_manager/tests/test_websockets.py
145 146 147 148 149 150 |
|
TranslatorDontCrossTheStreamsTestCase
Bases: TestTranslatorBaseCase
Two translators in one group, two in another group, single IP, ensure we get only the messages we expect.
Source code in scram/route_manager/tests/test_websockets.py
153 154 155 156 157 158 159 |
|
local_setup()
Define the actions and what we expect.
Source code in scram/route_manager/tests/test_websockets.py
156 157 158 159 |
|
TranslatorParametersTestCase
Bases: TestTranslatorBaseCase
Additional parameters in the JSONField.
Source code in scram/route_manager/tests/test_websockets.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
local_setup()
Define the message we want to send.
Source code in scram/route_manager/tests/test_websockets.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
TranslatorSequenceTestCase
Bases: TestTranslatorBaseCase
Test a sequence of WebSocket messages.
Source code in scram/route_manager/tests/test_websockets.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
local_setup()
Define the messages we want to send.
Source code in scram/route_manager/tests/test_websockets.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
get_communicators(actiontypes, should_match, *args, **kwds)
async
Create a set of communicators, and then handle tear-down.
Given two lists of the same length, a set of actiontypes, and set of boolean values, creates that many communicators, one for each actiontype-bool pair.
The boolean determines whether or not we're expecting to recieve a message to that communicator.
Returns a list of (communicator, should_match bool) pairs.
Source code in scram/route_manager/tests/test_websockets.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
urls
Register URLs known to Django, and the View that will handle each.
views
Define the Views that will handle the HTTP requests.
EntryDetailView
Bases: PermissionRequiredMixin
, DetailView
Define a view for the API to use.
Source code in scram/route_manager/views.py
111 112 113 114 115 116 |
|
EntryListView
Bases: ListView
Define a view for the API to use.
Source code in scram/route_manager/views.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
get_context_data(**kwargs)
Add action type grouping to context with separate paginators.
Source code in scram/route_manager/views.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
add_entry(request)
Send a WebSocket message when adding a new entry.
Source code in scram/route_manager/views.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
delete_entry(request, pk)
Wrap delete via the API and redirect to the home page.
Source code in scram/route_manager/views.py
103 104 105 106 107 108 |
|
home_page(request, prefilter=None)
Return the home page, autocreating a user if none exists.
Source code in scram/route_manager/views.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
process_updates(request)
For entries with an expiration, set them to inactive if expired.
Grab and announce any new entries added to the shared database by other SCRAM instances.
Return some simple stats.
Source code in scram/route_manager/views.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
search_entries(request)
Wrap the home page with a specified CIDR to restrict Entries to.
Source code in scram/route_manager/views.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|