diff options
author | Nathan Harold <nharold@google.com> | 2018-01-16 19:34:01 -0800 |
---|---|---|
committer | Nathan Harold <nharold@google.com> | 2018-01-16 19:38:10 -0800 |
commit | 5676f5fdae9a3aee8cf2cecef7502bfcc3bf49cb (patch) | |
tree | 3685cbc9202af8f2e38ec7ce209d5ea27e43c14f /tests/net/java/com/android/server/IpSecServiceTest.java | |
parent | a25233123b2d29fde83dd686f6313f0a232c5b2a (diff) |
Update IpSecService UnitTests
The IpSecService Unit tests relied on the
directionality of the IpSecConfig and previously
did not specify a source address. Unit tests
updated without functional change other than to
address these two requirements.
Bug: 71717213
Test: runtest frameworks-net
Change-Id: Iedbed735bc50fd4fdfe985f9e173956062a7b0d1
Diffstat (limited to 'tests/net/java/com/android/server/IpSecServiceTest.java')
-rw-r--r-- | tests/net/java/com/android/server/IpSecServiceTest.java | 121 |
1 files changed, 55 insertions, 66 deletions
diff --git a/tests/net/java/com/android/server/IpSecServiceTest.java b/tests/net/java/com/android/server/IpSecServiceTest.java index 49eec3f68cd8..b2a27e8c27b0 100644 --- a/tests/net/java/com/android/server/IpSecServiceTest.java +++ b/tests/net/java/com/android/server/IpSecServiceTest.java @@ -105,9 +105,6 @@ public class IpSecServiceTest { private static final IpSecAlgorithm AEAD_ALGO = new IpSecAlgorithm(IpSecAlgorithm.AUTH_CRYPT_AES_GCM, AEAD_KEY, 128); - private static final int[] DIRECTIONS = - new int[] {IpSecTransform.DIRECTION_IN, IpSecTransform.DIRECTION_OUT}; - static { try { INADDR_ANY = InetAddress.getByAddress(new byte[] {0, 0, 0, 0}); @@ -303,83 +300,75 @@ public class IpSecServiceTest { @Test public void testValidateAlgorithmsAuth() { - for (int direction : DIRECTIONS) { - // Validate that correct algorithm type succeeds - IpSecConfig config = new IpSecConfig(); - config.setAuthentication(direction, AUTH_ALGO); - mIpSecService.validateAlgorithms(config, direction); - - // Validate that incorrect algorithm types fails - for (IpSecAlgorithm algo : new IpSecAlgorithm[] {CRYPT_ALGO, AEAD_ALGO}) { - try { - config = new IpSecConfig(); - config.setAuthentication(direction, algo); - mIpSecService.validateAlgorithms(config, direction); - fail("Did not throw exception on invalid algorithm type"); - } catch (IllegalArgumentException expected) { - } + // Validate that correct algorithm type succeeds + IpSecConfig config = new IpSecConfig(); + config.setAuthentication(AUTH_ALGO); + mIpSecService.validateAlgorithms(config); + + // Validate that incorrect algorithm types fails + for (IpSecAlgorithm algo : new IpSecAlgorithm[] {CRYPT_ALGO, AEAD_ALGO}) { + try { + config = new IpSecConfig(); + config.setAuthentication(algo); + mIpSecService.validateAlgorithms(config); + fail("Did not throw exception on invalid algorithm type"); + } catch (IllegalArgumentException expected) { } } } @Test public void testValidateAlgorithmsCrypt() { - for (int direction : DIRECTIONS) { - // Validate that correct algorithm type succeeds - IpSecConfig config = new IpSecConfig(); - config.setEncryption(direction, CRYPT_ALGO); - mIpSecService.validateAlgorithms(config, direction); - - // Validate that incorrect algorithm types fails - for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, AEAD_ALGO}) { - try { - config = new IpSecConfig(); - config.setEncryption(direction, algo); - mIpSecService.validateAlgorithms(config, direction); - fail("Did not throw exception on invalid algorithm type"); - } catch (IllegalArgumentException expected) { - } + // Validate that correct algorithm type succeeds + IpSecConfig config = new IpSecConfig(); + config.setEncryption(CRYPT_ALGO); + mIpSecService.validateAlgorithms(config); + + // Validate that incorrect algorithm types fails + for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, AEAD_ALGO}) { + try { + config = new IpSecConfig(); + config.setEncryption(algo); + mIpSecService.validateAlgorithms(config); + fail("Did not throw exception on invalid algorithm type"); + } catch (IllegalArgumentException expected) { } } } @Test public void testValidateAlgorithmsAead() { - for (int direction : DIRECTIONS) { - // Validate that correct algorithm type succeeds - IpSecConfig config = new IpSecConfig(); - config.setAuthenticatedEncryption(direction, AEAD_ALGO); - mIpSecService.validateAlgorithms(config, direction); - - // Validate that incorrect algorithm types fails - for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, CRYPT_ALGO}) { - try { - config = new IpSecConfig(); - config.setAuthenticatedEncryption(direction, algo); - mIpSecService.validateAlgorithms(config, direction); - fail("Did not throw exception on invalid algorithm type"); - } catch (IllegalArgumentException expected) { - } + // Validate that correct algorithm type succeeds + IpSecConfig config = new IpSecConfig(); + config.setAuthenticatedEncryption(AEAD_ALGO); + mIpSecService.validateAlgorithms(config); + + // Validate that incorrect algorithm types fails + for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, CRYPT_ALGO}) { + try { + config = new IpSecConfig(); + config.setAuthenticatedEncryption(algo); + mIpSecService.validateAlgorithms(config); + fail("Did not throw exception on invalid algorithm type"); + } catch (IllegalArgumentException expected) { } } } @Test public void testValidateAlgorithmsAuthCrypt() { - for (int direction : DIRECTIONS) { - // Validate that correct algorithm type succeeds - IpSecConfig config = new IpSecConfig(); - config.setAuthentication(direction, AUTH_ALGO); - config.setEncryption(direction, CRYPT_ALGO); - mIpSecService.validateAlgorithms(config, direction); - } + // Validate that correct algorithm type succeeds + IpSecConfig config = new IpSecConfig(); + config.setAuthentication(AUTH_ALGO); + config.setEncryption(CRYPT_ALGO); + mIpSecService.validateAlgorithms(config); } @Test public void testValidateAlgorithmsNoAlgorithms() { IpSecConfig config = new IpSecConfig(); try { - mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); + mIpSecService.validateAlgorithms(config); fail("Expected exception; no algorithms specified"); } catch (IllegalArgumentException expected) { } @@ -388,10 +377,10 @@ public class IpSecServiceTest { @Test public void testValidateAlgorithmsAeadWithAuth() { IpSecConfig config = new IpSecConfig(); - config.setAuthenticatedEncryption(IpSecTransform.DIRECTION_IN, AEAD_ALGO); - config.setAuthentication(IpSecTransform.DIRECTION_IN, AUTH_ALGO); + config.setAuthenticatedEncryption(AEAD_ALGO); + config.setAuthentication(AUTH_ALGO); try { - mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); + mIpSecService.validateAlgorithms(config); fail("Expected exception; both AEAD and auth algorithm specified"); } catch (IllegalArgumentException expected) { } @@ -400,10 +389,10 @@ public class IpSecServiceTest { @Test public void testValidateAlgorithmsAeadWithCrypt() { IpSecConfig config = new IpSecConfig(); - config.setAuthenticatedEncryption(IpSecTransform.DIRECTION_IN, AEAD_ALGO); - config.setEncryption(IpSecTransform.DIRECTION_IN, CRYPT_ALGO); + config.setAuthenticatedEncryption(AEAD_ALGO); + config.setEncryption(CRYPT_ALGO); try { - mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); + mIpSecService.validateAlgorithms(config); fail("Expected exception; both AEAD and crypt algorithm specified"); } catch (IllegalArgumentException expected) { } @@ -412,11 +401,11 @@ public class IpSecServiceTest { @Test public void testValidateAlgorithmsAeadWithAuthAndCrypt() { IpSecConfig config = new IpSecConfig(); - config.setAuthenticatedEncryption(IpSecTransform.DIRECTION_IN, AEAD_ALGO); - config.setAuthentication(IpSecTransform.DIRECTION_IN, AUTH_ALGO); - config.setEncryption(IpSecTransform.DIRECTION_IN, CRYPT_ALGO); + config.setAuthenticatedEncryption(AEAD_ALGO); + config.setAuthentication(AUTH_ALGO); + config.setEncryption(CRYPT_ALGO); try { - mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); + mIpSecService.validateAlgorithms(config); fail("Expected exception; AEAD, auth and crypt algorithm specified"); } catch (IllegalArgumentException expected) { } |