Skip to content

Commit 1728367

Browse files
committed
Add MFA Tests
1 parent 4e290f3 commit 1728367

File tree

1 file changed

+81
-7
lines changed

1 file changed

+81
-7
lines changed

src/test/java/org/openapitools/client/api/MfaApiTest.java

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import org.openapitools.client.auth.HttpBasicAuth;
77
import org.openapitools.client.model.CodeRequest;
88
import org.openapitools.client.model.MessagingCodeResponse;
9+
import org.openapitools.client.model.VerifyCodeRequest;
10+
import org.openapitools.client.model.VerifyCodeResponse;
11+
import org.openapitools.client.model.VoiceCodeResponse;
912
import org.openapitools.client.Configuration;
1013
import org.junit.jupiter.api.Assertions;
1114
import org.junit.jupiter.api.Test;
1215

16+
import java.math.BigDecimal;
1317
import java.net.URI;
1418

1519
import javax.security.auth.AuthPermission;
@@ -47,33 +51,103 @@ public void successfulMfaGenerateMessagingCodeRequest() throws ApiException {
4751
}
4852

4953
@Test
50-
public void successfulMfaGenerateVoiceCodeRequest() {
54+
public void successfulMfaGenerateVoiceCodeRequest() throws ApiException {
5155
Basic.setUsername(BW_USERNAME);
5256
Basic.setPassword(BW_PASSWORD);
57+
58+
CodeRequest request = new CodeRequest();
59+
request.setTo(USER_NUMBER);
60+
request.setFrom(BW_NUMBER);
61+
request.setApplicationId(BW_VOICE_APPLICATION_ID);
62+
request.setScope("scope");
63+
request.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
64+
request.setDigits(6);
65+
ApiResponse<VoiceCodeResponse> response = api.generateVoiceCodeWithHttpInfo(BW_ACCOUNT_ID, request);
66+
assertThat(response.getStatusCode(), is(200));
67+
68+
assertThat(response.getData(), instanceOf(VoiceCodeResponse.class));
5369
}
5470

5571
@Test
56-
public void successfulMfaVerifyCodeRequest() {
72+
public void successfulMfaVerifyCodeRequest() throws ApiException {
5773
Basic.setUsername(BW_USERNAME);
5874
Basic.setPassword(BW_PASSWORD);
75+
BigDecimal expirationTime = new BigDecimal(3);
76+
77+
// Generate a random TN for the setTo - otherwise we get heavily rate limited
78+
Integer minTn = 1111111111;
79+
Long maxTn = 9999999999L;
80+
Integer random_int = (int) Math.floor(Math.random() * (maxTn - minTn + 1) + minTn);
81+
82+
VerifyCodeRequest request = new VerifyCodeRequest();
83+
request.setTo("+1" + random_int.toString());
84+
request.setScope("2FA");
85+
request.setExpirationTimeInMinutes(expirationTime);
86+
request.setCode("123456");
87+
88+
ApiResponse<VerifyCodeResponse> response = api.verifyCodeWithHttpInfo(BW_ACCOUNT_ID, request);
89+
90+
assertThat(response.getStatusCode(), is(200));
91+
assertThat(response.getData().getValid(), is(false));
5992
}
6093

6194
@Test
62-
public void badRequest() {
95+
public void badRequest() throws ApiException {
6396
Basic.setUsername(BW_USERNAME);
6497
Basic.setPassword(BW_PASSWORD);
98+
99+
CodeRequest badRequest = new CodeRequest();
100+
badRequest.setTo(USER_NUMBER);
101+
badRequest.setFrom(BW_NUMBER);
102+
badRequest.setApplicationId("not_an_application_id");
103+
badRequest.setScope("scope");
104+
badRequest.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
105+
badRequest.setDigits(6);
106+
107+
ApiException messagingException = Assertions.assertThrows(ApiException.class,
108+
() -> api.generateMessagingCodeWithHttpInfo(BW_ACCOUNT_ID,
109+
badRequest));
110+
assertThat(messagingException.getCode(), is(400));
111+
112+
ApiException voiceException = Assertions.assertThrows(ApiException.class,
113+
() -> api.generateVoiceCodeWithHttpInfo(BW_ACCOUNT_ID,
114+
badRequest));
115+
assertThat(voiceException.getCode(), is(400));
65116
}
66117

67118
@Test
68-
public void unauthorizedRequest() {
69-
Basic.setUsername("bad_username");
70-
Basic.setPassword("bad_password");
119+
public void unauthorizedRequest() throws ApiException {
120+
CodeRequest request = new CodeRequest();
121+
request.setTo(USER_NUMBER);
122+
request.setFrom(BW_NUMBER);
123+
request.setApplicationId(BW_VOICE_APPLICATION_ID);
124+
request.setScope("scope");
125+
request.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
126+
request.setDigits(6);
127+
128+
ApiException exception = Assertions.assertThrows(ApiException.class,
129+
() -> api.generateMessagingCodeWithHttpInfo(BW_ACCOUNT_ID,
130+
request));
131+
assertThat(exception.getCode(), is(401));
71132
}
72133

73134
@Test
74135
public void forbiddenRequest() {
75136
Basic.setUsername(FORBIDDEN_USERNAME);
76-
Basic.setPassword(FORBIDDEN_PASSWORD);
137+
Basic.setPassword("bad_password");
138+
139+
CodeRequest request = new CodeRequest();
140+
request.setTo(USER_NUMBER);
141+
request.setFrom(BW_NUMBER);
142+
request.setApplicationId(BW_MESSAGING_APPLICATION_ID);
143+
request.setScope("scope");
144+
request.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
145+
request.setDigits(6);
146+
147+
ApiException exception = Assertions.assertThrows(ApiException.class,
148+
() -> api.generateMessagingCodeWithHttpInfo(BW_ACCOUNT_ID,
149+
request));
150+
assertThat(exception.getCode(), is(403));
77151
}
78152

79153
}

0 commit comments

Comments
 (0)