Skip to content

Commit fa2f44a

Browse files
committed
test(core): Add tests for invalid creds
1 parent 5a6761b commit fa2f44a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

core/src/test/java/com/ibm/watson/developer_cloud/util/CredentialUtilsTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.util.Hashtable;
2121

2222
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertFalse;
2324
import static org.junit.Assert.assertNull;
25+
import static org.junit.Assert.assertTrue;
2426

2527
/**
2628
* The Class CredentialUtilsTest.
@@ -73,4 +75,26 @@ public void testGetVcapValueWithoutPlan() {
7375
public void testGetVcapValueWithMultiplePlans() {
7476
assertEquals(NOT_A_FREE_USERNAME, CredentialUtils.getVcapValue(SERVICE_NAME, USERNAME));
7577
}
78+
79+
@Test
80+
public void testBadCredentialChar() {
81+
// valid
82+
assertFalse(CredentialUtils.hasBadStartOrEndChar("this_is_fine"));
83+
84+
// starting bracket
85+
assertTrue(CredentialUtils.hasBadStartOrEndChar("{bad_username"));
86+
assertTrue(CredentialUtils.hasBadStartOrEndChar("{{still_bad"));
87+
88+
// ending bracket
89+
assertTrue(CredentialUtils.hasBadStartOrEndChar("invalid}"));
90+
assertTrue(CredentialUtils.hasBadStartOrEndChar("also_invalid}}"));
91+
92+
// starting quote
93+
assertTrue(CredentialUtils.hasBadStartOrEndChar("\"not_allowed_either"));
94+
assertTrue(CredentialUtils.hasBadStartOrEndChar("\"\"still_not"));
95+
96+
// ending quote
97+
assertTrue(CredentialUtils.hasBadStartOrEndChar("nope\""));
98+
assertTrue(CredentialUtils.hasBadStartOrEndChar("sorry\"\""));
99+
}
76100
}

0 commit comments

Comments
 (0)