Skip to content

Commit

Permalink
Add explicit test for function auth levels
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinderVosDeWael committed May 9, 2024
1 parent 747cc60 commit cb7c177
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/smoke/test_function_app.py
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."

0 comments on commit cb7c177

Please sign in to comment.