]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1010 added constraints to account, users and users_roles tables. added validat...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 17 Feb 2010 22:48:30 +0000 (22:48 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 17 Feb 2010 22:48:30 +0000 (22:48 +0000)
account,authn poms use consistent mysql jdbc driver version
test: account, security

M    services/authentication/jaxb/src/main/resources/authentication_identity_provider.xsd
M    services/authentication/pstore/src/main/resources/db/mysql/authentication.sql
M    services/authentication/pstore/pom.xml
M    services/account/jaxb/src/main/resources/accounts_common.xsd
M    services/account/pstore/src/main/resources/db/mysql/account.sql
M    services/account/pstore/pom.xml
M    services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java

services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java
services/account/jaxb/src/main/resources/accounts_common.xsd
services/account/pstore/pom.xml
services/account/pstore/src/main/resources/db/mysql/account.sql
services/authentication/jaxb/src/main/resources/authentication_identity_provider.xsd
services/authentication/pstore/pom.xml
services/authentication/pstore/src/main/resources/db/mysql/authentication.sql

index bdeba004dd8c1df68317aeb86ace1e760018b6e6..4d0f50a410f5b0a8ceaa414f3d790ebc5ba7c7f1 100644 (file)
@@ -83,7 +83,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
 
         // Submit the request to the service and store the response.
         AccountsCommon account =
-                createAccountInstance("barney", "hithere08", "barney@dinoland.com", true, true, true);
+                createAccountInstance("barney", "barney", "hithere08", "barney@dinoland.com",
+                true, true, true, true);
         ClientResponse<Response> res = client.create(account);
         int statusCode = res.getStatus();
 
@@ -108,6 +109,48 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
         }
     }
 
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
+    public void createForUniqueUser(String testName) throws Exception {
+
+        setupCreate(testName);
+
+        // Submit the request to the service and store the response.
+        AccountsCommon account =
+                createAccountInstance("barney1", "barney", "hithere08", "barney@dinoland.com",
+                true, true, true, true);
+        ClientResponse<Response> res = client.create(account);
+        int statusCode = res.getStatus();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+    }
+
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
+    public void createForUniqueScreenName(String testName) throws Exception {
+
+        setupCreate(testName);
+
+        // Submit the request to the service and store the response.
+        AccountsCommon account =
+                createAccountInstance("barney", "otherUser", "hithere08", "barney@dinoland.com",
+                true, true, true, true);
+        ClientResponse<Response> res = client.create(account);
+        int statusCode = res.getStatus();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+    }
+
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
     dependsOnMethods = {"create"})
     public void createWithoutTenant(String testName) throws Exception {
@@ -116,7 +159,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
 
         // Submit the request to the service and store the response.
         AccountsCommon account =
-                createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", false, true, true);
+                createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
+                true, false, true, true);
         ClientResponse<Response> res = client.create(account);
         int statusCode = res.getStatus();
         // Does it exactly match the expected status code?
@@ -137,7 +181,71 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
 
         // Submit the request to the service and store the response.
         AccountsCommon account =
-                createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", true, false, true);
+                createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
+                true, true, false, true);
+        ClientResponse<Response> res = client.create(account);
+        int statusCode = res.getStatus();
+        // Does it exactly match the expected status code?
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+    }
+
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
+    public void createWithInvalidEmail(String testName) throws Exception {
+
+        setupCreate(testName);
+
+        // Submit the request to the service and store the response.
+        AccountsCommon account =
+                createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
+                true, true, true, true);
+        ClientResponse<Response> res = client.create(account);
+        int statusCode = res.getStatus();
+        // Does it exactly match the expected status code?
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+    }
+
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
+    public void createWithoutScreenName(String testName) throws Exception {
+
+        setupCreate(testName);
+
+        // Submit the request to the service and store the response.
+        AccountsCommon account =
+                createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
+                false, true, true, true);
+        ClientResponse<Response> res = client.create(account);
+        int statusCode = res.getStatus();
+        // Does it exactly match the expected status code?
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+    }
+
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
+    public void createWithMostInvalid(String testName) throws Exception {
+
+        setupCreate(testName);
+
+        // Submit the request to the service and store the response.
+        AccountsCommon account =
+                createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
+                false, false, false, false);
         ClientResponse<Response> res = client.create(account);
         int statusCode = res.getStatus();
         // Does it exactly match the expected status code?
@@ -158,7 +266,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
         setupCreate(testName);
         // Submit the request to the service and store the response.
         AccountsCommon account1 =
-                createAccountInstance("curious", "hithere08", "curious@george.com", true, true, true);
+                createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
+                true, true, true, true);
         ClientResponse<Response> res = client.create(account1);
         int statusCode = res.getStatus();
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -167,7 +276,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
         resource1Id = extractId(res);
 
         AccountsCommon account2 =
