mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 09:03:37 +01:00
fix: report a jsDelivr 404 as repo_not_found, not token_expired
Without owner access, a jsDelivr 404 was sent to the GitHub API probe, which cannot run for the CDN token and failed with token_expired. The path comes from the stored tree of a pinned commit, so a CDN 404 means the repository is no longer public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
28b154b0eb
commit
f02999e774
2 files changed
+11
No files matched your search
@@ -3,6 +3,7 @@ import AnonymousError from "../AnonymousError";
|
||||
import { ExpiringMap } from "../expiring-map";
|
||||
import { octokit, waitForTokenGate, RateLimitDelayError } from "../GitHubUtils";
|
||||
import { GitHubBaseData } from "./GitHubBase";
|
||||
import { githubTokenContext } from "../github-token-context";
|
||||
|
||||
type Miss = "file_not_found" | "repo_not_found" | "commit_not_found";
|
||||
const results = new ExpiringMap<Miss>(2048);
|
||||
@@ -27,6 +28,10 @@ export async function classifyContentMiss(data: GitHubBaseData, token: string):
|
||||
if (active) return active;
|
||||
if (pending.size >= 64) throw new AnonymousError("cache_busy", { httpStatus: 503 });
|
||||
const probe = (async (): Promise<Miss> => {
|
||||
// A CDN read is commit-pinned and the path comes from that commit's stored
|
||||
// tree, so a CDN 404 means the repository is no longer public. The GitHub
|
||||
// API cannot be asked without the owner's access.
|
||||
if (githubTokenContext(token)?.cdnOnly) return "repo_not_found";
|
||||
const oct = octokit(token);
|
||||
const options = { owner: data.organization, repo: data.repoName, request: { timeout: 15_000 } };
|
||||
try {
|
||||
|
||||
@@ -56,6 +56,12 @@ describe("jsDelivr access without owner credentials", function () {
|
||||
await repo.refreshIfNeeded();
|
||||
});
|
||||
|
||||
it("reports a CDN 404 as an unavailable repository, not an expired token", async () => {
|
||||
const { classifyContentMiss } = require("../src/core/source/github-content-miss");
|
||||
const data = { repoId: "r", organization: "owner", repoName: "gone", commit, getToken: () => PUBLIC_CDN_TOKEN };
|
||||
expect(await classifyContentMiss(data, PUBLIC_CDN_TOKEN)).to.equal("repo_not_found");
|
||||
});
|
||||
|
||||
it("encodes owner, repository and path segments", () => {
|
||||
expect(jsDelivrFileUrl("o", "r", commit, "x/%2e")).to.equal(`https://cdn.jsdelivr.net/gh/o/r@${commit}/x/%252e`);
|
||||
for (const path of ["../x", "a/./b", "a//b", ""]) expect(() => jsDelivrFileUrl("o", "r", commit, path)).to.throw("invalid_path");
|
||||
|
||||
Reference in new issue
Block a user