From 148b74ef87ec95ca0babd6b2a954e28d9368c7c3 Mon Sep 17 00:00:00 2001 From: Johanna Date: Wed, 4 Oct 2023 14:34:45 -0400 Subject: [PATCH] Added test for the NobodyAuthenticatedException --- .../LoggedInAuthorizationServiceTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 backend/src/test/java/gov/cdc/usds/simplereport/service/LoggedInAuthorizationServiceTest.java diff --git a/backend/src/test/java/gov/cdc/usds/simplereport/service/LoggedInAuthorizationServiceTest.java b/backend/src/test/java/gov/cdc/usds/simplereport/service/LoggedInAuthorizationServiceTest.java new file mode 100644 index 0000000000..60379e2f28 --- /dev/null +++ b/backend/src/test/java/gov/cdc/usds/simplereport/service/LoggedInAuthorizationServiceTest.java @@ -0,0 +1,20 @@ +package gov.cdc.usds.simplereport.service; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import gov.cdc.usds.simplereport.service.errors.NobodyAuthenticatedException; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; + +public class LoggedInAuthorizationServiceTest extends BaseServiceTest { + @Autowired LoggedInAuthorizationService loggedInAuthorizationService; + + @Test + void findAllOrganizationRoles_NobodyAuthenticatedException() { + SecurityContextHolder.getContext().setAuthentication(null); + assertThrows( + NobodyAuthenticatedException.class, + () -> loggedInAuthorizationService.findAllOrganizationRoles()); + } +}