@Test
public void auth_createCollectionObject() {
- if(!isServerSecure()){
- return;
- }
String identifier = this.createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ if(!collectionObjectClient.isServerSecure()){
+ logger.warn("set -Dcspace.server.secure=true to run security tests");
+ return;
+ }
collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "test");
@Test(dependsOnMethods = {"auth_createCollectionObject"})
public void auth_createCollectionObjectWithoutUser() {
- if(!isServerSecure()){
- return;
- }
String identifier = this.createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ if(!collectionObjectClient.isServerSecure()){
+ logger.warn("set -Dcspace.server.secure=true to run security tests");
+ return;
+ }
collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
collectionObjectClient.removeProperty(CollectionSpaceClient.USER_PROPERTY);
collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "test");
@Test(dependsOnMethods = {"auth_createCollectionObjectWithoutUser"})
public void auth_createCollectionObjectWithoutPassword() {
- if(!isServerSecure()){
- logger.warn("set -Dcspace.server.secure=true to run security tests");
- return;
- }
String identifier = this.createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ if(!collectionObjectClient.isServerSecure()){
+ logger.warn("set -Dcspace.server.secure=true to run security tests");
+ return;
+ }
collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
collectionObjectClient.removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
@Test(dependsOnMethods = {"auth_createCollectionObjectWithoutPassword"})
public void auth_createCollectionObjectWithIncorrectPassword() {
- if(!isServerSecure()){
- logger.warn("set -Dcspace.server.secure=true to run security tests");
- return;
- }
String identifier = this.createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ if(!collectionObjectClient.isServerSecure()){
+ logger.warn("set -Dcspace.server.secure=true to run security tests");
+ return;
+ }
collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
@Test(dependsOnMethods = {"auth_createCollectionObjectWithoutPassword"})
public void auth_createCollectionObjectWithoutUserPassword() {
- if(!isServerSecure()){
- logger.warn("set -Dcspace.server.secure=true to run security tests");
- return;
- }
String identifier = this.createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ if(!collectionObjectClient.isServerSecure()){
+ logger.warn("set -Dcspace.server.secure=true to run security tests");
+ return;
+ }
collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
collectionObjectClient.removeProperty(CollectionSpaceClient.USER_PROPERTY);
collectionObjectClient.removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
@Test(dependsOnMethods = {"auth_createCollectionObjectWithoutPassword"})
public void auth_createCollectionObjectWithIncorrectUserPassword() {
- if(!isServerSecure()){
- logger.warn("set -Dcspace.server.secure=true to run security tests");
- return;
- }
String identifier = this.createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ if(!collectionObjectClient.isServerSecure()){
+ logger.warn("set -Dcspace.server.secure=true to run security tests");
+ return;
+ }
collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "foo");
collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
"expected " + Response.Status.UNAUTHORIZED.getStatusCode());
}
-
@Test(dependsOnMethods = {"auth_createCollectionObjectWithIncorrectUserPassword"})
public void auth_deleteCollectionObject() {
- if(!isServerSecure()){
+ CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient = new CollectionObjectClient();
+ if(!collectionObjectClient.isServerSecure()){
logger.warn("set -Dcspace.server.secure=true to run security tests");
return;
}
- CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
- collectionObjectClient = new CollectionObjectClient();
collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "test");
long identifier = System.currentTimeMillis();
return Long.toString(identifier);
}
-
- private boolean isServerSecure() {
- return Boolean.getBoolean("cspace.server.secure");
- }
}
<name>services.client</name>\r
\r
<dependencies>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-api</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-log4j12</artifactId>\r
+ </dependency>\r
<dependency>\r
<groupId>org.jboss.resteasy</groupId>\r
<artifactId>resteasy-jaxrs</artifactId>\r
<version>1.0.2.GA</version>\r
</dependency>\r
<dependency>\r
- <groupId>junit</groupId>\r
- <artifactId>junit</artifactId>\r
- <version>4.1</version>\r
- <scope>test</scope>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.slf4j</groupId>\r
- <artifactId>slf4j-api</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.slf4j</groupId>\r
- <artifactId>slf4j-log4j12</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.slf4j</groupId>\r
- <artifactId>slf4j-simple</artifactId>\r
+ <groupId>org.testng</groupId>\r
+ <artifactId>testng</artifactId>\r
+ <version>5.6</version>\r
<scope>test</scope>\r
- <version>1.5.2</version>\r
</dependency>\r
- <!-- javax -->\r
-\r
\r
+ <!-- javax -->\r
<dependency>\r
<groupId>javax.security</groupId>\r
<artifactId>jaas</artifactId>\r
<build>\r
<finalName>collectionspace-services-client</finalName>\r
<plugins>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-surefire-plugin</artifactId>\r
+ <configuration>\r
+ <systemProperties>\r
+ <property>\r
+ <name>log4j.configuration</name>\r
+ <value>file:target/test-classes/log4j.properties</value>\r
+ </property>\r
+ </systemProperties>\r
+ </configuration>\r
+ </plugin>\r
<plugin>\r
<groupId>org.apache.maven.plugins</groupId>\r
<artifactId>maven-compiler-plugin</artifactId>\r
}\r
}\r
}\r
+\r
+ @Override\r
+ public boolean isServerSecure() {\r
+ return Boolean.getBoolean("cspace.server.secure");\r
+ }\r
}\r
boolean useSSL();
+ /**
+ * checks System property cspace.server.secure
+ * @return
+ */
+ boolean isServerSecure();
+
}
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * 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.collectionspace.services.client;
+
+
+
+/**
+ * A CollectionObjectClient.
+
+ * @version $Revision:$
+ */
+public class TestServiceClient extends BaseServiceClient {
+
+
+ /**
+ *
+ * Default constructor for CollectionObjectClient class.
+ *
+ */
+ public TestServiceClient() {
+ }
+
+
+}
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * 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.collectionspace.services.client.test;
+
+import java.io.IOException;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.OptionsMethod;
+import org.apache.commons.httpclient.methods.TraceMethod;
+import org.collectionspace.services.client.TestServiceClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * A ServiceTest.
+
+ * @version $Revision:$
+ */
+public class ServiceTest {
+
+ final Logger logger = LoggerFactory.getLogger(ServiceTest.class);
+ private HttpClient httpClient = new HttpClient();
+ private TestServiceClient serviceClient = new TestServiceClient();
+
+ @Test
+ public void servicesExist() {
+ //use ID service that should always be present in a working service layer
+ String url = serviceClient.getBaseURL() + "ids";
+ OptionsMethod method = new OptionsMethod(url);
+ try{
+ int statusCode = httpClient.executeMethod(method);
+ if(logger.isDebugEnabled()){
+ logger.debug("servicesExist url=" + url + " status=" + statusCode);
+ }
+ Assert.assertEquals(statusCode, HttpStatus.SC_OK,
+ "expected " + HttpStatus.SC_OK);
+ }catch(HttpException e){
+ logger.error("Fatal protocol violation: ", e);
+ }catch(IOException e){
+ logger.error("Fatal transport error", e);
+ }catch(Exception e){
+ logger.error("unknown exception ", e);
+ }finally{
+ // Release the connection.
+ method.releaseConnection();
+ }
+ }
+
+ @Test
+ public void methodNotAllowed() {
+ //get is not allowed on id service
+ String url = serviceClient.getBaseURL() + "ids";
+ GetMethod method = new GetMethod(url);
+ try{
+ int statusCode = httpClient.executeMethod(method);
+ if(logger.isDebugEnabled()){
+ logger.debug(" methodNotAllowed url=" + url + " status=" + statusCode);
+ }
+ Assert.assertEquals(statusCode, HttpStatus.SC_METHOD_NOT_ALLOWED,
+ "expected " + HttpStatus.SC_METHOD_NOT_ALLOWED);
+ }catch(HttpException e){
+ logger.error("Fatal protocol violation: ", e);
+ }catch(IOException e){
+ logger.error("Fatal transport error", e);
+ }catch(Exception e){
+ logger.error("unknown exception ", e);
+ }finally{
+ // Release the connection.
+ method.releaseConnection();
+ }
+ }
+
+ @Test
+ public void noService() {
+
+ String url = serviceClient.getBaseURL() + "fake-service";
+ GetMethod method = new GetMethod(url);
+ try{
+ int statusCode = httpClient.executeMethod(method);
+ if(logger.isDebugEnabled()){
+ logger.debug("noService url=" + url + " status=" + statusCode);
+ }
+ Assert.assertEquals(statusCode, HttpStatus.SC_NOT_FOUND,
+ "expected " + HttpStatus.SC_NOT_FOUND);
+ }catch(HttpException e){
+ logger.error("Fatal protocol violation: ", e);
+ }catch(IOException e){
+ logger.error("Fatal transport error", e);
+ }catch(Exception e){
+ logger.error("unknown exception ", e);
+ }finally{
+ // Release the connection.
+ method.releaseConnection();
+ }
+ }
+
+ @Test
+ public void serviceSecure() {
+ if(!serviceClient.isServerSecure()){
+ logger.warn("set -Dcspace.server.secure=true to run security tests");
+ return;
+ }
+ String url = serviceClient.getBaseURL() + "collectionobjects";
+ GetMethod method = new GetMethod(url);
+ try{
+ int statusCode = httpClient.executeMethod(method);
+ if(logger.isDebugEnabled()){
+ logger.debug("serviceSecure url=" + url + " status=" + statusCode);
+ }
+ Assert.assertEquals(statusCode, HttpStatus.SC_UNAUTHORIZED,
+ "expected " + HttpStatus.SC_UNAUTHORIZED);
+ }catch(HttpException e){
+ logger.error("Fatal protocol violation: ", e);
+ }catch(IOException e){
+ logger.error("Fatal transport error", e);
+ }catch(Exception e){
+ logger.error("unknown exception ", e);
+ }finally{
+ // Release the connection.
+ method.releaseConnection();
+ }
+ }
+
+ @Test
+ public void traceSupported() {
+ String url = serviceClient.getBaseURL() + "collectionobjects";
+ TraceMethod method = new TraceMethod(url);
+ try{
+ int statusCode = httpClient.executeMethod(method);
+
+ if(logger.isDebugEnabled()){
+ logger.debug("traceSupported url=" + url + " status=" + statusCode);
+ logger.debug("traceSupported response=" + new String(method.getResponseBody()));
+ for(Header h : method.getResponseHeaders()){
+ logger.debug("traceSupported header name=" + h.getName() + " value=" + h.getValue());
+ }
+ }
+ Assert.assertEquals(statusCode, HttpStatus.SC_METHOD_NOT_ALLOWED,
+ "expected " + HttpStatus.SC_METHOD_NOT_ALLOWED);
+ }catch(HttpException e){
+ logger.error("Fatal protocol violation: ", e);
+ }catch(IOException e){
+ logger.error("Fatal transport error", e);
+ }catch(Exception e){
+ logger.error("unknown exception ", e);
+ }finally{
+ // Release the connection.
+ method.releaseConnection();
+ }
+ }
+
+ @Test
+ public void headSupported() {
+ String url = serviceClient.getBaseURL() + "intakes";
+ HeadMethod method = new HeadMethod(url);
+ try{
+ int statusCode = httpClient.executeMethod(method);
+ Assert.assertEquals(method.getResponseBody(), null, "expected null");
+ if(logger.isDebugEnabled()){
+ logger.debug("headSupported url=" + url + " status=" + statusCode);
+ for(Header h : method.getResponseHeaders()){
+ logger.debug("headSupported header name=" + h.getName() + " value=" + h.getValue());
+ }
+ }
+ Assert.assertEquals(statusCode, HttpStatus.SC_OK,
+ "expected " + HttpStatus.SC_OK);
+ }catch(HttpException e){
+ logger.error("Fatal protocol violation: ", e);
+ }catch(IOException e){
+ logger.error("Fatal transport error", e);
+ }catch(Exception e){
+ logger.error("unknown exception ", e);
+ }finally{
+ // Release the connection.
+ method.releaseConnection();
+ }
+ }
+}
--- /dev/null
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=target/test-client.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.apache=INFO\r
+log4j.logger.httpclient=INFO\r
+log4j.logger.org.jboss.resteasy=INFO\r