Skip to content

Commit e700d20

Browse files
committed
Reorganized one of the tests and added some new test cases.
1 parent 9fb1ff8 commit e700d20

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/test/java/org/owasp/esapi/crypto/CryptoTokenTest.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,34 +288,42 @@ public final void testSetAndGetAttribute() {
288288
// where attribute values contains each of the values that will
289289
// be quoted, namely: '\', '=', and ';'
290290
try {
291+
String[] attrValues = { "\\", ";", "=", "foo=", "bar\\=", "foobar=\"" };
291292
String complexValue = "kwwall;1291183520293;abc=x=yx;xyz=;efg=a;a;;bbb=quotes\\tuff";
292-
293-
ctok.setAttribute("..--__", ""); // Ugly, but legal attr name; empty is legal value.
294-
ctok.setAttribute("attr1", "\\");
295-
ctok.setAttribute("attr2", ";");
296-
ctok.setAttribute("attr3", "=");
293+
297294
ctok.setAttribute("complexAttr", complexValue);
295+
ctok.setAttribute("..--__", ""); // Ugly weird but legal attr name; empty is legal value.
296+
297+
for ( int i = 0; i < attrValues.length; i++ ) {
298+
String attrName = "attr" + i;
299+
String attrVal = attrValues[i];
300+
301+
ctok.setAttribute( attrName, attrVal );
302+
}
303+
298304
String tokenVal = ctok.getToken();
299305
assertNotNull("tokenVal should not be null", tokenVal);
300306

301307
CryptoToken ctok2 = new CryptoToken(tokenVal);
308+
302309
String weirdAttr = ctok2.getAttribute("..--__");
303310
assertTrue("Expecting empty string for value of weird attr, but got: " + weirdAttr,
304311
weirdAttr.equals(""));
305312

306-
String attr1 = ctok2.getAttribute("attr1");
307-
assertTrue("attr1 has unexpected value of " + attr1, attr1.equals("\\") );
308-
309-
String attr2 = ctok2.getAttribute("attr2");
310-
assertTrue("attr2 has unexpected value of " + attr2, attr2.equals(";") );
311-
312-
String attr3 = ctok2.getAttribute("attr3");
313-
assertTrue("attr3 has unexpected value of " + attr3, attr3.equals("=") );
314-
315313
String complexAttr = ctok2.getAttribute("complexAttr");
316314
assertNotNull(complexAttr);
317315
assertTrue("complexAttr has unexpected value of " + complexAttr, complexAttr.equals(complexValue) );
318316

317+
for ( int i = 0; i < attrValues.length; i++ ) {
318+
String attrName = "attr" + i;
319+
String attrVal = attrValues[i];
320+
String retrieved = ctok2.getAttribute( attrName );
321+
String assertMsg = "Exptected attribute '" + attrName + "' to have value of '" + attrVal + "', but had value of '" + retrieved;
322+
323+
assertTrue( assertMsg, attrVal.equals( attrVal ) );
324+
ctok.setAttribute( attrName, attrVal );
325+
}
326+
319327
} catch (ValidationException e) {
320328
fail("Caught unexpected ValidationException: " + e);
321329
} catch (Exception e) {

0 commit comments

Comments
 (0)