|
21 | 21 | import fr.xephi.authme.service.BukkitService; |
22 | 22 | import fr.xephi.authme.service.CommonService; |
23 | 23 | import fr.xephi.authme.service.DialogWindowService; |
| 24 | +import fr.xephi.authme.service.FloodgateService; |
24 | 25 | import fr.xephi.authme.service.PreJoinDialogService; |
25 | 26 | import fr.xephi.authme.service.PremiumLoginVerifier; |
26 | 27 | import fr.xephi.authme.service.SessionService; |
@@ -464,6 +465,7 @@ public void shouldSkipPreJoinDialogsForVerifiedPremiumPlayer() throws Exception |
464 | 465 | setField(listener, "sessionService", sessionService); |
465 | 466 | setField(listener, "proxySessionManager", proxySessionManager); |
466 | 467 | setField(listener, "premiumLoginVerifier", premiumLoginVerifier); |
| 468 | + setField(listener, "floodgateService", mock(FloodgateService.class)); |
467 | 469 |
|
468 | 470 | UUID premiumUuid = UUID.randomUUID(); |
469 | 471 | // Offline (v3) UUID simulates an offline-mode backend without proxy |
@@ -502,6 +504,74 @@ public void shouldSkipPreJoinDialogsForVerifiedPremiumPlayer() throws Exception |
502 | 504 | verifyNoInteractions(audience); |
503 | 505 | } |
504 | 506 |
|
| 507 | + @Test |
| 508 | + public void shouldSkipPreJoinDialogsForRegisteredFloodgatePlayer() throws Exception { |
| 509 | + PlayerAuth auth = PlayerAuth.builder().name(".bobby").password(new HashedPassword("hash")).build(); |
| 510 | + FloodgateService floodgateService = mock(FloodgateService.class); |
| 511 | + UUID playerId = UUID.fromString("00000000-0000-0000-0009-01f163ba2c3a"); |
| 512 | + given(floodgateService.canAutoLogin(playerId)).willReturn(true); |
| 513 | + |
| 514 | + PreJoinDialogService preJoinDialogService = mock(PreJoinDialogService.class); |
| 515 | + Audience audience = mock(Audience.class); |
| 516 | + |
| 517 | + configureFloodgateJoin(floodgateService, preJoinDialogService, audience, playerId, auth); |
| 518 | + |
| 519 | + verify(preJoinDialogService).markSkipPostJoinDialog(SESSION_ID); |
| 520 | + verifyNoInteractions(audience); |
| 521 | + } |
| 522 | + |
| 523 | + @Test |
| 524 | + public void shouldSkipPreJoinDialogsForUnregisteredFloodgatePlayerWithAutoRegister() throws Exception { |
| 525 | + FloodgateService floodgateService = mock(FloodgateService.class); |
| 526 | + UUID playerId = UUID.fromString("00000000-0000-0000-0009-01f163ba2c3a"); |
| 527 | + given(floodgateService.canAutoRegister(playerId)).willReturn(true); |
| 528 | + |
| 529 | + PreJoinDialogService preJoinDialogService = mock(PreJoinDialogService.class); |
| 530 | + Audience audience = mock(Audience.class); |
| 531 | + |
| 532 | + configureFloodgateJoin(floodgateService, preJoinDialogService, audience, playerId, null); |
| 533 | + |
| 534 | + verify(preJoinDialogService).markSkipPostJoinDialog(SESSION_ID); |
| 535 | + verifyNoInteractions(audience); |
| 536 | + } |
| 537 | + |
| 538 | + /** Runs onPlayerConfigure for the Bedrock player ".Bobby" (stored auth, or null if unregistered). */ |
| 539 | + private static void configureFloodgateJoin(FloodgateService floodgateService, |
| 540 | + PreJoinDialogService preJoinDialogService, Audience audience, |
| 541 | + UUID playerId, PlayerAuth auth) throws Exception { |
| 542 | + PaperDialogFlowListener listener = new PaperDialogFlowListener(); |
| 543 | + CommonService commonService = mock(CommonService.class); |
| 544 | + PlayerCache playerCache = mock(PlayerCache.class); |
| 545 | + DataSource dataSource = mock(DataSource.class); |
| 546 | + SessionService sessionService = mock(SessionService.class); |
| 547 | + ProxySessionManager proxySessionManager = mock(ProxySessionManager.class); |
| 548 | + setField(listener, "commonService", commonService); |
| 549 | + setField(listener, "playerCache", playerCache); |
| 550 | + setField(listener, "dataSource", dataSource); |
| 551 | + setField(listener, "preJoinDialogService", preJoinDialogService); |
| 552 | + setField(listener, "sessionService", sessionService); |
| 553 | + setField(listener, "proxySessionManager", proxySessionManager); |
| 554 | + setField(listener, "floodgateService", floodgateService); |
| 555 | + |
| 556 | + given(commonService.getProperty(RegistrationSettings.USE_PREJOIN_DIALOG_UI)).willReturn(true); |
| 557 | + given(commonService.getProperty(RestrictionSettings.UNRESTRICTED_NAMES)).willReturn(Set.of()); |
| 558 | + given(dataSource.getAuth(".bobby")).willReturn(auth); |
| 559 | + given(preJoinDialogService.openSession(".bobby")).willReturn(SESSION_ID); |
| 560 | + |
| 561 | + PlayerProfile profile = mock(PlayerProfile.class); |
| 562 | + given(profile.getId()).willReturn(playerId); |
| 563 | + given(profile.getName()).willReturn(".Bobby"); |
| 564 | + |
| 565 | + PlayerConfigurationConnection connection = mock(PlayerConfigurationConnection.class); |
| 566 | + given(connection.getProfile()).willReturn(profile); |
| 567 | + given(connection.getAudience()).willReturn(audience); |
| 568 | + |
| 569 | + AsyncPlayerConnectionConfigureEvent event = mock(AsyncPlayerConnectionConfigureEvent.class); |
| 570 | + given(event.getConnection()).willReturn(connection); |
| 571 | + |
| 572 | + listener.onPlayerConfigure(event); |
| 573 | + } |
| 574 | + |
505 | 575 | @Test |
506 | 576 | public void shouldNotSkipPreJoinDialogsForUnverifiedPremiumPlayer() throws Exception { |
507 | 577 | PaperDialogFlowListener listener = new PaperDialogFlowListener(); |
|
0 commit comments