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 | |
NoActiveEntryFound
Bases: APIException
An active entry was not found.
Source code in scram/route_manager/api/exceptions.py
33 34 35 36 37 38 | |
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
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 | |
Meta
Map to the Entry model, and specify the fields exposed by the API.
Source code in scram/route_manager/api/serializers.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
__init__(*args, **kwargs)
Make sure we do not allow changing these fields in our put/patch calls.
Source code in scram/route_manager/api/serializers.py
86 87 88 89 90 91 92 | |
create(validated_data)
Create or update an Entry, handling duplicates gracefully.
Source code in scram/route_manager/api/serializers.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
IgnoreEntrySerializer
Bases: ModelSerializer
Map the route to the right field type.
Source code in scram/route_manager/api/serializers.py
130 131 132 133 134 135 136 137 138 139 | |
Meta
Maps to the IgnoreEntry model, and specifies the fields exposed by the API.
Source code in scram/route_manager/api/serializers.py
135 136 137 138 139 | |
IsActiveSerializer
Bases: ModelSerializer
Map the serializer to the Entry model.
Source code in scram/route_manager/api/serializers.py
55 56 57 58 59 60 61 62 63 64 | |
Meta
Maps to the Entry model, but limits to the the appropriate fields.
Source code in scram/route_manager/api/serializers.py
60 61 62 63 64 | |
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
32 33 34 35 36 37 38 39 40 41 42 | |
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
58 59 60 61 62 63 64 65 66 67 68 69 70 | |
EntryViewSet
Bases: ModelViewSet
Lookup Entry when authenticated, and bind to the serializer.
Source code in scram/route_manager/api/views.py
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 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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
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
157 158 159 160 161 162 163 164 | |
destroy(request, pk=None, *args, **kwargs)
Only delete active (e.g. announced) entries.
Source code in scram/route_manager/api/views.py
275 276 277 278 279 280 | |
find_entries(arg, active_filter=None)
staticmethod
Query entries either by pk or overlapping route.
Source code in scram/route_manager/api/views.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
get_object()
Override get_object to use our custom find_entries logic.
Source code in scram/route_manager/api/views.py
234 235 236 237 238 239 240 241 242 | |
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
131 132 133 134 135 136 137 138 139 | |
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
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 | |
perform_update(serializer)
Update an existing Entry.
Source code in scram/route_manager/api/views.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
retrieve(request, pk=None, **kwargs)
Retrieve a single route.
Source code in scram/route_manager/api/views.py
269 270 271 272 273 | |
IgnoreEntryViewSet
Bases: ModelViewSet
Lookup IgnoreEntries by route when authenticated, and bind to the serializer.
Source code in scram/route_manager/api/views.py
45 46 47 48 49 50 51 52 53 54 55 | |
IsActiveViewSet
Bases: ReadOnlyModelViewSet
Look up a route to see if SCRAM considers it active or deactivated.
Source code in scram/route_manager/api/views.py
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 | |
get_queryset()
Focus queryset on active routes.
Source code in scram/route_manager/api/views.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
list(request)
Override the list function to just return a boolean instead of other metadata.
Source code in scram/route_manager/api/views.py
104 105 106 107 108 109 110 111 112 113 114 115 | |
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
21 22 23 24 25 26 27 28 29 30 31 | |
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 18 | |
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 | |
TestIsActive
Bases: APITestCase
Test the is_active endpoint.
Source code in scram/route_manager/tests/test_api.py
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 206 207 208 | |
setUp()
Set up test data.
Source code in scram/route_manager/tests/test_api.py
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 | |
test_active_ipv4_returns_true()
Check that an active IPv4 returns is_active=true.
Source code in scram/route_manager/tests/test_api.py
170 171 172 173 174 175 176 | |
test_active_ipv6_returns_true()
Check that an active IPv6 returns is_active=true.
Source code in scram/route_manager/tests/test_api.py
178 179 180 181 182 183 184 | |
test_inactive_entry_ipv4_returns_false()
Check that an inactive entry returns is_active=false.
Source code in scram/route_manager/tests/test_api.py
186 187 188 189 190 191 192 | |
test_inactive_entry_ipv6_returns_false()
Check that an inactive entry returns is_active=false.
Source code in scram/route_manager/tests/test_api.py
194 195 196 197 198 199 | |
test_unauthenticated_access_allowed()
Ensure unauthenticated clients can check if IPs are active.
Source code in scram/route_manager/tests/test_api.py
201 202 203 204 205 206 207 208 | |
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_common
Shared test framework for acceptance and integration tests.
steps_common
Define shared steps used by the Behave tests.
add_client(context, hostname, uuid)
Create a client with a specific UUID.
Source code in scram/route_manager/tests/test_common/steps_common.py
214 215 216 217 218 219 220 221 222 223 | |
add_entry(context, value)
Block the provided route.
Source code in scram/route_manager/tests/test_common/steps_common.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
add_entry_with_absolute_expiration(context, value, exp)
Block the provided route and add an absolute expiration datetime.
Source code in scram/route_manager/tests/test_common/steps_common.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
add_entry_with_comment(context, value, comment)
Block the provided route and add a comment.
Source code in scram/route_manager/tests/test_common/steps_common.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
add_entry_with_relative_expiration(context, value, secs)
Block the provided route and add a relative expiration.
Source code in scram/route_manager/tests/test_common/steps_common.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
add_ignore_entry(context, value)
Add an IgnoreEntry with the specified route.
Source code in scram/route_manager/tests/test_common/steps_common.py
158 159 160 161 162 163 164 | |
check_object(context, value, model)
Ensure that the arbitrary model has an object with the specified value.
Source code in scram/route_manager/tests/test_common/steps_common.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
check_status_code(context, status_code)
Ensure the status code response matches the expected value.
Source code in scram/route_manager/tests/test_common/steps_common.py
70 71 72 73 | |
count_objects(context, model, num)
Count the number of objects of an arbitrary model.
Source code in scram/route_manager/tests/test_common/steps_common.py
188 189 190 191 192 | |
create_actiontype(context, name)
Create an actiontype of that name.
Source code in scram/route_manager/tests/test_common/steps_common.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
create_authed_client(context, name)
Create a client and authorize it for that action type.
Source code in scram/route_manager/tests/test_common/steps_common.py
31 32 33 34 35 36 37 38 39 40 41 42 43 | |
create_unauthed_client(context, name)
Create a client that has no authorized action types.
Source code in scram/route_manager/tests/test_common/steps_common.py
46 47 48 49 50 51 52 53 | |
list_objects(context, model)
List all objects of an arbitrary model.
Source code in scram/route_manager/tests/test_common/steps_common.py
173 174 175 176 | |
login(context)
Login.
Source code in scram/route_manager/tests/test_common/steps_common.py
56 57 58 59 60 | |
remove_an_object(context, model, value)
Remove any model object with the matching value.
Source code in scram/route_manager/tests/test_common/steps_common.py
167 168 169 170 | |
remove_expired(context)
Call the function that removes expired entries.
Source code in scram/route_manager/tests/test_common/steps_common.py
152 153 154 155 | |
set_cidr_limit(context, v4_minprefix, v6_minprefix)
Override our settings with the provided values.
Source code in scram/route_manager/tests/test_common/steps_common.py
63 64 65 66 67 | |
update_object(context, model, value_from, value_to)
Modify any model object with the matching value to the new value instead.
Source code in scram/route_manager/tests/test_common/steps_common.py
179 180 181 182 183 184 185 | |
wait(context, secs)
Wait to allow messages to propagate.
Source code in scram/route_manager/tests/test_common/steps_common.py
146 147 148 149 | |
steps_ip
Define steps used for IP-related logic used by the Behave tests.
check_comment(context, value, comment)
Verify the comment for the Entry.
Source code in scram/route_manager/tests/test_common/steps_ip.py
43 44 45 46 47 48 49 50 51 | |
check_entry_comment_not_equal(context, value, comment)
Verify the comment was updated.
Source code in scram/route_manager/tests/test_common/steps_ip.py
64 65 66 67 68 | |
check_error(context)
Ensure we received a ValueError exception.
Source code in scram/route_manager/tests/test_common/steps_ip.py
37 38 39 40 | |
check_ip(context, ip)
Find an Entry for the specified IP.
Source code in scram/route_manager/tests/test_common/steps_ip.py
26 27 28 29 30 31 32 33 34 | |
check_route(context, route, model)
Perform a CIDR match on the matching object.
Source code in scram/route_manager/tests/test_common/steps_ip.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
search_ip(context, ip)
Search our main search bar for an IP.
Source code in scram/route_manager/tests/test_common/steps_ip.py
71 72 73 74 75 76 77 | |
update_entry_comment(context, value, comment)
Update the entry with a new comment.
Source code in scram/route_manager/tests/test_common/steps_ip.py
54 55 56 57 58 59 60 61 | |
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_process_updates
Unit tests for process_updates syncing logic.
TestCheckForOrphanedHistory
Tests for check_for_orphaned_history().
Source code in scram/route_manager/tests/test_process_updates.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
test_logs_warning_for_orphaned_entries(caplog, actiontype, other_instance)
Make sure we log a warning when history exists but Entry was deleted from underneath us.
Source code in scram/route_manager/tests/test_process_updates.py
194 195 196 197 198 199 200 201 202 203 204 205 | |
test_no_warning_when_entry_exists(caplog, actiontype, other_instance)
No warning when all entries in the set exist.
Source code in scram/route_manager/tests/test_process_updates.py
207 208 209 210 211 212 213 | |
TestGetEntriesToProcess
Tests for get_entries_to_process().
Source code in scram/route_manager/tests/test_process_updates.py
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 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 | |
test_empty_when_no_entries(db)
Returns empty list when no entries exist.
Source code in scram/route_manager/tests/test_process_updates.py
64 65 66 67 | |
test_expired_entry_found_as_inactive(actiontype, other_instance)
Expired entries are found but marked inactive after process_updates expires them.
Source code in scram/route_manager/tests/test_process_updates.py
167 168 169 170 171 172 173 174 175 176 177 | |
test_finds_entry_from_other_instance(actiontype, other_instance)
Finds entries created by other SCRAM instances.
Source code in scram/route_manager/tests/test_process_updates.py
69 70 71 72 73 74 75 76 77 | |
test_finds_modified_entries(actiontype, other_instance)
Finds entries modified after creation (uses history tracking).
Source code in scram/route_manager/tests/test_process_updates.py
89 90 91 92 93 94 95 96 97 98 99 100 101 | |
test_finds_soft_deleted_entries(actiontype, other_instance)
Finds entries that were deactivated (expiration, by hand, etc.).
Source code in scram/route_manager/tests/test_process_updates.py
103 104 105 106 107 108 109 110 111 112 113 114 | |
test_future_expiration_entry_active(actiontype, other_instance)
Entries with future expiration are processed as active.
Source code in scram/route_manager/tests/test_process_updates.py
155 156 157 158 159 160 161 162 163 164 165 | |
test_includes_current_instance_entries(actiontype, current_instance)
Processes entries from the current SCRAM instance.
Source code in scram/route_manager/tests/test_process_updates.py
79 80 81 82 83 84 85 86 87 | |
test_multiple_entries_from_different_instances(actiontype)
Entries from multiple other instances are all processed.
Source code in scram/route_manager/tests/test_process_updates.py
130 131 132 133 134 135 136 137 138 139 140 141 | |
test_processes_entries_from_current_instance(actiontype, current_instance)
Verifies that entries from the current instance are processed (PR #193 fix).
Source code in scram/route_manager/tests/test_process_updates.py
179 180 181 182 183 184 185 186 187 188 | |
test_reactivated_entry_found(actiontype, other_instance)
Reactivated entries are found for reprocessing.
Source code in scram/route_manager/tests/test_process_updates.py
143 144 145 146 147 148 149 150 151 152 153 | |
test_respects_cutoff_time(actiontype, other_instance)
Only returns entries modified after the cutoff time by faking the modified time.
Source code in scram/route_manager/tests/test_process_updates.py
116 117 118 119 120 121 122 123 124 125 126 127 128 | |
actiontype(db)
Create a block actiontype for tests.
Source code in scram/route_manager/tests/test_process_updates.py
12 13 14 15 | |
create_entry(actiontype, ip, instance, is_active=True, **kwargs)
Helper to create an entry with the given parameters.
Source code in scram/route_manager/tests/test_process_updates.py
47 48 49 50 51 52 53 54 55 56 57 58 | |
current_instance()
Return the current SCRAM hostname.
Source code in scram/route_manager/tests/test_process_updates.py
41 42 43 44 | |
other_instance()
Return a hostname different from the current instance.
Source code in scram/route_manager/tests/test_process_updates.py
35 36 37 38 | |
websocket_config(actiontype)
Create the WebSocket configuration needed for reprocess_entries.
Source code in scram/route_manager/tests/test_process_updates.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
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
112 113 114 115 116 117 | |
EntryListView
Bases: ListView
Define a view for the API to use.
Source code in scram/route_manager/views.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
get_context_data(**kwargs)
Add action type grouping to context with separate paginators.
Source code in scram/route_manager/views.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
add_entry(request)
Send a WebSocket message when adding a new entry.
Source code in scram/route_manager/views.py
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 | |
check_for_orphaned_history(recently_touched_ids, entries_to_process)
Check for orphaned history records where the Entry was deleted but history remains.
This shouldn't happen in production since Entry.delete() is overridden on the model, but we log a warning if it occurs for debugging purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recently_touched_ids
|
set
|
Set of Entry IDs that have recent history records. |
required |
entries_to_process
|
list
|
Entry objects fetched from the database. |
required |
Source code in scram/route_manager/views.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
delete_entry(request, pk)
Wrap delete via the API and redirect to the home page.
Source code in scram/route_manager/views.py
104 105 106 107 108 109 | |
get_entries_to_process(cutoff_time)
Return entries that have been recently modified by any SCRAM instance.
Queries the Entry history (simple history) table to find any entries modified since the cutoff time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff_time
|
timedelta
|
Only consider entries modified after this time. |
required |
Returns:
| Type | Description |
|---|---|
list[Entry]
|
List of Entry objects that need to be reprocessed. |
Source code in scram/route_manager/views.py
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 | |
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 70 | |
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
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
reprocess_entries(entries_to_process)
Take a list of Entries and send appropriate websocket messages to translators.
Effectively, this is a way to tell the translator "hey, do the stuff you need to do for this list of entries",
whether that is to block or unblock them. This is used by process_updates(). In this, we take each entry
and send either a translator_add or translator_remove message, depending on the entry's is_active state, and
notify translators to Do the Thing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_to_process
|
list[Entry]
|
Entry objects that need to be sent to translators. |
required |
Source code in scram/route_manager/views.py
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 | |
search_entries(request)
Wrap the home page with a specified CIDR to restrict Entries to.
Source code in scram/route_manager/views.py
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 | |