Skip to content

Commit 591dbbb

Browse files
committed
add check for null/missing AMR claim, fix tests
1 parent 37d2ef6 commit 591dbbb

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/main/java/us/kbase/auth2/providers/OrcIDIdentityProviderFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ private MfaStatus parseAmrClaim(final String jwt) throws IdentityRetrievalExcept
269269
final Map<String, Object> claims = MAPPER.readValue(payload, Map.class);
270270

271271
final Object amrClaim = claims.get("amr");
272-
if (amrClaim instanceof List) {
272+
if (amrClaim == null) {
273+
// No AMR claim present - MFA status unknown
274+
return MfaStatus.UNKNOWN;
275+
} else if (amrClaim instanceof List) {
273276
// OpenID Connect spec: AMR should be an array of strings
274277
@SuppressWarnings("unchecked")
275278
final List<String> amrList = (List<String>) amrClaim;

src/test/java/us/kbase/test/auth2/lib/identity/RemoteIdentityTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void remoteDetailsWithAllFields() throws Exception {
2222
assertThat("incorrect fullname", dets.getFullname(), is("full"));
2323
assertThat("incorrect email", dets.getEmail(), is("email"));
2424
assertThat("incorrect mfa authenticated", dets.getMfa(), is(MfaStatus.UNKNOWN));
25-
assertThat("incorrect hashcode", dets.hashCode(), is(-497844993));
25+
assertThat("incorrect hashcode", dets.hashCode(), is(1166981462));
2626
assertThat("incorrect toString()", dets.toString(),
2727
is("RemoteIdentityDetails [username=user, fullname=full, email=email, mfa=UNKNOWN]"));
2828
}
@@ -34,7 +34,7 @@ public void remoteDetailsWithEmptyFields() throws Exception {
3434
assertThat("incorrect fullname", dets.getFullname(), is((String) null));
3535
assertThat("incorrect email", dets.getEmail(), is((String) null));
3636
assertThat("incorrect mfa authenticated", dets.getMfa(), is(MfaStatus.UNKNOWN));
37-
assertThat("incorrect hashcode", dets.hashCode(), is(4522828));
37+
assertThat("incorrect hashcode", dets.hashCode(), is(1669349283));
3838
assertThat("incorrect toString()", dets.toString(),
3939
is("RemoteIdentityDetails [username=user, fullname=null, email=null, mfa=UNKNOWN]"));
4040

@@ -43,7 +43,7 @@ public void remoteDetailsWithEmptyFields() throws Exception {
4343
assertThat("incorrect fullname", dets2.getFullname(), is((String) null));
4444
assertThat("incorrect email", dets2.getEmail(), is((String) null));
4545
assertThat("incorrect mfa authenticated", dets2.getMfa(), is(MfaStatus.UNKNOWN));
46-
assertThat("incorrect hashcode", dets2.hashCode(), is(4522828));
46+
assertThat("incorrect hashcode", dets2.hashCode(), is(1669349283));
4747
assertThat("incorrect toString()", dets2.toString(),
4848
is("RemoteIdentityDetails [username=user, fullname=null, email=null, mfa=UNKNOWN]"));
4949
}
@@ -116,7 +116,7 @@ public void identity() throws Exception {
116116
final RemoteIdentity ri = new RemoteIdentity(id, dets);
117117
assertThat("incorrect id", ri.getRemoteID(), is(id));
118118
assertThat("incorrect details", ri.getDetails(), is(dets));
119-
assertThat("incorrect hashcode", ri.hashCode(), is(124952370));
119+
assertThat("incorrect hashcode", ri.hashCode(), is(194964923));
120120
assertThat("incorrect toString()", ri.toString(),
121121
is("RemoteIdentity [remoteID=RemoteIdentityID [provider=p, id=i], " +
122122
"details=RemoteIdentityDetails [username=u, fullname=f, email=e, mfa=UNKNOWN]]"));

src/test/java/us/kbase/test/auth2/providers/OrcIDIdentityProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public void getIdentityWithInvalidJWT() throws Exception {
573573
fail("Expected IdentityRetrievalException");
574574
} catch (IdentityRetrievalException e) {
575575
assertThat("incorrect exception message", e.getMessage(),
576-
containsString("Unable to decode JWT from ORCID"));
576+
containsString("Unable to parse JWT payload from ORCID"));
577577
}
578578
}
579579

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ userName, userUuid, new DisplayName("Test User"), inst(10000))
232232
assertThat("incorrect response code for token2", res2.getStatus(), is(200));
233233
@SuppressWarnings("unchecked")
234234
final Map<String, Object> response2 = res2.readEntity(Map.class);
235-
assertThat("token2 should have MFA=false", response2.get("mfa"), is(MfaStatus.NOT_USED));
235+
assertThat("token2 should have MFA=false", response2.get("mfa"), is(MfaStatus.NOT_USED.toString()));
236236
}
237237

238238
@Test

0 commit comments

Comments
 (0)