http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java index 884d4de..9ceb905 100755 --- a/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java @@ -18,26 +18,45 @@ package org.apache.atlas.web.resources; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.DefaultClientConfig; import org.apache.atlas.AtlasClient; +import org.apache.atlas.ParamChecker; import org.apache.atlas.typesystem.Referenceable; +import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.json.InstanceSerialization; import org.apache.atlas.typesystem.json.TypesSerialization; import org.apache.atlas.typesystem.persistence.Id; +import org.apache.atlas.typesystem.types.AttributeDefinition; import org.apache.atlas.typesystem.types.ClassType; +import org.apache.atlas.typesystem.types.DataTypes; +import org.apache.atlas.typesystem.types.EnumTypeDefinition; +import org.apache.atlas.typesystem.types.EnumValue; import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; +import org.apache.atlas.typesystem.types.IDataType; +import org.apache.atlas.typesystem.types.Multiplicity; +import org.apache.atlas.typesystem.types.StructTypeDefinition; +import org.apache.atlas.typesystem.types.TraitType; +import org.apache.atlas.typesystem.types.TypeUtils; +import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.web.util.Servlets; +import org.apache.commons.lang.RandomStringUtils; +import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.BeforeClass; import javax.ws.rs.HttpMethod; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; +import java.util.List; /** * Base class for integration tests. @@ -48,6 +67,7 @@ public abstract class BaseResourceIT { protected WebResource service; protected AtlasClient serviceClient; public static String baseUrl = "http://localhost:21000/"; + public static final Logger LOG = LoggerFactory.getLogger(BaseResourceIT.class); @BeforeClass public void setUp() throws Exception { @@ -89,11 +109,174 @@ public abstract class BaseResourceIT { String entityJSON = InstanceSerialization.toJson(referenceable, true); System.out.println("Submitting new entity= " + entityJSON); - JSONObject jsonObject = serviceClient.createEntity(entityJSON); - String guid = jsonObject.getString(AtlasClient.GUID); - System.out.println("created instance for type " + typeName + ", guid: " + guid); + JSONArray guids = serviceClient.createEntity(entityJSON); + System.out.println("created instance for type " + typeName + ", guid: " + guids); // return the reference to created instance with guid - return new Id(guid, 0, referenceable.getTypeName()); + return new Id(guids.getString(0), 0, referenceable.getTypeName()); + } + + protected static final String DATABASE_TYPE = "hive_db"; + protected static final String HIVE_TABLE_TYPE = "hive_table"; + protected static final String COLUMN_TYPE = "hive_column"; + protected static final String HIVE_PROCESS_TYPE = "hive_process"; + + protected void createTypeDefinitions() throws Exception { + HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil + .createClassTypeDef(DATABASE_TYPE, null, + TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), + TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE), + attrDef("locationUri", DataTypes.STRING_TYPE), + attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.INT_TYPE)); + + HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil + .createClassTypeDef(COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE), + attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE)); + + StructTypeDefinition structTypeDefinition = new StructTypeDefinition("serdeType", + new AttributeDefinition[]{TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), + TypesUtil.createRequiredAttrDef("serde", DataTypes.STRING_TYPE)}); + + EnumValue values[] = {new EnumValue("MANAGED", 1), new EnumValue("EXTERNAL", 2),}; + + EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", values); + + HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil + .createClassTypeDef(HIVE_TABLE_TYPE, ImmutableList.of("DataSet"), + attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE), + attrDef("lastAccessTime", DataTypes.DATE_TYPE), + attrDef("temporary", DataTypes.BOOLEAN_TYPE), + new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, true, null), + new AttributeDefinition("columns", DataTypes.arrayTypeName(COLUMN_TYPE), + Multiplicity.OPTIONAL, true, null), + new AttributeDefinition("tableType", "tableType", Multiplicity.OPTIONAL, false, null), + new AttributeDefinition("serde1", "serdeType", Multiplicity.OPTIONAL, false, null), + new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null)); + + HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil + .createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableList.of("Process"), + attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.INT_TYPE), + attrDef("endTime", DataTypes.LONG_TYPE), + attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), + attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), + attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), + attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED)); + + HierarchicalTypeDefinition<TraitType> classificationTrait = TypesUtil + .createTraitTypeDef("classification", ImmutableList.<String>of(), + TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); + HierarchicalTypeDefinition<TraitType> piiTrait = + TypesUtil.createTraitTypeDef("pii", ImmutableList.<String>of()); + HierarchicalTypeDefinition<TraitType> phiTrait = + TypesUtil.createTraitTypeDef("phi", ImmutableList.<String>of()); + HierarchicalTypeDefinition<TraitType> pciTrait = + TypesUtil.createTraitTypeDef("pci", ImmutableList.<String>of()); + HierarchicalTypeDefinition<TraitType> soxTrait = + TypesUtil.createTraitTypeDef("sox", ImmutableList.<String>of()); + HierarchicalTypeDefinition<TraitType> secTrait = + TypesUtil.createTraitTypeDef("sec", ImmutableList.<String>of()); + HierarchicalTypeDefinition<TraitType> financeTrait = + TypesUtil.createTraitTypeDef("finance", ImmutableList.<String>of()); + + HierarchicalTypeDefinition<TraitType> dimTraitDef = TypesUtil.createTraitTypeDef("Dimension", null); + + HierarchicalTypeDefinition<TraitType> factTraitDef = TypesUtil.createTraitTypeDef("Fact", null); + + HierarchicalTypeDefinition<TraitType> metricTraitDef = TypesUtil.createTraitTypeDef("Metric", null); + + HierarchicalTypeDefinition<TraitType> etlTraitDef = TypesUtil.createTraitTypeDef("ETL", null); + + TypesDef typesDef = TypeUtils.getTypesDef(ImmutableList.of(enumTypeDefinition), + ImmutableList.of(structTypeDefinition), + ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait, + dimTraitDef, factTraitDef, metricTraitDef, etlTraitDef), + ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)); + + createType(typesDef); + } + + AttributeDefinition attrDef(String name, IDataType dT) { + return attrDef(name, dT, Multiplicity.OPTIONAL, false, null); + } + + AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m) { + return attrDef(name, dT, m, false, null); + } + + AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m, boolean isComposite, + String reverseAttributeName) { + Preconditions.checkNotNull(name); + Preconditions.checkNotNull(dT); + return new AttributeDefinition(name, dT.getName(), m, isComposite, reverseAttributeName); + } + + protected String randomString() { + return RandomStringUtils.randomAlphanumeric(10); + } + + protected Referenceable createHiveTableInstance(String dbName, String tableName) throws Exception { + Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); + databaseInstance.set("name", dbName); + databaseInstance.set("description", "foo database"); + + Referenceable tableInstance = + new Referenceable(HIVE_TABLE_TYPE, "classification", "pii", "phi", "pci", "sox", "sec", "finance"); + tableInstance.set("name", tableName); + tableInstance.set("db", databaseInstance); + tableInstance.set("description", "bar table"); + tableInstance.set("lastAccessTime", "2014-07-11T08:00:00.000Z"); + tableInstance.set("type", "managed"); + tableInstance.set("level", 2); + tableInstance.set("tableType", 1); // enum + tableInstance.set("compressed", false); + + Struct traitInstance = (Struct) tableInstance.getTrait("classification"); + traitInstance.set("tag", "foundation_etl"); + + Struct serde1Instance = new Struct("serdeType"); + serde1Instance.set("name", "serde1"); + serde1Instance.set("serde", "serde1"); + tableInstance.set("serde1", serde1Instance); + + Struct serde2Instance = new Struct("serdeType"); + serde2Instance.set("name", "serde2"); + serde2Instance.set("serde", "serde2"); + tableInstance.set("serde2", serde2Instance); + + List<String> traits = tableInstance.getTraits(); + Assert.assertEquals(traits.size(), 7); + + return tableInstance; + } + + public interface Predicate { + + /** + * Perform a predicate evaluation. + * + * @return the boolean result of the evaluation. + * @throws Exception thrown if the predicate evaluation could not evaluate. + */ + boolean evaluate() throws Exception; + } + + /** + * Wait for a condition, expressed via a {@link Predicate} to become true. + * + * @param timeout maximum time in milliseconds to wait for the predicate to become true. + * @param predicate predicate waiting on. + */ + protected void waitFor(int timeout, Predicate predicate) throws Exception { + ParamChecker.notNull(predicate, "predicate"); + long mustEnd = System.currentTimeMillis() + timeout; + + boolean eval; + while (!(eval = predicate.evaluate()) && System.currentTimeMillis() < mustEnd) { + LOG.info("Waiting up to {} msec", mustEnd - System.currentTimeMillis()); + Thread.sleep(100); + } + if (!eval) { + throw new Exception("Waiting timed out after " + timeout + " msec"); + } } }
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java index e6a7325..43ad941 100755 --- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java @@ -32,13 +32,10 @@ import org.apache.atlas.typesystem.json.InstanceSerialization$; import org.apache.atlas.typesystem.json.TypesSerialization; import org.apache.atlas.typesystem.json.TypesSerialization$; import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.types.AttributeDefinition; import org.apache.atlas.typesystem.types.ClassType; import org.apache.atlas.typesystem.types.DataTypes; import org.apache.atlas.typesystem.types.EnumTypeDefinition; -import org.apache.atlas.typesystem.types.EnumValue; import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; -import org.apache.atlas.typesystem.types.Multiplicity; import org.apache.atlas.typesystem.types.StructTypeDefinition; import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TypeUtils; @@ -66,10 +63,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { private static final Logger LOG = LoggerFactory.getLogger(EntityJerseyResourceIT.class); - private static final String DATABASE_TYPE = "hive_database"; - private static final String DATABASE_NAME = "foo"; - private static final String TABLE_TYPE = "hive_table_type"; - private static final String TABLE_NAME = "bar"; + private final String DATABASE_NAME = "db" + randomString(); + private final String TABLE_NAME = "table" + randomString(); private static final String TRAITS = "traits"; private Referenceable tableInstance; @@ -80,12 +75,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT { public void setUp() throws Exception { super.setUp(); - createHiveTypes(); + createTypeDefinitions(); } @Test public void testSubmitEntity() throws Exception { - tableInstance = createHiveTableInstance(); + tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME); tableId = createInstance(tableInstance); final String guid = tableId._getId(); @@ -116,80 +111,25 @@ public class EntityJerseyResourceIT extends BaseResourceIT { } @Test - public void testUniqueAttribute() throws Exception { - //create type - String typeName = "type" + randomString(); - HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil - .createClassTypeDef(typeName, ImmutableList.<String>of(), - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); - TypesDef typesDef = TypeUtils - .getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), - ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), - ImmutableList.of(typeDefinition)); - createType(typesDef); - - //create entity - String name = "name" + randomString(); - Referenceable referenceable = new Referenceable(typeName); - referenceable.set("name", name); - createInstance(referenceable); - - //create entity with same name again - should fail - try { - createInstance(referenceable); - Assert.fail("Expected exception"); - } catch(Exception e) { - //expected exception - } - - //create another type with same attribute - should allow - typeName = "type" + randomString(); - typeDefinition = TypesUtil - .createClassTypeDef(typeName, ImmutableList.<String>of(), - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); - typesDef = TypeUtils - .getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), - ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), - ImmutableList.of(typeDefinition)); - createType(typesDef); + public void testGetEntityByAttribute() throws Exception { + Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); + String dbName = randomString(); + databaseInstance.set("name", dbName); + databaseInstance.set("description", "foo database"); + createInstance(databaseInstance); - referenceable = new Referenceable(typeName); - referenceable.set("name", name); - createInstance(referenceable); + //get entity by attribute + Referenceable referenceable = serviceClient.getEntity(DATABASE_TYPE, "name", dbName); + Assert.assertEquals(referenceable.getTypeName(), DATABASE_TYPE); + Assert.assertEquals(referenceable.get("name"), dbName); } @Test public void testSubmitEntityWithBadDateFormat() throws Exception { try { - Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); - databaseInstance.set("name", DATABASE_NAME); - databaseInstance.set("description", "foo database"); - - Referenceable tableInstance = - new Referenceable(TABLE_TYPE, "classification", "pii", "phi", "pci", "sox", "sec", "finance"); - tableInstance.set("name", TABLE_NAME); - tableInstance.set("description", "bar table"); - tableInstance.set("date", "2014-07-11"); - tableInstance.set("type", "managed"); - tableInstance.set("level", 2); - tableInstance.set("tableType", 1); // enum - tableInstance.set("database", databaseInstance); - tableInstance.set("compressed", false); - - Struct traitInstance = (Struct) tableInstance.getTrait("classification"); - traitInstance.set("tag", "foundation_etl"); - - Struct serde1Instance = new Struct("serdeType"); - serde1Instance.set("name", "serde1"); - serde1Instance.set("serde", "serde1"); - tableInstance.set("serde1", serde1Instance); - - Struct serde2Instance = new Struct("serdeType"); - serde2Instance.set("name", "serde2"); - serde2Instance.set("serde", "serde2"); - tableInstance.set("serde2", serde2Instance); - + Referenceable tableInstance = createHiveTableInstance("db" + randomString(), "table" + randomString()); + tableInstance.set("lastAccessTime", "2014-07-11"); tableId = createInstance(tableInstance); Assert.fail("Was expecting an exception here "); } catch (AtlasServiceException e) { @@ -216,13 +156,14 @@ public class EntityJerseyResourceIT extends BaseResourceIT { Assert.assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); //non-string property, update - clientResponse = addProperty(guid, "level", "4"); + String currentTime = String.valueOf(System.currentTimeMillis()); + clientResponse = addProperty(guid, "createTime", currentTime); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); entityRef = getEntityDefinition(getEntityDefinition(guid)); Assert.assertNotNull(entityRef); - tableInstance.set("level", 4); + tableInstance.set("createTime", currentTime); } @Test(dependsOnMethods = "testSubmitEntity", expectedExceptions = IllegalArgumentException.class) @@ -245,7 +186,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { public void testAddReferenceProperty() throws Exception { //Create new db instance Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); - databaseInstance.set("name", "newdb"); + databaseInstance.set("name", randomString()); databaseInstance.set("description", "new database"); Id dbInstance = createInstance(databaseInstance); @@ -253,7 +194,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { //Add reference property final String guid = tableId._getId(); - ClientResponse clientResponse = addProperty(guid, "database", dbId); + ClientResponse clientResponse = addProperty(guid, "db", dbId); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); } @@ -276,14 +217,14 @@ public class EntityJerseyResourceIT extends BaseResourceIT { } private ClientResponse addProperty(String guid, String property, String value) { - WebResource resource = service.path("api/atlas/entities").path(guid); + WebResource resource = service.path("api/atlas/entity").path(guid); return resource.queryParam("property", property).queryParam("value", value).accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.PUT, ClientResponse.class); } private ClientResponse getEntityDefinition(String guid) { - WebResource resource = service.path("api/atlas/entities").path(guid); + WebResource resource = service.path("api/atlas/entity").path(guid); return resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); } @@ -299,7 +240,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { @Test public void testGetInvalidEntityDefinition() throws Exception { - WebResource resource = service.path("api/atlas/entities").path("blah"); + WebResource resource = service.path("api/atlas/entity").path("blah"); ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); @@ -315,20 +256,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { @Test(dependsOnMethods = "testSubmitEntity") public void testGetEntityList() throws Exception { - ClientResponse clientResponse = - service.path("api/atlas/entities").queryParam("type", TABLE_TYPE).accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - - JSONObject response = new JSONObject(responseAsString); - Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); - - final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); - Assert.assertNotNull(list); - Assert.assertEquals(list.length(), 1); + List<String> entities = serviceClient.listEntities(HIVE_TABLE_TYPE); + Assert.assertNotNull(entities); + Assert.assertTrue(entities.contains(tableId._getId())); } @Test @@ -349,10 +279,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT { @Test public void testGetEntityListForNoInstances() throws Exception { - addNewType(); + String typeName = addNewType(); ClientResponse clientResponse = - service.path("api/atlas/entities").queryParam("type", "test").accept(Servlets.JSON_MEDIA_TYPE) + service.path("api/atlas/entities").queryParam("type", typeName).accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); @@ -366,21 +296,23 @@ public class EntityJerseyResourceIT extends BaseResourceIT { Assert.assertEquals(list.length(), 0); } - private void addNewType() throws Exception { + private String addNewType() throws Exception { + String typeName = "test" + randomString(); HierarchicalTypeDefinition<ClassType> testTypeDefinition = TypesUtil - .createClassTypeDef("test", ImmutableList.<String>of(), + .createClassTypeDef(typeName, ImmutableList.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE)); - String typesAsJSON = TypesSerialization.toJson(testTypeDefinition); + String typesAsJSON = TypesSerialization.toJson(testTypeDefinition, false); createType(typesAsJSON); + return typeName; } @Test(dependsOnMethods = "testSubmitEntity") public void testGetTraitNames() throws Exception { final String guid = tableId._getId(); ClientResponse clientResponse = - service.path("api/atlas/entities").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) + service.path("api/atlas/entity").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); @@ -410,7 +342,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { final String guid = tableId._getId(); ClientResponse clientResponse = - service.path("api/atlas/entities").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) + service.path("api/atlas/entity").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode()); @@ -433,7 +365,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { final String guid = tableId._getId(); ClientResponse clientResponse = - service.path("api/atlas/entities").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) + service.path("api/atlas/entity").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); @@ -456,7 +388,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { final String guid = tableId._getId(); ClientResponse clientResponse = - service.path("api/atlas/entities").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) + service.path("api/atlas/entity").path(guid).path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode()); @@ -497,7 +429,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); ClientResponse clientResponse = - service.path("api/atlas/entities").path("random").path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) + service.path("api/atlas/entity").path("random").path(TRAITS).accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); @@ -507,7 +439,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { public void testDeleteTrait() throws Exception { final String guid = tableId._getId(); - ClientResponse clientResponse = service.path("api/atlas/entities").path(guid).path(TRAITS).path(traitName) + ClientResponse clientResponse = service.path("api/atlas/entity").path(guid).path(TRAITS).path(traitName) .accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.DELETE, ClientResponse.class); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); @@ -525,7 +457,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { public void testDeleteTraitNonExistent() throws Exception { final String traitName = "blah_trait"; - ClientResponse clientResponse = service.path("api/atlas/entities").path("random").path(TRAITS).path(traitName) + ClientResponse clientResponse = service.path("api/atlas/entity").path("random").path(TRAITS).path(traitName) .accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.DELETE, ClientResponse.class); Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); @@ -544,10 +476,6 @@ public class EntityJerseyResourceIT extends BaseResourceIT { return RandomStringUtils.random(10); } - private String randomString() { - return RandomStringUtils.randomAlphanumeric(10); - } - @Test public void testUTF8() throws Exception { String classType = random(); @@ -572,90 +500,4 @@ public class EntityJerseyResourceIT extends BaseResourceIT { Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true); Assert.assertEquals(getReferenceable.get(attrName), attrValue); } - - private void createHiveTypes() throws Exception { - HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil - .createClassTypeDef(DATABASE_TYPE, ImmutableList.<String>of(), - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE)); - - StructTypeDefinition structTypeDefinition = new StructTypeDefinition("serdeType", - new AttributeDefinition[]{TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("serde", DataTypes.STRING_TYPE)}); - - EnumValue values[] = {new EnumValue("MANAGED", 1), new EnumValue("EXTERNAL", 2),}; - - EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", values); - - HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil - .createClassTypeDef(TABLE_TYPE, ImmutableList.<String>of(), - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), - TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("date", DataTypes.DATE_TYPE), - TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE), - new AttributeDefinition("tableType", "tableType", Multiplicity.REQUIRED, false, null), - new AttributeDefinition("serde1", "serdeType", Multiplicity.REQUIRED, false, null), - new AttributeDefinition("serde2", "serdeType", Multiplicity.REQUIRED, false, null), - new AttributeDefinition("database", DATABASE_TYPE, Multiplicity.REQUIRED, true, null), - new AttributeDefinition("compressed", DataTypes.BOOLEAN_TYPE.getName(), Multiplicity.OPTIONAL, - true, null)); - - HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil - .createTraitTypeDef("classification", ImmutableList.<String>of(), - TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); - HierarchicalTypeDefinition<TraitType> piiTrait = - TypesUtil.createTraitTypeDef("pii", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> phiTrait = - TypesUtil.createTraitTypeDef("phi", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> pciTrait = - TypesUtil.createTraitTypeDef("pci", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> soxTrait = - TypesUtil.createTraitTypeDef("sox", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> secTrait = - TypesUtil.createTraitTypeDef("sec", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> financeTrait = - TypesUtil.createTraitTypeDef("finance", ImmutableList.<String>of()); - - TypesDef typesDef = TypeUtils - .getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition), ImmutableList - .of(classificationTraitDefinition, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, - financeTrait), ImmutableList.of(databaseTypeDefinition, tableTypeDefinition)); - createType(typesDef); - } - - private Referenceable createHiveTableInstance() throws Exception { - Referenceable databaseInstance = new Referenceable(DATABASE_TYPE); - databaseInstance.set("name", DATABASE_NAME); - databaseInstance.set("description", "foo database"); - - Referenceable tableInstance = - new Referenceable(TABLE_TYPE, "classification", "pii", "phi", "pci", "sox", "sec", "finance"); - tableInstance.set("name", TABLE_NAME); - tableInstance.set("description", "bar table"); - tableInstance.set("date", "2014-07-11T08:00:00.000Z"); - tableInstance.set("type", "managed"); - tableInstance.set("level", 2); - tableInstance.set("tableType", 1); // enum - tableInstance.set("database", databaseInstance); - tableInstance.set("compressed", false); - - Struct traitInstance = (Struct) tableInstance.getTrait("classification"); - traitInstance.set("tag", "foundation_etl"); - - Struct serde1Instance = new Struct("serdeType"); - serde1Instance.set("name", "serde1"); - serde1Instance.set("serde", "serde1"); - tableInstance.set("serde1", serde1Instance); - - Struct serde2Instance = new Struct("serdeType"); - serde2Instance.set("name", "serde2"); - serde2Instance.set("serde", "serde2"); - tableInstance.set("serde2", serde2Instance); - - List<String> traits = tableInstance.getTraits(); - Assert.assertEquals(traits.size(), 7); - - return tableInstance; - } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/resources/HiveLineageJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/HiveLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/HiveLineageJerseyResourceIT.java index a884b5f..2df9095 100644 --- a/webapp/src/test/java/org/apache/atlas/web/resources/HiveLineageJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/HiveLineageJerseyResourceIT.java @@ -18,25 +18,12 @@ package org.apache.atlas.web.resources; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import org.apache.atlas.AtlasClient; import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.EnumTypeDefinition; -import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; -import org.apache.atlas.typesystem.types.IDataType; -import org.apache.atlas.typesystem.types.Multiplicity; -import org.apache.atlas.typesystem.types.StructTypeDefinition; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.TypeUtils; -import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.web.util.Servlets; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONObject; @@ -54,18 +41,20 @@ import java.util.List; public class HiveLineageJerseyResourceIT extends BaseResourceIT { private static final String BASE_URI = "api/atlas/lineage/hive/table/"; + private String salesFactTable; + private String salesMonthlyTable; @BeforeClass public void setUp() throws Exception { super.setUp(); - setUpTypes(); + createTypeDefinitions(); setupInstances(); } @Test public void testInputsGraph() throws Exception { - WebResource resource = service.path(BASE_URI).path("sales_fact_monthly_mv").path("inputs").path("graph"); + WebResource resource = service.path(BASE_URI).path(salesMonthlyTable).path("inputs").path("graph"); ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); @@ -93,7 +82,7 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT { @Test public void testOutputsGraph() throws Exception { - WebResource resource = service.path(BASE_URI).path("sales_fact").path("outputs").path("graph"); + WebResource resource = service.path(BASE_URI).path(salesFactTable).path("outputs").path("graph"); ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); @@ -121,7 +110,7 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT { @Test public void testSchema() throws Exception { - WebResource resource = service.path(BASE_URI).path("sales_fact").path("schema"); + WebResource resource = service.path(BASE_URI).path(salesFactTable).path("schema"); ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); @@ -167,105 +156,41 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT { Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); } - private void setUpTypes() throws Exception { - TypesDef typesDef = createTypeDefinitions(); - createType(typesDef); - } - - private static final String DATABASE_TYPE = "hive_db"; - private static final String HIVE_TABLE_TYPE = "hive_table"; - private static final String COLUMN_TYPE = "hive_column"; - private static final String HIVE_PROCESS_TYPE = "hive_process"; - - private TypesDef createTypeDefinitions() { - HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil - .createClassTypeDef(DATABASE_TYPE, null, attrDef("name", DataTypes.STRING_TYPE), - attrDef("description", DataTypes.STRING_TYPE), attrDef("locationUri", DataTypes.STRING_TYPE), - attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.INT_TYPE)); - - HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil - .createClassTypeDef(COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE), - attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE)); - - HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil - .createClassTypeDef(HIVE_TABLE_TYPE, ImmutableList.of("DataSet"), - attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.INT_TYPE), - attrDef("lastAccessTime", DataTypes.INT_TYPE), attrDef("tableType", DataTypes.STRING_TYPE), - attrDef("temporary", DataTypes.BOOLEAN_TYPE), - new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, false, null), - new AttributeDefinition("columns", DataTypes.arrayTypeName(COLUMN_TYPE), - Multiplicity.COLLECTION, true, null)); - - HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil - .createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableList.of("Process"), - attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.INT_TYPE), - attrDef("endTime", DataTypes.INT_TYPE), - attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), - attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), - attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), - attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED)); - - HierarchicalTypeDefinition<TraitType> dimTraitDef = TypesUtil.createTraitTypeDef("Dimension", null); - - HierarchicalTypeDefinition<TraitType> factTraitDef = TypesUtil.createTraitTypeDef("Fact", null); - - HierarchicalTypeDefinition<TraitType> metricTraitDef = TypesUtil.createTraitTypeDef("Metric", null); - - HierarchicalTypeDefinition<TraitType> etlTraitDef = TypesUtil.createTraitTypeDef("ETL", null); - - - HierarchicalTypeDefinition<TraitType> piiTraitDef = TypesUtil.createTraitTypeDef("PII", null); - - return TypeUtils.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), - ImmutableList.of(dimTraitDef, factTraitDef, metricTraitDef, etlTraitDef, piiTraitDef), - ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)); - } - - AttributeDefinition attrDef(String name, IDataType dT) { - return attrDef(name, dT, Multiplicity.OPTIONAL, false, null); - } - - AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m) { - return attrDef(name, dT, m, false, null); - } - - AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m, boolean isComposite, - String reverseAttributeName) { - Preconditions.checkNotNull(name); - Preconditions.checkNotNull(dT); - return new AttributeDefinition(name, dT.getName(), m, isComposite, reverseAttributeName); - } - private void setupInstances() throws Exception { - Id salesDB = database("Sales", "Sales Database", "John ETL", "hdfs://host:8000/apps/warehouse/sales"); + Id salesDB = database("Sales" + randomString(), "Sales Database", "John ETL", + "hdfs://host:8000/apps/warehouse/sales"); List<Referenceable> salesFactColumns = ImmutableList .of(column("time_id", "int", "time id"), column("product_id", "int", "product id"), - column("customer_id", "int", "customer id", "PII"), + column("customer_id", "int", "customer id", "pii"), column("sales", "double", "product id", "Metric")); - Id salesFact = table("sales_fact", "sales fact table", salesDB, "Joe", "Managed", salesFactColumns, "Fact"); + salesFactTable = "sales_fact" + randomString(); + Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns, "Fact"); List<Referenceable> timeDimColumns = ImmutableList .of(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"), column("weekDay", "int", "week Day")); Id timeDim = - table("time_dim", "time dimension table", salesDB, "John Doe", "External", timeDimColumns, "Dimension"); + table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL", + timeDimColumns, "Dimension"); Id reportingDB = - database("Reporting", "reporting database", "Jane BI", "hdfs://host:8000/apps/warehouse/reporting"); + database("Reporting" + randomString(), "reporting database", "Jane BI", + "hdfs://host:8000/apps/warehouse/reporting"); Id salesFactDaily = - table("sales_fact_daily_mv", "sales fact daily materialized view", reportingDB, "Joe BI", "Managed", - salesFactColumns, "Metric"); + table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB, + "Joe BI", "MANAGED", salesFactColumns, "Metric"); loadProcess("loadSalesDaily", "John ETL", ImmutableList.of(salesFact, timeDim), ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph", "ETL"); + salesMonthlyTable = "sales_fact_monthly_mv" + randomString(); Id salesFactMonthly = - table("sales_fact_monthly_mv", "sales fact monthly materialized view", reportingDB, "Jane BI", - "Managed", salesFactColumns, "Metric"); + table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI", + "MANAGED", salesFactColumns, "Metric"); loadProcess("loadSalesMonthly", "John ETL", ImmutableList.of(salesFactDaily), ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph", "ETL"); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java index 8664360..84036bd 100755 --- a/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java @@ -76,11 +76,9 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { Assert.assertEquals(response.getString("query"), dslQuery); Assert.assertEquals(response.getString("queryType"), "dsl"); - JSONObject results = response.getJSONObject(AtlasClient.RESULTS); + JSONArray results = response.getJSONArray(AtlasClient.RESULTS); Assert.assertNotNull(results); - - JSONArray rows = results.getJSONArray(AtlasClient.ROWS); - Assert.assertEquals(rows.length(), 1); + Assert.assertEquals(results.length(), 1); int numRows = response.getInt(AtlasClient.COUNT); Assert.assertEquals(numRows, 1); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java b/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java index 8af4a7e..b681fea 100644 --- a/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java @@ -113,6 +113,7 @@ public class BaseSecurityTest { protected PropertiesConfiguration getSSLConfiguration(String providerUrl) { String projectBaseDirectory = System.getProperty("projectBaseDir"); final PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.setProperty("atlas.services.enabled", false); configuration.setProperty(TLS_ENABLED, true); configuration.setProperty(TRUSTSTORE_FILE_KEY, projectBaseDirectory + "/webapp/target/atlas.keystore"); configuration.setProperty(KEYSTORE_FILE_KEY, projectBaseDirectory + "/webapp/target/atlas.keystore"); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosIT.java b/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosIT.java deleted file mode 100755 index 0b95b7a..0000000 --- a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosIT.java +++ /dev/null @@ -1,127 +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.atlas.web.security; - -import org.apache.atlas.AtlasClient; -import org.apache.atlas.AtlasException; -import org.apache.atlas.web.TestUtils; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.security.alias.JavaKeyStoreProvider; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.File; -import java.net.URL; -import java.nio.file.Files; - -import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED; - -/** - * Perform all the necessary setup steps for client and server comm over SSL/Kerberos, but then don't estalish a - * kerberos user for the invocation. Need a separate use case since the Jersey layer cached the URL connection handler, - * which indirectly caches the kerberos delegation token. - */ -public class NegativeSSLAndKerberosIT extends BaseSSLAndKerberosTest { - - private TestSecureEmbeddedServer secureEmbeddedServer; - private String originalConf; - private AtlasClient dgiClient; - - @BeforeClass - public void setUp() throws Exception { - jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); - providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); - - String persistDir = TestUtils.getTempDirectory(); - - setupKDCAndPrincipals(); - setupCredentials(); - - // client will actually only leverage subset of these properties - final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl); - configuration.setProperty("atlas.http.authentication.type", "kerberos"); - - TestUtils.writeConfiguration(configuration, persistDir + File.separator + "client.properties"); - - String confLocation = System.getProperty("atlas.conf"); - URL url; - if (confLocation == null) { - url = NegativeSSLAndKerberosIT.class.getResource("/application.properties"); - } else { - url = new File(confLocation, "application.properties").toURI().toURL(); - } - configuration.load(url); - - configuration.setProperty(TLS_ENABLED, true); - configuration.setProperty("atlas.http.authentication.enabled", "true"); - configuration.setProperty("atlas.http.authentication.kerberos.principal", "HTTP/localhost@" + kdc.getRealm()); - configuration.setProperty("atlas.http.authentication.kerberos.keytab", httpKeytabFile.getAbsolutePath()); - configuration.setProperty("atlas.http.authentication.kerberos.name.rules", - "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT"); - - TestUtils.writeConfiguration(configuration, persistDir + File.separator + "application.properties"); - - dgiClient = new AtlasClient(DGI_URL) { - @Override - protected PropertiesConfiguration getClientProperties() throws AtlasException { - return configuration; - } - }; - - // save original setting - originalConf = System.getProperty("atlas.conf"); - System.setProperty("atlas.conf", persistDir); - secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { - @Override - public PropertiesConfiguration getConfiguration() { - return configuration; - } - }; - secureEmbeddedServer.getServer().start(); - } - - @AfterClass - public void tearDown() throws Exception { - if (secureEmbeddedServer != null) { - secureEmbeddedServer.getServer().stop(); - } - - if (kdc != null) { - kdc.stop(); - } - - if (originalConf != null) { - System.setProperty("atlas.conf", originalConf); - } - } - - @Test - public void testUnsecuredClient() throws Exception { - try { - dgiClient.listTypes(); - Assert.fail("Should have failed with GSSException"); - } catch(Exception e) { - e.printStackTrace(); - Assert.assertTrue(e.getMessage().contains("Mechanism level: Failed to find any Kerberos tgt")); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java b/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java new file mode 100755 index 0000000..87d7cac --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java @@ -0,0 +1,127 @@ +/** + * 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.atlas.web.security; + +import org.apache.atlas.AtlasClient; +import org.apache.atlas.AtlasException; +import org.apache.atlas.web.TestUtils; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.security.alias.JavaKeyStoreProvider; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.File; +import java.net.URL; +import java.nio.file.Files; + +import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED; + +/** + * Perform all the necessary setup steps for client and server comm over SSL/Kerberos, but then don't estalish a + * kerberos user for the invocation. Need a separate use case since the Jersey layer cached the URL connection handler, + * which indirectly caches the kerberos delegation token. + */ +public class NegativeSSLAndKerberosTest extends BaseSSLAndKerberosTest { + + private TestSecureEmbeddedServer secureEmbeddedServer; + private String originalConf; + private AtlasClient dgiClient; + + @BeforeClass + public void setUp() throws Exception { + jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); + providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); + + String persistDir = TestUtils.getTempDirectory(); + + setupKDCAndPrincipals(); + setupCredentials(); + + // client will actually only leverage subset of these properties + final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl); + configuration.setProperty("atlas.http.authentication.type", "kerberos"); + + TestUtils.writeConfiguration(configuration, persistDir + File.separator + "client.properties"); + + String confLocation = System.getProperty("atlas.conf"); + URL url; + if (confLocation == null) { + url = NegativeSSLAndKerberosTest.class.getResource("/application.properties"); + } else { + url = new File(confLocation, "application.properties").toURI().toURL(); + } + configuration.load(url); + + configuration.setProperty(TLS_ENABLED, true); + configuration.setProperty("atlas.http.authentication.enabled", "true"); + configuration.setProperty("atlas.http.authentication.kerberos.principal", "HTTP/localhost@" + kdc.getRealm()); + configuration.setProperty("atlas.http.authentication.kerberos.keytab", httpKeytabFile.getAbsolutePath()); + configuration.setProperty("atlas.http.authentication.kerberos.name.rules", + "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT"); + + TestUtils.writeConfiguration(configuration, persistDir + File.separator + "application.properties"); + + dgiClient = new AtlasClient(DGI_URL) { + @Override + protected PropertiesConfiguration getClientProperties() throws AtlasException { + return configuration; + } + }; + + // save original setting + originalConf = System.getProperty("atlas.conf"); + System.setProperty("atlas.conf", persistDir); + secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { + @Override + public PropertiesConfiguration getConfiguration() { + return configuration; + } + }; + secureEmbeddedServer.getServer().start(); + } + + @AfterClass + public void tearDown() throws Exception { + if (secureEmbeddedServer != null) { + secureEmbeddedServer.getServer().stop(); + } + + if (kdc != null) { + kdc.stop(); + } + + if (originalConf != null) { + System.setProperty("atlas.conf", originalConf); + } + } + + @Test + public void testUnsecuredClient() throws Exception { + try { + dgiClient.listTypes(); + Assert.fail("Should have failed with GSSException"); + } catch(Exception e) { + e.printStackTrace(); + Assert.assertTrue(e.getMessage().contains("Mechanism level: Failed to find any Kerberos tgt")); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosIT.java b/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosIT.java deleted file mode 100755 index f00ac64..0000000 --- a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosIT.java +++ /dev/null @@ -1,163 +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.atlas.web.security; - -import org.apache.atlas.AtlasClient; -import org.apache.atlas.AtlasException; -import org.apache.atlas.web.TestUtils; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.security.UserGroupInformation; -import org.apache.hadoop.security.alias.JavaKeyStoreProvider; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import javax.security.auth.Subject; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.auth.login.LoginContext; -import javax.security.auth.login.LoginException; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.security.PrivilegedExceptionAction; - -import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED; - -public class SSLAndKerberosIT extends BaseSSLAndKerberosTest { - public static final String TEST_USER_JAAS_SECTION = "TestUser"; - public static final String TESTUSER = "testuser"; - public static final String TESTPASS = "testpass"; - - private static final String DGI_URL = "https://localhost:21443/"; - private AtlasClient dgiCLient; - private TestSecureEmbeddedServer secureEmbeddedServer; - private Subject subject; - private String originalConf; - - @BeforeClass - public void setUp() throws Exception { - jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); - providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); - - String persistDir = TestUtils.getTempDirectory(); - - setupKDCAndPrincipals(); - setupCredentials(); - - // client will actually only leverage subset of these properties - final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl); - configuration.setProperty("atlas.http.authentication.type", "kerberos"); - TestUtils.writeConfiguration(configuration, persistDir + File.separator + "client.properties"); - - String confLocation = System.getProperty("atlas.conf"); - URL url; - if (confLocation == null) { - url = SSLAndKerberosIT.class.getResource("/application.properties"); - } else { - url = new File(confLocation, "application.properties").toURI().toURL(); - } - configuration.load(url); - configuration.setProperty(TLS_ENABLED, true); - configuration.setProperty("atlas.http.authentication.enabled", "true"); - configuration.setProperty("atlas.http.authentication.kerberos.principal", "HTTP/localhost@" + kdc.getRealm()); - configuration.setProperty("atlas.http.authentication.kerberos.keytab", httpKeytabFile.getAbsolutePath()); - configuration.setProperty("atlas.http.authentication.kerberos.name.rules", - "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT"); - - TestUtils.writeConfiguration(configuration, persistDir + File.separator + "application.properties"); - - subject = loginTestUser(); - UserGroupInformation.loginUserFromSubject(subject); - UserGroupInformation proxyUser = UserGroupInformation.createProxyUser( - "testUser", - UserGroupInformation.getLoginUser()); - - dgiCLient = proxyUser.doAs(new PrivilegedExceptionAction<AtlasClient>() { - @Override - public AtlasClient run() throws Exception { - return new AtlasClient(DGI_URL) { - @Override - protected PropertiesConfiguration getClientProperties() throws AtlasException { - return configuration; - } - }; - } - }); - - // save original setting - originalConf = System.getProperty("atlas.conf"); - System.setProperty("atlas.conf", persistDir); - secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { - @Override - public PropertiesConfiguration getConfiguration() { - return configuration; - } - }; - secureEmbeddedServer.getServer().start(); - } - - @AfterClass - public void tearDown() throws Exception { - if (secureEmbeddedServer != null) { - secureEmbeddedServer.getServer().stop(); - } - - if (kdc != null) { - kdc.stop(); - } - - if (originalConf != null) { - System.setProperty("atlas.conf", originalConf); - } - } - - protected Subject loginTestUser() throws LoginException, IOException { - LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() { - - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { - for (int i = 0; i < callbacks.length; i++) { - if (callbacks[i] instanceof PasswordCallback) { - PasswordCallback passwordCallback = (PasswordCallback) callbacks[i]; - passwordCallback.setPassword(TESTPASS.toCharArray()); - } - if (callbacks[i] instanceof NameCallback) { - NameCallback nameCallback = (NameCallback) callbacks[i]; - nameCallback.setName(TESTUSER); - } - } - } - }); - // attempt authentication - lc.login(); - return lc.getSubject(); - } - - @Test - public void testService() throws Exception { - dgiCLient.listTypes(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java b/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java new file mode 100755 index 0000000..6e48239 --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java @@ -0,0 +1,163 @@ +/** + * 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.atlas.web.security; + +import org.apache.atlas.AtlasClient; +import org.apache.atlas.AtlasException; +import org.apache.atlas.web.TestUtils; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.security.alias.JavaKeyStoreProvider; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.security.PrivilegedExceptionAction; + +import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED; + +public class SSLAndKerberosTest extends BaseSSLAndKerberosTest { + public static final String TEST_USER_JAAS_SECTION = "TestUser"; + public static final String TESTUSER = "testuser"; + public static final String TESTPASS = "testpass"; + + private static final String DGI_URL = "https://localhost:21443/"; + private AtlasClient dgiCLient; + private TestSecureEmbeddedServer secureEmbeddedServer; + private Subject subject; + private String originalConf; + + @BeforeClass + public void setUp() throws Exception { + jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); + providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); + + String persistDir = TestUtils.getTempDirectory(); + + setupKDCAndPrincipals(); + setupCredentials(); + + // client will actually only leverage subset of these properties + final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl); + configuration.setProperty("atlas.http.authentication.type", "kerberos"); + TestUtils.writeConfiguration(configuration, persistDir + File.separator + "client.properties"); + + String confLocation = System.getProperty("atlas.conf"); + URL url; + if (confLocation == null) { + url = SSLAndKerberosTest.class.getResource("/application.properties"); + } else { + url = new File(confLocation, "application.properties").toURI().toURL(); + } + configuration.load(url); + configuration.setProperty(TLS_ENABLED, true); + configuration.setProperty("atlas.http.authentication.enabled", "true"); + configuration.setProperty("atlas.http.authentication.kerberos.principal", "HTTP/localhost@" + kdc.getRealm()); + configuration.setProperty("atlas.http.authentication.kerberos.keytab", httpKeytabFile.getAbsolutePath()); + configuration.setProperty("atlas.http.authentication.kerberos.name.rules", + "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT"); + + TestUtils.writeConfiguration(configuration, persistDir + File.separator + "application.properties"); + + subject = loginTestUser(); + UserGroupInformation.loginUserFromSubject(subject); + UserGroupInformation proxyUser = UserGroupInformation.createProxyUser( + "testUser", + UserGroupInformation.getLoginUser()); + + dgiCLient = proxyUser.doAs(new PrivilegedExceptionAction<AtlasClient>() { + @Override + public AtlasClient run() throws Exception { + return new AtlasClient(DGI_URL) { + @Override + protected PropertiesConfiguration getClientProperties() throws AtlasException { + return configuration; + } + }; + } + }); + + // save original setting + originalConf = System.getProperty("atlas.conf"); + System.setProperty("atlas.conf", persistDir); + secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { + @Override + public PropertiesConfiguration getConfiguration() { + return configuration; + } + }; + secureEmbeddedServer.getServer().start(); + } + + @AfterClass + public void tearDown() throws Exception { + if (secureEmbeddedServer != null) { + secureEmbeddedServer.getServer().stop(); + } + + if (kdc != null) { + kdc.stop(); + } + + if (originalConf != null) { + System.setProperty("atlas.conf", originalConf); + } + } + + protected Subject loginTestUser() throws LoginException, IOException { + LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() { + + @Override + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof PasswordCallback) { + PasswordCallback passwordCallback = (PasswordCallback) callbacks[i]; + passwordCallback.setPassword(TESTPASS.toCharArray()); + } + if (callbacks[i] instanceof NameCallback) { + NameCallback nameCallback = (NameCallback) callbacks[i]; + nameCallback.setName(TESTUSER); + } + } + } + }); + // attempt authentication + lc.login(); + return lc.getSubject(); + } + + @Test + public void testService() throws Exception { + dgiCLient.listTypes(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/security/SSLIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/SSLIT.java b/webapp/src/test/java/org/apache/atlas/web/security/SSLIT.java deleted file mode 100755 index 3e23185..0000000 --- a/webapp/src/test/java/org/apache/atlas/web/security/SSLIT.java +++ /dev/null @@ -1,137 +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.atlas.web.security; - -import org.apache.atlas.AtlasClient; -import org.apache.atlas.AtlasException; -import org.apache.atlas.web.TestUtils; -import org.apache.atlas.web.service.SecureEmbeddedServer; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.security.alias.CredentialProvider; -import org.apache.hadoop.security.alias.CredentialProviderFactory; -import org.apache.hadoop.security.alias.JavaKeyStoreProvider; -import org.eclipse.jetty.server.Server; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; - -import static org.apache.atlas.security.SecurityProperties.KEYSTORE_PASSWORD_KEY; -import static org.apache.atlas.security.SecurityProperties.SERVER_CERT_PASSWORD_KEY; -import static org.apache.atlas.security.SecurityProperties.TRUSTSTORE_PASSWORD_KEY; - -public class SSLIT extends BaseSSLAndKerberosTest { - private AtlasClient dgiCLient; - private Path jksPath; - private String providerUrl; - private TestSecureEmbeddedServer secureEmbeddedServer; - - class TestSecureEmbeddedServer extends SecureEmbeddedServer { - - public TestSecureEmbeddedServer(int port, String path) throws IOException { - super(port, path); - } - - public Server getServer() { - return server; - } - - @Override - public org.apache.commons.configuration.Configuration getConfiguration() { - return super.getConfiguration(); - } - } - - @BeforeClass - public void setUp() throws Exception { - jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); - providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); - - String persistDir = TestUtils.getTempDirectory(); - - setupCredentials(); - - final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl); - TestUtils.writeConfiguration(configuration, persistDir + File.separator + "client.properties"); - - dgiCLient = new AtlasClient(DGI_URL) { - @Override - protected PropertiesConfiguration getClientProperties() throws AtlasException { - return configuration; - } - }; - - secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { - @Override - public PropertiesConfiguration getConfiguration() { - return configuration; - } - }; - secureEmbeddedServer.getServer().start(); - } - - @AfterClass - public void tearDown() throws Exception { - if (secureEmbeddedServer != null) { - secureEmbeddedServer.getServer().stop(); - } - } - - protected void setupCredentials() throws Exception { - Configuration conf = new Configuration(false); - - File file = new File(jksPath.toUri().getPath()); - file.delete(); - conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); - - CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); - - // create new aliases - try { - - char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; - provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass); - - char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; - provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass); - - char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'}; - provider.createCredentialEntry("ssl.client.truststore.password", trustpass2); - - char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; - provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass); - - // write out so that it can be found in checks - provider.flush(); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testService() throws Exception { - dgiCLient.listTypes(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java b/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java new file mode 100755 index 0000000..e5e2d64 --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java @@ -0,0 +1,137 @@ +/** + * 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.atlas.web.security; + +import org.apache.atlas.AtlasClient; +import org.apache.atlas.AtlasException; +import org.apache.atlas.web.TestUtils; +import org.apache.atlas.web.service.SecureEmbeddedServer; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.security.alias.CredentialProvider; +import org.apache.hadoop.security.alias.CredentialProviderFactory; +import org.apache.hadoop.security.alias.JavaKeyStoreProvider; +import org.eclipse.jetty.server.Server; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +import static org.apache.atlas.security.SecurityProperties.KEYSTORE_PASSWORD_KEY; +import static org.apache.atlas.security.SecurityProperties.SERVER_CERT_PASSWORD_KEY; +import static org.apache.atlas.security.SecurityProperties.TRUSTSTORE_PASSWORD_KEY; + +public class SSLTest extends BaseSSLAndKerberosTest { + private AtlasClient dgiCLient; + private Path jksPath; + private String providerUrl; + private TestSecureEmbeddedServer secureEmbeddedServer; + + class TestSecureEmbeddedServer extends SecureEmbeddedServer { + + public TestSecureEmbeddedServer(int port, String path) throws IOException { + super(port, path); + } + + public Server getServer() { + return server; + } + + @Override + public org.apache.commons.configuration.Configuration getConfiguration() { + return super.getConfiguration(); + } + } + + @BeforeClass + public void setUp() throws Exception { + jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); + providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); + + String persistDir = TestUtils.getTempDirectory(); + + setupCredentials(); + + final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl); + TestUtils.writeConfiguration(configuration, persistDir + File.separator + "client.properties"); + + dgiCLient = new AtlasClient(DGI_URL) { + @Override + protected PropertiesConfiguration getClientProperties() throws AtlasException { + return configuration; + } + }; + + secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { + @Override + public PropertiesConfiguration getConfiguration() { + return configuration; + } + }; + secureEmbeddedServer.getServer().start(); + } + + @AfterClass + public void tearDown() throws Exception { + if (secureEmbeddedServer != null) { + secureEmbeddedServer.getServer().stop(); + } + } + + protected void setupCredentials() throws Exception { + Configuration conf = new Configuration(false); + + File file = new File(jksPath.toUri().getPath()); + file.delete(); + conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); + + CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); + + // create new aliases + try { + + char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; + provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass); + + char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; + provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass); + + char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'}; + provider.createCredentialEntry("ssl.client.truststore.password", trustpass2); + + char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; + provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass); + + // write out so that it can be found in checks + provider.flush(); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testService() throws Exception { + dgiCLient.listTypes(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1bfda02a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerIT.java b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerIT.java deleted file mode 100644 index e1f9b54..0000000 --- a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerIT.java +++ /dev/null @@ -1,63 +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.atlas.web.service; - -import org.apache.atlas.web.TestUtils; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.net.HttpURLConnection; -import java.net.URL; - -import static org.apache.atlas.security.SecurityProperties.CERT_STORES_CREDENTIAL_PROVIDER_PATH; - -public class SecureEmbeddedServerIT extends SecureEmbeddedServerITBase { - @Test - public void testServerConfiguredUsingCredentialProvider() throws Exception { - // setup the configuration - final PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); - // setup the credential provider - setupCredentials(); - - SecureEmbeddedServer secureEmbeddedServer = null; - try { - secureEmbeddedServer = new SecureEmbeddedServer(21443, TestUtils.getWarPath()) { - @Override - protected PropertiesConfiguration getConfiguration() { - return configuration; - } - }; - secureEmbeddedServer.server.start(); - - URL url = new URL("https://localhost:21443/"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - - // test to see whether server is up and root page can be served - Assert.assertEquals(connection.getResponseCode(), 200); - } catch(Throwable e) { - Assert.fail("War deploy failed", e); - } finally { - secureEmbeddedServer.server.stop(); - } - - } -}