-                createAccountInstance("tom", "hithere09", "tom@jerry.com", true, true, true);
+                createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
+                true, true, true, true);
         res = client.create(account2);
         statusCode = res.getStatus();
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -176,7 +286,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
         resource2Id = extractId(res);
 
         AccountsCommon account3 =
-                createAccountInstance("mj", "hithere10", "mj@dinoland.com", true, true, true);
+                createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
+                true, true, true, true);
         res = client.create(account3);
         statusCode = res.getStatus();
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -624,7 +735,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
         // Note: The ID used in this 'create' call may be arbitrary.
         // The only relevant ID may be the one used in updateAccount(), below.
         AccountsCommon account =
-                createAccountInstance("simba", "tiger", "simba@lionking.com", true, true, true);
+                createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
+                true, true, true, true);
         ClientResponse<AccountsCommon> res =
                 client.update(NON_EXISTENT_ID, account);
         int statusCode = res.getStatus();
@@ -788,26 +900,35 @@ public class AccountServiceTest extends AbstractServiceTestImpl {
     // ---------------------------------------------------------------
     // Utility methods used by tests above
     // ---------------------------------------------------------------
-    /*
-     * createAccountInstance
-     * @param tenant fillup tenant
-     * @param user to fill up user
-     * @param password to fill up password
+    /**
+     * create account instance
+     * @param screenName
+     * @param userName
+     * @param passwd
+     * @param email
+     * @param useScreenName
+     * @param useTenant
+     * @param useUser
+     * @param usePassword
+     * @return
      */
     private AccountsCommon createAccountInstance(String screenName,
-            String passwd, String email, boolean tenant, boolean user, boolean password) {
+            String userName, String passwd, String email,
+            boolean useScreenName, boolean useTenant, boolean useUser, boolean usePassword) {
 
         AccountsCommon account = new AccountsCommon();
-        account.setScreenName(screenName);
-        if (user) {
-            account.setUserId(screenName);
+        if (useScreenName) {
+            account.setScreenName(screenName);
+        }
+        if (useUser) {
+            account.setUserId(userName);
         }
-        if (password) {
+        if (usePassword) {
             account.setPassword(Base64.encodeBase64(passwd.getBytes()));
         }
         account.setEmail(email);
         account.setPhone("1234567890");
-        if (tenant) {
+        if (useTenant) {
             List<AccountsCommon.Tenant> atl = new ArrayList<AccountsCommon.Tenant>();
             AccountsCommon.Tenant at = new AccountsCommon.Tenant();
             at.setId(UUID.randomUUID().toString());
index efc5f0336a62933e2dcd0e962b7c3911621c162a..33d307939e706b24b792c4654afc0ed5a6c09c8a 100644 (file)
             <xs:annotation>
                 <xs:appinfo>
                     <hj:entity>
-                        <orm:table name="accounts_common"/>
+                        <orm:table name="accounts_common">
+                            <orm:unique-constraint>
+                                <orm:column-name>screen_name</orm:column-name>
+                            </orm:unique-constraint>
+                        </orm:table>
                     </hj:entity>
                 </xs:appinfo>
             </xs:annotation>
index 8dcd7084a9c43e5d4c04dee387ccb6fa1ad1f145..bf8f35f7f9bb077e1187eabf9126eeed11d154f2 100644 (file)
                             <dependency>\r
                                 <groupId>mysql</groupId>\r
                                 <artifactId>mysql-connector-java</artifactId>\r
-                                <version>5.0.5</version>\r
+                                <version>5.1.5</version>\r
                             </dependency>\r
                         </dependencies>\r
                     </plugin>\r
index 2f5c9a0b1a4ac053cfda2033f7fe340cd677b569..b7cebc854d9108de9f966fc18ab3d13c7dbbc15e 100644 (file)
@@ -1,6 +1,6 @@
 alter table tenants drop foreign key FKAAE82D09C4F08FD6;
 drop table if exists accounts_common;
 drop table if exists tenants;
-create table accounts_common (csid varchar(255) not null, email longtext not null, mobile varchar(255), phone varchar(255), screen_name varchar(128) not null, status varchar(15) not null, userid longtext not null, primary key (csid));
+create table accounts_common (csid varchar(255) not null, email longtext not null, mobile varchar(255), phone varchar(255), screen_name varchar(128) not null, status varchar(15) not null, userid longtext not null, primary key (csid), unique (screen_name));
 create table tenants (HJID bigint not null auto_increment, id varchar(255) not null, name varchar(255) not null, TENANT_ACCOUNTSCOMMON_CSID varchar(255), primary key (HJID));
 alter table tenants add index FKAAE82D09C4F08FD6 (TENANT_ACCOUNTSCOMMON_CSID), add constraint FKAAE82D09C4F08FD6 foreign key (TENANT_ACCOUNTSCOMMON_CSID) references accounts_common (csid);
index 76eca985bd1788b828a05b409ca35a9d2883c439..46e3266ba6f038ff5f90f539e1be8638ef3b0e2b 100644 (file)
@@ -2,31 +2,37 @@
 
 <!--
     CollectionSpace default (security) identity provider schema (XSD)
-    
+
     Entity(s)  : users, roles, users_roles
-    Used for: 
-    
+    Used for:
+
     $LastChangedRevision: 916 $
     $LastChangedDate: 2009-11-05 16:59:20 -0800 (Thu, 05 Nov 2009) $
 -->
 
 <xs:schema 
-  xmlns:xs="http://www.w3.org/2001/XMLSchema"
-  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
-  xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
-  xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
-  xmlns:ns="http://collectionspace.org/servics/authentication"
-  xmlns="http://collectionspace.org/services/authentication"
-  targetNamespace="http://collectionspace.org/services/authentication"
-  version="0.1"
-  jaxb:extensionBindingPrefixes="hj orm"
->
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+    xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
+    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
+    xmlns:ns="http://collectionspace.org/servics/authentication"
+    xmlns="http://collectionspace.org/services/authentication"
+    targetNamespace="http://collectionspace.org/services/authentication"
+    version="0.1"
+    jaxb:extensionBindingPrefixes="hj orm"
+    >
 
-<!--
+    <!--
     Avoid XmlRootElement nightmare:
     See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
 -->
-
+<!--
+    Notes for MySQL
+    MySQL puts key length limit of 1000 bytes
+    username - rolename constraint shoudl be within 1000 bytes
+    hbm2ddl makes column length >= 256 as long text, such as column cannot be used
+    in defining a key (pk, fk or constraint)
+-->
     <xs:element name="user">
         <xs:complexType>
             <xs:annotation>
@@ -41,7 +47,7 @@
                     <xs:annotation>
                         <xs:appinfo>
                             <hj:id>
-                                <orm:column name="username"  nullable="false"/>
+                                <orm:column name="username" length="128" nullable="false"/>
                             </hj:id>
                         </xs:appinfo>
                     </xs:annotation>
@@ -73,7 +79,7 @@
                     <xs:annotation>
                         <xs:appinfo>
                             <hj:id>
-                                <orm:column name="rolename" nullable="false"/>
+                                <orm:column name="rolename" length="200" nullable="false"/>
                             </hj:id>
                         </xs:appinfo>
                     </xs:annotation>
             <xs:annotation>
                 <xs:appinfo>
                     <hj:entity>
-                        <orm:table name="users_roles"/>
+                        <orm:table name="users_roles">
+                            <orm:unique-constraint>
+                                <!-- combined length should be < 1000 bytes -->
+                                <orm:column-name>username</orm:column-name>
+                                <orm:column-name>rolename</orm:column-name>
+                            </orm:unique-constraint>
+                        </orm:table>
                     </hj:entity>
                 </xs:appinfo>
             </xs:annotation>
                     <xs:annotation>
                         <xs:appinfo>
                             <hj:basic>
-                                <orm:column name="username" nullable="false"/>
+                                <orm:column name="username" length="128" nullable="false"/>
                             </hj:basic>
                         </xs:appinfo>
                     </xs:annotation>
                     <xs:annotation>
                         <xs:appinfo>
                             <hj:basic>
-                                <orm:column name="rolename" nullable="false"/>
+                                <orm:column name="rolename" length="200" nullable="false"/>
                             </hj:basic>
                         </xs:appinfo>
                     </xs:annotation>
index cb896ca76780f1fe2eb391a8b834a4112eec5086..1233816f6211e3f3d8adef0318050cb57339c09e 100644 (file)
                             <dependency>\r
                                 <groupId>mysql</groupId>\r
                                 <artifactId>mysql-connector-java</artifactId>\r
-                                <version>5.0.5</version>\r
+                                <version>5.1.5</version>\r
                             </dependency>\r
                         </dependencies>\r
                     </plugin>\r
index a985e957e635c801b1d97b48ed1c94f9379046bf..3827bd2c4d05ab77d2d28e77d9e806dde999279c 100644 (file)
@@ -1,6 +1,6 @@
 drop table if exists roles;
 drop table if exists users;
 drop table if exists users_roles;
-create table roles (rolename varchar(255) not null, rolegroup varchar(255) not null, primary key (rolename));
-create table users (username varchar(255) not null, passwd varchar(128) not null, primary key (username));
-create table users_roles (HJID bigint not null auto_increment, rolename varchar(255) not null, username varchar(255) not null, primary key (HJID));
+create table roles (rolename varchar(200) not null, rolegroup varchar(255) not null, primary key (rolename));
+create table users (username varchar(128) not null, passwd varchar(128) not null, primary key (username));
+create table users_roles (HJID bigint not null auto_increment, rolename varchar(200) not null, username varchar(128) not null, primary key (HJID), unique (username, rolename));