Skip to content

Commit 53ed176

Browse files
committed
update tests
1 parent 9dfc0a7 commit 53ed176

File tree

2 files changed

+41
-48
lines changed

2 files changed

+41
-48
lines changed

src/test/java/us/kbase/test/auth2/lib/AuthenticationTokenTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,11 +1187,5 @@ public void deleteLoginOrLinkStateNull() throws Exception {
11871187
}
11881188
}
11891189

1190-
@Test
1191-
public void getMfaStatusNull() throws Exception {
1192-
final Authentication auth = initTestMocks().auth;
1193-
1194-
assertThat("incorrect mfa status", auth.getMfaStatus(null), is((Boolean) null));
1195-
}
11961190

11971191
}

src/test/java/us/kbase/test/auth2/service/api/TokenEndpointTest.java

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -666,20 +666,20 @@ private void kbaseTokenSuccess(
666666
public void getTokenWithMfaTrue() throws Exception {
667667
final UUID id = UUID.randomUUID();
668668
final IncomingToken it = new IncomingToken("mfatokenvalue");
669+
final UserName userName = new UserName("mfauser");
669670

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()));
678676

677+
// Create token with MFA=true
679678
manager.storage.storeToken(StoredToken.getBuilder(
680-
TokenType.AGENT, id, new UserName("mfauser"))
679+
TokenType.AGENT, id, userName)
681680
.withLifeTime(Instant.ofEpochMilli(10000), Instant.ofEpochMilli(1000000000000000L))
682681
.withTokenName(new TokenName("mfatoken"))
682+
.withMfaAuthenticated(true)
683683
.build(), it.getHashedToken().getTokenHash());
684684

685685
final URI target = UriBuilder.fromUri(host).path("/api/V2/token").build();
@@ -704,20 +704,20 @@ TokenType.AGENT, id, new UserName("mfauser"))
704704
public void getTokenWithMfaFalse() throws Exception {
705705
final UUID id = UUID.randomUUID();
706706
final IncomingToken it = new IncomingToken("nomfatokenvalue");
707+
final UserName userName = new UserName("nomfauser");
707708

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()));
716714

715+
// Create token with MFA=false
717716
manager.storage.storeToken(StoredToken.getBuilder(
718-
TokenType.AGENT, id, new UserName("nomfauser"))
717+
TokenType.AGENT, id, userName)
719718
.withLifeTime(Instant.ofEpochMilli(10000), Instant.ofEpochMilli(1000000000000000L))
720719
.withTokenName(new TokenName("nomfatoken"))
720+
.withMfaAuthenticated(false)
721721
.build(), it.getHashedToken().getTokenHash());
722722

723723
final URI target = UriBuilder.fromUri(host).path("/api/V2/token").build();
@@ -742,20 +742,20 @@ TokenType.AGENT, id, new UserName("nomfauser"))
742742
public void getTokenWithMfaNull() throws Exception {
743743
final UUID id = UUID.randomUUID();
744744
final IncomingToken it = new IncomingToken("unknownmfatokenvalue");
745+
final UserName userName = new UserName("unknownmfauser");
745746

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()));
754752

753+
// Create token with MFA=null (unknown)
755754
manager.storage.storeToken(StoredToken.getBuilder(
756-
TokenType.AGENT, id, new UserName("unknownmfauser"))
755+
TokenType.AGENT, id, userName)
757756
.withLifeTime(Instant.ofEpochMilli(10000), Instant.ofEpochMilli(1000000000000000L))
758757
.withTokenName(new TokenName("unknownmfatoken"))
758+
.withMfaAuthenticated(null)
759759
.build(), it.getHashedToken().getTokenHash());
760760

761761
final URI target = UriBuilder.fromUri(host).path("/api/V2/token").build();
@@ -777,23 +777,22 @@ TokenType.AGENT, id, new UserName("unknownmfauser"))
777777
}
778778

779779
@Test
780-
public void getTokenWithNonOrcidProvider() throws Exception {
780+
public void getTokenWithNoMfaSet() throws Exception {
781781
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");
783784

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()));
792790

791+
// Create token without explicitly setting MFA (should default to null)
793792
manager.storage.storeToken(StoredToken.getBuilder(
794-
TokenType.AGENT, id, new UserName("googleuser"))
793+
TokenType.AGENT, id, userName)
795794
.withLifeTime(Instant.ofEpochMilli(10000), Instant.ofEpochMilli(1000000000000000L))
796-
.withTokenName(new TokenName("googletoken"))
795+
.withTokenName(new TokenName("nomfasettoken"))
797796
.build(), it.getHashedToken().getTokenHash());
798797

799798
final URI target = UriBuilder.fromUri(host).path("/api/V2/token").build();
@@ -809,9 +808,9 @@ TokenType.AGENT, id, new UserName("googleuser"))
809808
@SuppressWarnings("unchecked")
810809
final Map<String, Object> response = res.readEntity(Map.class);
811810

812-
// Non-ORCID providers should return null for MFA status
811+
// Should return null when MFA not explicitly set
813812
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"));
816815
}
817816
}

0 commit comments

Comments
 (0)