#!/usr/bin/env bash set -eo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" TACHYON_LIB="$ROOT_DIR/tachyon/files/usr/lib" WORK_DIR="$(mktemp -d)" cleanup() { rm -rf "$WORK_DIR" } trap cleanup EXIT fail() { printf 'FAIL: %s\n' "$1" >&2 exit 1 } # Canonical serialized secret for key 367a189aee18fa31c190054efd4a8e95 with # faketls host google.com. CANONICAL='ee367a189aee18fa31c190054efd4a8e95676f6f676c652e636f6d' fixture_with_secret() { cat >"$WORK_DIR/mtproto_fixture.json" <"$WORK_DIR/validate_secret.uc" <<'UC' let common = require("core.common"); let secret = ARGV[1]; printf("%s", common.mtproto_secret_canonical(secret, "google.com") == null ? "invalid" : "valid"); UC [ "$(ucode -L "$TACHYON_LIB" "$WORK_DIR/validate_secret.uc" x "$CANONICAL")" = "valid" ] || fail "validator helper must accept the canonical hex secret" [ "$(ucode -L "$TACHYON_LIB" "$WORK_DIR/validate_secret.uc" x '7jZ6GJruGPoxwZAFTv1KjpVnb29nbGUuY29t')" = "valid" ] || fail "validator helper must accept the base64 form of the secret" [ "$(ucode -L "$TACHYON_LIB" "$WORK_DIR/validate_secret.uc" x 'not a real secret')" = "invalid" ] || fail "validator helper must reject unparseable secrets" [ "$(ucode -L "$TACHYON_LIB" "$WORK_DIR/validate_secret.uc" x '')" = "invalid" ] || fail "validator helper must reject an empty secret" printf 'MTProto server configuration checks passed\n'