Skip to content
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ yarn.lock
.DS_Store
.idea
*.iml
*.tgz
scripts/*.json

lib/
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ node_js:
sudo: false
after_script:
- nyc report --reporter=text-lcov | coveralls
jobs:
include:
- stage: hosting functional test
node_js: '6'
before_script: ./scripts/decrypt-app-credentials.sh
script: ./scripts/test-hosting.sh
after_script: skip
cache:
directories:
- node_modules
Binary file added scripts/creds-private.json.enc
Binary file not shown.
Binary file added scripts/creds-public.json.enc
Binary file not shown.
18 changes: 18 additions & 0 deletions scripts/decrypt-app-credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e

openssl aes-256-cbc \
-K $encrypted_830857fa25dd_key \
-iv $encrypted_830857fa25dd_iv \
-in scripts/creds-public.json.enc \
-out scripts/creds-public.json \
-d || true

openssl aes-256-cbc \
-K $encrypted_830857fa25dd_key \
-iv $encrypted_830857fa25dd_iv \
-in scripts/creds-private.json.enc \
-out scripts/creds-private.json \
-d || true

test -f scripts/creds-public.json || test -f scripts/creds-private.json || (echo "No Credentials Decrypted" && false)
78 changes: 78 additions & 0 deletions scripts/test-hosting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
set -e

if [ "${TRAVIS}" != "true" ]; then
TRAVIS_COMMIT="localtesting"
TRAVIS_JOB_ID="$(echo $RANDOM)"
TRAVIS_REPO_SLUG="firebase/firebase-tools"
fi

CWD="$(pwd)"
TARGET_FILE="${TRAVIS_COMMIT}-${TRAVIS_JOB_ID}.txt"

GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-private.json"
if [ "${TRAVIS_REPO_SLUG}" == "firebase/firebase-tools" ]; then
GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-public.json"
fi
export GOOGLE_APPLICATION_CREDENTIALS

echo "Running in ${CWD}"
echo "Running with node: $(which node)"
echo "Running with npm: $(which npm)"
echo "Running with Application Creds: ${GOOGLE_APPLICATION_CREDENTIALS}"

echo "Target project: ${FBTOOLS_TARGET_PROJECT}"

echo "Initalizing some variables..."
DATE="$(date)"
echo "Variables initalized..."

echo "Creating temp directory..."
TEMP_DIR="$(mktemp -d)"
echo "Created temp directory: ${TEMP_DIR}"

echo "Building and packaging firebase-tools..."
npm pack
FBT_PACKAGE="$(pwd)/$(ls *.tgz)"
echo "Built and packaged firebase-tools: ${FBT_PACKAGE}"

echo "Installing firebase-tools..."
npm install --global "${FBT_PACKAGE}"
echo "Installed firebase-tools: $(which firebase)"

echo "Initalizing temp directory..."
cd "${TEMP_DIR}"
cat > "firebase.json" <<- EOM
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
EOM
mkdir "public"
touch "public/${TARGET_FILE}"
echo "${DATE}" > "public/${TARGET_FILE}"
echo "Initalized temp directory."

echo "Testing local serve..."
PORT=8685
firebase serve --only hosting --project "${FBTOOLS_TARGET_PROJECT}" --port "${PORT}" &
PID="$!"
sleep 5
VALUE="$(curl localhost:${PORT}/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
kill "$PID"
wait
echo "Tested local serve."

echo "Testing hosting deployment..."
firebase deploy --only hosting --project "${FBTOOLS_TARGET_PROJECT}"
sleep 5
VALUE="$(curl https://${FBTOOLS_TARGET_PROJECT}.firebaseapp.com/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting deployment."
3 changes: 3 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ var api = {
setAccessToken: function(token) {
accessToken = token;
},
getScopes: function() {
return commandScopes;
},
setScopes: function(s) {
commandScopes = _.uniq(
_.flatten(
Expand Down
6 changes: 3 additions & 3 deletions src/requireAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ function _autoAuth(options, authScopes) {
});
}

module.exports = function(options, authScopes) {
module.exports = function(options) {
api.setScopes([scopes.CLOUD_PLATFORM, scopes.FIREBASE_PLATFORM]);
options.authScopes = api.commandScopes;
options.authScopes = api.getScopes();

var tokens = configstore.get("tokens");
var user = configstore.get("user");
Expand All @@ -48,7 +48,7 @@ module.exports = function(options, authScopes) {
} else if (user) {
logger.debug("> authorizing via signed-in user");
} else {
return _autoAuth(options, authScopes);
return _autoAuth(options, options.authScopes);
}

tokenOpt = tokenOpt || process.env.FIREBASE_TOKEN;
Expand Down