You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pl...@apache.org on 2015/07/30 08:24:45 UTC
[38/50] [abbrv] directory-kerby git commit: DIRKRB-384 Refactor
backend unit tests in order to share some codes for benchmark tests
DIRKRB-384 Refactor backend unit tests in order to share some codes for benchmark tests
Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/3f0a6b6c
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/3f0a6b6c
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/3f0a6b6c
Branch: refs/heads/pkinit-support
Commit: 3f0a6b6cbaa54b97b7e314ae6ae794b1f036f11d
Parents: 516cee1
Author: drankye <ka...@intel.com>
Authored: Wed Jul 22 06:01:26 2015 +0800
Committer: Drankye <dr...@gmail.com>
Committed: Wed Jul 22 06:01:26 2015 +0800
----------------------------------------------------------------------
kerby-backend/json-backend/pom.xml | 7 -
kerby-backend/ldap-backend/pom.xml | 7 -
kerby-backend/mavibot-backend/pom.xml | 1 -
.../org/apache/kerby/MavibotBackendTest.java | 3 +-
kerby-backend/zookeeper-backend/pom.xml | 1 -
kerby-kerb/kerb-identity-test/pom.xml | 28 ++-
.../kerb/identity/backend/BackendTest.java | 138 ++++++++++++++
.../kerb/identity/backend/BackendTestBase.java | 73 ++++++++
.../kerb/identity/backend/BackendTestUtil.java | 88 +++++++++
.../kerb/identity/backend/BackendTest.java | 183 -------------------
.../kerb/identity/backend/BackendTestBase.java | 73 --------
11 files changed, 313 insertions(+), 289 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/json-backend/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/json-backend/pom.xml b/kerby-backend/json-backend/pom.xml
index d0150e3..92512de 100644
--- a/kerby-backend/json-backend/pom.xml
+++ b/kerby-backend/json-backend/pom.xml
@@ -41,7 +41,6 @@
<groupId>org.apache.kerby</groupId>
<artifactId>kerb-identity-test</artifactId>
<version>${project.version}</version>
- <type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
@@ -49,11 +48,5 @@
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/ldap-backend/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/pom.xml b/kerby-backend/ldap-backend/pom.xml
index 7346471..b4cbf74 100644
--- a/kerby-backend/ldap-backend/pom.xml
+++ b/kerby-backend/ldap-backend/pom.xml
@@ -90,13 +90,6 @@
<groupId>org.apache.kerby</groupId>
<artifactId>kerb-identity-test</artifactId>
<version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/mavibot-backend/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/pom.xml b/kerby-backend/mavibot-backend/pom.xml
index cc5dfa8..c9a1841 100644
--- a/kerby-backend/mavibot-backend/pom.xml
+++ b/kerby-backend/mavibot-backend/pom.xml
@@ -39,7 +39,6 @@
<groupId>org.apache.kerby</groupId>
<artifactId>kerb-identity-test</artifactId>
<version>${project.version}</version>
- <type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java
index cd81cf9..6fa17dc 100644
--- a/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java
+++ b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java
@@ -23,6 +23,7 @@ package org.apache.kerby;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
import org.apache.kerby.kerberos.kerb.identity.backend.BackendTestBase;
+import org.apache.kerby.kerberos.kerb.identity.backend.BackendTestUtil;
import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -61,7 +62,7 @@ public class MavibotBackendTest extends BackendTestBase {
// overriding this cause MavibotBackend doesn't support range search
@Override
protected void testGetIdentities(IdentityBackend backend) throws KrbException {
- KrbIdentity[] identities = createManyIdentities();
+ KrbIdentity[] identities = BackendTestUtil.createManyIdentities();
for (KrbIdentity identity : identities) {
backend.addIdentity(identity);
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/zookeeper-backend/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/pom.xml b/kerby-backend/zookeeper-backend/pom.xml
index 3a0fb75..e3488b2 100644
--- a/kerby-backend/zookeeper-backend/pom.xml
+++ b/kerby-backend/zookeeper-backend/pom.xml
@@ -50,7 +50,6 @@
<groupId>org.apache.kerby</groupId>
<artifactId>kerb-identity-test</artifactId>
<version>${project.version}</version>
- <type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/pom.xml b/kerby-kerb/kerb-identity-test/pom.xml
index a86d027..8224b40 100644
--- a/kerby-kerb/kerb-identity-test/pom.xml
+++ b/kerby-kerb/kerb-identity-test/pom.xml
@@ -52,21 +52,17 @@
<artifactId>kerb-identity</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>${assertj.version}</version>
+ </dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
new file mode 100644
index 0000000..ccb738c
--- /dev/null
+++ b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.kerby.kerberos.kerb.identity.backend;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.apache.kerby.kerberos.kerb.identity.backend.BackendTestUtil.TEST_PRINCIPAL;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * A common backend test utility
+ */
+public abstract class BackendTest {
+
+ protected void testGet(IdentityBackend backend) throws KrbException {
+ KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL);
+ backend.addIdentity(kid);
+ // clear the identity cache.
+ backend.release();
+
+ KrbIdentity identity = backend.getIdentity(TEST_PRINCIPAL);
+ assertThat(identity).isNotNull();
+ assertThat(identity.getExpireTime()).isEqualTo(kid.getExpireTime());
+ assertThat(identity.isDisabled()).isEqualTo(kid.isDisabled());
+ assertThat(identity.getKeyVersion()).isEqualTo(kid.getKeyVersion());
+ for (EncryptionKey expectedKey : kid.getKeys().values()) {
+ EncryptionType actualType = EncryptionType.fromValue(expectedKey.getKeyType().getValue());
+ EncryptionKey actualKey = identity.getKey(actualType);
+ assertThat(actualKey.getKeyType().getValue()).isEqualTo(expectedKey.getKeyType().getValue());
+ assertThat(actualKey.getKeyData()).isEqualTo(expectedKey.getKeyData());
+ assertThat(actualKey.getKvno()).isEqualTo(expectedKey.getKvno());
+ }
+
+ //tearDown
+ backend.deleteIdentity(TEST_PRINCIPAL);
+ }
+
+ protected void testStore(IdentityBackend backend) throws KrbException {
+ KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL);
+ backend.addIdentity(kid);
+ // clear the identity cache.
+ backend.release();
+ KrbIdentity kid2 = backend.getIdentity(TEST_PRINCIPAL);
+
+ assertThat(kid).isEqualTo(kid2);
+
+ //tearDown
+ backend.deleteIdentity(TEST_PRINCIPAL);
+ }
+
+ protected void testUpdate(IdentityBackend backend) throws KrbException {
+ KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL);
+ backend.addIdentity(kid);
+
+ kid.setDisabled(true);
+ backend.updateIdentity(kid);
+
+ // clear the identity cache.
+ backend.release();
+ assertThat(backend.getIdentity(TEST_PRINCIPAL)).isEqualTo(kid);
+
+ //tearDown
+ backend.deleteIdentity(TEST_PRINCIPAL);
+ }
+
+ protected void testDelete(IdentityBackend backend) throws KrbException {
+ KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL);
+ backend.addIdentity(kid);
+ // clear the identity cache.
+ backend.release();
+
+ assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNotNull();
+
+ backend.deleteIdentity(TEST_PRINCIPAL);
+ assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNull();
+ }
+
+ protected void testGetIdentities(IdentityBackend backend) throws KrbException {
+ KrbIdentity[] identities = BackendTestUtil.createManyIdentities();
+
+ for (KrbIdentity identity : identities) {
+ backend.addIdentity(identity);
+ }
+
+ // clear the identity cache.
+ backend.release();
+
+ Iterable<String> principals = backend.getIdentities();
+ Iterator<String> iterator = principals.iterator();
+ List<String> principalList = new LinkedList<>();
+ while (iterator.hasNext()) {
+ principalList.add(iterator.next());
+ }
+ assertThat(principalList).hasSize(identities.length)
+ .contains(identities[0].getPrincipalName())
+ .contains(identities[1].getPrincipalName())
+ .contains(identities[2].getPrincipalName())
+ .contains(identities[3].getPrincipalName())
+ .contains(identities[4].getPrincipalName());
+
+ //tearDown
+ for (KrbIdentity identity : identities) {
+ backend.deleteIdentity(identity.getPrincipalName());
+ }
+ }
+
+ protected void cleanIdentities(IdentityBackend backend) throws KrbException {
+ Iterable<String> identities = backend.getIdentities();
+ Iterator<String> iterator = identities.iterator();
+ while (iterator.hasNext()) {
+ backend.deleteIdentity(iterator.next());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java
new file mode 100644
index 0000000..bb542a0
--- /dev/null
+++ b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.kerby.kerberos.kerb.identity.backend;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Json backend test
+ */
+public abstract class BackendTestBase extends BackendTest {
+ protected static IdentityBackend backend;
+
+ /**
+ * Create and prepare an identity backend for the tests. Must override.
+ */
+ @BeforeClass
+ public static void setup() throws Exception {
+ //backend = prepareBackend();
+ }
+
+ @Test
+ public void testGet() throws KrbException {
+ super.testGet(backend);
+ }
+
+ @Test
+ public void testStore() throws KrbException {
+ super.testStore(backend);
+ }
+
+ @Test
+ public void testUpdate() throws KrbException {
+ testUpdate(backend);
+ }
+
+ @Test
+ public void testDelete() throws KrbException {
+ testDelete(backend);
+ }
+
+ @Test
+ public void testGetIdentities() throws KrbException {
+ testGetIdentities(backend);
+ }
+
+ @AfterClass
+ public static void tearDown() throws KrbException {
+ if (backend != null) {
+ backend.stop();
+ backend.release();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java
new file mode 100644
index 0000000..843e3ee
--- /dev/null
+++ b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.kerby.kerberos.kerb.identity.backend;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.common.EncryptionUtil;
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A common backend test utility
+ */
+public final class BackendTestUtil {
+
+ static final String TEST_PRINCIPAL_PREFIX = "test";
+ static final String TEST_REALM = "EXAMPLE.COM";
+
+ public static final String TEST_PRINCIPAL = TEST_PRINCIPAL_PREFIX + "@" + TEST_REALM;
+
+ static final EncryptionType[] ENC_TYPES = new EncryptionType[]{
+ EncryptionType.AES128_CTS,
+ EncryptionType.DES3_CBC_SHA1_KD
+ };
+
+ public static KrbIdentity[] createManyIdentities() throws KrbException {
+ List<KrbIdentity> results = createManyIdentities(20);
+ return results.toArray(new KrbIdentity[results.size()]);
+ }
+
+ public static List<KrbIdentity> createManyIdentities(
+ int count) throws KrbException {
+ List<KrbIdentity> results = new ArrayList<>(count);
+
+ for (int i = 0; i < count; ++i) {
+ String tmp = TEST_PRINCIPAL_PREFIX + i + "@" + TEST_REALM;
+ results.add(createOneIdentity(tmp));
+ }
+
+ return results;
+ }
+
+ public static KrbIdentity createOneIdentity() throws KrbException {
+ return createOneIdentity(TEST_PRINCIPAL);
+ }
+
+ public static KrbIdentity createOneIdentity(String principal) throws KrbException {
+ KrbIdentity kid = new KrbIdentity(principal);
+ kid.setCreatedTime(KerberosTime.now());
+ kid.setExpireTime(KerberosTime.now());
+ kid.setDisabled(false);
+ kid.setKeyVersion(1);
+ kid.setLocked(false);
+ kid.addKeys(generateKeys());
+
+ return kid;
+ }
+
+ public static List<EncryptionKey> generateKeys() throws KrbException {
+ return EncryptionUtil.generateKeys(getEncryptionTypes());
+ }
+
+ public static List<EncryptionType> getEncryptionTypes() {
+ return Arrays.asList(ENC_TYPES);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java b/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
deleted file mode 100644
index dd3c2b6..0000000
--- a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.kerby.kerberos.kerb.identity.backend;
-
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.common.EncryptionUtil;
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.UUID;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * A common backend test utility
- */
-public abstract class BackendTest {
-
- static final String TEST_PRINCIPAL = "test@EXAMPLE.COM";
-
- static final EncryptionType[] ENC_TYPES = new EncryptionType[]{
- EncryptionType.AES128_CTS,
- EncryptionType.DES3_CBC_SHA1_KD
- };
-
- protected void testGet(IdentityBackend backend) throws KrbException {
- KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
- backend.addIdentity(kid);
- // clear the identity cache.
- backend.release();
-
- KrbIdentity identity = backend.getIdentity(TEST_PRINCIPAL);
- assertThat(identity).isNotNull();
- assertThat(identity.getExpireTime()).isEqualTo(kid.getExpireTime());
- assertThat(identity.isDisabled()).isEqualTo(kid.isDisabled());
- assertThat(identity.getKeyVersion()).isEqualTo(kid.getKeyVersion());
- for (EncryptionKey expectedKey : kid.getKeys().values()) {
- EncryptionType actualType = EncryptionType.fromValue(expectedKey.getKeyType().getValue());
- EncryptionKey actualKey = identity.getKey(actualType);
- assertThat(actualKey.getKeyType().getValue()).isEqualTo(expectedKey.getKeyType().getValue());
- assertThat(actualKey.getKeyData()).isEqualTo(expectedKey.getKeyData());
- assertThat(actualKey.getKvno()).isEqualTo(expectedKey.getKvno());
- }
-
- //tearDown
- backend.deleteIdentity(TEST_PRINCIPAL);
- }
-
- protected void testStore(IdentityBackend backend) throws KrbException {
- KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
- backend.addIdentity(kid);
- // clear the identity cache.
- backend.release();
- KrbIdentity kid2 = backend.getIdentity(TEST_PRINCIPAL);
-
- assertThat(kid).isEqualTo(kid2);
-
- //tearDown
- backend.deleteIdentity(TEST_PRINCIPAL);
- }
-
- protected void testUpdate(IdentityBackend backend) throws KrbException {
- KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
- backend.addIdentity(kid);
-
- kid.setDisabled(true);
- backend.updateIdentity(kid);
-
- // clear the identity cache.
- backend.release();
- assertThat(backend.getIdentity(TEST_PRINCIPAL)).isEqualTo(kid);
-
- //tearDown
- backend.deleteIdentity(TEST_PRINCIPAL);
- }
-
- protected void testDelete(IdentityBackend backend) throws KrbException {
- KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
- backend.addIdentity(kid);
- // clear the identity cache.
- backend.release();
-
- assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNotNull();
-
- backend.deleteIdentity(TEST_PRINCIPAL);
- assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNull();
- }
-
- protected void testGetIdentities(IdentityBackend backend) throws KrbException {
- KrbIdentity[] identities = createManyIdentities();
-
- for (KrbIdentity identity : identities) {
- backend.addIdentity(identity);
- }
-
- // clear the identity cache.
- backend.release();
-
- Iterable<String> principals = backend.getIdentities();
- Iterator<String> iterator = principals.iterator();
- List<String> principalList = new LinkedList<>();
- while (iterator.hasNext()) {
- principalList.add(iterator.next());
- }
- assertThat(principalList).hasSize(identities.length)
- .contains(identities[0].getPrincipalName())
- .contains(identities[1].getPrincipalName())
- .contains(identities[2].getPrincipalName())
- .contains(identities[3].getPrincipalName())
- .contains(identities[4].getPrincipalName());
-
- //tearDown
- for (KrbIdentity identity : identities) {
- backend.deleteIdentity(identity.getPrincipalName());
- }
- }
-
- protected KrbIdentity[] createManyIdentities() {
- return new KrbIdentity[] {
- createOneIdentity("test1@EXAMPLE.COM"),
- createOneIdentity("test2@EXAMPLE.COM"),
- createOneIdentity("test3@EXAMPLE.COM"),
- createOneIdentity("test4@EXAMPLE.COM"),
- createOneIdentity("test5@EXAMPLE.COM"),
- createOneIdentity("test6@EXAMPLE.COM"),
- };
- }
- protected KrbIdentity createOneIdentity(String principal) {
- KrbIdentity kid = new KrbIdentity(principal);
- kid.setCreatedTime(KerberosTime.now());
- kid.setExpireTime(new KerberosTime(253402300799900L));
- kid.setDisabled(false);
- kid.setKeyVersion(1);
- kid.setLocked(false);
- kid.addKeys(generateKeys(kid.getPrincipalName()));
-
- return kid;
- }
-
- protected List<EncryptionKey> generateKeys(String principal) {
- String passwd = UUID.randomUUID().toString();
- try {
- return EncryptionUtil.generateKeys(principal, passwd, getEncryptionTypes());
- } catch (KrbException e) {
- throw new RuntimeException("Failed to create keys", e);
- }
- }
-
- protected List<EncryptionType> getEncryptionTypes() {
- return Arrays.asList(ENC_TYPES);
- }
-
- protected void cleanIdentities(IdentityBackend backend) throws KrbException {
- Iterable<String> identities = backend.getIdentities();
- Iterator<String> iterator = identities.iterator();
- while (iterator.hasNext()) {
- backend.deleteIdentity(iterator.next());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java b/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java
deleted file mode 100644
index bb542a0..0000000
--- a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.kerby.kerberos.kerb.identity.backend;
-
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Json backend test
- */
-public abstract class BackendTestBase extends BackendTest {
- protected static IdentityBackend backend;
-
- /**
- * Create and prepare an identity backend for the tests. Must override.
- */
- @BeforeClass
- public static void setup() throws Exception {
- //backend = prepareBackend();
- }
-
- @Test
- public void testGet() throws KrbException {
- super.testGet(backend);
- }
-
- @Test
- public void testStore() throws KrbException {
- super.testStore(backend);
- }
-
- @Test
- public void testUpdate() throws KrbException {
- testUpdate(backend);
- }
-
- @Test
- public void testDelete() throws KrbException {
- testDelete(backend);
- }
-
- @Test
- public void testGetIdentities() throws KrbException {
- testGetIdentities(backend);
- }
-
- @AfterClass
- public static void tearDown() throws KrbException {
- if (backend != null) {
- backend.stop();
- backend.release();
- }
- }
-}