@@ -666,20 +666,20 @@ private void kbaseTokenSuccess(
666
666
public void getTokenWithMfaTrue () throws Exception {
667
667
final UUID id = UUID .randomUUID ();
668
668
final IncomingToken it = new IncomingToken ("mfatokenvalue" );
669
+ final UserName userName = new UserName ("mfauser" );
669
670
670
- // Create user with ORCID identity that used MFA
671
- final us .kbase .auth2 .lib .identity .RemoteIdentity orcidId = new us .kbase .auth2 .lib .identity .RemoteIdentity (
672
- new us .kbase .auth2 .lib .identity .RemoteIdentityID ("OrcID" , "0000-0001-1234-5678" ),
673
- new us .
kbase .
auth2 .
lib .
identity .
RemoteIdentityDetails (
"orciduser" ,
"ORCID User" ,
"[email protected] " ,
true ));
674
-
675
- manager .storage .createUser (us .kbase .auth2 .lib .user .NewUser .getBuilder (
676
- new UserName ("mfauser" ), id , new DisplayName ("MFA User" ), inst (10000 ), orcidId )
677
- .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build ());
671
+ // Create simple local user
672
+ manager .storage .createLocalUser (LocalUser .getLocalUserBuilder (
673
+ userName , id , new DisplayName ("MFA User" ), inst (10000 ))
674
+ .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build (),
675
+ new PasswordHashAndSalt ("password" .getBytes (), "salt" .getBytes ()));
678
676
677
+ // Create token with MFA=true
679
678
manager .storage .storeToken (StoredToken .getBuilder (
680
- TokenType .AGENT , id , new UserName ( "mfauser" ) )
679
+ TokenType .AGENT , id , userName )
681
680
.withLifeTime (Instant .ofEpochMilli (10000 ), Instant .ofEpochMilli (1000000000000000L ))
682
681
.withTokenName (new TokenName ("mfatoken" ))
682
+ .withMfaAuthenticated (true )
683
683
.build (), it .getHashedToken ().getTokenHash ());
684
684
685
685
final URI target = UriBuilder .fromUri (host ).path ("/api/V2/token" ).build ();
@@ -704,20 +704,20 @@ TokenType.AGENT, id, new UserName("mfauser"))
704
704
public void getTokenWithMfaFalse () throws Exception {
705
705
final UUID id = UUID .randomUUID ();
706
706
final IncomingToken it = new IncomingToken ("nomfatokenvalue" );
707
+ final UserName userName = new UserName ("nomfauser" );
707
708
708
- // Create user with ORCID identity that did NOT use MFA
709
- final us .kbase .auth2 .lib .identity .RemoteIdentity orcidId = new us .kbase .auth2 .lib .identity .RemoteIdentity (
710
- new us .kbase .auth2 .lib .identity .RemoteIdentityID ("OrcID" , "0000-0001-1234-9999" ),
711
- new us .
kbase .
auth2 .
lib .
identity .
RemoteIdentityDetails (
"orciduser2" ,
"ORCID User 2" ,
"[email protected] " ,
false ));
712
-
713
- manager .storage .createUser (us .kbase .auth2 .lib .user .NewUser .getBuilder (
714
- new UserName ("nomfauser" ), id , new DisplayName ("No MFA User" ), inst (10000 ), orcidId )
715
- .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build ());
709
+ // Create simple local user
710
+ manager .storage .createLocalUser (LocalUser .getLocalUserBuilder (
711
+ userName , id , new DisplayName ("No MFA User" ), inst (10000 ))
712
+ .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build (),
713
+ new PasswordHashAndSalt ("password" .getBytes (), "salt" .getBytes ()));
716
714
715
+ // Create token with MFA=false
717
716
manager .storage .storeToken (StoredToken .getBuilder (
718
- TokenType .AGENT , id , new UserName ( "nomfauser" ) )
717
+ TokenType .AGENT , id , userName )
719
718
.withLifeTime (Instant .ofEpochMilli (10000 ), Instant .ofEpochMilli (1000000000000000L ))
720
719
.withTokenName (new TokenName ("nomfatoken" ))
720
+ .withMfaAuthenticated (false )
721
721
.build (), it .getHashedToken ().getTokenHash ());
722
722
723
723
final URI target = UriBuilder .fromUri (host ).path ("/api/V2/token" ).build ();
@@ -742,20 +742,20 @@ TokenType.AGENT, id, new UserName("nomfauser"))
742
742
public void getTokenWithMfaNull () throws Exception {
743
743
final UUID id = UUID .randomUUID ();
744
744
final IncomingToken it = new IncomingToken ("unknownmfatokenvalue" );
745
+ final UserName userName = new UserName ("unknownmfauser" );
745
746
746
- // Create user with ORCID identity that has unknown MFA status
747
- final us .kbase .auth2 .lib .identity .RemoteIdentity orcidId = new us .kbase .auth2 .lib .identity .RemoteIdentity (
748
- new us .kbase .auth2 .lib .identity .RemoteIdentityID ("OrcID" , "0000-0001-1234-0000" ),
749
- new us .
kbase .
auth2 .
lib .
identity .
RemoteIdentityDetails (
"orciduser3" ,
"ORCID User 3" ,
"[email protected] " ,
null ));
750
-
751
- manager .storage .createUser (us .kbase .auth2 .lib .user .NewUser .getBuilder (
752
- new UserName ("unknownmfauser" ), id , new DisplayName ("Unknown MFA User" ), inst (10000 ), orcidId )
753
- .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build ());
747
+ // Create simple local user
748
+ manager .storage .createLocalUser (LocalUser .getLocalUserBuilder (
749
+ userName , id , new DisplayName ("Unknown MFA User" ), inst (10000 ))
750
+ .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build (),
751
+ new PasswordHashAndSalt ("password" .getBytes (), "salt" .getBytes ()));
754
752
753
+ // Create token with MFA=null (unknown)
755
754
manager .storage .storeToken (StoredToken .getBuilder (
756
- TokenType .AGENT , id , new UserName ( "unknownmfauser" ) )
755
+ TokenType .AGENT , id , userName )
757
756
.withLifeTime (Instant .ofEpochMilli (10000 ), Instant .ofEpochMilli (1000000000000000L ))
758
757
.withTokenName (new TokenName ("unknownmfatoken" ))
758
+ .withMfaAuthenticated (null )
759
759
.build (), it .getHashedToken ().getTokenHash ());
760
760
761
761
final URI target = UriBuilder .fromUri (host ).path ("/api/V2/token" ).build ();
@@ -777,23 +777,22 @@ TokenType.AGENT, id, new UserName("unknownmfauser"))
777
777
}
778
778
779
779
@ Test
780
- public void getTokenWithNonOrcidProvider () throws Exception {
780
+ public void getTokenWithNoMfaSet () throws Exception {
781
781
final UUID id = UUID .randomUUID ();
782
- final IncomingToken it = new IncomingToken ("googletokenvalue" );
782
+ final IncomingToken it = new IncomingToken ("nomfasettokenvalue" );
783
+ final UserName userName = new UserName ("nomfasetuser" );
783
784
784
- // Create user with non-ORCID identity (e.g., Google)
785
- final us .kbase .auth2 .lib .identity .RemoteIdentity googleId = new us .kbase .auth2 .lib .identity .RemoteIdentity (
786
- new us .kbase .auth2 .lib .identity .RemoteIdentityID ("Google" , "googleid123" ),
787
- new us .
kbase .
auth2 .
lib .
identity .
RemoteIdentityDetails (
"googleuser" ,
"Google User" ,
"[email protected] " ,
null ));
788
-
789
- manager .storage .createUser (us .kbase .auth2 .lib .user .NewUser .getBuilder (
790
- new UserName ("googleuser" ), id , new DisplayName ("Google User" ), inst (10000 ), googleId )
791
- .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build ());
785
+ // Create simple local user
786
+ manager .storage .createLocalUser (LocalUser .getLocalUserBuilder (
787
+ userName , id , new DisplayName ("No MFA Set User" ), inst (10000 ))
788
+ .
withEmailAddress (
new EmailAddress (
"[email protected] " )).
build (),
789
+ new PasswordHashAndSalt ("password" .getBytes (), "salt" .getBytes ()));
792
790
791
+ // Create token without explicitly setting MFA (should default to null)
793
792
manager .storage .storeToken (StoredToken .getBuilder (
794
- TokenType .AGENT , id , new UserName ( "googleuser" ) )
793
+ TokenType .AGENT , id , userName )
795
794
.withLifeTime (Instant .ofEpochMilli (10000 ), Instant .ofEpochMilli (1000000000000000L ))
796
- .withTokenName (new TokenName ("googletoken " ))
795
+ .withTokenName (new TokenName ("nomfasettoken " ))
797
796
.build (), it .getHashedToken ().getTokenHash ());
798
797
799
798
final URI target = UriBuilder .fromUri (host ).path ("/api/V2/token" ).build ();
@@ -809,9 +808,9 @@ TokenType.AGENT, id, new UserName("googleuser"))
809
808
@ SuppressWarnings ("unchecked" )
810
809
final Map <String , Object > response = res .readEntity (Map .class );
811
810
812
- // Non-ORCID providers should return null for MFA status
811
+ // Should return null when MFA not explicitly set
813
812
assertThat ("incorrect MFA status" , response .get ("mfaAuthenticated" ), is ((Object ) null ));
814
- assertThat ("incorrect user" , response .get ("user" ), is ("googleuser " ));
815
- assertThat ("incorrect token name" , response .get ("name" ), is ("googletoken " ));
813
+ assertThat ("incorrect user" , response .get ("user" ), is ("nomfasetuser " ));
814
+ assertThat ("incorrect token name" , response .get ("name" ), is ("nomfasettoken " ));
816
815
}
817
816
}
0 commit comments