Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 2 | # 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 Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 5 | |
Bogdan Caprita | 2b21936 | 2014-12-09 17:03:33 -0800 | [diff] [blame] | 6 | # Test the device manager and related services and tools. |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 7 | # |
| 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 Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 14 | # When this script is invoked with the --with_suid <user1> <user2> flag, it |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 15 | # installs the device manager in its more secure multi-account |
Robert Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 16 | # 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 Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 19 | # agent passphrase. |
| 20 | # |
| 21 | # For exanple: |
| 22 | # |
Bogdan Caprita | c8b29da | 2015-02-26 19:24:08 -0800 | [diff] [blame] | 23 | # ./suid_test.sh --with_suid devicemanager vana |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 24 | # |
| 25 | # to test a device manager with multi-account support enabled for app |
Robert Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 26 | # account vana. |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 27 | # |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 28 | |
Robert Kroeger | 38cc2d8 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 29 | # 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. |
| 34 | WITH_SUID="${1:-no}" |
Bogdan Caprita | d2cdd53 | 2015-02-25 11:51:19 -0800 | [diff] [blame] | 35 | # 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 Kroeger | 38cc2d8 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 38 | if [[ "${WITH_SUID}" == "--with_suid" ]]; then |
Robert Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 39 | DEVMGR_USER="${2:?--with_suid requires a devicemgr user}" |
| 40 | SUID_USER="${3:?--with_suid requires a app user}" |
Robert Kroeger | 38cc2d8 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 41 | SUDO_USER="root" |
| 42 | TMPDIR=/tmp |
| 43 | umask 066 |
| 44 | fi |
| 45 | |
Todd Wang | 236b421 | 2015-03-25 17:35:59 -0700 | [diff] [blame] | 46 | source "$(go list -f {{.Dir}} v.io/x/ref/cmd/mgmt)/shell_test.sh" |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 47 | |
Ankur | 5dab76d | 2015-01-07 11:06:46 -0800 | [diff] [blame] | 48 | # Run the test under the security agent. |
| 49 | shell_test::enable_agent "$@" |
| 50 | |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 51 | readonly WORKDIR="${shell_test_WORK_DIR}" |
| 52 | |
| 53 | build() { |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 54 | echo ">> Building binaries" |
Todd Wang | 1f7a6c6 | 2015-04-03 17:05:09 -0700 | [diff] [blame] | 55 | 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 Wang | 159f6ee | 2015-04-02 18:57:46 -0700 | [diff] [blame] | 57 | 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 Simsa | ffceefa | 2015-02-28 11:03:34 -0800 | [diff] [blame] | 59 | AGENTD_BIN="$(shell_test::build_go_binary 'v.io/x/ref/security/agent/agentd')" |
Todd Wang | 392a9cc | 2015-04-06 14:35:11 -0700 | [diff] [blame^] | 60 | 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 Simsa | ffceefa | 2015-02-28 11:03:34 -0800 | [diff] [blame] | 62 | DEVICEMANAGER_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/mgmt/device/deviced')" |
Matt Rosencrantz | bca4981 | 2015-03-01 21:32:54 -0800 | [diff] [blame] | 63 | 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 Wang | 4aaf8fa | 2015-04-03 18:14:26 -0700 | [diff] [blame] | 66 | DEBUG_BIN="$(shell_test::build_go_binary 'v.io/x/ref/services/debug/debug')" |
Matt Rosencrantz | bca4981 | 2015-03-01 21:32:54 -0800 | [diff] [blame] | 67 | DEVICE_SCRIPT="$(go list -f {{.Dir}} v.io/x/ref/cmd/mgmt/device)/devicex" |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 70 | # 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 Caprita | 4ea9b03 | 2014-12-27 14:56:51 -0800 | [diff] [blame] | 78 | # old mount entry value (if specified, waits until a different value appears) |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 79 | # Returns: |
| 80 | # 0 if the name was successfully found, and 1 if the timeout expires before |
| 81 | # the name appears. |
Bogdan Caprita | 4ea9b03 | 2014-12-27 14:56:51 -0800 | [diff] [blame] | 82 | # Prints the new value of the mount entry. |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 83 | ############################################################################### |
| 84 | wait_for_mountentry() { |
| 85 | local -r NAMESPACE_BIN="$1" |
| 86 | local -r TIMEOUT="$2" |
| 87 | local -r NAME="$3" |
Bogdan Caprita | 4ea9b03 | 2014-12-27 14:56:51 -0800 | [diff] [blame] | 88 | local -r OLD_ENTRY="${4:+}" |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 89 | for i in $(seq 1 "${TIMEOUT}"); do |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 90 | local ENTRY=$("${NAMESPACE_BIN}" resolve "${NAME}" 2>/dev/null) |
Bogdan Caprita | 4ea9b03 | 2014-12-27 14:56:51 -0800 | [diff] [blame] | 91 | if [[ -n "${ENTRY}" && "${ENTRY}" != "${OLD_ENTRY}" ]]; then |
| 92 | echo ${ENTRY} |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 93 | return 0 |
| 94 | fi |
| 95 | sleep 1 |
| 96 | done |
Bogdan Caprita | 4ea9b03 | 2014-12-27 14:56:51 -0800 | [diff] [blame] | 97 | echo "Timed out waiting for ${NAME} to have a mounttable entry different from ${OLD_ENTRY}." |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 98 | return 1 |
| 99 | } |
| 100 | |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 101 | ############################################################################### |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 102 | # Waits until the given name disappears from the mounttable, within a set |
| 103 | # timeout. |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 104 | # Arguments: |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 105 | # path to namespace command-line tool |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 106 | # timeout in seconds |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 107 | # name to look up |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 108 | # Returns: |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 109 | # 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 Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 111 | ############################################################################### |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 112 | wait_for_no_mountentry() { |
| 113 | local -r NAMESPACE_BIN="$1" |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 114 | local -r TIMEOUT="$2" |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 115 | local -r NAME="$3" |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 116 | for i in $(seq 1 "${TIMEOUT}"); do |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 117 | local ENTRY=$("${NAMESPACE_BIN}" resolve "${NAME}" 2>/dev/null) |
| 118 | if [[ -z "${ENTRY}" ]]; then |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 119 | return 0 |
| 120 | fi |
| 121 | sleep 1 |
| 122 | done |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 123 | echo "Timed out waiting for ${NAME} to disappear from the mounttable." |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 124 | return 1 |
| 125 | } |
| 126 | |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 127 | main() { |
| 128 | cd "${WORKDIR}" |
| 129 | build |
| 130 | |
Robin Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 131 | local -r APPLICATIOND_NAME="applicationd" |
| 132 | local -r DEVICED_APP_NAME="${APPLICATIOND_NAME}/deviced/test" |
| 133 | |
Robin Thellend | 9299b78 | 2015-02-03 08:42:46 -0800 | [diff] [blame] | 134 | BIN_STAGING_DIR="${WORKDIR}/bin" |
| 135 | mkdir -p "${BIN_STAGING_DIR}" |
Bogdan Caprita | 29a3b35 | 2015-01-16 16:28:49 -0800 | [diff] [blame] | 136 | cp "${AGENTD_BIN}" "${SUIDHELPER_BIN}" "${INITHELPER_BIN}" "${DEVICEMANAGER_BIN}" "${BIN_STAGING_DIR}" |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 137 | shell_test::setup_server_test |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 138 | |
Robert Kroeger | 38cc2d8 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 139 | if [[ "${WITH_SUID}" == "--with_suid" ]]; then |
| 140 | chmod go+x "${WORKDIR}" |
| 141 | fi |
| 142 | |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 143 | echo ">> Installing and starting the device manager" |
Robin Thellend | 9299b78 | 2015-02-03 08:42:46 -0800 | [diff] [blame] | 144 | DM_INSTALL_DIR="${WORKDIR}/dm" |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 145 | |
Bogdan Caprita | d7b3047 | 2015-04-01 17:04:12 -0700 | [diff] [blame] | 146 | export V23_DEVICE_DIR="${DM_INSTALL_DIR}" |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 147 | |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 148 | if [[ "${WITH_SUID}" != "--with_suid" ]]; then |
Robert Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 149 | local -r extra_arg="--single_user" |
| 150 | else |
| 151 | local -r extra_arg="--devuser=${DEVMGR_USER}" |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 152 | fi |
| 153 | |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 154 | local -r NEIGHBORHOODNAME="$(hostname)-$$-${RANDOM}" |
| 155 | "${DEVICE_SCRIPT}" install "${BIN_STAGING_DIR}" \ |
| 156 | ${extra_arg} \ |
| 157 | --origin="${DEVICED_APP_NAME}" \ |
| 158 | -- \ |
Asim Shankar | f32d24d | 2015-04-01 16:34:26 -0700 | [diff] [blame] | 159 | --v23.tcp.address=127.0.0.1:0 \ |
Suharsh Sivakumar | f77f91f | 2015-04-01 19:17:16 -0700 | [diff] [blame] | 160 | --neighborhood-name="${NEIGHBORHOODNAME}" |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 161 | |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 162 | "${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 Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 169 | |
Ankur | 5dab76d | 2015-01-07 11:06:46 -0800 | [diff] [blame] | 170 | # 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 Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 180 | |
Bogdan Caprita | 2b21936 | 2014-12-09 17:03:33 -0800 | [diff] [blame] | 181 | # Claim the device as "alice/myworkstation". |
Robin Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 182 | echo ">> Claiming the device manager" |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 183 | "${DEVICE_BIN}" claim "${MT_NAME}/devmgr/device" myworkstation |
Asim Shankar | 23dac32 | 2015-02-14 12:42:26 -0800 | [diff] [blame] | 184 | # 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 Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 186 | |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 187 | if [[ "${WITH_SUID}" == "--with_suid" ]]; then |
Robert Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 188 | echo ">> Verify that devicemanager has valid association for alice" |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 189 | "${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 Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 191 | "alice ${SUID_USER}" "${LINENO}" |
Robert Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 192 | 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 Caprita | c8b29da | 2015-02-26 19:24:08 -0800 | [diff] [blame] | 203 | local -r COMPUTED_DEVMGR_USER=$(awk '/^Uid:/{print $2}' /proc/${DPID}/status | \ |
| 204 | xargs getent passwd | awk -F: '{print $1}') |
Robert Kroeger | f639a41 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 205 | ;; |
| 206 | esac |
| 207 | shell_test::assert_eq "${COMPUTED_DEVMGR_USER}" \ |
| 208 | "${DEVMGR_USER}" \ |
| 209 | "${LINENO}" |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 210 | fi |
| 211 | |
Bogdan Caprita | 2b21936 | 2014-12-09 17:03:33 -0800 | [diff] [blame] | 212 | # Verify the device's default blessing is as expected. |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 213 | shell_test::assert_contains "$("${DEBUG_BIN}" stats read "${MT_NAME}/devmgr/__debug/stats/security/principal/*/blessingstore" | head -1)" \ |
Suharsh Sivakumar | 5ca4664 | 2015-01-30 10:33:38 -0800 | [diff] [blame] | 214 | "Default blessings: alice/myworkstation" "${LINENO}" |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 215 | |
Bogdan Caprita | 54ae80e | 2015-01-20 13:37:52 -0800 | [diff] [blame] | 216 | # Get the device's profile. |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 217 | local -r DEVICE_PROFILE=$("${DEVICE_BIN}" describe "${MT_NAME}/devmgr/device" | sed -e 's/{Profiles:map\[\(.*\):{}]}/\1/') |
Bogdan Caprita | 54ae80e | 2015-01-20 13:37:52 -0800 | [diff] [blame] | 218 | |
Ankur | 5dab76d | 2015-01-07 11:06:46 -0800 | [diff] [blame] | 219 | # Start a binary server under the blessing "alice/myworkstation/binaryd" so that |
| 220 | # the device ("alice/myworkstation") can talk to it. |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 221 | local -r BINARYD_NAME="binaryd" |
Ankur | 5dab76d | 2015-01-07 11:06:46 -0800 | [diff] [blame] | 222 | shell_test::start_server "${VRUN}" --name=myworkstation/binaryd "${BINARYD_BIN}" --name="${BINARYD_NAME}" \ |
Suharsh Sivakumar | 65e3850 | 2015-04-01 18:33:18 -0700 | [diff] [blame] | 223 | --root-dir="${WORKDIR}/binstore" --v23.tcp.address=127.0.0.1:0 --http=127.0.0.1:0 \ |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 224 | || 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 Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 229 | echo ">> Uploading ${SAMPLE_APP_BIN_NAME}" |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 230 | "${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 | |
Ankur | 5dab76d | 2015-01-07 11:06:46 -0800 | [diff] [blame] | 236 | # Start an application server under the blessing "alice/myworkstation/applicationd" so that |
| 237 | # the device ("alice/myworkstation") can talk to it. |
Robin Thellend | 9299b78 | 2015-02-03 08:42:46 -0800 | [diff] [blame] | 238 | mkdir -p "${WORKDIR}/appstore" |
Ankur | 5dab76d | 2015-01-07 11:06:46 -0800 | [diff] [blame] | 239 | shell_test::start_server "${VRUN}" --name=myworkstation/applicationd "${APPLICATIOND_BIN}" --name="${APPLICATIOND_NAME}" \ |
Asim Shankar | f32d24d | 2015-04-01 16:34:26 -0700 | [diff] [blame] | 240 | --store="${WORKDIR}/appstore" --v23.tcp.address=127.0.0.1:0 \ |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 241 | || 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 Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 246 | echo ">> Uploading ${SAMPLE_APP_NAME}" |
Suharsh Sivakumar | 65e3850 | 2015-04-01 18:33:18 -0700 | [diff] [blame] | 247 | 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 Caprita | c25a48c | 2015-02-12 13:45:51 -0800 | [diff] [blame] | 248 | "${APPLICATION_BIN}" put "${SAMPLE_APP_NAME}" "${DEVICE_PROFILE}" ./app.envelope |
| 249 | rm ./app.envelope |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 250 | |
| 251 | # Verify that the envelope we uploaded shows up with glob. |
Bogdan Caprita | 54ae80e | 2015-01-20 13:37:52 -0800 | [diff] [blame] | 252 | shell_test::assert_eq "$("${APPLICATION_BIN}" match "${SAMPLE_APP_NAME}" "${DEVICE_PROFILE}" | grep Title | sed -e 's/^.*"Title": "'// | sed -e 's/",//')" \ |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 253 | "BINARYD" "${LINENO}" |
| 254 | |
Bogdan Caprita | 2b21936 | 2014-12-09 17:03:33 -0800 | [diff] [blame] | 255 | # Install the app on the device. |
Robin Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 256 | echo ">> Installing ${SAMPLE_APP_NAME}" |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 257 | local -r INSTALLATION_NAME=$("${DEVICE_BIN}" install "${MT_NAME}/devmgr/apps" "${SAMPLE_APP_NAME}" | sed -e 's/Successfully installed: "//' | sed -e 's/"//') |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 258 | |
Bogdan Caprita | 2b21936 | 2014-12-09 17:03:33 -0800 | [diff] [blame] | 259 | # Verify that the installation shows up when globbing the device manager. |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 260 | shell_test::assert_eq "$("${NAMESPACE_BIN}" glob "${MT_NAME}/devmgr/apps/BINARYD/*")" \ |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 261 | "${INSTALLATION_NAME}" "${LINENO}" |
| 262 | |
| 263 | # Start an instance of the app, granting it blessing extension myapp. |
Robin Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 264 | echo ">> Starting ${INSTALLATION_NAME}" |
Bogdan Caprita | a456f47 | 2014-12-10 10:18:03 -0800 | [diff] [blame] | 265 | local -r INSTANCE_NAME=$("${DEVICE_BIN}" start "${INSTALLATION_NAME}" myapp | sed -e 's/Successfully started: "//' | sed -e 's/"//') |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 266 | wait_for_mountentry "${NAMESPACE_BIN}" "5" "${MT_NAME}/${APP_PUBLISH_NAME}" |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 267 | |
Bogdan Caprita | 2b21936 | 2014-12-09 17:03:33 -0800 | [diff] [blame] | 268 | # Verify that the instance shows up when globbing the device manager. |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 269 | shell_test::assert_eq "$("${NAMESPACE_BIN}" glob "${MT_NAME}/devmgr/apps/BINARYD/*/*")" "${INSTANCE_NAME}" "${LINENO}" |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 270 | |
Robert Kroeger | 38cc2d8 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 271 | 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 Caprita | c8b29da | 2015-02-26 19:24:08 -0800 | [diff] [blame] | 280 | local -r COMPUTED_SUID_USER=$(awk '/^Uid:/{print $2}' /proc/${PID}/status | \ |
| 281 | xargs getent passwd | awk -F: '{print $1}') |
Robert Kroeger | 38cc2d8 | 2015-02-09 17:54:12 -0800 | [diff] [blame] | 282 | ;; |
| 283 | esac |
| 284 | shell_test::assert_eq "${COMPUTED_SUID_USER}" "${SUID_USER}" "${LINENO}" |
| 285 | fi |
Robert Kroeger | 1697c4a | 2015-01-26 16:37:08 -0800 | [diff] [blame] | 286 | |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 287 | # Verify the app's default blessing. |
Suharsh Sivakumar | 5ca4664 | 2015-01-30 10:33:38 -0800 | [diff] [blame] | 288 | shell_test::assert_contains "$("${DEBUG_BIN}" stats read "${INSTANCE_NAME}/stats/security/principal/*/blessingstore" | head -1)" \ |
| 289 | "Default blessings: alice/myapp/BINARYD" "${LINENO}" |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 290 | |
| 291 | # Stop the instance. |
Robin Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 292 | echo ">> Stopping ${INSTANCE_NAME}" |
Bogdan Caprita | a456f47 | 2014-12-10 10:18:03 -0800 | [diff] [blame] | 293 | "${DEVICE_BIN}" stop "${INSTANCE_NAME}" |
Bogdan Caprita | 4ad0499 | 2014-12-04 21:56:23 -0800 | [diff] [blame] | 294 | |
| 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 Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 299 | # 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 Caprita | c25a48c | 2015-02-12 13:45:51 -0800 | [diff] [blame] | 306 | 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 Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 309 | # Update the device manager. |
| 310 | echo ">> Updating device manager" |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 311 | "${DEVICE_BIN}" update "${MT_NAME}/devmgr/device" |
| 312 | MT_EP=$(wait_for_mountentry "${NAMESPACE_BIN}" 5 "${MT_NAME}" "${MT_EP}") |
Robin Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 313 | |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 314 | # 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 Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 317 | |
| 318 | # Revert the device manager. |
| 319 | echo ">> Reverting device manager" |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 320 | "${DEVICE_BIN}" revert "${MT_NAME}/devmgr/device" |
| 321 | MT_EP=$(wait_for_mountentry "${NAMESPACE_BIN}" 5 "${MT_NAME}" "${MT_EP}") |
Robin Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 322 | |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 323 | # 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 Thellend | f9385c6 | 2015-01-29 14:00:06 -0800 | [diff] [blame] | 326 | |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 327 | # 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 Shankar | 59b8b69 | 2015-03-30 01:23:36 -0700 | [diff] [blame] | 330 | shell_test::assert_eq $("${NAMESPACE_BIN}" resolve "${MT_EP}/global") "[alice/myworkstation]${V23_NAMESPACE}" "${LINENO}" |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 331 | 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 Caprita | 4ea9b03 | 2014-12-27 14:56:51 -0800 | [diff] [blame] | 336 | |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 337 | # Stop the device manager. |
| 338 | "${DEVICE_SCRIPT}" stop |
Robin Thellend | acaa432 | 2015-02-05 11:00:28 -0800 | [diff] [blame] | 339 | wait_for_no_mountentry "${NAMESPACE_BIN}" "5" "${MT_NAME}" |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 340 | |
Bogdan Caprita | c7e72b6 | 2015-01-07 19:22:23 -0800 | [diff] [blame] | 341 | "${DEVICE_SCRIPT}" uninstall |
Bogdan Caprita | d7b3047 | 2015-04-01 17:04:12 -0700 | [diff] [blame] | 342 | if [[ -n "$(ls -A "${V23_DEVICE_DIR}" 2>/dev/null)" ]]; then |
| 343 | shell_test::fail "${V23_DEVICE_DIR} is not empty" |
Bogdan Caprita | a40d338 | 2014-12-19 16:30:26 -0800 | [diff] [blame] | 344 | fi |
Bogdan Caprita | c98a8b5 | 2014-12-01 10:08:47 -0800 | [diff] [blame] | 345 | shell_test::pass |
| 346 | } |
| 347 | |
| 348 | main "$@" |