jamesnetherton commented on code in PR #31163:
URL: https://github.com/apache/camel/pull/31163#discussion_r4752238450
##########
components/camel-salesforce/it/resources/setup-salesforce.sh:
##########
@@ -231,35 +170,50 @@ fi
# Get org information including refresh token
echo ""
echo "Retrieving org information..."
-ORG_INFO=$(sf org display --verbose --json)
+ORG_INFO=$(sf org display --json)
INSTANCE_URL=$(echo "$ORG_INFO" | jq -r '.result.instanceUrl')
ORG_USERNAME=$(echo "$ORG_INFO" | jq -r '.result.username')
-SFDX_AUTH_URL=$(echo "$ORG_INFO" | jq -r '.result.sfdxAuthUrl // empty')
-# Extract refresh token from sfdxAuthUrl (format:
force://clientId::refreshToken@instanceUrl)
-if [ -n "$SFDX_AUTH_URL" ]; then
- REFRESH_TOKEN=$(echo "$SFDX_AUTH_URL" | sed -n
's|force://[^:]*::\([^@]*\)@.*|\1|p')
+# sf org display redacts the auth URL, whose format is
force://clientId:clientSecret:refreshToken@instanceUrl
+SFDX_AUTH_URL=$(sf org auth show-sfdx-auth-url --json | jq -r
'.result.sfdxAuthUrl // empty')
+CLIENT_ID=$(echo "$SFDX_AUTH_URL" | sed -n 's|force://\([^:]*\):.*|\1|p')
+CLIENT_SECRET=$(echo "$SFDX_AUTH_URL" | sed -n
's|force://[^:]*:\([^:]*\):.*|\1|p')
+REFRESH_TOKEN=$(echo "$SFDX_AUTH_URL" | sed -n
's|force://[^:]*:[^:]*:\([^@]*\)@.*|\1|p')
+
+if [ -z "$REFRESH_TOKEN" ]; then
+ if [ -n "$HAS_PASSWORD" ] || [ -n "$SALESFORCE_REFRESH_TOKEN" ] || [ -n
"$SALESFORCE_KEYSTORE_RESOURCE" ] || [ -f "$LOGIN_PROPERTIES" ]; then
+ echo "WARNING: No refresh token for $ORG_USERNAME, the tests must get
their credentials elsewhere"
+ else
+ echo "ERROR: Could not get a refresh token for $ORG_USERNAME"
+ echo "It is only available for orgs authenticated with a web-based
OAuth flow, such as scratch orgs."
+ exit 1
+ fi
+else
+ fail_on_password_with_refresh_token
fi
echo "✓ Instance URL: $INSTANCE_URL"
echo "✓ Username: $ORG_USERNAME"
-if [ -n "$REFRESH_TOKEN" ]; then
- echo "✓ Refresh token available"
-fi
# Store credentials for integration tests
-# Using refresh token flow with PlatformCLI (SF CLI's built-in connected app)
+# Using refresh token flow with the app the org was logged in with, by default
PlatformCLI (SF CLI's built-in connected app)
CREDENTIALS_FILE="$PROJECT_DIR/.local/test-credentials.json"
-# Ensure .local directory exists
+# Only the user may read the credentials; chmod as well, as rewriting a file
keeps its permissions
mkdir -p "$PROJECT_DIR/.local"
+chmod 700 "$PROJECT_DIR/.local"
echo ""
echo "Storing credentials for integration tests..."
+umask 077
+touch "$CREDENTIALS_FILE"
+chmod 600 "$CREDENTIALS_FILE"
cat > "$CREDENTIALS_FILE" << EOF
{
- "clientId": "PlatformCLI",
- "refreshToken": "${REFRESH_TOKEN:-}",
+ "clientId": "${CLIENT_ID:-PlatformCLI}",
+ "clientSecret": "$CLIENT_SECRET",
+ "refreshToken": "$REFRESH_TOKEN",
Review Comment:
Done, the credentials file is now written with `jq -n`. The values go to
`jq` through its environment rather than `--arg`, so the refresh token and
client secret do not appear on the command line, where other users of the
machine could see them with `ps`.
_Claude Code on behalf of jamesnetherton_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]