Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/mount

Issue 2645008: Update on feedback, update dbus API, add unit tests. TEST=manual,unit,BVT BUG=3628 323 (Closed) Base URL: ssh://git@chromiumos-git/cryptohome.git
Patch Set: Address second round of feedback. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/mocks ('k') | username_passkey.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
2 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 #
6 # Tests behavior specific to bin/mount
7 # (not cryptohome::mount_or_create)
8
9 testNoUserEnvVariable() {
10 unset CHROMEOS_USER
11 mock mount mock::ok
12 mock chown mock::ok
13 export DISABLED_ENCRYPTION_FILE=<(echo -n "notme@example.com")
14 function incognito_error() { true; }
15 mount_main 1>${stdoutF} 2>${stderrF} 3>${logF}
16 ret=$?
17 assertEquals 'expecting return code of 0' 0 ${ret}
18 assertNull 'unexpected output to stdout' "$(cat ${stdoutF})"
19 assertNull 'unexpected output to stderr' "$(cat ${stderrF})"
20 expected_log="\
21 CHROMEOS_USER not exported.
22 Assuming incognito mode...
23 disabled_encryption_file present
24 incognito mount completed"
25 assertSame 'unexpected output to log' \
26 "$(echo -ne "$expected_log")" \
27 "$(cat ${logF})"
28 }
29
30
31 testDisabledEncryptionLogic() {
32 export CHROMEOS_USER=exampleuser@example.com
33 mock test mock::ok
34 mock grep mock::ok
35 mount_main 1>${stdoutF} 2>${stderrF} 3>${logF}
36 ret=$?
37 assertEquals 'expecting return code of 0' 0 ${ret}
38 assertNull 'unexpected output to stdout' "$(cat ${stdoutF})"
39 assertNull 'unexpected output to stderr' "$(cat ${stderrF})"
40 expected_log="\
41 disabled_encryption_file present
42 $CHROMEOS_USER has opted out of encryption"
43 assertSame 'unexpected output to log' \
44 "$(echo -ne "$expected_log")" \
45 "$(cat ${logF})"
46
47 unmock_all
48 }
49
50 testDisabledEncryptionCheckSingle() {
51 export CHROMEOS_USER=exampleuser@example.com
52 export DISABLED_ENCRYPTION_FILE=<(echo -n "exampleuser@example.com")
53 mount_main 1>${stdoutF} 2>${stderrF} 3>${logF}
54 ret=$?
55 assertEquals 'expecting return code of 0' 0 ${ret}
56 assertNull 'unexpected output to stdout' "$(cat ${stdoutF})"
57 assertNull 'unexpected output to stderr' "$(cat ${stderrF})"
58 expected_log="\
59 disabled_encryption_file present
60 $CHROMEOS_USER has opted out of encryption"
61 assertSame 'unexpected output to log' \
62 "$(echo -ne "$expected_log")" \
63 "$(cat ${logF})"
64
65 unmock_all
66 }
67
68 testDisabledEncryptionCheckMulti() {
69 export CHROMEOS_USER=exampleuser@example.com
70 export DISABLED_ENCRYPTION_FILE=<(echo -en "someexampleuser@example.com\nexamp leuser@example.com")
71 mount_main 1>${stdoutF} 2>${stderrF} 3>${logF}
72 ret=$?
73 assertEquals 'expecting return code of 0' 0 ${ret}
74 assertNull 'unexpected output to stdout' "$(cat ${stdoutF})"
75 assertNull 'unexpected output to stderr' "$(cat ${stderrF})"
76 expected_log="\
77 disabled_encryption_file present
78 $CHROMEOS_USER has opted out of encryption"
79 assertSame 'unexpected output to log' \
80 "$(echo -ne "$expected_log")" \
81 "$(cat ${logF})"
82
83 unmock_all
84 }
85
86 testDisabledEncryptionCheckPartial() {
87 export CHROMEOS_USER=exampleuser@example.com
88 export DISABLED_ENCRYPTION_FILE=<(echo -n "someexampleuser@example.com")
89 function error_handler() { true; }
90 set -E
91 trap error_handler ERR
92 # Make sure it fails at cat.
93 mock cat mock::ok
94 mock openssl mock::ok
95 function cryptohome::mount_or_create { echo -n "reached"; true; }
96
97 mount_main 1>${stdoutF} 2>${stderrF} 3>${logF}
98 ret=$?
99 assertEquals 'expecting return code of 0' 0 ${ret}
100 assertSame 'unexpected output to stdout' "reached" "$(cat ${stdoutF})"
101 assertNull 'unexpected output to stderr' "$(cat ${stderrF})"
102 expected_log="\
103 disabled_encryption_file present"
104 assertSame 'unexpected output to log' \
105 "$(echo -ne "$expected_log")" \
106 "$(cat ${logF})"
107
108 unmock_all
109 }
110
111 testUserIdAndPassGrab() {
112 export CHROMEOS_USER=exampleuser@example.com
113 function error_handler() { true; }
114 set -E
115 trap error_handler ERR
116 # Make sure it fails at cat.
117 function cryptohome::mount_or_create { echo -n "reached"; true; }
118 echo "salt" > $outputDir/salt
119 IMAGE_DIR=$outputDir
120 USERID=""
121 PASSWORD=""
122 mount_main 1>${stdoutF} 2>${stderrF} 3>${logF} < <(echo password)
123 ret=$?
124 assertEquals 'expecting return code of 0' 0 ${ret}
125 assertSame 'unexpected output to stdout' "reached" "$(cat ${stdoutF})"
126 assertNull 'unexpected output to stderr' "$(cat ${stderrF})"
127 assertNull 'unexpected output to log' "$(cat ${logF})"
128 # userid = sha1(salt || CHROMEOS_USER)
129 assertEquals 'unexpected userid' \
130 'c8458d2ff3c2a94283cf66c721c22b0506d2070e' \
131 "$USERID"
132 assertEquals 'unexpected password' \
133 'password' \
134 "$PASSWORD"
135
136
137 unmock_all
138 }
139
140
141
142 oneTimeSetUp() {
143 outputDir="${__shunit_tmpDir}/output"
144 mkdir "${outputDir}"
145 stdoutF="${outputDir}/stdout"
146 stderrF="${outputDir}/stderr"
147 testDir="${__shunit_tmpDir}/some_test_dir"
148 echo "Output dir: ${outputDir}"
149 }
150
151 oneTimeTearDown() {
152 true
153 }
154
155 setUp() {
156 source $location/../tests/mocks
157 source $location/../lib/common
158 source $location/../bin/mount
159 logF="${outputDir}/log"
160 set +e
161 trap mock::ok ERR
162 # Disable error handling. We don't care about it right now.
163 function cryptohome::log() {
164 echo -e "$@" >> $logF
165 }
166 # Disable I/O redirection
167 mock exec mock::ok
168 STDOUT_FILE=/dev/null
169 STDERR_FILE=/dev/null
170
171 }
172
173 tearDown() {
174 true
175 }
176
177 if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
178 SHUNIT_PARENT=$0
179 pushd "${0%/*}" &> /dev/null
180 popd &> /dev/null
181 location=$OLDPWD
182 . $location/../shunit2/files/src/shell/shunit2
183 fi
OLDNEW
« no previous file with comments | « tests/mocks ('k') | username_passkey.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698