Skip to content

Commit

Permalink
fix: test: pass proper db url to testing
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Murdaca <[email protected]>

fix: yet another db url fix in tests

Signed-off-by: Antonio Murdaca <[email protected]>

fix: is it selinux?

Signed-off-by: Antonio Murdaca <[email protected]>
  • Loading branch information
runcom committed Aug 15, 2024
1 parent 64b3b1b commit afb76ec
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions test/fmf/tests/onboarding/run-onboarding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ STORES_DIR="${CONF_DIR}/stores"
MIGRATIONS_BASE_DIR=/usr/share/doc/fdo/migrations/
PRIMARY_IP=$(hostname -I | cut -f 1 -d ' ')
DEVICE_CREDENTIAL=/etc/device-credentials
ONBOARDIG_PERFORMED=/etc/device_onboarding_performed
ONBOARDING_PERFORMED=/etc/device_onboarding_performed

OWNER_DATABASE="owner_onboarding"
MANUFACTURER_DATABASE="manufacturing"
Expand All @@ -25,6 +25,9 @@ DATABASE_DIR=/var/lib/fdo
DATABASE_USER="fdo"
DATABASE_PASSWORD="redhat"

[ "$DATABASE_DRIVER" != "postgresql" ] || DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_USER}:${DATABASE_PASSWORD}@127.0.0.1/fdo"
[ "$DATABASE_DRIVER" != "sqlite" ] || DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_DIR}/fido-device-onboard.db"

generate_keys() {
ORGANIZATION="Red Hat"
COUNTRY="US"
Expand All @@ -47,43 +50,25 @@ setup_postgresql() {
su - postgres -c "dropuser -e --if-exists ${DATABASE_USER}"
su - postgres -c "createuser -e ${DATABASE_USER}"
su - postgres -c "psql -e -c \"ALTER USER ${DATABASE_USER} WITH PASSWORD '${DATABASE_PASSWORD}'\""
su - postgres -c "dropdb -e --if-exists fdo"
su - postgres -c "createdb -e -O ${DATABASE_USER} fdo"
for DATABASE in ${DATABASES}; do
su - postgres -c "dropdb -e --if-exists ${DATABASE}"
su - postgres -c "createdb -e -O ${DATABASE_USER} ${DATABASE}"
su - postgres -c "PGPASSWORD=${DATABASE_PASSWORD} psql --host 127.0.0.1 --username ${DATABASE_USER} --echo-queries $DATABASE < ${MIGRATIONS_BASE_DIR}/migrations_${DATABASE}_server_postgres/up.sql"
su - postgres -c "PGPASSWORD=${DATABASE_PASSWORD} psql --host 127.0.0.1 --username ${DATABASE_USER} --echo-queries fdo < ${MIGRATIONS_BASE_DIR}/migrations_${DATABASE}_server_postgres/up.sql"
done
}

setup_sqlite() {
mkdir -p ${DATABASE_DIR}
DATABASE_FILE="${DATABASE_DIR}/fido-device-onboard.db"
> ${DATABASE_FILE}
for DATABASE in ${DATABASES}; do
DATABASE_FILE="${DATABASE_DIR}/${DATABASE}.db"
> ${DATABASE_FILE}
sqlite3 ${DATABASE_FILE} < "${MIGRATIONS_BASE_DIR}/migrations_${DATABASE}_server_sqlite/up.sql"
done
}

setup_systemd() {
for DATABASE in ${DATABASES}; do
SYSTEMD_OVERWRITE_DIR=/etc/systemd/system/fdo-${DATABASE/_/-}-server.service.d/
rm -rf "$SYSTEMD_OVERWRITE_DIR}"
if [ "${OV_STORE_DRIVER}" != "Directory" ]; then
mkdir -p "${SYSTEMD_OVERWRITE_DIR}"
DATABASE_ENV_VAR="$(tr [:lower:] [:upper:] <<<${OV_STORE_DRIVER})_$(tr [:lower:] [:upper:] <<<$DATABASE |sed -e 's|MANUFACTURING|MANUFACTURER|' -e 's|OWNER_ONBOARDING|OWNER|')_DATABASE_URL"
[ "$DATABASE_DRIVER" != "postgresql" ] || DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_USER}:${DATABASE_PASSWORD}@127.0.0.1/${DATABASE}"
[ "$DATABASE_DRIVER" != "sqlite" ] || DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_DIR}/${DATABASE}.db"
tee "$SYSTEMD_OVERWRITE_DIR/override.conf" <<EOF
[Service]
Environment=${DATABASE_ENV_VAR}=${DATABASE_URL}
EOF
fi
done
systemctl daemon-reload
}

