Skip to content

Commit be74cae

Browse files
committed
increase coverage
1 parent 8bef936 commit be74cae

3 files changed

Lines changed: 99 additions & 2 deletions

File tree

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public class AuthAPITest {
4141
private static final String DOMAIN = "domain.auth0.com";
4242
private static final String CLIENT_ID = "clientId";
4343
private static final String CLIENT_SECRET = "clientSecret";
44-
private static final String PASSWORD_STRENGTH_ERROR_RESPONSE = "src/test/resources/auth/password_strength_error.json";
44+
private static final String PASSWORD_STRENGTH_ERROR_RESPONSE_NONE = "src/test/resources/auth/password_strength_error_none.json";
45+
private static final String PASSWORD_STRENGTH_ERROR_RESPONSE_SOME = "src/test/resources/auth/password_strength_error_some.json";
4546

4647
private MockServer server;
4748
private AuthAPI api;
@@ -387,14 +388,25 @@ public void shouldThrowOnUsernameSignUpWithNullConnection() throws Exception {
387388
@Test
388389
public void shouldHaveNotStrongPasswordWithDetailedDescription() throws Exception {
389390
ObjectMapper mapper = new ObjectMapper();
390-
FileReader fr = new FileReader(PASSWORD_STRENGTH_ERROR_RESPONSE);
391+
FileReader fr = new FileReader(PASSWORD_STRENGTH_ERROR_RESPONSE_NONE);
391392
Map<String, Object> mapPayload = mapper.readValue(fr, new TypeReference<Map<String, Object>>() {});
392393
APIException ex = new APIException(mapPayload, 400);
393394
assertThat(ex.getError(), is("invalid_password"));
394395
String expectedDescription = "At least 10 characters in length; Contain at least 3 of the following 4 types of characters: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9), special characters (e.g. !@#$%^&*); Should contain: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9), special characters (e.g. !@#$%^&*); No more than 2 identical characters in a row (e.g., \"aaa\" not allowed)";
395396
assertThat(ex.getDescription(), is(expectedDescription));
396397
}
397398

399+
@Test
400+
public void shouldHaveNotStrongPasswordWithShortDetailedDescription() throws Exception {
401+
ObjectMapper mapper = new ObjectMapper();
402+
FileReader fr = new FileReader(PASSWORD_STRENGTH_ERROR_RESPONSE_SOME);
403+
Map<String, Object> mapPayload = mapper.readValue(fr, new TypeReference<Map<String, Object>>() {});
404+
APIException ex = new APIException(mapPayload, 400);
405+
assertThat(ex.getError(), is("invalid_password"));
406+
String expectedDescription = "Should contain: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9), special characters (e.g. !@#$%^&*)";
407+
assertThat(ex.getDescription(), is(expectedDescription));
408+
}
409+
398410
@Test
399411
public void shouldCreateSignUpRequestWithUsername() throws Exception {
400412
SignUpRequest request = api.signUp("me@auth0.com", "me", "p455w0rd", "db-connection");

src/test/resources/auth/password_strength_error.json renamed to src/test/resources/auth/password_strength_error_none.json

File renamed without changes.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"code": "invalid_password",
3+
"description": {
4+
"rules": [
5+
{
6+
"code": "lengthAtLeast",
7+
"format": [
8+
10
9+
],
10+
"message": "At least %d characters in length",
11+
"verified": true
12+
},
13+
{
14+
"code": "containsAtLeast",
15+
"format": [
16+
3,
17+
4
18+
],
19+
"items": [
20+
{
21+
"code": "lowerCase",
22+
"message": "lower case letters (a-z)",
23+
"verified": true
24+
},
25+
{
26+
"code": "upperCase",
27+
"message": "upper case letters (A-Z)",
28+
"verified": true
29+
},
30+
{
31+
"code": "numbers",
32+
"message": "numbers (i.e. 0-9)",
33+
"verified": true
34+
},
35+
{
36+
"code": "specialCharacters",
37+
"message": "special characters (e.g. !@#$%^&*)",
38+
"verified": false
39+
}
40+
],
41+
"message": "Contain at least %d of the following %d types of characters:",
42+
"verified": true
43+
},
44+
{
45+
"code": "shouldContain",
46+
"items": [
47+
{
48+
"code": "lowerCase",
49+
"message": "lower case letters (a-z)",
50+
"verified": false
51+
},
52+
{
53+
"code": "upperCase",
54+
"message": "upper case letters (A-Z)",
55+
"verified": false
56+
},
57+
{
58+
"code": "numbers",
59+
"message": "numbers (i.e. 0-9)",
60+
"verified": false
61+
},
62+
{
63+
"code": "specialCharacters",
64+
"message": "special characters (e.g. !@#$%^&*)",
65+
"verified": false
66+
}
67+
],
68+
"message": "Should contain:",
69+
"verified": false
70+
},
71+
{
72+
"code": "identicalChars",
73+
"format": [
74+
2,
75+
"aaa"
76+
],
77+
"message": "No more than %d identical characters in a row (e.g., \"%s\" not allowed)",
78+
"verified": true
79+
}
80+
],
81+
"verified": false
82+
},
83+
"name": "PasswordStrengthError",
84+
"statusCode": 400
85+
}

0 commit comments

Comments
 (0)