|
12 | 12 | import fr.xephi.authme.service.ProxyLoginRequestValidator; |
13 | 13 | import fr.xephi.authme.settings.Settings; |
14 | 14 | import fr.xephi.authme.settings.properties.HooksSettings; |
| 15 | +import fr.xephi.authme.settings.properties.PremiumSettings; |
15 | 16 | import org.bukkit.Server; |
16 | 17 | import org.bukkit.entity.Player; |
17 | 18 | import org.bukkit.plugin.messaging.Messenger; |
|
24 | 25 | import org.mockito.junit.jupiter.MockitoSettings; |
25 | 26 | import org.mockito.quality.Strictness; |
26 | 27 |
|
| 28 | +import java.util.List; |
27 | 29 | import java.util.UUID; |
28 | 30 |
|
29 | 31 | import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToRunTaskAsynchronously; |
30 | 32 | import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToScheduleSyncEntityTaskFromOptionallyAsyncTask; |
| 33 | +import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask; |
31 | 34 | import static org.hamcrest.MatcherAssert.assertThat; |
32 | 35 | import static org.hamcrest.Matchers.equalTo; |
33 | 36 | import static org.hamcrest.Matchers.nullValue; |
@@ -81,6 +84,7 @@ static void initLogger() { |
81 | 84 | void setUp() { |
82 | 85 | given(plugin.getServer()).willReturn(server); |
83 | 86 | given(server.getMessenger()).willReturn(messenger); |
| 87 | + given(settings.getProperty(PremiumSettings.ENABLE_PREMIUM)).willReturn(true); |
84 | 88 | } |
85 | 89 |
|
86 | 90 | @Test |
@@ -288,6 +292,58 @@ void shouldRejectConfigPhasePerformLoginWithInvalidHmac() { |
288 | 292 | verify(proxySessionManager, never()).processProxySessionMessage(any(), any()); |
289 | 293 | } |
290 | 294 |
|
| 295 | + @Test |
| 296 | + void shouldSendEmptyPremiumListOnProxyStartedWhenPremiumIsDisabled() { |
| 297 | + // given |
| 298 | + given(settings.getProperty(HooksSettings.BUNGEECORD)).willReturn(true); |
| 299 | + given(settings.getProperty(PremiumSettings.ENABLE_PREMIUM)).willReturn(false); |
| 300 | + setBukkitServiceToRunTaskAsynchronously(bukkitService); |
| 301 | + setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService); |
| 302 | + |
| 303 | + Player carrier = mock(Player.class); |
| 304 | + given(bukkitService.getOnlinePlayers()).willReturn(List.of(carrier)); |
| 305 | + |
| 306 | + BungeeReceiver receiver = |
| 307 | + new BungeeReceiver(plugin, bukkitService, proxySessionManager, management, bungeeSender, dataSource, |
| 308 | + proxyLoginRequestValidator, settings); |
| 309 | + |
| 310 | + // when |
| 311 | + receiver.onPluginMessageReceived("authme:main", carrier, buildProxyStartedPayload("velocity")); |
| 312 | + |
| 313 | + // then |
| 314 | + verify(dataSource, never()).getPremiumUsernames(); |
| 315 | + verify(bungeeSender).sendPremiumList(carrier, List.of()); |
| 316 | + } |
| 317 | + |
| 318 | + @Test |
| 319 | + void shouldSendEmptyPremiumListOnProxyStartedWhenNoPremiumUsersAreStored() { |
| 320 | + // given |
| 321 | + given(settings.getProperty(HooksSettings.BUNGEECORD)).willReturn(true); |
| 322 | + given(dataSource.getPremiumUsernames()).willReturn(List.of()); |
| 323 | + setBukkitServiceToRunTaskAsynchronously(bukkitService); |
| 324 | + setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService); |
| 325 | + |
| 326 | + Player carrier = mock(Player.class); |
| 327 | + given(bukkitService.getOnlinePlayers()).willReturn(List.of(carrier)); |
| 328 | + |
| 329 | + BungeeReceiver receiver = |
| 330 | + new BungeeReceiver(plugin, bukkitService, proxySessionManager, management, bungeeSender, dataSource, |
| 331 | + proxyLoginRequestValidator, settings); |
| 332 | + |
| 333 | + // when |
| 334 | + receiver.onPluginMessageReceived("authme:main", carrier, buildProxyStartedPayload("velocity")); |
| 335 | + |
| 336 | + // then |
| 337 | + verify(bungeeSender).sendPremiumList(carrier, List.of()); |
| 338 | + } |
| 339 | + |
| 340 | + private static byte[] buildProxyStartedPayload(String proxyName) { |
| 341 | + ByteArrayDataOutput out = ByteStreams.newDataOutput(); |
| 342 | + out.writeUTF(MessageType.PROXY_STARTED.getId()); |
| 343 | + out.writeUTF(proxyName); |
| 344 | + return out.toByteArray(); |
| 345 | + } |
| 346 | + |
291 | 347 | private static byte[] buildPerformLoginPayload(String playerName, long timestamp, String hmac) { |
292 | 348 | return buildPerformLoginPayload(playerName, timestamp, "", hmac); |
293 | 349 | } |
|
0 commit comments