@@ -133,99 +133,6 @@ async def test_bind_params_callable(
133133 assert "row4" not in response
134134
135135
136- @pytest .mark .asyncio
137- @pytest .mark .usefixtures ("toolbox_server" )
138- class TestAuth :
139- async def test_run_tool_unauth_with_auth (
140- self , toolbox : ToolboxClient , auth_token2 : str
141- ):
142- """Tests running a tool that doesn't require auth, with auth provided."""
143-
144- with pytest .raises (
145- ValueError ,
146- match = rf"Validation failed for tool 'get-row-by-id': unused auth tokens: my-test-auth" ,
147- ):
148- await toolbox .load_tool (
149- "get-row-by-id" ,
150- auth_token_getters = {"my-test-auth" : lambda : auth_token2 },
151- )
152-
153- async def test_run_tool_no_auth (self , toolbox : ToolboxClient ):
154- """Tests running a tool requiring auth without providing auth."""
155- tool = await toolbox .load_tool ("get-row-by-id-auth" )
156- with pytest .raises (
157- RuntimeError ,
158- match = "unauthorized Tool call" ,
159- ):
160- await tool (id = "2" )
161-
162- async def test_run_tool_wrong_auth (self , toolbox : ToolboxClient , auth_token2 : str ):
163- """Tests running a tool with incorrect auth. The tool
164- requires a different authentication than the one provided."""
165- tool = await toolbox .load_tool ("get-row-by-id-auth" )
166- auth_tool = tool .add_auth_token_getters ({"my-test-auth" : lambda : auth_token2 })
167- with pytest .raises (
168- RuntimeError ,
169- match = "tool invocation not authorized" ,
170- ):
171- await auth_tool (id = "2" )
172-
173- async def test_run_tool_auth (self , toolbox : ToolboxClient , auth_token1 : str ):
174- """Tests running a tool with correct auth."""
175- tool = await toolbox .load_tool ("get-row-by-id-auth" )
176- auth_tool = tool .add_auth_token_getters ({"my-test-auth" : lambda : auth_token1 })
177- response = await auth_tool (id = "2" )
178- assert "row2" in response
179-
180- @pytest .mark .asyncio
181- async def test_run_tool_async_auth (self , toolbox : ToolboxClient , auth_token1 : str ):
182- """Tests running a tool with correct auth using an async token getter."""
183- tool = await toolbox .load_tool ("get-row-by-id-auth" )
184-
185- async def get_token_asynchronously ():
186- return auth_token1
187-
188- auth_tool = tool .add_auth_token_getters (
189- {"my-test-auth" : get_token_asynchronously }
190- )
191- response = await auth_tool (id = "2" )
192- assert "row2" in response
193-
194- async def test_run_tool_param_auth_no_auth (self , toolbox : ToolboxClient ):
195- """Tests running a tool with a param requiring auth, without auth."""
196- tool = await toolbox .load_tool ("get-row-by-email-auth" )
197- with pytest .raises (
198- PermissionError ,
199- match = "One or more of the following authn services are required to invoke this tool: my-test-auth" ,
200- ):
201- await tool ()
202-
203- async def test_run_tool_param_auth (self , toolbox : ToolboxClient , auth_token1 : str ):
204- """Tests running a tool with a param requiring auth, with correct auth."""
205- tool = await toolbox .load_tool (
206- "get-row-by-email-auth" ,
207- auth_token_getters = {"my-test-auth" : lambda : auth_token1 },
208- )
209- response = await tool ()
210- assert "row4" in response
211- assert "row5" in response
212- assert "row6" in response
213-
214- async def test_run_tool_param_auth_no_field (
215- self , toolbox : ToolboxClient , auth_token1 : str
216- ):
217- """Tests running a tool with a param requiring auth, with insufficient auth."""
218- tool = await toolbox .load_tool (
219- "get-row-by-content-auth" ,
220- auth_token_getters = {"my-test-auth" : lambda : auth_token1 },
221- )
222- with pytest .raises (
223- Exception ,
224- match = "no field named row_data in claims" ,
225- ):
226- await tool ()
227-
228-
229136@pytest .mark .asyncio
230137@pytest .mark .usefixtures ("toolbox_server" )
231138class TestOptionalParams :
0 commit comments