Skip to content

Commit e5af154

Browse files
committed
Fix more
1 parent feb747f commit e5af154

File tree

3 files changed

+6
-205
lines changed

3 files changed

+6
-205
lines changed

stytch/consumer/api/test/test_consumer_idp.py

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from stytch.shared.rbac_local import (
1616
RBACPermissionError,
1717
perform_consumer_scope_authorization_check,
18-
perform_consumer_scope_authorization_check_local,
1918
)
2019

2120

@@ -166,94 +165,6 @@ def test_perform_consumer_scope_authorization_check_multiple_scopes(self) -> Non
166165
# Act & Assert - should not raise an exception
167166
perform_consumer_scope_authorization_check(self.policy, scopes, req)
168167

169-
def test_perform_consumer_scope_authorization_check_local_success(self) -> None:
170-
"""Test successful local authorization with matching scope and action."""
171-
# Arrange
172-
scopes = [self.write_scope.scope]
173-
req = ConsumerAuthorizationCheck(
174-
resource_id="foo",
175-
action="write",
176-
)
177-
178-
# Act & Assert - should not raise an exception
179-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
180-
181-
def test_perform_consumer_scope_authorization_check_local_wildcard_success(self) -> None:
182-
"""Test successful local authorization with wildcard scope."""
183-
# Arrange
184-
scopes = [self.wildcard_scope.scope]
185-
req = ConsumerAuthorizationCheck(
186-
resource_id="foo",
187-
action="delete", # Action not explicitly defined but covered by wildcard
188-
)
189-
190-
# Act & Assert - should not raise an exception
191-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
192-
193-
def test_perform_consumer_scope_authorization_check_local_wrong_resource(self) -> None:
194-
"""Test local authorization failure when resource doesn't match."""
195-
# Arrange
196-
scopes = [self.write_scope.scope]
197-
req = ConsumerAuthorizationCheck(
198-
resource_id="baz", # Resource not in scope
199-
action="write",
200-
)
201-
202-
# Act & Assert
203-
with self.assertRaises(RBACPermissionError):
204-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
205-
206-
def test_perform_consumer_scope_authorization_check_local_wrong_action(self) -> None:
207-
"""Test local authorization failure when action doesn't match."""
208-
# Arrange
209-
scopes = [self.read_scope.scope]
210-
req = ConsumerAuthorizationCheck(
211-
resource_id="foo",
212-
action="write", # Action not in read scope
213-
)
214-
215-
# Act & Assert
216-
with self.assertRaises(RBACPermissionError):
217-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
218-
219-
def test_perform_consumer_scope_authorization_check_local_no_matching_scope(self) -> None:
220-
"""Test local authorization failure when no scope matches."""
221-
# Arrange
222-
scopes = ["nonexistent:scope"]
223-
req = ConsumerAuthorizationCheck(
224-
resource_id="foo",
225-
action="read",
226-
)
227-
228-
# Act & Assert
229-
with self.assertRaises(RBACPermissionError):
230-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
231-
232-
def test_perform_consumer_scope_authorization_check_local_empty_scopes(self) -> None:
233-
"""Test local authorization failure with empty scopes list."""
234-
# Arrange
235-
scopes = []
236-
req = ConsumerAuthorizationCheck(
237-
resource_id="foo",
238-
action="read",
239-
)
240-
241-
# Act & Assert
242-
with self.assertRaises(RBACPermissionError):
243-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
244-
245-
def test_perform_consumer_scope_authorization_check_local_multiple_scopes(self) -> None:
246-
"""Test successful local authorization with multiple scopes where one matches."""
247-
# Arrange
248-
scopes = ["nonexistent:scope", self.read_scope.scope, "another:scope"]
249-
req = ConsumerAuthorizationCheck(
250-
resource_id="foo",
251-
action="read",
252-
)
253-
254-
# Act & Assert - should not raise an exception
255-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
256-
257168
@patch('stytch.consumer.api.idp.rbac_local.perform_consumer_scope_authorization_check')
258169
def test_introspect_token_network_with_authorization_check(self, mock_auth_check) -> None:
259170
"""Test that introspect_token_network calls authorization check when provided."""