setup_manufacturing() {
[ "${OV_STORE_DRIVER}" != "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n path: ${STORES_DIR}/owner_vouchers")
[ "${OV_STORE_DRIVER}" = "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n Manufacturer")
[ "${OV_STORE_DRIVER}" = "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n server: Manufacturer\n url: ${DATABASE_URL}")
tee "${CONF_DIR}/manufacturing-server.yml" <<EOF
---
session_store_driver:
Expand Down Expand Up @@ -121,7 +106,7 @@ EOF

setup_owner() {
[ "${OV_STORE_DRIVER}" != "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n path: ${STORES_DIR}/owner_vouchers")
[ "${OV_STORE_DRIVER}" = "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n Owner")
[ "${OV_STORE_DRIVER}" = "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n server: Owner\n url: ${DATABASE_URL}")
tee "${CONF_DIR}/owner-onboarding-server.yml" <<EOF
---
ownership_voucher_store_driver:
Expand Down Expand Up @@ -149,7 +134,7 @@ EOF

setup_rendezvous() {
[ "${OV_STORE_DRIVER}" != "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n path: ${STORES_DIR}/rendezvous_registered")
[ "${OV_STORE_DRIVER}" = "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n Rendezvous")
[ "${OV_STORE_DRIVER}" = "Directory" ] || OV_STORE_DRIVER_CONF=$(echo -e "${OV_STORE_DRIVER}:\n server: Rendezvous\n url: ${DATABASE_URL}")
tee "${CONF_DIR}/rendezvous-server.yml" <<EOF
---
storage_driver:
Expand Down Expand Up @@ -187,16 +172,12 @@ export_import_vouchers() {
MANUFACTURER_EXPORT_DIR="${STORES_DIR}/manufacturer_export_dir"
rm -rf "${MANUFACTURER_EXPORT_DIR}"
mkdir -p "${MANUFACTURER_EXPORT_DIR}"
[ "$DATABASE_DRIVER" != "postgresql" ] || MANUFACTURER_DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_USER}:${DATABASE_PASSWORD}@127.0.0.1/${MANUFACTURER_DATABASE}"
[ "$DATABASE_DRIVER" != "postgresql" ] || OWNER_DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_USER}:${DATABASE_PASSWORD}@127.0.0.1/${OWNER_DATABASE}"
[ "$DATABASE_DRIVER" != "sqlite" ] || MANUFACTURER_DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_DIR}/${MANUFACTURER_DATABASE}.db"
[ "$DATABASE_DRIVER" != "sqlite" ] || OWNER_DATABASE_URL="${DATABASE_DRIVER}://${DATABASE_DIR}/${OWNER_DATABASE}.db"
fdo-owner-tool export-manufacturer-vouchers "$(tr [:upper:] [:lower:] <<< ${OV_STORE_DRIVER})" "${MANUFACTURER_DATABASE_URL}" "${MANUFACTURER_EXPORT_DIR}"
fdo-owner-tool import-ownership-vouchers "$(tr [:upper:] [:lower:] <<< ${OV_STORE_DRIVER})" "${OWNER_DATABASE_URL}" "${MANUFACTURER_EXPORT_DIR}"
fdo-owner-tool export-manufacturer-vouchers "$(tr [:upper:] [:lower:] <<< ${OV_STORE_DRIVER})" "${DATABASE_URL}" "${MANUFACTURER_EXPORT_DIR}"
fdo-owner-tool import-ownership-vouchers "$(tr [:upper:] [:lower:] <<< ${OV_STORE_DRIVER})" "${DATABASE_URL}" "${MANUFACTURER_EXPORT_DIR}"
}

perform_no_plain_di() {
rm -f "${DEVICE_CREDENTIAL}" "${ONBOARDIG_PERFORMED}"
rm -f "${DEVICE_CREDENTIAL}" "${ONBOARDING_PERFORMED}"
/usr/libexec/fdo/fdo-manufacturing-client no-plain-di \
--manufacturing-server-url http://${PRIMARY_IP}:8080 \
--rootcerts ${KEYS_DIR}/diun_cert.pem
Expand Down Expand Up @@ -258,12 +239,13 @@ EOF
[ "${OV_STORE_DRIVER}" != "Postgres" ] || setup_postgresql
fix_selinux_policies
generate_keys
setup_systemd
setup_manufacturing
setup_owner
setup_rendezvous
setup_serviceinfo
systemctl restart fdo-{manufacturing,owner-onboarding,rendezvous,serviceinfo-api}-server.service
systemctl status fdo-{manufacturing,owner-onboarding,rendezvous,serviceinfo-api}-server.service
sudo setenforce 0
perform_no_plain_di
[ "${OV_STORE_DRIVER}" = "Directory" ] || export_import_vouchers
sleep 60
Expand Down

0 comments on commit afb76ec

Please sign in to comment.