From 368077ee10123f2904eca04da1c839dd67df71cc Mon Sep 17 00:00:00 2001 From: Dario Ghunney Ware Date: Wed, 26 Nov 2025 14:56:32 +0000 Subject: [PATCH] closing gap in grandfathering logic --- .../service/UserLicenseSettingsService.java | 5 +-- .../UserLicenseSettingsServiceTest.java | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.java b/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.java index 352ce0ed29..9d7a8a3adc 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.java @@ -184,8 +184,9 @@ public class UserLicenseSettingsService { long oauthUsersCount = userService.countOAuthUsers(); long grandfatheredCount = userService.countGrandfatheredOAuthUsers(); - if (oauthUsersCount > 0 && grandfatheredCount == 0) { - // We have OAuth users but none are grandfathered - this is first run after upgrade + if (oauthUsersCount > 0 && grandfatheredCount < oauthUsersCount) { + // We have OAuth users but not all have been grandfathered - this is first run after + // upgrade int updated = userService.grandfatherAllOAuthUsers(); log.warn( "OAuth GRANDFATHERING: Marked {} existing OAuth/SAML users as grandfathered. " diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceTest.java index c819055e47..046c6745e0 100644 --- a/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceTest.java +++ b/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceTest.java @@ -2,6 +2,9 @@ package stirling.software.proprietary.service; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Optional; @@ -198,4 +201,35 @@ class UserLicenseSettingsServiceTest { assertEquals(5, result, "Should fall back to default 5 users if grandfathered is 0"); } + + @Test + void grandfatherExistingOAuthUsers_runsWhenSomeUsersNotGrandfathered() { + when(userService.countOAuthUsers()).thenReturn(10L); + when(userService.countGrandfatheredOAuthUsers()).thenReturn(4L); + when(userService.grandfatherAllOAuthUsers()).thenReturn(6); + + service.grandfatherExistingOAuthUsers(); + + verify(userService, times(1)).grandfatherAllOAuthUsers(); + } + + @Test + void grandfatherExistingOAuthUsers_skipsWhenAllUsersGrandfathered() { + when(userService.countOAuthUsers()).thenReturn(10L); + when(userService.countGrandfatheredOAuthUsers()).thenReturn(10L); + + service.grandfatherExistingOAuthUsers(); + + verify(userService, never()).grandfatherAllOAuthUsers(); + } + + @Test + void grandfatherExistingOAuthUsers_skipsWhenNoOAuthUsers() { + when(userService.countOAuthUsers()).thenReturn(0L); + when(userService.countGrandfatheredOAuthUsers()).thenReturn(0L); + + service.grandfatherExistingOAuthUsers(); + + verify(userService, never()).grandfatherAllOAuthUsers(); + } }