stytch/shared/rbac_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def perform_consumer_authorization_check(
9393
return
9494

9595
# If we made it here, we didn't find a matching permission
96-
raise RBACPermissionError(authorization_check)
96+
raise RBACConsumerPermissionError(authorization_check)
9797

9898

9999
def perform_scope_authorization_check(

stytch/shared/tests/test_rbac_local.py

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
AuthorizationCheck as ConsumerAuthorizationCheck,
1313
)
1414
from stytch.shared.rbac_local import (
15+
RBACConsumerPermissionError,
1516
RBACPermissionError,
1617
TenancyError,
1718
perform_authorization_check,
1819
perform_consumer_scope_authorization_check,
19-
perform_consumer_scope_authorization_check_local,
2020
perform_scope_authorization_check,
2121
)
2222

@@ -218,7 +218,7 @@ def test_perform_scope_authorization_check(self) -> None:
218218

219219
def test_perform_consumer_scope_authorization_check(self) -> None:
220220
with self.subTest("has matching action but not resource"):
221-
with self.assertRaises(RBACPermissionError):
221+
with self.assertRaises(RBACConsumerPermissionError):
222222
# Arrange
223223
scopes = [self.write_scope.scope]
224224
req = ConsumerAuthorizationCheck(
@@ -229,7 +229,7 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
229229
perform_consumer_scope_authorization_check(self.policy, scopes, req)
230230

231231
with self.subTest("has matching resource but not action"):
232-
with self.assertRaises(RBACPermissionError):
232+
with self.assertRaises(RBACConsumerPermissionError):
233233
# Arrange
234234
scopes = [self.read_scope.scope]
235235
req = ConsumerAuthorizationCheck(
@@ -262,7 +262,7 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
262262
# Assertion is that no exception is raised
263263

264264
with self.subTest("no matching scope"):
265-
with self.assertRaises(RBACPermissionError):
265+
with self.assertRaises(RBACConsumerPermissionError):
266266
# Arrange
267267
scopes = ["nonexistent:scope"]
268268
req = ConsumerAuthorizationCheck(
@@ -273,7 +273,7 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
273273
perform_consumer_scope_authorization_check(self.policy, scopes, req)
274274

275275
with self.subTest("empty scopes list"):
276-
with self.assertRaises(RBACPermissionError):
276+
with self.assertRaises(RBACConsumerPermissionError):
277277
# Arrange
278278
scopes = []
279279
req = ConsumerAuthorizationCheck(
@@ -293,113 +293,3 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
293293
# Act
294294
perform_consumer_scope_authorization_check(self.policy, scopes, req)
295295
# Assertion is that no exception is raised
296-
297-
def test_perform_consumer_scope_authorization_check_local(self) -> None:
298-
with self.subTest("has matching action but not resource"):
299-
with self.assertRaises(RBACPermissionError):
300-
# Arrange
301-
scopes = [self.write_scope.scope]
302-
req = ConsumerAuthorizationCheck(
303-
resource_id="baz",
304-
action="write",
305-
)
306-
# Act
307-
perform_consumer_scope_authorization_check_local(
308-
self.policy, scopes, req
309-
)
310-
311-
with self.subTest("has matching resource but not action"):
312-
with self.assertRaises(RBACPermissionError):
313-
# Arrange
314-
scopes = [self.read_scope.scope]
315-
req = ConsumerAuthorizationCheck(
316-
resource_id="foo",
317-
action="write",
318-
)
319-
# Act
320-
perform_consumer_scope_authorization_check_local(
321-
self.policy, scopes, req
322-
)
323-
324-
with self.subTest("has matching resource and specific action"):
325-
# Arrange
326-
scopes = [self.write_scope.scope]
327-
req = ConsumerAuthorizationCheck(
328-
resource_id="foo",
329-
action="write",
330-
)
331-
# Act
332-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
333-
# Assertion is that no exception is raised
334-
335-
with self.subTest("has matching resource and star action"):
336-
# Arrange
337-
scopes = [self.wildcard_scope.scope]
338-
req = ConsumerAuthorizationCheck(
339-
resource_id="foo",
340-
action="write",
341-
)
342-
# Act
343-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
344-
# Assertion is that no exception is raised
345-
346-
with self.subTest("no matching scope"):
347-
with self.assertRaises(RBACPermissionError):
348-
# Arrange
349-
scopes = ["nonexistent:scope"]
350-
req = ConsumerAuthorizationCheck(
351-
resource_id="foo",
352-
action="read",
353-
)
354-
# Act
355-
perform_consumer_scope_authorization_check_local(
356-
self.policy, scopes, req
357-
)
358-
359-
with self.subTest("empty scopes list"):
360-
with self.assertRaises(RBACPermissionError):
361-
# Arrange
362-
scopes = []
363-
req = ConsumerAuthorizationCheck(
364-
resource_id="foo",
365-
action="read",
366-
)
367-
# Act
368-
perform_consumer_scope_authorization_check_local(
369-
self.policy, scopes, req
370-
)
371-
372-
with self.subTest("multiple scopes with one matching"):
373-
# Arrange
374-
scopes = ["nonexistent:scope", self.read_scope.scope, "another:scope"]
375-
req = ConsumerAuthorizationCheck(
376-
resource_id="foo",
377-
action="read",
378-
)
379-
# Act
380-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
381-
# Assertion is that no exception is raised
382-
383-
with self.subTest("bar resource with write scope"):
384-
# Arrange
385-
scopes = [
386-
self.write_scope.scope
387-
] # Use the write scope which includes bar resource
388-
req = ConsumerAuthorizationCheck(
389-
resource_id="bar",
390-
action="write",
391-
)
392-
# Act
393-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
394-
# Assertion is that no exception is raised
395-
396-
with self.subTest("wildcard scope with delete action"):
397-
# Arrange
398-
scopes = [self.wildcard_scope.scope] # Use the wildcard scope
399-
req = ConsumerAuthorizationCheck(
400-
resource_id="foo",
401-
action="delete",
402-
)
403-
# Act
404-
perform_consumer_scope_authorization_check_local(self.policy, scopes, req)
405-
# Assertion is that no exception is raised

0 commit comments

Comments
 (0)