@@ -101,11 +101,7 @@ def _verify(app, token: str):
101101 # hash, and a revision tag prefixes the service with `tag---`.
102102 "https://beforecreate-123456789.us-central1.run.app" ,
103103 "https://tag---beforecreate-123456789.us-central1.run.app" ,
104- # Regions the SupportedRegion enum predates, and a hypothetical shape with
105- # more than one hyphen, since the region is matched by shape.
106104 f"https://northamerica-northeast1-{ PROJECT_ID } .cloudfunctions.net/before_create" ,
107- f"https://me-west1-{ PROJECT_ID } .cloudfunctions.net/before_create" ,
108- f"https://us-far-west1-{ PROJECT_ID } .cloudfunctions.net/before_create" ,
109105 ],
110106)
111107def test_accepts_function_url_audiences (app , signing_key , audience ):
@@ -115,12 +111,9 @@ def test_accepts_function_url_audiences(app, signing_key, audience):
115111@pytest .mark .parametrize (
116112 "audience" ,
117113 [
118- "https://us-east1-other-project.cloudfunctions.net/before_create" ,
114+ # A regular Firebase ID token for the same project.
115+ PROJECT_ID ,
119116 "https://example.com/before_create" ,
120- # A project id ending with this one must not be accepted as a suffix.
121- f"https://us-east1-other-{ PROJECT_ID } .cloudfunctions.net/before_create" ,
122- f"https://us-east1-x1-{ PROJECT_ID } .cloudfunctions.net/before_create" ,
123- f"https://us-east1-a-{ PROJECT_ID } .cloudfunctions.net/before_create" ,
124117 # The expected host must be the host, not text anywhere in the URL.
125118 f"https://us-east1-{ PROJECT_ID } .cloudfunctions.net.example.com/before_create" ,
126119 f"https://example.com/{ PROJECT_ID } .cloudfunctions.net/before_create" ,
@@ -135,15 +128,16 @@ def test_rejects_foreign_audience(app, signing_key, audience):
135128 _verify (app , _token (signing_key , audience ))
136129
137130
138- def test_accepts_any_run_host (app , signing_key ):
139- """The run.app form is not project-scoped; `iss` is what pins the project."""
140- assert _verify (app , _token (signing_key , "https://svc-999.us-central1.run.app" ))["uid" ] == (
141- "uid123"
131+ @pytest .mark .parametrize (
132+ "other_project" ,
133+ ["other-project" , f"other-{ PROJECT_ID } " , f"x1-{ PROJECT_ID } " , f"a-{ PROJECT_ID } " ],
134+ )
135+ def test_rejects_function_url_from_another_project (app , signing_key , other_project ):
136+ token = _token (
137+ signing_key ,
138+ f"https://us-east1-{ other_project } .cloudfunctions.net/before_create" ,
139+ issuer = f"https://securetoken.google.com/{ other_project } " ,
142140 )
143-
144-
145- def test_rejects_wrong_issuer (app , signing_key ):
146- token = _token (signing_key , RUN_APP_AUDIENCE , issuer = "https://securetoken.google.com/other" )
147141 with pytest .raises (token_verifier .InvalidAuthBlockingTokenError , match = '"iss"' ):
148142 _verify (app , token )
149143
0 commit comments