Add TC for platform upgrade script 52/86652/1
authorsangwan.kwon <sangwan.kwon@samsung.com>
Fri, 2 Sep 2016 07:03:43 +0000 (16:03 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Fri, 2 Sep 2016 07:14:54 +0000 (16:14 +0900)
* TC #1. disabled_certs table migration
* TC #2. enabled column on ssl table migration

Change-Id: I52cda7882849000b21f8b49a440c435e504f6788
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
etc/CMakeLists.txt
etc/cert-svc-db-upgrade.sh.in [deleted file]
etc/cert-svc-disabled-certs-upgrade.sh.in [deleted file]
etc/upgrade/CMakeLists.txt [new file with mode: 0644]
etc/upgrade/cert-svc-db-upgrade.sh.in [new file with mode: 0755]
etc/upgrade/cert-svc-disabled-certs-upgrade.sh.in [new file with mode: 0755]
packaging/cert-svc.spec
tests/CMakeLists.txt
tests/upgrade/CMakeLists.txt [new file with mode: 0644]
tests/upgrade/cert-svc-test-upgrade.sh.in [new file with mode: 0755]
tests/upgrade/certs-meta-old.db [new file with mode: 0644]

index 40dac002c99431b41837c967137858b74320327f..d5005d2e89d9b053a796c759f90888a17a622a1d 100644 (file)
@@ -36,14 +36,4 @@ INSTALL(FILES
     DESTINATION ${CERT_SVC_DB_PATH}
     )
 
-CONFIGURE_FILE(cert-svc-db-upgrade.sh.in cert-svc-db-upgrade.sh @ONLY)
-CONFIGURE_FILE(
-    cert-svc-disabled-certs-upgrade.sh.in
-    cert-svc-disabled-certs-upgrade.sh @ONLY
-    )
-
-INSTALL(FILES
-    ${ETC_DIR}/cert-svc-db-upgrade.sh
-    ${ETC_DIR}/cert-svc-disabled-certs-upgrade.sh
-    DESTINATION ${UPGRADE_SCRIPT_PATH}
-    )
+ADD_SUBDIRECTORY(upgrade)
diff --git a/etc/cert-svc-db-upgrade.sh.in b/etc/cert-svc-db-upgrade.sh.in
deleted file mode 100755 (executable)
index 395c42b..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-#
-#    Licensed 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.
-#
-# @file        cert-svc-db-upgrade.sh.in
-# @author      Sangwan Kwon (sangwan.kwon@samsung.com)
-# @brief       cert-svc db migration scripts for platform upgrade 2.4 -> 3.0
-#
-
-OLD_DB=@CERT_SVC_OLD_DB_PATH@/certs-meta-old.db
-NEW_DB=@CERT_SVC_DB_PATH@/certs-meta.db
-
-# backup old database
-mv @CERT_SVC_OLD_DB_PATH@/certs-meta.db $OLD_DB
-rm -rf @CERT_SVC_OLD_DB_PATH@/certs-meta.db-journal
-
-# install new database
-cp @UPGRADE_DATA_PATH@/certs-meta.db $NEW_DB
-
-# update disabled certs on db
-disabled_certs_cnt=`sqlite3 $OLD_DB "SELECT count(*) FROM disabled_certs;"`
-if [ "$disabled_certs_cnt" != "0" ]
-then
-       @UPGRADE_SCRIPT_PATH@/cert-svc-disabled-certs-upgrade.sh $OLD_DB $NEW_DB
-fi
-
-rm -rf $OLD_DB
-
-# generate blank journal file newly
-touch $NEW_DB-journal
-
-# change permission
-chsmack -a @SMACK_DOMAIN_NAME@ @CERT_SVC_DB_PATH@/*
-chown @USER_NAME@:@GROUP_NAME@ @CERT_SVC_DB_PATH@/*
-chmod 644 @CERT_SVC_DB_PATH@/*
diff --git a/etc/cert-svc-disabled-certs-upgrade.sh.in b/etc/cert-svc-disabled-certs-upgrade.sh.in
deleted file mode 100755 (executable)
index 91f0805..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/bash
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-#
-#    Licensed 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.
-#
-# @file        cert-svc-disabled-certs-upgrade.sh.in
-# @author      Sangwan Kwon (sangwan.kwon@samsung.com)
-# @brief       cert-svc disabled certs upgrade for platform upgrade 2.4 -> 3.0
-#
-
-# TODO(sangwan.kwon) Migration user certs(WIFI, VPN, EMAIL)
-
-# check this script invoked by cert-svc-db-upgrade
-if [ "$#" != "2" ]
-then
-       exit 0
-fi
-
-OLD_DB=$1
-NEW_DB=$2
-OLD_GNAME_LIST=@CERT_SVC_DB_PATH@/old-gname-list
-OLD_CERTS_DIR=@CERT_SVC_DB_PATH@/old-certs
-
-rm -rf $OLD_CERTS_DIR
-mkdir -p $OLD_CERTS_DIR
-
-# get disabled ceritificates list from old db
-sqlite3 $OLD_DB "SELECT gname FROM disabled_certs;" > $OLD_GNAME_LIST
-
-# since gname is different between Tizen 2.4 and 3.0, compare certicate
-index=1
-for gname in `cat $OLD_GNAME_LIST`
-do
-       sqlite3 $OLD_DB "SELECT certificate FROM disabled_certs
-                                        WHERE gname='$gname';" > $OLD_CERTS_DIR/$index
-       index=$(expr $index + 1)
-done
-
-# restore disabled certs to new db
-for fname in `find $OLD_CERTS_DIR/* | sort`
-do
-       certs=`cat $fname`
-       # check certificate's existence on new db
-       ret=`sqlite3 $NEW_DB "SELECT EXISTS (
-                                                               SELECT certificate
-                                                               FROM ssl
-                                                               WHERE certificate='$certs');"`
-
-       if [ "$ret" == "1" ]
-       then
-               # TODO(sangwan.kwon) Consider is_root_app column (it depends on master app)
-               # update ssl, disabled_certs table
-               gname=`sqlite3 $NEW_DB "SELECT gname FROM ssl WHERE certificate='$certs';"`
-               sqlite3 $NEW_DB "INSERT INTO disabled_certs VALUES ('$gname', '$certs');"
-               sqlite3 $NEW_DB "UPDATE ssl SET enabled=0 WHERE gname='$gname';"
-
-               # TODO(sangwan.kwon) unlink file between rw & ro area
-       fi
-done
-
-rm -rf $OLD_GNAME_LIST
-rm -rf $OLD_CERTS_DIR
diff --git a/etc/upgrade/CMakeLists.txt b/etc/upgrade/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7d5ad25
--- /dev/null
@@ -0,0 +1,30 @@
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed 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.
+#
+# @file        CMakeLists.txt
+# @author      Sangwan Kwon (sangwan.kwon@samsung.com)
+#
+
+CONFIGURE_FILE(
+       cert-svc-db-upgrade.sh.in
+       cert-svc-db-upgrade.sh @ONLY)
+CONFIGURE_FILE(
+       cert-svc-disabled-certs-upgrade.sh.in
+       cert-svc-disabled-certs-upgrade.sh @ONLY)
+
+INSTALL(FILES
+       cert-svc-db-upgrade.sh
+       cert-svc-disabled-certs-upgrade.sh
+       DESTINATION ${UPGRADE_SCRIPT_PATH}
+)
diff --git a/etc/upgrade/cert-svc-db-upgrade.sh.in b/etc/upgrade/cert-svc-db-upgrade.sh.in
new file mode 100755 (executable)
index 0000000..395c42b
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed 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.
+#
+# @file        cert-svc-db-upgrade.sh.in
+# @author      Sangwan Kwon (sangwan.kwon@samsung.com)
+# @brief       cert-svc db migration scripts for platform upgrade 2.4 -> 3.0
+#
+
+OLD_DB=@CERT_SVC_OLD_DB_PATH@/certs-meta-old.db
+NEW_DB=@CERT_SVC_DB_PATH@/certs-meta.db
+
+# backup old database
+mv @CERT_SVC_OLD_DB_PATH@/certs-meta.db $OLD_DB
+rm -rf @CERT_SVC_OLD_DB_PATH@/certs-meta.db-journal
+
+# install new database
+cp @UPGRADE_DATA_PATH@/certs-meta.db $NEW_DB
+
+# update disabled certs on db
+disabled_certs_cnt=`sqlite3 $OLD_DB "SELECT count(*) FROM disabled_certs;"`
+if [ "$disabled_certs_cnt" != "0" ]
+then
+       @UPGRADE_SCRIPT_PATH@/cert-svc-disabled-certs-upgrade.sh $OLD_DB $NEW_DB
+fi
+
+rm -rf $OLD_DB
+
+# generate blank journal file newly
+touch $NEW_DB-journal
+
+# change permission
+chsmack -a @SMACK_DOMAIN_NAME@ @CERT_SVC_DB_PATH@/*
+chown @USER_NAME@:@GROUP_NAME@ @CERT_SVC_DB_PATH@/*
+chmod 644 @CERT_SVC_DB_PATH@/*
diff --git a/etc/upgrade/cert-svc-disabled-certs-upgrade.sh.in b/etc/upgrade/cert-svc-disabled-certs-upgrade.sh.in
new file mode 100755 (executable)
index 0000000..91f0805
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/bash
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed 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.
+#
+# @file        cert-svc-disabled-certs-upgrade.sh.in
+# @author      Sangwan Kwon (sangwan.kwon@samsung.com)
+# @brief       cert-svc disabled certs upgrade for platform upgrade 2.4 -> 3.0
+#
+
+# TODO(sangwan.kwon) Migration user certs(WIFI, VPN, EMAIL)
+
+# check this script invoked by cert-svc-db-upgrade
+if [ "$#" != "2" ]
+then
+       exit 0
+fi
+
+OLD_DB=$1
+NEW_DB=$2
+OLD_GNAME_LIST=@CERT_SVC_DB_PATH@/old-gname-list
+OLD_CERTS_DIR=@CERT_SVC_DB_PATH@/old-certs
+
+rm -rf $OLD_CERTS_DIR
+mkdir -p $OLD_CERTS_DIR
+
+# get disabled ceritificates list from old db
+sqlite3 $OLD_DB "SELECT gname FROM disabled_certs;" > $OLD_GNAME_LIST
+
+# since gname is different between Tizen 2.4 and 3.0, compare certicate
+index=1
+for gname in `cat $OLD_GNAME_LIST`
+do
+       sqlite3 $OLD_DB "SELECT certificate FROM disabled_certs
+                                        WHERE gname='$gname';" > $OLD_CERTS_DIR/$index
+       index=$(expr $index + 1)
+done
+
+# restore disabled certs to new db
+for fname in `find $OLD_CERTS_DIR/* | sort`
+do
+       certs=`cat $fname`
+       # check certificate's existence on new db
+       ret=`sqlite3 $NEW_DB "SELECT EXISTS (
+                                                               SELECT certificate
+                                                               FROM ssl
+                                                               WHERE certificate='$certs');"`
+
+       if [ "$ret" == "1" ]
+       then
+               # TODO(sangwan.kwon) Consider is_root_app column (it depends on master app)
+               # update ssl, disabled_certs table
+               gname=`sqlite3 $NEW_DB "SELECT gname FROM ssl WHERE certificate='$certs';"`
+               sqlite3 $NEW_DB "INSERT INTO disabled_certs VALUES ('$gname', '$certs');"
+               sqlite3 $NEW_DB "UPDATE ssl SET enabled=0 WHERE gname='$gname';"
+
+               # TODO(sangwan.kwon) unlink file between rw & ro area
+       fi
+done
+
+rm -rf $OLD_GNAME_LIST
+rm -rf $OLD_CERTS_DIR
index a3d0d52ae938723b6d3ecaec341e160c8d1605f3..ee90b4f3d67e4d0981210a3e7c70895e0b26bcdf 100644 (file)
@@ -179,8 +179,8 @@ fi
 %attr(-, %{USER_NAME}, %{GROUP_NAME}) %CERT_SVC_DB_PATH/certs-meta.db-journal
 %attr(-, %{USER_NAME}, %{GROUP_NAME}) %CERT_SVC_RO_PATH
 
-%attr(755, root, root) %{UPGRADE_SCRIPT_PATH}/cert-svc-db-upgrade.sh
-%attr(755, root, root) %{UPGRADE_SCRIPT_PATH}/cert-svc-disabled-certs-upgrade.sh
+%attr(755, root, root) %UPGRADE_SCRIPT_PATH/cert-svc-db-upgrade.sh
+%attr(755, root, root) %UPGRADE_SCRIPT_PATH/cert-svc-disabled-certs-upgrade.sh
 %{UPGRADE_DATA_PATH}/certs-meta.db
 
 %files devel
@@ -193,4 +193,6 @@ fi
 %TZ_SYS_BIN/cert-svc-test*
 %CERT_SVC_TESTS
 %_libdir/libcert-svc-validator-plugin.so
+%attr(755, root, root) %UPGRADE_SCRIPT_PATH/cert-svc-test-upgrade.sh
+%{UPGRADE_DATA_PATH}/certs-meta-old.db
 %endif
index c0c4c307f42636a5b9a98c51a282915abdb3ec8c..58bfe1eac55607c6d9541f5ddb9cfbede4b648a7 100644 (file)
@@ -53,3 +53,4 @@ ADD_SUBDIRECTORY(capi)
 ADD_SUBDIRECTORY(pkcs12)
 ADD_SUBDIRECTORY(vcore)
 ADD_SUBDIRECTORY(plugin)
+ADD_SUBDIRECTORY(upgrade)
diff --git a/tests/upgrade/CMakeLists.txt b/tests/upgrade/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a8b22b0
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed 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.
+#
+# @file        CMakeLists.txt
+# @author      Sangwan Kwon (sangwan.kwon@samsung.com)
+#
+
+CONFIGURE_FILE(
+       cert-svc-test-upgrade.sh.in
+       cert-svc-test-upgrade.sh @ONLY)
+
+INSTALL(FILES
+       cert-svc-test-upgrade.sh
+       DESTINATION ${UPGRADE_SCRIPT_PATH}
+)
+
+INSTALL(FILES
+       certs-meta-old.db
+       DESTINATION ${UPGRADE_DATA_PATH}
+)
diff --git a/tests/upgrade/cert-svc-test-upgrade.sh.in b/tests/upgrade/cert-svc-test-upgrade.sh.in
new file mode 100755 (executable)
index 0000000..00b8de3
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed 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.
+#
+# @file        cert-svc-test-upgrade.sh.in
+# @author      Sangwan Kwon (sangwan.kwon@samsung.com)
+# @brief       test script for platform upgrade Tizen 2.4 -> 3.0
+#
+
+NEW_DB=@CERT_SVC_DB_PATH@/certs-meta.db
+
+# set test old database
+rm -rf @CERT_SVC_OLD_DB_PATH@/*
+cp @UPGRADE_DATA_PATH@/certs-meta-old.db @CERT_SVC_OLD_DB_PATH@/certs-meta.db
+
+# run db upgrade
+@UPGRADE_SCRIPT_PATH@/cert-svc-db-upgrade.sh
+
+# testcase 1. disabled_certs table should have 2 column
+disabled_certs_cnt=`sqlite3 $NEW_DB "SELECT count(*) FROM disabled_certs;"`
+if [ "$disabled_certs_cnt" != "2" ]
+then
+       echo "Failed to upgrade disabled_cers table."
+fi
+
+# testcase 2. below gname's enabled column should off
+enabled_column=`sqlite3 $NEW_DB "SELECT enabled from ssl WHERE gname='6410666e.0';"`
+if [ "$enabled_column" != "0" ]
+then
+       echo "Failed to upgrade ssl table."
+fi
diff --git a/tests/upgrade/certs-meta-old.db b/tests/upgrade/certs-meta-old.db
new file mode 100644 (file)
index 0000000..3d48d9f
Binary files /dev/null and b/tests/upgrade/certs-meta-old.db differ