|
6 | 6 | import org.openapitools.client.auth.HttpBasicAuth; |
7 | 7 | import org.openapitools.client.model.CodeRequest; |
8 | 8 | 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; |
9 | 12 | import org.openapitools.client.Configuration; |
10 | 13 | import org.junit.jupiter.api.Assertions; |
11 | 14 | import org.junit.jupiter.api.Test; |
12 | 15 |
|
| 16 | +import java.math.BigDecimal; |
13 | 17 | import java.net.URI; |
14 | 18 |
|
15 | 19 | import javax.security.auth.AuthPermission; |
@@ -47,33 +51,103 @@ public void successfulMfaGenerateMessagingCodeRequest() throws ApiException { |
47 | 51 | } |
48 | 52 |
|
49 | 53 | @Test |
50 | | - public void successfulMfaGenerateVoiceCodeRequest() { |
| 54 | + public void successfulMfaGenerateVoiceCodeRequest() throws ApiException { |
51 | 55 | Basic.setUsername(BW_USERNAME); |
52 | 56 | 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)); |
53 | 69 | } |
54 | 70 |
|
55 | 71 | @Test |
56 | | - public void successfulMfaVerifyCodeRequest() { |
| 72 | + public void successfulMfaVerifyCodeRequest() throws ApiException { |
57 | 73 | Basic.setUsername(BW_USERNAME); |
58 | 74 | 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)); |
59 | 92 | } |
60 | 93 |
|
61 | 94 | @Test |
62 | | - public void badRequest() { |
| 95 | + public void badRequest() throws ApiException { |
63 | 96 | Basic.setUsername(BW_USERNAME); |
64 | 97 | 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)); |
65 | 116 | } |
66 | 117 |
|
67 | 118 | @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)); |
71 | 132 | } |
72 | 133 |
|
73 | 134 | @Test |
74 | 135 | public void forbiddenRequest() { |
75 | 136 | 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)); |
77 | 151 | } |
78 | 152 |
|
79 | 153 | } |
0 commit comments