generated from childmindresearch/template-python-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explicit test for function auth levels
- Loading branch information
1 parent
747cc60
commit cb7c177
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Smoke tests for the function app module.""" | ||
|
||
import inspect | ||
import json | ||
|
||
import function_app | ||
from azure.functions.decorators import function_app as azure_function_app | ||
|
||
|
||
def get_function_auth_level( | ||
function: azure_function_app.FunctionBuilder, | ||
) -> str: | ||
"""Gets the auth level of a function.""" | ||
settings = json.loads(function._function.get_function_json()) | ||
return settings["bindings"][0]["authLevel"] | ||
|
||
|
||
def test_function_auth_level() -> None: | ||
"""Tests that no function has the anonymous auth level.""" | ||
endpoints = inspect.getmembers( | ||
function_app, | ||
lambda attribute: isinstance(attribute, azure_function_app.FunctionBuilder), | ||
) | ||
allowed_auth_levels = ["FUNCTION", "ADMIN"] | ||
|
||
for name, endpoint in endpoints: | ||
auth_level = get_function_auth_level(endpoint) | ||
|
||
assert auth_level in allowed_auth_levels, f"{name} has the wrong auth level." |