Skip to content

Commit

Permalink
fix: Off by one assertion for invoker property (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 authored Aug 4, 2024
1 parent db1eb6c commit e1c57d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/firebase_functions/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ def _endpoint(
invoker = [invoker]
assert len(
invoker
) > 1, "HttpsOptions: Invalid option for invoker - must be a non-empty list."
) >= 1, "HttpsOptions: Invalid option for invoker - must be a non-empty list."
assert "" not in invoker, (
"HttpsOptions: Invalid option for invoker - must be a non-empty string."
)
Expand Down
18 changes: 16 additions & 2 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from firebase_functions import options, https_fn
from firebase_functions import params
from firebase_functions.private.serving import functions_as_yaml, merge_required_apis
from pytest import raises
# pylint: disable=protected-access


Expand Down Expand Up @@ -44,7 +45,7 @@ def test_global_options_merged_with_provider_options():
Testing a global option is used when no provider option is set.
"""
options.set_global_options(max_instances=66)
pubsub_options = options.PubSubOptions(topic="foo") #pylint: disable=unexpected-keyword-arg
pubsub_options = options.PubSubOptions(topic="foo") # pylint: disable=unexpected-keyword-arg
pubsub_options_dict = pubsub_options._asdict_with_global_options()
assert (pubsub_options_dict["topic"] == "foo"
), "'topic' property missing from dict"
Expand Down Expand Up @@ -170,7 +171,7 @@ def test_merge_apis_duplicate_apis():
This test evaluates the merge_required_apis function when the
input list contains duplicate APIs with different reasons.
The desired outcome for this test is a list where the duplicate
APIs are merged properly and reasons are combined.
APIs are merged properly and reasons are combined.
This test ensures that the function correctly merges the duplicate
APIs and combines the reasons associated with them.
"""
Expand Down Expand Up @@ -217,3 +218,16 @@ def test_merge_apis_duplicate_apis():
for actual_item in merged_apis:
assert (actual_item in expected_output
), f"Unexpected item {actual_item} found in the merged list"


def test_invoker_with_one_element_doesnt_throw():
options.HttpsOptions(invoker=["public"])._endpoint(func_name="test")


def test_invoker_with_no_element_throws():
with raises(
AssertionError,
match=
"HttpsOptions: Invalid option for invoker - must be a non-empty list."
):
options.HttpsOptions(invoker=[])._endpoint(func_name="test")

1 comment on commit e1c57d1

@sjudd
Copy link

@sjudd sjudd commented on e1c57d1 Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to see this released! :)

Please sign in to comment.