[e2e] Enable CORS for CouchDB in CI (#5702)

This commit is contained in:
Jesse Mazzella 2022-08-25 12:19:37 -07:00 committed by GitHub
parent 0f12aa1eae
commit e3770dc701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,6 +83,18 @@ create_admin_user () {
curl -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/admins/$COUCH_ADMIN_USER -d \'"$COUCH_ADMIN_PASSWORD"\'
}
is_cors_enabled() {
resource_exists $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/httpd/enable_cors
}
enable_cors () {
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/httpd/enable_cors -d '"true"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/origins -d '"http://localhost:8080"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/credentials -d '"true"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/headers -d '"accept, authorization, content-type, origin, referer, x-csrf-token"'
}
if [ "$(admin_user_exists)" == "FALSE" ]; then
echo "Admin user does not exist, creating..."
create_admin_user
@ -123,3 +135,10 @@ if [ "{\"ok\":true}" == "${response}" ]; then
else
echo "Database permissions not updated"
fi
if [ "FALSE" == $(is_cors_enabled) ]; then
echo "Enabling CORS"
enable_cors
else
echo "CORS enabled, nothing to do"
fi