From acd23e633178776b5d138dad920dbbf5d21d3e88 Mon Sep 17 00:00:00 2001 From: Elv1zz Date: Thu, 6 Jul 2023 22:27:29 +0200 Subject: [PATCH] Added unit test for AKMAlias.matches Added an unit test for the `AKMAlias.matches` method before refactoring it. Signed-off-by: Elv1zz --- .../network/AdvancedX509KeyManagerTests.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt diff --git a/library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt b/library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt new file mode 100644 index 0000000000..56150c2401 --- /dev/null +++ b/library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt @@ -0,0 +1,44 @@ +package com.owncloud.android.lib.common.network + +import com.owncloud.android.lib.common.network.AdvancedX509KeyManager.AKMAlias +import org.junit.Assert +import org.junit.Test + +class AdvancedX509KeyManagerTests { + + @Test + fun testAKMAlias_matches() { + val akmAlias1 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname", 123) + val akmAlias2 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname", 123) + + Assert.assertTrue(akmAlias1.matches(akmAlias1)) + Assert.assertTrue(akmAlias1.matches(akmAlias2)) + + val akmAlias3 = AKMAlias(AKMAlias.Type.KEYSTORE, "alias", "hostname", 123) + Assert.assertFalse(akmAlias1.matches(akmAlias3)) + + val akmAlias4 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias1", "hostname", 123) + Assert.assertFalse(akmAlias1.matches(akmAlias4)) + + val akmAlias5 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname1", 123) + Assert.assertFalse(akmAlias1.matches(akmAlias5)) + + val akmAlias6 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname", 1234) + Assert.assertFalse(akmAlias1.matches(akmAlias6)) + + // parameters being null are considered "do-not-care" + val akmAlias7 = AKMAlias(null, "alias", "hostname", 123) + Assert.assertTrue(akmAlias1.matches(akmAlias7)) + + val akmAlias8 = AKMAlias(AKMAlias.Type.KEYCHAIN, null, "hostname", 123) + Assert.assertTrue(akmAlias1.matches(akmAlias8)) + + val akmAlias9 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", null, 123) + Assert.assertTrue(akmAlias1.matches(akmAlias9)) + + val akmAlias10 = AKMAlias(null, null, null, 123) + Assert.assertTrue(akmAlias1.matches(akmAlias10)) + + } + +} \ No newline at end of file