Skip to content

Commit 0017c14

Browse files
committed
Merge remote-tracking branch 'origin/main' into column-casing-hints
2 parents 0c7ec2c + da11b86 commit 0017c14

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

.github/workflows/sf_cli_integration.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ jobs:
1717
- name: Checkout code
1818
uses: actions/checkout@v4
1919

20+
- name: Set mock server TLS cert paths
21+
run: |
22+
echo "MOCK_SF_CERT_FILE=$RUNNER_TEMP/mock_sf_cert.pem" >> "$GITHUB_ENV"
23+
echo "MOCK_SF_KEY_FILE=$RUNNER_TEMP/mock_sf_key.pem" >> "$GITHUB_ENV"
24+
25+
- name: Generate mock server TLS cert
26+
run: |
27+
openssl req -x509 -newkey rsa:2048 -nodes \
28+
-keyout "$MOCK_SF_KEY_FILE" -out "$MOCK_SF_CERT_FILE" \
29+
-days 1 -subj "/CN=localhost" \
30+
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
31+
2032
- name: Set up Python 3.11
2133
uses: actions/setup-python@v5
2234
with:
@@ -73,7 +85,7 @@ jobs:
7385
sfdx_dir.mkdir(exist_ok=True)
7486
auth = {
7587
"accessToken": "00D000000000001AAA!fakeTokenForCITesting",
76-
"instanceUrl": "http://localhost:8888",
88+
"instanceUrl": "https://localhost:8888",
7789
"loginUrl": "https://login.salesforce.com",
7890
"orgId": "00D000000000001AAA",
7991
"userId": "005000000000001AAA",
@@ -164,6 +176,9 @@ jobs:
164176
# ── Script: run ───────────────────────────────────────────────────────────
165177

166178
- name: '[script] run — sf data-code-extension script run --entrypoint testScript/payload/entrypoint.py -o dev1'
179+
env:
180+
NODE_EXTRA_CA_CERTS: ${{ env.MOCK_SF_CERT_FILE }}
181+
REQUESTS_CA_BUNDLE: ${{ env.MOCK_SF_CERT_FILE }}
167182
run: |
168183
sf data-code-extension script run \
169184
--entrypoint testScript/payload/entrypoint.py \
@@ -175,6 +190,9 @@ jobs:
175190
# ── Script: deploy ───────────────────────────────────────────────────────
176191

177192
- name: '[script] deploy — sf data-code-extension script deploy'
193+
env:
194+
NODE_EXTRA_CA_CERTS: ${{ env.MOCK_SF_CERT_FILE }}
195+
REQUESTS_CA_BUNDLE: ${{ env.MOCK_SF_CERT_FILE }}
178196
run: |
179197
sf data-code-extension script deploy \
180198
--name test-script-deploy \
@@ -262,6 +280,9 @@ jobs:
262280
# ── Function: run ─────────────────────────────────────────────────────────
263281

264282
- name: '[function] run — sf data-code-extension function run --entrypoint testFunction/payload/entrypoint.py --test-with testFunction/payload/tests/test.json -o dev1'
283+
env:
284+
NODE_EXTRA_CA_CERTS: ${{ env.MOCK_SF_CERT_FILE }}
285+
REQUESTS_CA_BUNDLE: ${{ env.MOCK_SF_CERT_FILE }}
265286
run: |
266287
sf data-code-extension function run \
267288
--entrypoint testFunction/payload/entrypoint.py \
@@ -273,6 +294,9 @@ jobs:
273294
# ── Function: deploy ─────────────────────────────────────────────────────
274295

275296
- name: '[function] deploy — sf data-code-extension function deploy'
297+
env:
298+
NODE_EXTRA_CA_CERTS: ${{ env.MOCK_SF_CERT_FILE }}
299+
REQUESTS_CA_BUNDLE: ${{ env.MOCK_SF_CERT_FILE }}
276300
run: |
277301
sf data-code-extension function deploy \
278302
--name test-function-deploy \

scripts/mock_sf_server.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,25 @@
4040
python scripts/mock_sf_server.py # listens on port 8888
4141
MOCK_SF_PORT=9000 python scripts/mock_sf_server.py
4242
python scripts/mock_sf_server.py 9000
43+
44+
Serves TLS (the deploy path requires an HTTPS upload URL) using a pre-generated
45+
cert/key pair — this script does not generate one. Set ``MOCK_SF_CERT_FILE`` /
46+
``MOCK_SF_KEY_FILE`` to the pair's paths; generate a throwaway one with:
47+
48+
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem \\
49+
-days 1 -subj "/CN=localhost" \\
50+
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
51+
52+
Point clients at the cert so they trust it: ``NODE_EXTRA_CA_CERTS`` (CLI) and
53+
``REQUESTS_CA_BUNDLE`` (SDK).
4354
"""
4455

4556
from __future__ import annotations
4657

4758
from http.server import BaseHTTPRequestHandler, HTTPServer
4859
import json
4960
import os
61+
import ssl
5062
import sys
5163

5264
PORT = (
@@ -68,7 +80,7 @@
6880

6981
_TOKEN_RESPONSE = {
7082
"access_token": "00D000000000001AAA!fakeAccessTokenForCITesting",
71-
"instance_url": f"http://localhost:{PORT}",
83+
"instance_url": f"https://localhost:{PORT}",
7284
"token_type": "Bearer",
7385
"scope": "api",
7486
}
@@ -135,7 +147,9 @@ def do_POST(self) -> None:
135147
elif path == _DATA_CUSTOM_CODE_PATH:
136148
# create_deployment() — return a presigned upload URL
137149
self._send_json(
138-
{"fileUploadUrl": f"http://localhost:{PORT}/upload/fake-deployment.zip"}
150+
{
151+
"fileUploadUrl": f"https://localhost:{PORT}/upload/fake-deployment.zip"
152+
}
139153
)
140154
elif path == _DATA_TRANSFORMS_PATH:
141155
# create_data_transform() — script packages only
@@ -150,7 +164,18 @@ def do_PUT(self) -> None:
150164

151165

152166
if __name__ == "__main__":
167+
cert_path = os.environ.get("MOCK_SF_CERT_FILE")
168+
key_path = os.environ.get("MOCK_SF_KEY_FILE")
169+
if not cert_path or not key_path:
170+
sys.exit(
171+
"MOCK_SF_CERT_FILE and MOCK_SF_KEY_FILE must both be set to an "
172+
"existing TLS cert/key pair — see the module docstring."
173+
)
174+
153175
server = HTTPServer(("localhost", PORT), MockSFHandler)
154176
server.allow_reuse_address = True
155-
print(f"[MOCK SF] Listening on http://localhost:{PORT}", flush=True)
177+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
178+
ctx.load_cert_chain(cert_path, key_path)
179+
server.socket = ctx.wrap_socket(server.socket, server_side=True)
180+
print(f"[MOCK SF] Listening on https://localhost:{PORT}", flush=True)
156181
server.serve_forever()

0 commit comments

Comments
 (0)