Fix upgrade script number
[platform/core/security/cert-svc.git] / tests / upgrade / cert-svc-test-upgrade.sh.in
1 #!/bin/bash
2 PATH=/bin:/usr/bin:/sbin:/usr/sbin
3
4 # Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
5 #
6 #    Licensed under the Apache License, Version 2.0 (the "License");
7 #    you may not use this file except in compliance with the License.
8 #    You may obtain a copy of the License at
9 #
10 #        http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #    Unless required by applicable law or agreed to in writing, software
13 #    distributed under the License is distributed on an "AS IS" BASIS,
14 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #    See the License for the specific language governing permissions and
16 #    limitations under the License.
17 #
18 # @file        cert-svc-test-upgrade.sh.in
19 # @author      Sangwan Kwon (sangwan.kwon@samsung.com)
20 # @brief       test script for platform upgrade Tizen 2.4 -> 3.0
21 #
22
23 NEW_DB=@CERT_SVC_DB_PATH@/certs-meta.db
24 TEST_GNAME1="6410666e.0"
25 TEST_GNAME2="790a7190.0"
26
27 # set test old database
28 rm -rf @CERT_SVC_OLD_DB_PATH@/*
29 cp @UPGRADE_DATA_PATH@/certs-meta-old.db @CERT_SVC_OLD_DB_PATH@/certs-meta.db
30
31 before_upgrade_certs_cnt=`ls -l @TZ_SYS_CA_CERTS@ | grep ^l | wc -l`
32 before_upgrade_bundle_line=`cat @TZ_SYS_CA_BUNDLE@ | wc -l`
33
34 # run db upgrade
35 @UPGRADE_SCRIPT_PATH@/242.cert-svc-db-upgrade.sh
36
37 # testcase 1. disabled_certs table should have 2 column
38 disabled_certs_cnt=`sqlite3 $NEW_DB "SELECT count(*) FROM disabled_certs;"`
39 if [ "$disabled_certs_cnt" != "2" ]
40 then
41         echo "[-] Failed to upgrade disabled_certs table."
42 else
43         echo "[+] Success to upgrade disabled_certs table."
44 fi
45
46 # testcase 2. below gname's enabled column should off
47 enabled_column1=`sqlite3 $NEW_DB "SELECT enabled from ssl WHERE gname='$TEST_GNAME1';"`
48 if [ "$enabled_column1" != "0" ]
49 then
50         echo "[-] Failed to upgrade ssl table."
51 else
52         echo "[+] Success to upgrade ssl table."
53 fi
54 enabled_column2=`sqlite3 $NEW_DB "SELECT enabled from ssl WHERE gname='$TEST_GNAME2';"`
55 if [ "$enabled_column2" != "0" ]
56 then
57         echo "[-] Failed to upgrade ssl table."
58 else
59         echo "[+] Success to upgrade ssl table."
60 fi
61
62 # testcase 3. check to exist disabled certs on rw area
63 link_path1="@TZ_SYS_CA_CERTS@/$TEST_GNAME1"
64 if [ -f $link_path1 ]
65 then
66         echo "[-] Failed to unlink disabled certs."
67 else
68         echo "[+] Success to unlink disabled certs."
69 fi
70 link_path2="@TZ_SYS_CA_CERTS@/$TEST_GNAME2"
71 if [ -f $link_path1 ]
72 then
73         echo "[-] Failed to unlink disabled certs."
74 else
75         echo "[+] Success to unlink disabled certs."
76 fi
77
78 # check certificate's count was reduced
79 after_upgrade_certs_cnt=`ls -l @TZ_SYS_CA_CERTS@ | grep ^l | wc -l`
80 diff_cnt=$(expr $before_upgrade_certs_cnt - $after_upgrade_certs_cnt)
81 if [ "$diff_cnt" != "2" ]
82 then
83         echo "[-] Failed to unlink disabled certs."
84         echo "[-] Check ca-certificate package's upgrade has done."
85 else
86         echo "[+] Success to unlink disabled certs."
87 fi
88
89 # testcase 4. bundle file should update
90 after_upgrade_bundle_line=`cat @TZ_SYS_CA_BUNDLE@ | wc -l`
91 diff_line1=$(expr $before_upgrade_bundle_line - $after_upgrade_bundle_line)
92 if [ "$diff_line1" != "56" ]
93 then
94         echo "[-] Failed to update bundle file."
95         echo "[-] Check ca-certificate package's upgrade has done."
96 else
97         echo "[+] Success to update bundle file."
98 fi
99
100 after_symbol_bundle_line=`cat @CERT_SVC_CA_BUNDLE@ | wc -l`
101 diff_line2=$(expr $after_upgrade_bundle_line - $after_symbol_bundle_line)
102 if [ "$diff_line2" != "0" ]
103 then
104         echo "[-] Failed to sync bundle file with CERT_SVC_CA_BUNDLE."
105 else
106         echo "[+] Success to sync bundle file with CERT_SVC_CA_BUNDLE."
107 fi
108
109 # testcase 5. user table migration
110 wifi_certs_cnt=`sqlite3 $NEW_DB "SELECT count(*) FROM wifi;"`
111 if [ "$wifi_certs_cnt" != "1" ]
112 then
113         echo "[-] Failed to migrate wifi table."
114 else
115         echo "[+] Success to migrate wifi table."
116 fi
117
118 vpn_certs_cnt=`sqlite3 $NEW_DB "SELECT count(*) FROM vpn;"`
119 if [ "$vpn_certs_cnt" != "1" ]
120 then
121         echo "[-] Failed to migrate vpn table."
122 else
123         echo "[+] Success to migrate vpn table."
124 fi
125
126 email_certs_cnt=`sqlite3 $NEW_DB "SELECT count(*) FROM email;"`
127 if [ "$email_certs_cnt" != "1" ]
128 then
129         echo "[-] Failed to migrate email table."
130 else
131         echo "[+] Success to migrate email table."
132 fi