@@ -295,14 +295,16 @@ void test_auth_test_success() throws Exception {
295295 }
296296
297297 @ Test
298- @ DisplayName ("Test authorization code password auth success" )
298+ @ DisplayName ("Test authorization code auth success" )
299299 void test_auth_authorizationCode_success () throws Exception {
300300 createAuthorizationCodeAuthInfo (createAuthorizationCodeAuthParam ());
301301 AuthA authorizationCodeAuth = createAuth ().createAuthorizationCodeAuth ();
302302 Assertions .assertThat (authorizationCodeAuth ).isNotNull ();
303303 Assertions .assertThatCode (() -> domainService .auth (authorizationCodeAuth )).doesNotThrowAnyException ();
304304 Mockito .verify (tenantGateway , Mockito .times (1 )).getTenantId (this .tenantCode );
305305 Mockito .verify (httpRequest , Mockito .times (1 )).getParameterMap ();
306+ Mockito .verify (captchaValidator , Mockito .times (1 ))
307+ .validateCaptcha (RedisKeyUtils .getAuthorizationCodeAuthCaptchaKey (this .uuid ), this .captcha );
306308 Mockito .verify (passwordValidator , Mockito .times (1 )).validatePassword (this .password , this .password );
307309 Mockito .verify (userGateway , Mockito .times (1 )).getUserProfile (createUserVByAuthorizationCode ());
308310 Mockito .verify (menuGateway , Mockito .times (1 )).getMenuPermissions (createUserE ());
@@ -432,9 +434,16 @@ private void createAuthorizationCodeAuthInfo(AuthorizationCodAuthParam authoriza
432434 Mockito .doAnswer (invocation -> {
433435 AuthA authA = invocation .getArgument (0 );
434436 UserV userV = authA .getUserV ();
437+ CaptchaV captchaV = authA .getCaptchaV ();
435438 if (StringExtUtils .isEmpty (userV .tenantCode ())) {
436439 throw new IllegalArgumentException ("tenant code must not be empty" );
437440 }
441+ if (StringExtUtils .isEmpty (captchaV .uuid ())) {
442+ throw new IllegalArgumentException ("uuid must not be empty" );
443+ }
444+ if (StringExtUtils .isEmpty (captchaV .captcha ())) {
445+ throw new IllegalArgumentException ("captcha must not be empty" );
446+ }
438447 if (StringExtUtils .isEmpty (userV .username ())) {
439448 throw new IllegalArgumentException ("username must not be empty" );
440449 }
@@ -444,6 +453,7 @@ private void createAuthorizationCodeAuthInfo(AuthorizationCodAuthParam authoriza
444453 return null ;
445454 }).when (authorizationCodeAuthParamValidator ).validateAuth (Mockito .any ());
446455 Mockito .when (passwordValidator .validatePassword (Mockito .anyString (), Mockito .anyString ())).thenReturn (true );
456+ Mockito .when (captchaValidator .validateCaptcha (Mockito .anyString (), Mockito .anyString ())).thenReturn (true );
447457 Mockito .when (tenantGateway .getTenantId (Mockito .anyString ())).thenReturn (1L );
448458 Mockito .when (roleGateway .getDataScopes (Mockito .any ())).thenReturn (Set .of ("self" , "custom" ));
449459 Mockito .when (deptGateway .getDeptIds (Mockito .any (), Mockito .any ())).thenReturn (Set .of (1L ));
@@ -453,8 +463,11 @@ private void createAuthorizationCodeAuthInfo(AuthorizationCodAuthParam authoriza
453463 Map <String , String []> params = MapUtils .newHashMap (4 );
454464 params .put (Constants .USERNAME , new String [] { authorizationCodeAuthParam .username () });
455465 params .put (Constants .PASSWORD , new String [] { authorizationCodeAuthParam .password () });
466+ params .put (Constants .UUID , new String [] { authorizationCodeAuthParam .uuid () });
467+ params .put (Constants .CAPTCHA , new String [] { authorizationCodeAuthParam .captcha () });
456468 params .put (Constants .TENANT_CODE , new String [] { authorizationCodeAuthParam .tenantCode () });
457469 params .put (Constants .GRANT_TYPE , new String [] { authorizationCodeAuthParam .grantType () });
470+
458471 Mockito .when (httpRequest .getParameterMap ()).thenReturn (params );
459472 }
460473
@@ -535,7 +548,7 @@ private TestAuthParam createTestAuthParam() {
535548 }
536549
537550 private AuthorizationCodAuthParam createAuthorizationCodeAuthParam () {
538- return new AuthorizationCodAuthParam (this .username , this .password , this .tenantCode ,
551+ return new AuthorizationCodAuthParam (this .uuid , this . captcha , this . username , this .password , this .tenantCode ,
539552 GrantType .AUTHORIZATION_CODE .getCode ());
540553 }
541554
@@ -552,7 +565,7 @@ private TestAuthParam createTestEmptyAuthParam() {
552565 }
553566
554567 private AuthorizationCodAuthParam createAuthorizationCodeEmptyAuthParam () {
555- return new AuthorizationCodAuthParam (null , null , null , GrantType .AUTHORIZATION_CODE .getCode ());
568+ return new AuthorizationCodAuthParam (null , null , null , null , null , GrantType .AUTHORIZATION_CODE .getCode ());
556569 }
557570
558571 private UserV createUserVByUsernamePassword () throws Exception {
@@ -624,7 +637,8 @@ private record MailAuthParam(String mail, String code, String tenantCode, String
624637 private record TestAuthParam (String username , String password , String tenantCode , String grantType ) {
625638 }
626639
627- private record AuthorizationCodAuthParam (String username , String password , String tenantCode , String grantType ) {
640+ private record AuthorizationCodAuthParam (String uuid , String captcha , String username , String password ,
641+ String tenantCode , String grantType ) {
628642 }
629643
630644}
0 commit comments