Skip to content

Commit b6938e1

Browse files
More test coverage
1 parent 8bd77fa commit b6938e1

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

src/test/java/com/auth0/client/auth/AuthAPITest.java

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,14 @@ public void addOobAuthenticatorDeprecatedThrowsWhenPhoneNumberNull() {
15651565
"'phone number' cannot be null!");
15661566
}
15671567

1568+
@SuppressWarnings("deprecation")
1569+
@Test
1570+
public void addOobAuthenticatorDeprecatedThrowsWhenPhoneNumberNullVoiceChannel() {
1571+
verifyThrows(IllegalArgumentException.class,
1572+
() -> api.addOobAuthenticator("mfaToken", Collections.singletonList("voice"), null),
1573+
"'phone number' cannot be null!");
1574+
}
1575+
15681576
@SuppressWarnings("deprecation")
15691577
@Test
15701578
public void addOobAuthenticatorDeprecatedRequest() throws Exception {
@@ -1590,6 +1598,30 @@ public void addOobAuthenticatorDeprecatedRequest() throws Exception {
15901598
assertThat(response.getRecoveryCodes(), notNullValue());
15911599
}
15921600

1601+
@SuppressWarnings("deprecation")
1602+
@Test
1603+
public void addOobAuthenticatorDeprecatedRequestWithNoPhoneNumber() throws Exception {
1604+
Request<CreatedOobResponse> request = api.addOobAuthenticator("mfaToken", Collections.singletonList("auth0"), null);
1605+
1606+
server.jsonResponse(AUTH_OOB_AUTHENTICATOR_RESPONSE, 200);
1607+
CreatedOobResponse response = request.execute().getBody();
1608+
RecordedRequest recordedRequest = server.takeRequest();
1609+
1610+
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/mfa/associate"));
1611+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
1612+
1613+
Map<String, Object> body = bodyFromRequest(recordedRequest);
1614+
assertThat(body, hasEntry("authenticator_types", Collections.singletonList("oob")));
1615+
assertThat(body, hasEntry("oob_channels", Collections.singletonList("auth0")));
1616+
1617+
assertThat(response, is(notNullValue()));
1618+
assertThat(response.getAuthenticatorType(), not(emptyOrNullString()));
1619+
assertThat(response.getOobChannel(), not(emptyOrNullString()));
1620+
assertThat(response.getOobCode(), not(emptyOrNullString()));
1621+
assertThat(response.getBarcodeUri(), not(emptyOrNullString()));
1622+
assertThat(response.getRecoveryCodes(), notNullValue());
1623+
}
1624+
15931625
@Test
15941626
public void addOobAuthenticatorThrowsWhenTokenNull() {
15951627
verifyThrows(IllegalArgumentException.class,
@@ -1605,6 +1637,20 @@ public void addOobAuthenticatorThrowsWhenChannelsNull() {
16051637
"'OOB channels' cannot be null!");
16061638
}
16071639

1640+
@Test
1641+
public void addOobAuthenticatorThrowsWhenChannelsNullWithPhoneNumber() {
1642+
verifyThrows(IllegalArgumentException.class,
1643+
() -> api.addOobAuthenticator("mfaToken", null, "phone-number", null),
1644+
"'OOB channels' cannot be null!");
1645+
}
1646+
1647+
@Test
1648+
public void addOobAuthenticatorThrowsWhenChannelsNullWithEmail() {
1649+
verifyThrows(IllegalArgumentException.class,
1650+
() -> api.addOobAuthenticator("mfaToken", null, null, "email-address"),
1651+
"'OOB channels' cannot be null!");
1652+
}
1653+
16081654
@Test
16091655
public void addOobAuthenticatorThrowsWhenPhoneNumberNull() {
16101656
verifyThrows(IllegalArgumentException.class,
@@ -1674,9 +1720,32 @@ public void addOobAuthenticatorRequestWithEmail() throws Exception {
16741720
assertThat(response.getRecoveryCodes(), notNullValue());
16751721
}
16761722

1723+
@Test
1724+
public void addOobAuthenticatorRequestWithNoContactInfo() throws Exception {
1725+
Request<CreatedOobResponse> request = api.addOobAuthenticator("mfaToken", Collections.singletonList("auth0"), null, null);
1726+
1727+
server.jsonResponse(AUTH_OOB_AUTHENTICATOR_RESPONSE, 200);
1728+
CreatedOobResponse response = request.execute().getBody();
1729+
RecordedRequest recordedRequest = server.takeRequest();
1730+
1731+
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/mfa/associate"));
1732+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
1733+
1734+
Map<String, Object> body = bodyFromRequest(recordedRequest);
1735+
assertThat(body, hasEntry("authenticator_types", Collections.singletonList("oob")));
1736+
assertThat(body, hasEntry("oob_channels", Collections.singletonList("auth0")));
1737+
1738+
assertThat(response, is(notNullValue()));
1739+
assertThat(response.getAuthenticatorType(), not(emptyOrNullString()));
1740+
assertThat(response.getOobChannel(), not(emptyOrNullString()));
1741+
assertThat(response.getOobCode(), not(emptyOrNullString()));
1742+
assertThat(response.getBarcodeUri(), not(emptyOrNullString()));
1743+
assertThat(response.getRecoveryCodes(), notNullValue());
1744+
}
1745+
16771746
@Test
16781747
public void addOobAuthenticatorRequestWithMultipleChannels() throws Exception {
1679-
Request<CreatedOobResponse> request = api.addOobAuthenticator("mfaToken", Arrays.asList("sms", "email"), "phone-number", "email-address");
1748+
Request<CreatedOobResponse> request = api.addOobAuthenticator("mfaToken", Arrays.asList("sms", "email", "auth0"), "phone-number", "email-address");
16801749

16811750
server.jsonResponse(AUTH_OOB_AUTHENTICATOR_RESPONSE, 200);
16821751
CreatedOobResponse response = request.execute().getBody();
@@ -1687,7 +1756,7 @@ public void addOobAuthenticatorRequestWithMultipleChannels() throws Exception {
16871756

16881757
Map<String, Object> body = bodyFromRequest(recordedRequest);
16891758
assertThat(body, hasEntry("authenticator_types", Collections.singletonList("oob")));
1690-
assertThat(body, hasEntry("oob_channels", Arrays.asList("sms", "email")));
1759+
assertThat(body, hasEntry("oob_channels", Arrays.asList("sms", "email", "auth0")));
16911760
assertThat(body, hasEntry("phone_number", "phone-number"));
16921761
assertThat(body, hasEntry("email", "email-address"));
16931762

0 commit comments

Comments
 (0)