Skip to content

Commit c5c5886

Browse files
committed
Rebase and complete test for twilio/sns and reset
1 parent fcb7089 commit c5c5886

6 files changed

Lines changed: 80 additions & 14 deletions

src/test/java/com/auth0/client/MockServer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ public class MockServer {
5353
public static final String MGMT_GUARDIAN_FACTOR = "src/test/resources/mgmt/guardian_factor.json";
5454
public static final String MGMT_GUARDIAN_FACTORS_LIST = "src/test/resources/mgmt/guardian_factors_list.json";
5555
public static final String MGMT_GUARDIAN_TEMPLATES = "src/test/resources/mgmt/guardian_templates.json";
56+
public static final String MGMT_GUARDIAN_SNS_FACTOR_PROVIDER_EMPTY = "src/test/resources/mgmt/guardian_sns_factor_provider_empty.json";
5657
public static final String MGMT_GUARDIAN_SNS_FACTOR_PROVIDER = "src/test/resources/mgmt/guardian_sns_factor_provider.json";
57-
public static final String MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER = "src/test/resources/mgmt/guardian_twilio_factor_provider.json";
58+
public static final String MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_EMPTY = "src/test/resources/mgmt/guardian_twilio_factor_provider_empty.json";
59+
public static final String MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_WITH_FROM = "src/test/resources/mgmt/guardian_twilio_factor_provider_with_from.json";
60+
public static final String MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_WITH_MSSID = "src/test/resources/mgmt/guardian_twilio_factor_provider_with_messaging_service_sid.json";
5861
public static final String MGMT_TENANT = "src/test/resources/mgmt/tenant.json";
5962
public static final String MGMT_ACTIVE_USERS_COUNT = "src/test/resources/mgmt/active_users_count.json";
6063
public static final String MGMT_DAILY_STATS_LIST = "src/test/resources/mgmt/daily_stats_list.json";

src/test/java/com/auth0/client/mgmt/GuardianEntityTest.java

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,27 @@ public void shouldUpdateGuardianFactor() throws Exception {
167167
}
168168

169169
@Test
170-
public void shouldGetGuardianTwilioFactorProvider() throws Exception {
170+
public void shouldGetGuardianTwilioFactorProviderWithMSSID() throws Exception {
171171
Request<TwilioFactorProvider> request = api.guardian().getTwilioFactorProvider();
172172
assertThat(request, is(notNullValue()));
173173

174-
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER, 200);
174+
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_WITH_MSSID, 200);
175+
TwilioFactorProvider response = request.execute();
176+
RecordedRequest recordedRequest = server.takeRequest();
177+
178+
assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/guardian/factors/sms/providers/twilio"));
179+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
180+
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
181+
182+
assertThat(response, is(notNullValue()));
183+
}
184+
185+
@Test
186+
public void shouldGetGuardianTwilioFactorProviderWithFrom() throws Exception {
187+
Request<TwilioFactorProvider> request = api.guardian().getTwilioFactorProvider();
188+
assertThat(request, is(notNullValue()));
189+
190+
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_WITH_FROM, 200);
175191
TwilioFactorProvider response = request.execute();
176192
RecordedRequest recordedRequest = server.takeRequest();
177193

@@ -190,12 +206,12 @@ public void shouldThrowOnUpdateGuardianTwilioFactorProviderWithNullData() throws
190206
}
191207

192208
@Test
193-
public void shouldUpdateGuardianTwilioFactorProvider() throws Exception {
194-
TwilioFactorProvider provider = new TwilioFactorProvider("from", "messagingServiceSID", "authToken", "sid");
209+
public void shouldUpdateGuardianTwilioFactorProviderWithFrom() throws Exception {
210+
TwilioFactorProvider provider = new TwilioFactorProvider("+156789", null, "aToKen", "3123");
195211
Request<TwilioFactorProvider> request = api.guardian().updateTwilioFactorProvider(provider);
196212
assertThat(request, is(notNullValue()));
197213

198-
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER, 200);
214+
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_WITH_FROM, 200);
199215
TwilioFactorProvider response = request.execute();
200216
RecordedRequest recordedRequest = server.takeRequest();
201217

