diff options
author | Jesse Wilson <jessewilson@google.com> | 2010-06-24 15:38:06 -0700 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2010-06-24 16:21:54 -0700 |
commit | f979bbd1277c77ca945ad981e7864fb4e9f6ae05 (patch) | |
tree | 57f3dcf28eb988e52a4e992e2642ee0737a7c157 /luni/src/test/java/tests/security/SecureRandomTest.java | |
parent | 561247df42b6d84bf0fae8412b7547ead01bf4f5 (diff) | |
download | libcore-f979bbd1277c77ca945ad981e7864fb4e9f6ae05.zip libcore-f979bbd1277c77ca945ad981e7864fb4e9f6ae05.tar.gz libcore-f979bbd1277c77ca945ad981e7864fb4e9f6ae05.tar.bz2 |
Scrubbing tests marked @BrokenTest.
This rearranges the security test support infrastructure. We no longer
rely on many top-level classes defined in CipherHelper.java to provide
test support. Instead these each have their own top level class in our
test support package: support/src/test/java/tests/security. Similarly
for abstract classes intended to be subclassed by cipher-specific
tests.
Other test methods that were duplicated in Harmony have been removed.
We need to pay closer attention to Harmony failures because they are
now our only source of coverage for some of these tests.
Change-Id: I1a1ca8a046bc9b6a33d5fa3f55fecc0d39f72c16
Diffstat (limited to 'luni/src/test/java/tests/security/SecureRandomTest.java')
-rw-r--r-- | luni/src/test/java/tests/security/SecureRandomTest.java | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/luni/src/test/java/tests/security/SecureRandomTest.java b/luni/src/test/java/tests/security/SecureRandomTest.java new file mode 100644 index 0000000..cf9c6dc --- /dev/null +++ b/luni/src/test/java/tests/security/SecureRandomTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Arrays; +import junit.framework.TestCase; +public abstract class SecureRandomTest extends TestCase { + + + private final String algorithmName; + + private int counter=0; + + protected SecureRandomTest(String name) { + this.algorithmName = name; + } + + protected void setUp() throws Exception { + super.setUp(); + } + + @TestTargets({ + @TestTargetNew( + level=TestLevel.ADDITIONAL, + method="getInstance", + args={String.class} + ), + @TestTargetNew( + level=TestLevel.ADDITIONAL, + method="setSeed", + args={long.class} + ), + @TestTargetNew( + level=TestLevel.ADDITIONAL, + method="nextBytes", + args={byte[].class} + ), + @TestTargetNew( + level=TestLevel.COMPLETE, + method="method", + args={} + ) + }) + public void testSecureRandom() { + SecureRandom secureRandom1 = null; + try { + secureRandom1 = SecureRandom.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + + SecureRandom secureRandom2 = null; + try { + secureRandom2 = SecureRandom.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + + byte[] testRandom1 = getRandomBytes(secureRandom1); + byte[] testRandom2 = getRandomBytes(secureRandom2); + + assertFalse(Arrays.equals(testRandom1, testRandom2)); + + + } + + private byte[] getRandomBytes(SecureRandom random) { + byte[] randomData = new byte[64]; + + random.setSeed(System.currentTimeMillis()+counter); + counter++; + + random.nextBytes(randomData); + + return randomData; + } +} |