@@ -423,3 +423,35 @@ async def test_news_likes_endpoint(
423423 assert stored_news is not None
424424 assert stored_news .likes == 0
425425 assert stored_news .user_email_list == "[]"
426+
427+
428+ @pytest .mark .asyncio
429+ async def test_news_endpoint_blocks_unauthorized_access (
430+ async_client : AsyncClient ,
431+ ):
432+ news_data = {
433+ "title" : "Test News" ,
434+ "content" : "Test news content." ,
435+ "category" : "test_category" ,
436+ "tags" : "test_tag" ,
437+ "source_url" : "https://example.com/test-news" ,
438+ "social_media_url" : "https://test.com/test_news" ,
439+ }
440+ response : Response = await async_client .post (
441+ url = "/api/news" , json = news_data
442+ )
443+ assert response .status_code == status .HTTP_401_UNAUTHORIZED
444+
445+ response : Response = await async_client .get (url = "/api/news" )
446+ assert response .status_code == status .HTTP_401_UNAUTHORIZED
447+
448+ response : Response = await async_client .put (
449+ url = "/api/news/1" , json = news_data
450+ )
451+ assert response .status_code == status .HTTP_401_UNAUTHORIZED
452+
453+ response : Response = await async_client .post (url = "/api/news/1/like" )
454+ assert response .status_code == status .HTTP_401_UNAUTHORIZED
455+
456+ response : Response = await async_client .delete (url = "/api/news/1/like" )
457+ assert response .status_code == status .HTTP_401_UNAUTHORIZED
0 commit comments