@@ -204,21 +220,51 @@ public void shouldUpdateGuardianTwilioFactorProvider() throws Exception {
204220
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
205221

206222
Map<String, Object> body = bodyFromRequest(recordedRequest);
207-
assertThat(body.size(), is(4));
208-
assertThat(body, hasEntry("from", (Object) "from"));
209-
assertThat(body, hasEntry("messaging_service_sid", (Object) "messagingServiceSID"));
210-
assertThat(body, hasEntry("auth_token", (Object) "authToken"));
211-
assertThat(body, hasEntry("sid", (Object) "sid"));
223+
assertThat(body.size(), is(3));
224+
assertThat(body, hasEntry("from", (Object) "+156789"));
225+
assertThat(body, hasEntry("auth_token", (Object) "aToKen"));
226+
assertThat(body, hasEntry("sid", (Object) "3123"));
212227

213228
assertThat(response, is(notNullValue()));
229+
assertThat(response.getFrom(), is(equalTo("+156789")));
230+
assertThat(response.getMessagingServiceSID(), is(nullValue()));
231+
assertThat(response.getAuthToken(), is(equalTo("aToKen")));
232+
assertThat(response.getSID(), is(equalTo("3123")));
233+
}
234+
235+
@Test
236+
public void shouldUpdateGuardianTwilioFactorProviderWithMSSID() throws Exception {
237+
TwilioFactorProvider provider = new TwilioFactorProvider(null, "aac", "aToKen", "3123");
238+
Request<TwilioFactorProvider> request = api.guardian().updateTwilioFactorProvider(provider);
239+
assertThat(request, is(notNullValue()));
240+
241+
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_WITH_MSSID, 200);
242+
TwilioFactorProvider response = request.execute();
243+
RecordedRequest recordedRequest = server.takeRequest();
244+
245+
assertThat(recordedRequest, hasMethodAndPath("PUT", "/api/v2/guardian/factors/sms/providers/twilio"));
246+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
247+
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
248+
249+
Map<String, Object> body = bodyFromRequest(recordedRequest);
250+
assertThat(body.size(), is(3));
251+
assertThat(body, hasEntry("messaging_service_sid", (Object) "aac"));
252+
assertThat(body, hasEntry("auth_token", (Object) "aToKen"));
253+
assertThat(body, hasEntry("sid", (Object) "3123"));
254+
255+
assertThat(response, is(notNullValue()));
256+
assertThat(response.getFrom(), is(nullValue()));
257+
assertThat(response.getMessagingServiceSID(), is(equalTo("aac")));
258+
assertThat(response.getAuthToken(), is(equalTo("aToKen")));
259+
assertThat(response.getSID(), is(equalTo("3123")));
214260
}
215261

216262
@Test
217263
public void shouldResetGuardianTwilioFactorProvider() throws Exception {
218264
Request<TwilioFactorProvider> request = api.guardian().resetTwilioFactorProvider();
219265
assertThat(request, is(notNullValue()));
220266

221-
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER, 200);
267+
server.jsonResponse(MGMT_GUARDIAN_TWILIO_FACTOR_PROVIDER_EMPTY, 200);
222268
TwilioFactorProvider response = request.execute();
223269
RecordedRequest recordedRequest = server.takeRequest();
224270

@@ -230,6 +276,10 @@ public void shouldResetGuardianTwilioFactorProvider() throws Exception {
230276
assertThat(body.size(), is(0));
231277

232278
assertThat(response, is(notNullValue()));
279+
assertThat(response.getFrom(), is(nullValue()));
280+
assertThat(response.getMessagingServiceSID(), is(nullValue()));
281+
assertThat(response.getAuthToken(), is(nullValue()));
282+
assertThat(response.getSID(), is(nullValue()));
233283
}
234284

235285
@Test
@@ -285,7 +335,7 @@ public void shouldResetGuardianSnsFactorProvider() throws Exception {
285335
Request<SNSFactorProvider> request = api.guardian().resetSNSFactorProvider();
286336
assertThat(request, is(notNullValue()));
287337

288-
server.jsonResponse(MGMT_GUARDIAN_SNS_FACTOR_PROVIDER, 200);
338+
server.jsonResponse(MGMT_GUARDIAN_SNS_FACTOR_PROVIDER_EMPTY, 200);
289339
SNSFactorProvider response = request.execute();
290340
RecordedRequest recordedRequest = server.takeRequest();
291341

@@ -297,5 +347,10 @@ public void shouldResetGuardianSnsFactorProvider() throws Exception {
297347
assertThat(body.size(), is(0));
298348

299349
assertThat(response, is(notNullValue()));
350+
assertThat(response.getAWSAccessKeyId(), is(nullValue()));
351+
assertThat(response.getAWSRegion(), is(nullValue()));
352+
assertThat(response.getAWSSecretAccessKey(), is(nullValue()));
353+
assertThat(response.getSNSAPNSPlatformApplicationARN(), is(nullValue()));
354+
assertThat(response.getSNSGCMPlatformApplicationARN(), is(nullValue()));
300355
}
301356
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"from": "+156789",
3+
"messaging_service_sid": null,
4+
"auth_token": "aToKen",
5+
"sid": "3123"
6+
}

src/test/resources/mgmt/guardian_twilio_factor_provider.json renamed to src/test/resources/mgmt/guardian_twilio_factor_provider_with_messaging_service_sid.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"from": "+156789",
2+
"from": null,
33
"messaging_service_sid": "aac",
44
"auth_token": "aToKen",
55
"sid": "3123"

0 commit comments

Comments
 (0)