codewhale 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/codewhale-notices/LICENSE +21 -0
- package/codewhale-notices/THIRD_PARTY_NOTICES.md +1011 -0
- package/codewhale-notices/docs/THIRD_PARTY_NOTICES.md +66 -0
- package/package.json +4 -3
- package/scripts/artifacts.js +128 -17
- package/scripts/install.js +37 -11
- package/scripts/verify-release-assets.js +102 -126
- package/test/artifacts.test.js +73 -10
- package/test/install.test.js +58 -0
- package/test/release-assets.test.js +65 -0
- package/test/source-selection.test.js +14 -1
|
@@ -8,8 +8,10 @@ const {
|
|
|
8
8
|
checksumManifestUrl,
|
|
9
9
|
CNB_BINARY_ASSET_NAMES,
|
|
10
10
|
CNB_RELEASE_ASSET_NAMES,
|
|
11
|
+
redactUrl,
|
|
11
12
|
releaseAssetUrl,
|
|
12
13
|
usesCnbMirror,
|
|
14
|
+
validateReleaseUrl,
|
|
13
15
|
} = require("./artifacts");
|
|
14
16
|
|
|
15
17
|
const pkg = require("../package.json");
|
|
@@ -76,12 +78,13 @@ const limits = {
|
|
|
76
78
|
// Reject first, then tear the request down: an error passed to `destroy()` can
|
|
77
79
|
// surface on an emitter nobody listens to once a response has started.
|
|
78
80
|
function armTotalTimeout(req, url, reject) {
|
|
81
|
+
const safeUrl = redactUrl(url);
|
|
79
82
|
const fail = (error) => {
|
|
80
83
|
reject(error);
|
|
81
84
|
req.destroy();
|
|
82
85
|
};
|
|
83
86
|
const timer = setTimeout(
|
|
84
|
-
() => fail(new Error(`Request exceeded ${limits.totalMs} ms: ${
|
|
87
|
+
() => fail(new Error(`Request exceeded ${limits.totalMs} ms: ${safeUrl}`)),
|
|
85
88
|
limits.totalMs,
|
|
86
89
|
);
|
|
87
90
|
timer.unref();
|
|
@@ -89,161 +92,134 @@ function armTotalTimeout(req, url, reject) {
|
|
|
89
92
|
req.on("close", clear);
|
|
90
93
|
req.on("error", clear);
|
|
91
94
|
req.on("timeout", () =>
|
|
92
|
-
fail(new Error(`Request timed out after ${limits.idleMs} ms without data: ${
|
|
95
|
+
fail(new Error(`Request timed out after ${limits.idleMs} ms without data: ${safeUrl}`)),
|
|
93
96
|
);
|
|
94
97
|
return { clear, fail };
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
function requestRelease(url, options = {}, redirects = 0) {
|
|
101
|
+
const method = options.method || "GET";
|
|
102
|
+
const readBody = Boolean(options.readBody);
|
|
103
|
+
const maxRedirects = options.maxRedirects == null ? 10 : options.maxRedirects;
|
|
104
|
+
const safeUrl = redactUrl(url);
|
|
105
|
+
if (redirects > maxRedirects) {
|
|
106
|
+
return Promise.reject(new Error(`Too many redirects while requesting ${safeUrl}`));
|
|
107
|
+
}
|
|
108
|
+
let parsedUrl;
|
|
109
|
+
try {
|
|
110
|
+
parsedUrl = validateReleaseUrl(url);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
return Promise.reject(err);
|
|
113
|
+
}
|
|
114
|
+
const client = parsedUrl.protocol === "https:" ? https : http;
|
|
115
|
+
const headers = {
|
|
116
|
+
...(options.headers || {}),
|
|
117
|
+
"User-Agent": "codewhale-npm-release-check",
|
|
118
|
+
};
|
|
119
|
+
if (options.attachGitHubToken) {
|
|
120
|
+
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
121
|
+
if (token && parsedUrl.origin === "https://api.github.com") {
|
|
122
|
+
headers.Authorization = `Bearer ${token}`;
|
|
123
|
+
}
|
|
100
124
|
}
|
|
101
|
-
const client = url.startsWith("https:") ? https : http;
|
|
102
125
|
return new Promise((resolve, reject) => {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
timeout: limits.idleMs,
|
|
108
|
-
headers: {
|
|
109
|
-
"User-Agent": "codewhale-npm-release-check",
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
(res) => {
|
|
113
|
-
const status = res.statusCode || 0;
|
|
114
|
-
const location = res.headers.location;
|
|
126
|
+
const onResponse = (res) => {
|
|
127
|
+
const status = res.statusCode || 0;
|
|
128
|
+
const location = res.headers && res.headers.location;
|
|
129
|
+
if (status >= 300 && status < 400 && location) {
|
|
115
130
|
res.resume();
|
|
116
131
|
clear();
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
let next;
|
|
133
|
+
try {
|
|
134
|
+
next = new URL(location, url).toString();
|
|
135
|
+
} catch (err) {
|
|
136
|
+
reject(new Error(`Invalid redirect location from ${safeUrl}: ${err.message}`));
|
|
120
137
|
return;
|
|
121
138
|
}
|
|
122
|
-
resolve(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
resolve(requestRelease(next, options, redirects + 1));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!readBody) {
|
|
143
|
+
res.resume();
|
|
144
|
+
clear();
|
|
145
|
+
resolve({ status, url: safeUrl, body: "" });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const chunks = [];
|
|
149
|
+
let size = 0;
|
|
150
|
+
res.setEncoding("utf8");
|
|
151
|
+
res.on("error", reject);
|
|
152
|
+
res.on("data", (chunk) => {
|
|
153
|
+
size += Buffer.byteLength(chunk);
|
|
154
|
+
if (size > limits.maxBodyBytes) {
|
|
155
|
+
guard.fail(new Error(`Response exceeds ${limits.maxBodyBytes} bytes: ${safeUrl}`));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
chunks.push(chunk);
|
|
159
|
+
});
|
|
160
|
+
res.on("end", () => resolve({ status, url: safeUrl, body: chunks.join("") }));
|
|
161
|
+
};
|
|
162
|
+
const req =
|
|
163
|
+
method === "GET"
|
|
164
|
+
? client.get(url, { headers, timeout: limits.idleMs }, onResponse)
|
|
165
|
+
: client.request(url, { method, headers, timeout: limits.idleMs }, onResponse);
|
|
166
|
+
const guard = armTotalTimeout(req, url, reject);
|
|
167
|
+
const clear = guard.clear;
|
|
126
168
|
req.on("error", reject);
|
|
127
|
-
|
|
169
|
+
if (method !== "GET") {
|
|
170
|
+
req.end();
|
|
171
|
+
}
|
|
128
172
|
});
|
|
129
173
|
}
|
|
130
174
|
|
|
175
|
+
async function requestStatus(url, method = "HEAD", redirects = 0) {
|
|
176
|
+
const result = await requestRelease(url, { method, readBody: false }, redirects);
|
|
177
|
+
return result.status;
|
|
178
|
+
}
|
|
179
|
+
|
|
131
180
|
async function verifyAsset(url, label) {
|
|
132
181
|
let status = await requestStatus(url, "HEAD");
|
|
133
182
|
if (status === 403 || status === 405) {
|
|
134
183
|
status = await requestStatus(url, "GET");
|
|
135
184
|
}
|
|
136
185
|
if (status < 200 || status >= 400) {
|
|
137
|
-
throw new Error(`${label} returned HTTP ${status} (${url})`);
|
|
186
|
+
throw new Error(`${label} returned HTTP ${status} (${redactUrl(url)})`);
|
|
138
187
|
}
|
|
139
188
|
}
|
|
140
189
|
|
|
141
190
|
async function downloadText(url, redirects = 0) {
|
|
142
|
-
|
|
143
|
-
|
|
191
|
+
const result = await requestRelease(url, { method: "GET", readBody: true }, redirects);
|
|
192
|
+
if (result.status !== 200) {
|
|
193
|
+
throw new Error(`Request failed with status ${result.status}: ${result.url}`);
|
|
144
194
|
}
|
|
145
|
-
|
|
146
|
-
return new Promise((resolve, reject) => {
|
|
147
|
-
const req = client.get(
|
|
148
|
-
url,
|
|
149
|
-
{
|
|
150
|
-
timeout: limits.idleMs,
|
|
151
|
-
headers: {
|
|
152
|
-
"User-Agent": "codewhale-npm-release-check",
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
(res) => {
|
|
156
|
-
const status = res.statusCode || 0;
|
|
157
|
-
if (status >= 300 && status < 400 && res.headers.location) {
|
|
158
|
-
const next = new URL(res.headers.location, url).toString();
|
|
159
|
-
res.resume();
|
|
160
|
-
resolve(downloadText(next, redirects + 1));
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (status !== 200) {
|
|
164
|
-
reject(new Error(`Request failed with status ${status}: ${url}`));
|
|
165
|
-
res.resume();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const chunks = [];
|
|
169
|
-
let size = 0;
|
|
170
|
-
res.setEncoding("utf8");
|
|
171
|
-
res.on("error", reject);
|
|
172
|
-
res.on("data", (chunk) => {
|
|
173
|
-
size += Buffer.byteLength(chunk);
|
|
174
|
-
if (size > limits.maxBodyBytes) {
|
|
175
|
-
guard.fail(new Error(`Response exceeds ${limits.maxBodyBytes} bytes: ${url}`));
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
chunks.push(chunk);
|
|
179
|
-
});
|
|
180
|
-
res.on("end", () => resolve(chunks.join("")));
|
|
181
|
-
},
|
|
182
|
-
);
|
|
183
|
-
const guard = armTotalTimeout(req, url, reject);
|
|
184
|
-
req.on("error", reject);
|
|
185
|
-
});
|
|
195
|
+
return result.body;
|
|
186
196
|
}
|
|
187
197
|
|
|
188
198
|
async function downloadJson(url, redirects = 0) {
|
|
189
|
-
|
|
190
|
-
|
|
199
|
+
const result = await requestRelease(
|
|
200
|
+
url,
|
|
201
|
+
{
|
|
202
|
+
method: "GET",
|
|
203
|
+
readBody: true,
|
|
204
|
+
attachGitHubToken: true,
|
|
205
|
+
headers: {
|
|
206
|
+
Accept: "application/vnd.github+json",
|
|
207
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
redirects,
|
|
211
|
+
);
|
|
212
|
+
let parsed;
|
|
213
|
+
try {
|
|
214
|
+
parsed = result.body ? JSON.parse(result.body) : {};
|
|
215
|
+
} catch (error) {
|
|
216
|
+
throw new Error(`Invalid JSON from ${result.url}: ${error.message}`);
|
|
191
217
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
throw new Error(
|
|
218
|
+
if (result.status < 200 || result.status >= 300) {
|
|
219
|
+
const message = parsed.message ? `: ${parsed.message}` : "";
|
|
220
|
+
throw new Error(`GitHub API request failed with status ${result.status}${message} (${result.url})`);
|
|
195
221
|
}
|
|
196
|
-
return
|
|
197
|
-
const headers = {
|
|
198
|
-
Accept: "application/vnd.github+json",
|
|
199
|
-
"User-Agent": "codewhale-npm-release-check",
|
|
200
|
-
"X-GitHub-Api-Version": "2022-11-28",
|
|
201
|
-
};
|
|
202
|
-
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
203
|
-
if (token && parsedUrl.origin === "https://api.github.com") {
|
|
204
|
-
headers.Authorization = `Bearer ${token}`;
|
|
205
|
-
}
|
|
206
|
-
const req = https
|
|
207
|
-
.get(url, { headers, timeout: limits.idleMs }, (res) => {
|
|
208
|
-
const status = res.statusCode || 0;
|
|
209
|
-
if (status >= 300 && status < 400 && res.headers.location) {
|
|
210
|
-
const next = new URL(res.headers.location, url).toString();
|
|
211
|
-
res.resume();
|
|
212
|
-
resolve(downloadJson(next, redirects + 1));
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const chunks = [];
|
|
216
|
-
let size = 0;
|
|
217
|
-
res.setEncoding("utf8");
|
|
218
|
-
res.on("error", reject);
|
|
219
|
-
res.on("data", (chunk) => {
|
|
220
|
-
size += Buffer.byteLength(chunk);
|
|
221
|
-
if (size > limits.maxBodyBytes) {
|
|
222
|
-
guard.fail(new Error(`Response exceeds ${limits.maxBodyBytes} bytes: ${url}`));
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
chunks.push(chunk);
|
|
226
|
-
});
|
|
227
|
-
res.on("end", () => {
|
|
228
|
-
const body = chunks.join("");
|
|
229
|
-
let parsed;
|
|
230
|
-
try {
|
|
231
|
-
parsed = body ? JSON.parse(body) : {};
|
|
232
|
-
} catch (error) {
|
|
233
|
-
reject(new Error(`Invalid JSON from ${url}: ${error.message}`));
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
if (status < 200 || status >= 300) {
|
|
237
|
-
const message = parsed.message ? `: ${parsed.message}` : "";
|
|
238
|
-
reject(new Error(`GitHub API request failed with status ${status}${message} (${url})`));
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
resolve(parsed);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
const guard = armTotalTimeout(req, url, reject);
|
|
245
|
-
req.on("error", reject);
|
|
246
|
-
});
|
|
222
|
+
return parsed;
|
|
247
223
|
}
|
|
248
224
|
|
|
249
225
|
function githubApiUrl(repo, path) {
|
package/test/artifacts.test.js
CHANGED
|
@@ -20,22 +20,27 @@ function withMockedOs(platform, arch, fn) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// Native HarmonyOS used to receive the static Linux build as a best effort.
|
|
24
|
+
// It has its own target now, so the Linux names must not come back: shipping a
|
|
25
|
+
// glibc-less musl Linux binary to `openharmony` was the behaviour that made
|
|
26
|
+
// `codewhale` fail to start with no explanation on the device.
|
|
27
|
+
test("openharmony arm64 resolves to the native HarmonyOS assets", () => {
|
|
28
|
+
withMockedOs("openharmony", "arm64", () => {
|
|
25
29
|
const { detectBinaryNames } = require(ARTIFACTS_PATH);
|
|
26
30
|
const result = detectBinaryNames();
|
|
27
|
-
assert.equal(result.codewhale, "codewhale-
|
|
28
|
-
assert.equal(result.codew, "codew-
|
|
29
|
-
assert.equal(result.tui, undefined);
|
|
31
|
+
assert.equal(result.codewhale, "codewhale-ohos-arm64");
|
|
32
|
+
assert.equal(result.codew, "codew-ohos-arm64");
|
|
30
33
|
});
|
|
31
34
|
});
|
|
32
35
|
|
|
33
|
-
test("openharmony
|
|
34
|
-
withMockedOs("openharmony", "
|
|
36
|
+
test("openharmony x64 has no asset and is pointed at a source build", () => {
|
|
37
|
+
withMockedOs("openharmony", "x64", () => {
|
|
35
38
|
const { detectBinaryNames } = require(ARTIFACTS_PATH);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
assert.throws(
|
|
40
|
+
() => detectBinaryNames(),
|
|
41
|
+
/Unsupported architecture: x64 on platform openharmony/,
|
|
42
|
+
"only ARM64 is published for native HarmonyOS",
|
|
43
|
+
);
|
|
39
44
|
});
|
|
40
45
|
});
|
|
41
46
|
|
|
@@ -227,3 +232,61 @@ test("an explicit release base takes precedence over the CNB shortcut", () => {
|
|
|
227
232
|
}
|
|
228
233
|
});
|
|
229
234
|
});
|
|
235
|
+
|
|
236
|
+
test("validateReleaseUrl enforces HTTPS and allowlisted release hosts", () => {
|
|
237
|
+
const { redactUrl, validateReleaseUrl } = require(ARTIFACTS_PATH);
|
|
238
|
+
|
|
239
|
+
assert.equal(
|
|
240
|
+
validateReleaseUrl("https://github.com/codewhale-hq/CodeWhale/releases/download/v1.0.0/asset").hostname,
|
|
241
|
+
"github.com",
|
|
242
|
+
);
|
|
243
|
+
assert.equal(
|
|
244
|
+
validateReleaseUrl("https://sub.cnb.cool/path").hostname,
|
|
245
|
+
"sub.cnb.cool",
|
|
246
|
+
);
|
|
247
|
+
assert.equal(
|
|
248
|
+
validateReleaseUrl("https://mirror.example/v1/asset", {
|
|
249
|
+
env: { CODEWHALE_RELEASE_BASE_URL: "https://mirror.example/v1" },
|
|
250
|
+
}).hostname,
|
|
251
|
+
"mirror.example",
|
|
252
|
+
);
|
|
253
|
+
assert.equal(
|
|
254
|
+
validateReleaseUrl("https://cdn.example.net/asset", {
|
|
255
|
+
env: { CODEWHALE_UPDATE_ALLOWED_HOSTS: "other.example, cdn.example.net" },
|
|
256
|
+
}).hostname,
|
|
257
|
+
"cdn.example.net",
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
assert.throws(
|
|
261
|
+
() => validateReleaseUrl("http://github.com/asset"),
|
|
262
|
+
/requires HTTPS/,
|
|
263
|
+
);
|
|
264
|
+
assert.throws(
|
|
265
|
+
() =>
|
|
266
|
+
validateReleaseUrl("http://mirror.example/asset", {
|
|
267
|
+
env: { CODEWHALE_RELEASE_BASE_URL: "http://mirror.example" },
|
|
268
|
+
}),
|
|
269
|
+
/requires HTTPS/,
|
|
270
|
+
);
|
|
271
|
+
assert.throws(
|
|
272
|
+
() => validateReleaseUrl("http://127.0.0.1:8080/asset"),
|
|
273
|
+
/requires HTTPS/,
|
|
274
|
+
);
|
|
275
|
+
assert.equal(
|
|
276
|
+
validateReleaseUrl("http://127.0.0.1:8080/asset", { allowLoopbackHttp: true }).hostname,
|
|
277
|
+
"127.0.0.1",
|
|
278
|
+
);
|
|
279
|
+
assert.throws(
|
|
280
|
+
() => validateReleaseUrl("https://unlisted.example.test/asset", { env: {} }),
|
|
281
|
+
/not an allowed release host/,
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
assert.equal(
|
|
285
|
+
redactUrl("https://user:secret@github.com/path?q=1"),
|
|
286
|
+
"https://github.com/path?q=1",
|
|
287
|
+
);
|
|
288
|
+
assert.equal(
|
|
289
|
+
redactUrl("http://user:secret@not a valid host/path"),
|
|
290
|
+
"http://not a valid host/path",
|
|
291
|
+
);
|
|
292
|
+
});
|
package/test/install.test.js
CHANGED
|
@@ -452,3 +452,61 @@ test("a body paused by a slow consumer is not reported as a stall", { timeout: 5
|
|
|
452
452
|
await done;
|
|
453
453
|
assert.equal(body, "first chunk rest of the body");
|
|
454
454
|
});
|
|
455
|
+
|
|
456
|
+
test("followRedirects and downloadText refuse plain HTTP and disallowed redirect targets without connecting", async (t) => {
|
|
457
|
+
const http = require("node:http");
|
|
458
|
+
const https = require("node:https");
|
|
459
|
+
const { PassThrough } = require("node:stream");
|
|
460
|
+
const { EventEmitter } = require("node:events");
|
|
461
|
+
let hits = 0;
|
|
462
|
+
const server = http.createServer((_req, res) => {
|
|
463
|
+
hits += 1;
|
|
464
|
+
res.writeHead(200);
|
|
465
|
+
res.end("unexpected");
|
|
466
|
+
});
|
|
467
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
468
|
+
t.after(() => {
|
|
469
|
+
server.closeAllConnections();
|
|
470
|
+
return new Promise((resolve) => server.close(resolve));
|
|
471
|
+
});
|
|
472
|
+
const localHttpUrl = `http://127.0.0.1:${server.address().port}/asset`;
|
|
473
|
+
|
|
474
|
+
await assert.rejects(
|
|
475
|
+
_internal.followRedirects(localHttpUrl, { env: {} }),
|
|
476
|
+
/requires HTTPS/,
|
|
477
|
+
);
|
|
478
|
+
await assert.rejects(
|
|
479
|
+
_internal.downloadText("http://user:secret@github.com/asset", { env: {} }),
|
|
480
|
+
(error) => {
|
|
481
|
+
assert.match(error.message, /requires HTTPS/);
|
|
482
|
+
assert.doesNotMatch(error.message, /secret/);
|
|
483
|
+
return true;
|
|
484
|
+
},
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
let nextRedirect = localHttpUrl;
|
|
488
|
+
t.mock.method(https, "request", (_opts, callback) => {
|
|
489
|
+
const req = new EventEmitter();
|
|
490
|
+
req.destroy = () => {};
|
|
491
|
+
req.end = () => {};
|
|
492
|
+
const res = new PassThrough();
|
|
493
|
+
res.statusCode = 302;
|
|
494
|
+
res.headers = { location: nextRedirect };
|
|
495
|
+
process.nextTick(() => {
|
|
496
|
+
callback(res);
|
|
497
|
+
res.end();
|
|
498
|
+
});
|
|
499
|
+
return req;
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
await assert.rejects(
|
|
503
|
+
_internal.followRedirects("https://github.com/start", { env: {} }),
|
|
504
|
+
/requires HTTPS/,
|
|
505
|
+
);
|
|
506
|
+
nextRedirect = "https://unlisted.example.test/asset";
|
|
507
|
+
await assert.rejects(
|
|
508
|
+
_internal.followRedirects("https://github.com/start", { env: {} }),
|
|
509
|
+
/not an allowed release host/,
|
|
510
|
+
);
|
|
511
|
+
assert.equal(hits, 0);
|
|
512
|
+
});
|
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
checksummedReleaseAssetNames,
|
|
15
15
|
detectBinaryNames,
|
|
16
16
|
LEGACY_TUI_BRIDGE_ASSET_NAMES,
|
|
17
|
+
transportOptions,
|
|
17
18
|
} = require("../scripts/artifacts");
|
|
18
19
|
const {
|
|
19
20
|
assertChecksumManifestIncludes,
|
|
@@ -318,10 +319,14 @@ test("downloadJson confines credentials to the GitHub API origin across redirect
|
|
|
318
319
|
const { PassThrough } = require("node:stream");
|
|
319
320
|
const { EventEmitter } = require("node:events");
|
|
320
321
|
const previous = process.env.GITHUB_TOKEN;
|
|
322
|
+
const previousAllowed = process.env.CODEWHALE_UPDATE_ALLOWED_HOSTS;
|
|
321
323
|
process.env.GITHUB_TOKEN = "test-release-token";
|
|
324
|
+
process.env.CODEWHALE_UPDATE_ALLOWED_HOSTS = "downloads.example.test";
|
|
322
325
|
t.after(() => {
|
|
323
326
|
if (previous === undefined) delete process.env.GITHUB_TOKEN;
|
|
324
327
|
else process.env.GITHUB_TOKEN = previous;
|
|
328
|
+
if (previousAllowed === undefined) delete process.env.CODEWHALE_UPDATE_ALLOWED_HOSTS;
|
|
329
|
+
else process.env.CODEWHALE_UPDATE_ALLOWED_HOSTS = previousAllowed;
|
|
325
330
|
});
|
|
326
331
|
const calls = [];
|
|
327
332
|
const replies = [
|
|
@@ -361,6 +366,11 @@ function shrinkLimits(t, overrides) {
|
|
|
361
366
|
}
|
|
362
367
|
|
|
363
368
|
function listen(t, handler) {
|
|
369
|
+
const previousLoopback = transportOptions.allowLoopbackHttp;
|
|
370
|
+
transportOptions.allowLoopbackHttp = true;
|
|
371
|
+
t.after(() => {
|
|
372
|
+
transportOptions.allowLoopbackHttp = previousLoopback;
|
|
373
|
+
});
|
|
364
374
|
const http = require("node:http");
|
|
365
375
|
const server = http.createServer(handler);
|
|
366
376
|
t.after(() => {
|
|
@@ -416,3 +426,58 @@ test("downloadJson destroys a metadata request that stalls", async (t) => {
|
|
|
416
426
|
await assert.rejects(downloadJson("https://api.github.com/stalled"), /timed out/);
|
|
417
427
|
assert.equal(seen.timeout, 40);
|
|
418
428
|
});
|
|
429
|
+
|
|
430
|
+
test("verifier requests refuse plain HTTP and disallowed redirect targets without connecting", async (t) => {
|
|
431
|
+
const http = require("node:http");
|
|
432
|
+
const https = require("node:https");
|
|
433
|
+
const { PassThrough } = require("node:stream");
|
|
434
|
+
const { EventEmitter } = require("node:events");
|
|
435
|
+
let hits = 0;
|
|
436
|
+
const server = http.createServer((_req, res) => {
|
|
437
|
+
hits += 1;
|
|
438
|
+
res.writeHead(200);
|
|
439
|
+
res.end("unexpected");
|
|
440
|
+
});
|
|
441
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
442
|
+
t.after(() => {
|
|
443
|
+
server.closeAllConnections();
|
|
444
|
+
server.close();
|
|
445
|
+
});
|
|
446
|
+
const localHttpUrl = `http://127.0.0.1:${server.address().port}/asset`;
|
|
447
|
+
|
|
448
|
+
await assert.rejects(requestStatus(localHttpUrl, "HEAD"), /requires HTTPS/);
|
|
449
|
+
await assert.rejects(downloadText(localHttpUrl), /requires HTTPS/);
|
|
450
|
+
await assert.rejects(downloadJson(localHttpUrl), /requires HTTPS/);
|
|
451
|
+
await assert.rejects(downloadText("http://user:secret@github.com/asset"), (error) => {
|
|
452
|
+
assert.match(error.message, /requires HTTPS/);
|
|
453
|
+
assert.doesNotMatch(error.message, /secret/);
|
|
454
|
+
return true;
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
let nextRedirect = localHttpUrl;
|
|
458
|
+
const mockHandler = (_url, _options, callback) => {
|
|
459
|
+
const req = new EventEmitter();
|
|
460
|
+
req.destroy = () => {};
|
|
461
|
+
req.end = () => {};
|
|
462
|
+
const res = new PassThrough();
|
|
463
|
+
res.statusCode = 302;
|
|
464
|
+
res.headers = { location: nextRedirect };
|
|
465
|
+
process.nextTick(() => {
|
|
466
|
+
callback(res);
|
|
467
|
+
res.end();
|
|
468
|
+
});
|
|
469
|
+
return req;
|
|
470
|
+
};
|
|
471
|
+
t.mock.method(https, "get", mockHandler);
|
|
472
|
+
t.mock.method(https, "request", mockHandler);
|
|
473
|
+
|
|
474
|
+
await assert.rejects(requestStatus("https://github.com/start", "HEAD"), /requires HTTPS/);
|
|
475
|
+
await assert.rejects(downloadText("https://github.com/start"), /requires HTTPS/);
|
|
476
|
+
await assert.rejects(downloadJson("https://api.github.com/start"), /requires HTTPS/);
|
|
477
|
+
|
|
478
|
+
nextRedirect = "https://unlisted.example.test/asset";
|
|
479
|
+
await assert.rejects(requestStatus("https://github.com/start", "HEAD"), /not an allowed release host/);
|
|
480
|
+
await assert.rejects(downloadText("https://github.com/start"), /not an allowed release host/);
|
|
481
|
+
await assert.rejects(downloadJson("https://api.github.com/start"), /not an allowed release host/);
|
|
482
|
+
assert.equal(hits, 0);
|
|
483
|
+
});
|
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
githubReleaseBaseUrl,
|
|
15
15
|
hasExplicitReleaseBase,
|
|
16
16
|
shouldRaceFirstPartyMirrors,
|
|
17
|
+
transportOptions,
|
|
17
18
|
} = require("../scripts/artifacts");
|
|
18
19
|
const { run, _internal } = require("../scripts/install");
|
|
19
20
|
|
|
@@ -118,7 +119,9 @@ async function withoutForcedDownload(callback) {
|
|
|
118
119
|
|
|
119
120
|
test("Linux x64 races first-party sources unless an explicit override is set", () => {
|
|
120
121
|
assert.equal(shouldRaceFirstPartyMirrors({}, "linux", "x64"), true);
|
|
121
|
-
|
|
122
|
+
// The CNB mirror publishes Linux assets only, and native HarmonyOS resolves to
|
|
123
|
+
// its own asset family; it must not be handed a Linux x64 URL.
|
|
124
|
+
assert.equal(shouldRaceFirstPartyMirrors({}, "openharmony", "x64"), false);
|
|
122
125
|
assert.equal(shouldRaceFirstPartyMirrors({}, "linux", "arm64"), false);
|
|
123
126
|
assert.equal(shouldRaceFirstPartyMirrors({}, "darwin", "arm64"), false);
|
|
124
127
|
assert.equal(
|
|
@@ -708,7 +711,16 @@ test("source selection is visible in progress output", async () => {
|
|
|
708
711
|
}
|
|
709
712
|
});
|
|
710
713
|
|
|
714
|
+
function allowLoopbackHttp(t) {
|
|
715
|
+
const previous = transportOptions.allowLoopbackHttp;
|
|
716
|
+
transportOptions.allowLoopbackHttp = true;
|
|
717
|
+
t.after(() => {
|
|
718
|
+
transportOptions.allowLoopbackHttp = previous;
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
|
|
711
722
|
test("aborting a losing manifest probe closes a body already in progress", async (t) => {
|
|
723
|
+
allowLoopbackHttp(t);
|
|
712
724
|
const responseStarted = deferred();
|
|
713
725
|
const responseClosed = deferred();
|
|
714
726
|
const server = http.createServer((_req, res) => {
|
|
@@ -750,6 +762,7 @@ test("aborting a losing manifest probe closes a body already in progress", async
|
|
|
750
762
|
});
|
|
751
763
|
|
|
752
764
|
test("HTTP fixture never starts the losing source's full binary download", async (t) => {
|
|
765
|
+
allowLoopbackHttp(t);
|
|
753
766
|
const dir = await makeTempDir(t);
|
|
754
767
|
const cnbWhale = Buffer.from("fixture-cnb-whale");
|
|
755
768
|
const cnbCodew = Buffer.from("fixture-cnb-codew");
|