gnodet-bot commented on code in PR #31163:
URL: https://github.com/apache/camel/pull/31163#discussion_r4752028387
##########
components/camel-salesforce/camel-salesforce-component/pom.xml:
##########
@@ -401,12 +401,12 @@
${salesforce.component.root}/it/resources/salesforce-source]]></message>
<argument>setup-salesforce.sh</argument>
</arguments>
<environmentVariables>
-
<SALESFORCE_USERNAME>${env.SALESFORCE_USERNAME}</SALESFORCE_USERNAME>
-
<SALESFORCE_PASSWORD>${env.SALESFORCE_PASSWORD}</SALESFORCE_PASSWORD>
-
<SALESFORCE_LOGIN_URL>${env.SALESFORCE_LOGIN_URL}</SALESFORCE_LOGIN_URL>
<SALESFORCE_DEV_HUB>${env.SALESFORCE_DEV_HUB}</SALESFORCE_DEV_HUB>
<SALESFORCE_DEPLOY_SOURCE>${env.SALESFORCE_DEPLOY_SOURCE}</SALESFORCE_DEPLOY_SOURCE>
<SALESFORCE_SCRATCH_ORG_DURATION>${env.SALESFORCE_SCRATCH_ORG_DURATION}</SALESFORCE_SCRATCH_ORG_DURATION>
+ <!-- -D options reach the tests as
system properties, the script checks them -->
+
<MAVEN_SALESFORCE_PASSWORD>${salesforce.password}</MAVEN_SALESFORCE_PASSWORD>
+
<MAVEN_SALESFORCE_AUTH_TYPE>${salesforce.auth.type}</MAVEN_SALESFORCE_AUTH_TYPE>
Review Comment:
**Bug — undefined Maven property passes literal string to env var**
`${salesforce.password}` and `${salesforce.auth.type}` are not declared in
`<properties>`. When the user does **not** pass `-Dsalesforce.password=…`,
Maven leaves the expression unresolved and the env var
`MAVEN_SALESFORCE_PASSWORD` is set to the **literal string**
`${salesforce.password}`.
In the shell script, `has_login_setting` checks `[ -n "$maven_value" ]` —
that literal string is non-empty, so `HAS_PASSWORD` is always `true` when run
from Maven. If the org has a refresh token,
`fail_on_password_with_refresh_token` then fails the build:
```
ERROR: A Salesforce password is set as well as the refresh token…
```
Fix: declare empty defaults so Maven resolves to empty when no `-D` is
provided.
```suggestion
<!-- -D options reach the tests as
system properties, the script checks them -->
<MAVEN_SALESFORCE_PASSWORD>${env.MAVEN_SALESFORCE_PASSWORD}</MAVEN_SALESFORCE_PASSWORD>
<MAVEN_SALESFORCE_AUTH_TYPE>${env.MAVEN_SALESFORCE_AUTH_TYPE}</MAVEN_SALESFORCE_AUTH_TYPE>
```
Alternatively, add to the `<properties>` block of the `integration` profile:
```xml
<salesforce.password></salesforce.password>
<salesforce.auth.type></salesforce.auth.type>
```
Both approaches resolve to empty when the user hasn't set anything.
##########
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:
**Minor — heredoc JSON is not safe for arbitrary values**
`$ORG_USERNAME` (an email) and `$INSTANCE_URL` (a URL) are injected into the
heredoc without JSON escaping. If a value ever contained a `"` or `\`, the JSON
would be malformed. In practice these are always clean values (email address,
HTTPS URL, base64url tokens), so this is not a real-world risk today — but `jq
-n` would make it bulletproof for free:
```bash
jq -n \
--arg cid "${CLIENT_ID:-PlatformCLI}" \
--arg cs "$CLIENT_SECRET" \
--arg rt "$REFRESH_TOKEN" \
--arg user "$ORG_USERNAME" \
--arg url "$INSTANCE_URL" \
'{clientId:$cid, clientSecret:$cs, refreshToken:$rt, username:$user,
instanceUrl:$url}' \
> "$CREDENTIALS_FILE"
```
Since `jq` is already a prerequisite this adds no new dependency.
--
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]