X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Ftest%2FJU_Base64.java;h=e819d574a7e48c0f86ca2a73fe014137d1b28bdd;hb=refs%2Fchanges%2F75%2F65275%2F1;hp=801259d4c11d2433caae96e79bf934bddddcc7e8;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Base64.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Base64.java index 801259d4..e819d574 100644 --- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Base64.java +++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Base64.java @@ -34,59 +34,59 @@ import org.onap.aaf.cadi.Symm; import org.onap.aaf.cadi.config.Config; public class JU_Base64 { - private static final String encoding = "Man is distinguished, not only by his reason, but by this singular " + - "passion from other animals, which is a lust of the mind, that by a " + - "perseverance of delight in the continued and indefatigable generation of " + - "knowledge, exceeds the short vehemence of any carnal pleasure."; + private static final String encoding = "Man is distinguished, not only by his reason, but by this singular " + + "passion from other animals, which is a lust of the mind, that by a " + + "perseverance of delight in the continued and indefatigable generation of " + + "knowledge, exceeds the short vehemence of any carnal pleasure."; - private static final String expected = - "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\n" + - "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\n" + - "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\n" + - "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\n" + - "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="; + private static final String expected = + "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\n" + + "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\n" + + "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\n" + + "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\n" + + "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="; - @Test - public void test() throws Exception { - // Test with different Padding - assertEncoded("leas", "bGVhcw=="); - assertEncoded("leasu", "bGVhc3U="); - assertEncoded("leasur", "bGVhc3Vy"); - assertEncoded("leasure", "bGVhc3VyZQ=="); - assertEncoded("leasure.", "bGVhc3VyZS4="); + @Test + public void test() throws Exception { + // Test with different Padding + assertEncoded("leas", "bGVhcw=="); + assertEncoded("leasu", "bGVhc3U="); + assertEncoded("leasur", "bGVhc3Vy"); + assertEncoded("leasure", "bGVhc3VyZQ=="); + assertEncoded("leasure.", "bGVhc3VyZS4="); - // Test with line ends - assertEncoded(encoding, expected); - } + // Test with line ends + assertEncoded(encoding, expected); + } - @Test - public void symmetric() throws IOException { - String symmetric = new String(Symm.keygen()); - Symm bsym = Symm.obtain(symmetric); - String result = bsym.encode(encoding); - assertThat(bsym.decode(result), is(encoding)); + @Test + public void symmetric() throws IOException { + String symmetric = new String(Symm.keygen()); + Symm bsym = Symm.obtain(symmetric); + String result = bsym.encode(encoding); + assertThat(bsym.decode(result), is(encoding)); - char[] manipulate = symmetric.toCharArray(); - int spot = new SecureRandom().nextInt(manipulate.length); - manipulate[spot]|=0xFF; - String newsymmetric = new String(manipulate); - assertThat(symmetric, is(not(newsymmetric))); - try { - bsym = Symm.obtain(newsymmetric); - result = bsym.decode(result); - assertThat(result, is(encoding)); - } catch (IOException e) { - // this is what we want to see if key wrong - } - } + char[] manipulate = symmetric.toCharArray(); + int spot = new SecureRandom().nextInt(manipulate.length); + manipulate[spot]|=0xFF; + String newsymmetric = new String(manipulate); + assertThat(symmetric, is(not(newsymmetric))); + try { + bsym = Symm.obtain(newsymmetric); + result = bsym.decode(result); + assertThat(result, is(encoding)); + } catch (IOException e) { + // this is what we want to see if key wrong + } + } - private void assertEncoded(String toEncode, String expected) throws IOException { - String result = Symm.base64.encode(toEncode); - assertThat(result, is(expected)); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - Symm.base64.decode(new ByteArrayInputStream(result.getBytes()), baos); - result = baos.toString(Config.UTF_8); - assertThat(result, is(toEncode)); - } + private void assertEncoded(String toEncode, String expected) throws IOException { + String result = Symm.base64.encode(toEncode); + assertThat(result, is(expected)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Symm.base64.decode(new ByteArrayInputStream(result.getBytes()), baos); + result = baos.toString(Config.UTF_8); + assertThat(result, is(toEncode)); + } }