blob: 9467ae12cd5c647920b32ed9c5d744c1d34d2e71 [file] [log] [blame]
Bogdan Capritac98a8b52014-12-01 10:08:47 -08001#!/bin/bash
Jiri Simsad7616c92015-03-24 23:44:30 -07002# Copyright 2015 The Vanadium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file.
Bogdan Capritac98a8b52014-12-01 10:08:47 -08005
Bogdan Caprita2b219362014-12-09 17:03:33 -08006# Test the device manager and related services and tools.
Robert Kroeger1697c4a2015-01-26 16:37:08 -08007#
8#
9# By default, this script tests the device manager in a fashion amenable
10# to automatic testing: the --single_user is passed to the device
11# manager so that all device manager components run as the same user and
12# no user input (such as an agent pass phrase) is needed.
13#
Robert Kroegerf639a412015-02-09 17:54:12 -080014# When this script is invoked with the --with_suid <user1> <user2> flag, it
Robert Kroeger1697c4a2015-01-26 16:37:08 -080015# installs the device manager in its more secure multi-account
Robert Kroegerf639a412015-02-09 17:54:12 -080016# configuration where the device manager runs under the account of <user1>
17# while test apps will be executed as <user2>. This mode will
18# require root permissions to install and may require configuring an
Robert Kroeger1697c4a2015-01-26 16:37:08 -080019# agent passphrase.
20#
21# For exanple:
22#
Bogdan Capritac8b29da2015-02-26 19:24:08 -080023# ./suid_test.sh --with_suid devicemanager vana
Robert Kroeger1697c4a2015-01-26 16:37:08 -080024#
25# to test a device manager with multi-account support enabled for app
Robert Kroegerf639a412015-02-09 17:54:12 -080026# account vana.
Robert Kroeger1697c4a2015-01-26 16:37:08 -080027#
Bogdan Capritac98a8b52014-12-01 10:08:47 -080028
Robert Kroeger38cc2d82015-02-09 17:54:12 -080029# When running --with_suid, TMPDIR must grant the invoking user rwx
30# permissions and x permissions for all directories back to / for world.
31# Otherwise, the with_suid user will not be able to use absolute paths.
32# On Darwin, TMPDIR defaults to a directory hieararchy in /var that is
33# 0700. This is unworkable so force TMPDIR to /tmp in this case.
34WITH_SUID="${1:-no}"
Bogdan Capritad2cdd532015-02-25 11:51:19 -080035# TODO(caprita,rjkroege): Add logic to the integration test that verifies
36# installing and accessing packages from apps. This would add coverage to the
37# package-related code in suid mode.
Robert Kroeger38cc2d82015-02-09 17:54:12 -080038if [[ "${WITH_SUID}" == "--with_suid" ]]; then
Robert Kroegerf639a412015-02-09 17:54:12 -080039 DEVMGR_USER="${2:?--with_suid requires a devicemgr user}"
40 SUID_USER="${3:?--with_suid requires a app user}"
Robert Kroeger38cc2d82015-02-09 17:54:12 -080041 SUDO_USER="root"
42 TMPDIR=/tmp
43 umask 066
44fi
45
Todd Wang236b4212015-03-25 17:35:59 -070046 source "$(go list -f {{.Dir}} v.io/x/ref/cmd/mgmt)/shell_test.sh"
Bogdan Capritac98a8b52014-12-01 10:08:47 -080047
Ankur5dab76d2015-01-07 11:06:46 -080048# Run the test under the security agent.
49shell_test::enable_agent "$@"
50
Bogdan Capritac98a8b52014-12-01 10:08:47 -080051readonly WORKDIR="${shell_test_WORK_DIR}"
52
53build() {
Robin Thellendacaa4322015-02-05 11:00:28 -080054 echo ">> Building binaries"
Todd Wang1f7a6c62015-04-03 17:05:09 -070055 BINARYD_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/binary/binaryd')"
56 BINARY_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/binary/binary')"
Todd Wang159f6ee2015-04-02 18:57:46 -070057 APPLICATIOND_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/application/applicationd')"
58 APPLICATION_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/application/application')"
Jiri Simsaffceefa2015-02-28 11:03:34 -080059 AGENTD_BIN="$(shell_test::build_go_binary 'v.io/x/ref/security/agent/agentd')"
Todd Wang392a9cc2015-04-06 14:35:11 -070060 SUIDHELPER_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/device/suidhelper')"
61 INITHELPER_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/device/inithelper')"
Jiri Simsaffceefa2015-02-28 11:03:34 -080062 DEVICEMANAGER_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/mgmt/device/deviced')"
Matt Rosencrantzbca49812015-03-01 21:32:54 -080063 DEVICE_BIN="$(shell_test::build_go_binary 'v.io/x/ref/cmd/mgmt/device')"
64 NAMESPACE_BIN="$(shell_test::build_go_binary 'v.io/x/ref/cmd/namespace')"
65 PRINCIPAL_BIN="$(shell_test::build_go_binary 'v.io/x/ref/cmd/principal')"
Todd Wang4aaf8fa2015-04-03 18:14:26 -070066 DEBUG_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/debug/debug')"
Matt Rosencrantzbca49812015-03-01 21:32:54 -080067 DEVICE_SCRIPT="$(go list -f {{.Dir}} v.io/x/ref/cmd/mgmt/device)/devicex"
Bogdan Capritac98a8b52014-12-01 10:08:47 -080068}
69
Bogdan Caprita4ad04992014-12-04 21:56:23 -080070# TODO(caprita): Move to shell_tesh.sh
71
72###############################################################################
73# Waits until the given name appears in the mounttable, within a set timeout.
74# Arguments:
75# path to namespace command-line tool
76# timeout in seconds
77# name to look up
Bogdan Caprita4ea9b032014-12-27 14:56:51 -080078# old mount entry value (if specified, waits until a different value appears)
Bogdan Caprita4ad04992014-12-04 21:56:23 -080079# Returns:
80# 0 if the name was successfully found, and 1 if the timeout expires before
81# the name appears.
Bogdan Caprita4ea9b032014-12-27 14:56:51 -080082# Prints the new value of the mount entry.
Bogdan Caprita4ad04992014-12-04 21:56:23 -080083###############################################################################
84wait_for_mountentry() {
85 local -r NAMESPACE_BIN="$1"
86 local -r TIMEOUT="$2"
87 local -r NAME="$3"
Bogdan Caprita4ea9b032014-12-27 14:56:51 -080088 local -r OLD_ENTRY="${4:+}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -080089 for i in $(seq 1 "${TIMEOUT}"); do
Bogdan Capritac7e72b62015-01-07 19:22:23 -080090 local ENTRY=$("${NAMESPACE_BIN}" resolve "${NAME}" 2>/dev/null)
Bogdan Caprita4ea9b032014-12-27 14:56:51 -080091 if [[ -n "${ENTRY}" && "${ENTRY}" != "${OLD_ENTRY}" ]]; then
92 echo ${ENTRY}
Bogdan Caprita4ad04992014-12-04 21:56:23 -080093 return 0
94 fi
95 sleep 1
96 done
Bogdan Caprita4ea9b032014-12-27 14:56:51 -080097 echo "Timed out waiting for ${NAME} to have a mounttable entry different from ${OLD_ENTRY}."
Bogdan Caprita4ad04992014-12-04 21:56:23 -080098 return 1
99}
100
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800101###############################################################################
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800102# Waits until the given name disappears from the mounttable, within a set
103# timeout.
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800104# Arguments:
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800105# path to namespace command-line tool
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800106# timeout in seconds
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800107# name to look up
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800108# Returns:
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800109# 0 if the name was gone from the mounttable, and 1 if the timeout expires
110# while the name is still in the mounttable.
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800111###############################################################################
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800112wait_for_no_mountentry() {
113 local -r NAMESPACE_BIN="$1"
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800114 local -r TIMEOUT="$2"
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800115 local -r NAME="$3"
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800116 for i in $(seq 1 "${TIMEOUT}"); do
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800117 local ENTRY=$("${NAMESPACE_BIN}" resolve "${NAME}" 2>/dev/null)
118 if [[ -z "${ENTRY}" ]]; then
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800119 return 0
120 fi
121 sleep 1
122 done
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800123 echo "Timed out waiting for ${NAME} to disappear from the mounttable."
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800124 return 1
125}
126
Bogdan Capritac98a8b52014-12-01 10:08:47 -0800127main() {
128 cd "${WORKDIR}"
129 build
130
Robin Thellendf9385c62015-01-29 14:00:06 -0800131 local -r APPLICATIOND_NAME="applicationd"
132 local -r DEVICED_APP_NAME="${APPLICATIOND_NAME}/deviced/test"
133
Robin Thellend9299b782015-02-03 08:42:46 -0800134 BIN_STAGING_DIR="${WORKDIR}/bin"
135 mkdir -p "${BIN_STAGING_DIR}"
Bogdan Caprita29a3b352015-01-16 16:28:49 -0800136 cp "${AGENTD_BIN}" "${SUIDHELPER_BIN}" "${INITHELPER_BIN}" "${DEVICEMANAGER_BIN}" "${BIN_STAGING_DIR}"
Bogdan Capritac98a8b52014-12-01 10:08:47 -0800137 shell_test::setup_server_test
Bogdan Capritac98a8b52014-12-01 10:08:47 -0800138
Robert Kroeger38cc2d82015-02-09 17:54:12 -0800139 if [[ "${WITH_SUID}" == "--with_suid" ]]; then
140 chmod go+x "${WORKDIR}"
141 fi
142
Robin Thellendacaa4322015-02-05 11:00:28 -0800143 echo ">> Installing and starting the device manager"
Robin Thellend9299b782015-02-03 08:42:46 -0800144 DM_INSTALL_DIR="${WORKDIR}/dm"
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800145
Bogdan Capritad7b30472015-04-01 17:04:12 -0700146 export V23_DEVICE_DIR="${DM_INSTALL_DIR}"
Robert Kroeger1697c4a2015-01-26 16:37:08 -0800147
Robin Thellendacaa4322015-02-05 11:00:28 -0800148 if [[ "${WITH_SUID}" != "--with_suid" ]]; then
Robert Kroegerf639a412015-02-09 17:54:12 -0800149 local -r extra_arg="--single_user"
150 else
151 local -r extra_arg="--devuser=${DEVMGR_USER}"
Robert Kroeger1697c4a2015-01-26 16:37:08 -0800152 fi
153
Robin Thellendacaa4322015-02-05 11:00:28 -0800154 local -r NEIGHBORHOODNAME="$(hostname)-$$-${RANDOM}"
155 "${DEVICE_SCRIPT}" install "${BIN_STAGING_DIR}" \
156 ${extra_arg} \
157 --origin="${DEVICED_APP_NAME}" \
158 -- \
Asim Shankarf32d24d2015-04-01 16:34:26 -0700159 --v23.tcp.address=127.0.0.1:0 \
Suharsh Sivakumarf77f91f2015-04-01 19:17:16 -0700160 --neighborhood-name="${NEIGHBORHOODNAME}"
Bogdan Capritac98a8b52014-12-01 10:08:47 -0800161
Robin Thellendacaa4322015-02-05 11:00:28 -0800162 "${VRUN}" "${DEVICE_SCRIPT}" start
163 local -r MT_NAME=devices/$(hostname)
164 MT_EP=$(wait_for_mountentry "${NAMESPACE_BIN}" 5 "${MT_NAME}")
165
166 # Verify that device manager's mounttable is published under the expected name
167 # (hostname).
168 shell_test::assert_ne "$("${NAMESPACE_BIN}" glob "${MT_NAME}")" "" "${LINENO}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800169
Ankur5dab76d2015-01-07 11:06:46 -0800170 # Create a self-signed blessing with name "alice" and set it as default and
171 # shareable with all peers on the principal that this process is running
172 # as. This blessing will be used by all commands except those running under
173 # "vrun" which gets a principal forked from the process principal.
174 "${PRINCIPAL_BIN}" blessself alice > alice.bless || \
175 shell_test::fail "line ${LINENO}: blessself alice failed"
176 "${PRINCIPAL_BIN}" store setdefault alice.bless || \
177 shell_test::fail "line ${LINENO}: store setdefault failed"
178 "${PRINCIPAL_BIN}" store set alice.bless ... || \
179 shell_test::fail "line ${LINENO}: store set failed"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800180
Bogdan Caprita2b219362014-12-09 17:03:33 -0800181 # Claim the device as "alice/myworkstation".
Robin Thellendf9385c62015-01-29 14:00:06 -0800182 echo ">> Claiming the device manager"
Robin Thellendacaa4322015-02-05 11:00:28 -0800183 "${DEVICE_BIN}" claim "${MT_NAME}/devmgr/device" myworkstation
Asim Shankar23dac322015-02-14 12:42:26 -0800184 # Wait for the device manager to re-mount after being claimed
185 MT_EP=$(wait_for_mountentry "${NAMESPACE_BIN}" 5 "${MT_NAME}" "${MT_EP}")
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800186
Robert Kroeger1697c4a2015-01-26 16:37:08 -0800187 if [[ "${WITH_SUID}" == "--with_suid" ]]; then
Robert Kroegerf639a412015-02-09 17:54:12 -0800188 echo ">> Verify that devicemanager has valid association for alice"
Robin Thellendacaa4322015-02-05 11:00:28 -0800189 "${DEVICE_BIN}" associate add "${MT_NAME}/devmgr/device" "${SUID_USER}" "alice"
190 shell_test::assert_eq "$("${DEVICE_BIN}" associate list "${MT_NAME}/devmgr/device")" \
Robert Kroeger1697c4a2015-01-26 16:37:08 -0800191 "alice ${SUID_USER}" "${LINENO}"
Robert Kroegerf639a412015-02-09 17:54:12 -0800192 echo ">> Verify that devicemanager runs as ${DEVMGR_USER}"
193 local -r DPID=$("${DEBUG_BIN}" stats read \
194 "${MT_NAME}/devmgr/__debug/stats/system/pid" \
195 | awk '{print $2}')
196 # ps flags need to be different on linux
197 case "$(uname)" in
198 "Darwin")
199 local -r COMPUTED_DEVMGR_USER=$(ps -ej | \
200 awk '$2 ~'"${DPID}"' { print $1 }')
201 ;;
202 "Linux")
Bogdan Capritac8b29da2015-02-26 19:24:08 -0800203 local -r COMPUTED_DEVMGR_USER=$(awk '/^Uid:/{print $2}' /proc/${DPID}/status | \
204 xargs getent passwd | awk -F: '{print $1}')
Robert Kroegerf639a412015-02-09 17:54:12 -0800205 ;;
206 esac
207 shell_test::assert_eq "${COMPUTED_DEVMGR_USER}" \
208 "${DEVMGR_USER}" \
209 "${LINENO}"
Robert Kroeger1697c4a2015-01-26 16:37:08 -0800210 fi
211
Bogdan Caprita2b219362014-12-09 17:03:33 -0800212 # Verify the device's default blessing is as expected.
Robin Thellendacaa4322015-02-05 11:00:28 -0800213 shell_test::assert_contains "$("${DEBUG_BIN}" stats read "${MT_NAME}/devmgr/__debug/stats/security/principal/*/blessingstore" | head -1)" \
Suharsh Sivakumar5ca46642015-01-30 10:33:38 -0800214 "Default blessings: alice/myworkstation" "${LINENO}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800215
Bogdan Caprita54ae80e2015-01-20 13:37:52 -0800216 # Get the device's profile.
Robin Thellendacaa4322015-02-05 11:00:28 -0800217 local -r DEVICE_PROFILE=$("${DEVICE_BIN}" describe "${MT_NAME}/devmgr/device" | sed -e 's/{Profiles:map\[\(.*\):{}]}/\1/')
Bogdan Caprita54ae80e2015-01-20 13:37:52 -0800218
Ankur5dab76d2015-01-07 11:06:46 -0800219 # Start a binary server under the blessing "alice/myworkstation/binaryd" so that
220 # the device ("alice/myworkstation") can talk to it.
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800221 local -r BINARYD_NAME="binaryd"
Ankur5dab76d2015-01-07 11:06:46 -0800222 shell_test::start_server "${VRUN}" --name=myworkstation/binaryd "${BINARYD_BIN}" --name="${BINARYD_NAME}" \
Suharsh Sivakumar65e38502015-04-01 18:33:18 -0700223 --root-dir="${WORKDIR}/binstore" --v23.tcp.address=127.0.0.1:0 --http=127.0.0.1:0 \
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800224 || shell_test::fail "line ${LINENO} failed to start binaryd"
225
226 # Upload a binary to the binary server. The binary we upload is binaryd
227 # itself.
228 local -r SAMPLE_APP_BIN_NAME="${BINARYD_NAME}/testapp"
Robin Thellendf9385c62015-01-29 14:00:06 -0800229 echo ">> Uploading ${SAMPLE_APP_BIN_NAME}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800230 "${BINARY_BIN}" upload "${SAMPLE_APP_BIN_NAME}" "${BINARYD_BIN}"
231
232 # Verify that the binary we uploaded is shown by glob.
233 shell_test::assert_eq "$("${NAMESPACE_BIN}" glob "${SAMPLE_APP_BIN_NAME}")" \
234 "${SAMPLE_APP_BIN_NAME}" "${LINENO}"
235
Ankur5dab76d2015-01-07 11:06:46 -0800236 # Start an application server under the blessing "alice/myworkstation/applicationd" so that
237 # the device ("alice/myworkstation") can talk to it.
Robin Thellend9299b782015-02-03 08:42:46 -0800238 mkdir -p "${WORKDIR}/appstore"
Ankur5dab76d2015-01-07 11:06:46 -0800239 shell_test::start_server "${VRUN}" --name=myworkstation/applicationd "${APPLICATIOND_BIN}" --name="${APPLICATIOND_NAME}" \
Asim Shankarf32d24d2015-04-01 16:34:26 -0700240 --store="${WORKDIR}/appstore" --v23.tcp.address=127.0.0.1:0 \
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800241 || shell_test::fail "line ${LINENO} failed to start applicationd"
242
243 # Upload an envelope for our test app.
244 local -r SAMPLE_APP_NAME="${APPLICATIOND_NAME}/testapp/v0"
245 local -r APP_PUBLISH_NAME="testbinaryd"
Robin Thellendf9385c62015-01-29 14:00:06 -0800246 echo ">> Uploading ${SAMPLE_APP_NAME}"
Suharsh Sivakumar65e38502015-04-01 18:33:18 -0700247 echo "{\"Title\":\"BINARYD\", \"Args\":[\"--name=${APP_PUBLISH_NAME}\", \"--root-dir=./binstore\", \"--v23.tcp.address=127.0.0.1:0\"], \"Binary\":{\"File\":\"${SAMPLE_APP_BIN_NAME}\"}, \"Env\":[]}" > ./app.envelope
Bogdan Capritac25a48c2015-02-12 13:45:51 -0800248 "${APPLICATION_BIN}" put "${SAMPLE_APP_NAME}" "${DEVICE_PROFILE}" ./app.envelope
249 rm ./app.envelope
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800250
251 # Verify that the envelope we uploaded shows up with glob.
Bogdan Caprita54ae80e2015-01-20 13:37:52 -0800252 shell_test::assert_eq "$("${APPLICATION_BIN}" match "${SAMPLE_APP_NAME}" "${DEVICE_PROFILE}" | grep Title | sed -e 's/^.*"Title": "'// | sed -e 's/",//')" \
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800253 "BINARYD" "${LINENO}"
254
Bogdan Caprita2b219362014-12-09 17:03:33 -0800255 # Install the app on the device.
Robin Thellendf9385c62015-01-29 14:00:06 -0800256 echo ">> Installing ${SAMPLE_APP_NAME}"
Robin Thellendacaa4322015-02-05 11:00:28 -0800257 local -r INSTALLATION_NAME=$("${DEVICE_BIN}" install "${MT_NAME}/devmgr/apps" "${SAMPLE_APP_NAME}" | sed -e 's/Successfully installed: "//' | sed -e 's/"//')
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800258
Bogdan Caprita2b219362014-12-09 17:03:33 -0800259 # Verify that the installation shows up when globbing the device manager.
Robin Thellendacaa4322015-02-05 11:00:28 -0800260 shell_test::assert_eq "$("${NAMESPACE_BIN}" glob "${MT_NAME}/devmgr/apps/BINARYD/*")" \
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800261 "${INSTALLATION_NAME}" "${LINENO}"
262
263 # Start an instance of the app, granting it blessing extension myapp.
Robin Thellendf9385c62015-01-29 14:00:06 -0800264 echo ">> Starting ${INSTALLATION_NAME}"
Bogdan Capritaa456f472014-12-10 10:18:03 -0800265 local -r INSTANCE_NAME=$("${DEVICE_BIN}" start "${INSTALLATION_NAME}" myapp | sed -e 's/Successfully started: "//' | sed -e 's/"//')
Robin Thellendacaa4322015-02-05 11:00:28 -0800266 wait_for_mountentry "${NAMESPACE_BIN}" "5" "${MT_NAME}/${APP_PUBLISH_NAME}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800267
Bogdan Caprita2b219362014-12-09 17:03:33 -0800268 # Verify that the instance shows up when globbing the device manager.
Robin Thellendacaa4322015-02-05 11:00:28 -0800269 shell_test::assert_eq "$("${NAMESPACE_BIN}" glob "${MT_NAME}/devmgr/apps/BINARYD/*/*")" "${INSTANCE_NAME}" "${LINENO}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800270
Robert Kroeger38cc2d82015-02-09 17:54:12 -0800271 if [[ "${WITH_SUID}" == "--with_suid" ]]; then
272 echo ">> Verifying that the app is actually running as the associated user"
273 local -r PID=$("${DEBUG_BIN}" stats read "${MT_NAME}/devmgr/apps/BINARYD/*/*/stats/system/pid" | awk '{print $2}')
274 # ps flags need to be different on linux
275 case "$(uname)" in
276 "Darwin")
277 local -r COMPUTED_SUID_USER=$(ps -ej | awk '$2 ~'"${PID}"' { print $1 }')
278 ;;
279 "Linux")
Bogdan Capritac8b29da2015-02-26 19:24:08 -0800280 local -r COMPUTED_SUID_USER=$(awk '/^Uid:/{print $2}' /proc/${PID}/status | \
281 xargs getent passwd | awk -F: '{print $1}')
Robert Kroeger38cc2d82015-02-09 17:54:12 -0800282 ;;
283 esac
284 shell_test::assert_eq "${COMPUTED_SUID_USER}" "${SUID_USER}" "${LINENO}"
285 fi
Robert Kroeger1697c4a2015-01-26 16:37:08 -0800286
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800287 # Verify the app's default blessing.
Suharsh Sivakumar5ca46642015-01-30 10:33:38 -0800288 shell_test::assert_contains "$("${DEBUG_BIN}" stats read "${INSTANCE_NAME}/stats/security/principal/*/blessingstore" | head -1)" \
289 "Default blessings: alice/myapp/BINARYD" "${LINENO}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800290
291 # Stop the instance.
Robin Thellendf9385c62015-01-29 14:00:06 -0800292 echo ">> Stopping ${INSTANCE_NAME}"
Bogdan Capritaa456f472014-12-10 10:18:03 -0800293 "${DEVICE_BIN}" stop "${INSTANCE_NAME}"
Bogdan Caprita4ad04992014-12-04 21:56:23 -0800294
295 # Verify that logs, but not stats, show up when globbing the stopped instance.
296 shell_test::assert_eq "$("${NAMESPACE_BIN}" glob "${INSTANCE_NAME}/stats/...")" "" "${LINENO}"
297 shell_test::assert_ne "$("${NAMESPACE_BIN}" glob "${INSTANCE_NAME}/logs/...")" "" "${LINENO}"
298
Robin Thellendf9385c62015-01-29 14:00:06 -0800299 # Upload a deviced binary.
300 local -r DEVICED_APP_BIN_NAME="${BINARYD_NAME}/deviced"
301 echo ">> Uploading ${DEVICEMANAGER_BIN}"
302 "${BINARY_BIN}" upload "${DEVICED_APP_BIN_NAME}" "${DEVICEMANAGER_BIN}"
303
304 # Upload a device manager envelope.
305 echo ">> Uploading ${DEVICED_APP_NAME}"
Bogdan Capritac25a48c2015-02-12 13:45:51 -0800306 echo "{\"Title\":\"device manager\", \"Binary\":{\"File\":\"${DEVICED_APP_BIN_NAME}\"}}" > ./deviced.envelope
307 "${APPLICATION_BIN}" put "${DEVICED_APP_NAME}" "${DEVICE_PROFILE}" ./deviced.envelope
308 rm ./deviced.envelope
Robin Thellendf9385c62015-01-29 14:00:06 -0800309 # Update the device manager.
310 echo ">> Updating device manager"
Robin Thellendacaa4322015-02-05 11:00:28 -0800311 "${DEVICE_BIN}" update "${MT_NAME}/devmgr/device"
312 MT_EP=$(wait_for_mountentry "${NAMESPACE_BIN}" 5 "${MT_NAME}" "${MT_EP}")
Robin Thellendf9385c62015-01-29 14:00:06 -0800313
Robin Thellendacaa4322015-02-05 11:00:28 -0800314 # Verify that device manager's mounttable is still published under the
315 # expected name (hostname).
316 shell_test::assert_ne "$("${NAMESPACE_BIN}" glob "${MT_NAME}")" "" "${LINENO}"
Robin Thellendf9385c62015-01-29 14:00:06 -0800317
318 # Revert the device manager.
319 echo ">> Reverting device manager"
Robin Thellendacaa4322015-02-05 11:00:28 -0800320 "${DEVICE_BIN}" revert "${MT_NAME}/devmgr/device"
321 MT_EP=$(wait_for_mountentry "${NAMESPACE_BIN}" 5 "${MT_NAME}" "${MT_EP}")
Robin Thellendf9385c62015-01-29 14:00:06 -0800322
Robin Thellendacaa4322015-02-05 11:00:28 -0800323 # Verify that device manager's mounttable is still published under the
324 # expected name (hostname).
325 shell_test::assert_ne "$("${NAMESPACE_BIN}" glob "${MT_NAME}")" "" "${LINENO}"
Robin Thellendf9385c62015-01-29 14:00:06 -0800326
Robin Thellendacaa4322015-02-05 11:00:28 -0800327 # Verify that the local mounttable exists, and that the device manager, the
328 # global namespace, and the neighborhood are mounted on it.
329 shell_test::assert_ne $("${NAMESPACE_BIN}" resolve "${MT_EP}/devmgr") "" "${LINENO}"
Asim Shankar59b8b692015-03-30 01:23:36 -0700330 shell_test::assert_eq $("${NAMESPACE_BIN}" resolve "${MT_EP}/global") "[alice/myworkstation]${V23_NAMESPACE}" "${LINENO}"
Robin Thellendacaa4322015-02-05 11:00:28 -0800331 shell_test::assert_ne $("${NAMESPACE_BIN}" resolve "${MT_EP}/nh") "" "${LINENO}"
332
333 # Suspend the device manager.
334 "${DEVICE_BIN}" suspend "${MT_NAME}/devmgr/device"
335 wait_for_mountentry "${NAMESPACE_BIN}" "5" "${MT_NAME}" "${MT_EP}"
Bogdan Caprita4ea9b032014-12-27 14:56:51 -0800336
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800337 # Stop the device manager.
338 "${DEVICE_SCRIPT}" stop
Robin Thellendacaa4322015-02-05 11:00:28 -0800339 wait_for_no_mountentry "${NAMESPACE_BIN}" "5" "${MT_NAME}"
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800340
Bogdan Capritac7e72b62015-01-07 19:22:23 -0800341 "${DEVICE_SCRIPT}" uninstall
Bogdan Capritad7b30472015-04-01 17:04:12 -0700342 if [[ -n "$(ls -A "${V23_DEVICE_DIR}" 2>/dev/null)" ]]; then
343 shell_test::fail "${V23_DEVICE_DIR} is not empty"
Bogdan Capritaa40d3382014-12-19 16:30:26 -0800344 fi
Bogdan Capritac98a8b52014-12-01 10:08:47 -0800345 shell_test::pass
346}
347
348main "$@"