Remove Docker Hub registry support and references

Eliminates support for Docker Hub ('cr-docker') from platform configuration, request handling logic, and all related tests. Updates terminology and test cases to use other container registries (e.g., GHCR) and removes Docker-specific path and scope transformations. This simplifies container registry support and focuses on currently supported platforms.
This commit is contained in:
xixu-me committed 2025-07-25 19:02:40 +08:00
1 parent 46288a92da
commit ba5b728b2f
4 files changed
+61 -164

No files matched your search

@@ -1,7 +1,7 @@
import { SELF } from 'cloudflare:test';
import { describe, expect, it } from 'vitest';
describe('Docker Registry Support', () => {
describe('Container Registry Support', () => {
describe('Docker API Version Check', () => {
it('should handle /v2/ endpoint correctly', async () => {
const response = await SELF.fetch('https://example.com/v2/');
@@ -22,23 +22,7 @@ describe('Docker Registry Support', () => {
});
});
describe('Docker Registry URL Transformation', () => {
it('should handle Docker Hub manifest requests', async () => {
const testUrl = 'https://example.com/cr/docker/v2/library/nginx/manifests/latest';
const response = await SELF.fetch(testUrl, { method: 'HEAD' });
// Should attempt to proxy to Docker Hub
expect(response.status).not.toBe(400);
});
it('should handle Docker Hub without library prefix', async () => {
const testUrl = 'https://example.com/cr/docker/v2/nginx/manifests/latest';
const response = await SELF.fetch(testUrl, { method: 'HEAD' });
// Should attempt to proxy to Docker Hub with library prefix added
expect(response.status).not.toBe(400);
});
describe('Container Registry URL Transformation', () => {
it('should handle Quay.io registry requests', async () => {
const testUrl = 'https://example.com/cr/quay/v2/bitnami/nginx/manifests/latest';
const response = await SELF.fetch(testUrl, { method: 'HEAD' });
@@ -67,7 +51,7 @@ describe('Docker Registry Support', () => {
describe('Docker Authentication', () => {
it('should pass through 401 authentication challenges', async () => {
// This test simulates an upstream 401 response which should be passed through
const testUrl = 'https://example.com/cr/docker/v2/private/repo/manifests/latest';
const testUrl = 'https://example.com/cr/ghcr/v2/private/repo/manifests/latest';
const response = await SELF.fetch(testUrl, {
headers: {
Accept: 'application/vnd.docker.distribution.manifest.v2+json'
@@ -81,8 +65,8 @@ describe('Docker Registry Support', () => {
}
});
it('should handle Docker registry token requests', async () => {
const testUrl = 'https://example.com/cr/docker/v2/auth';
it('should handle container registry token requests', async () => {
const testUrl = 'https://example.com/cr/ghcr/v2/auth';
const response = await SELF.fetch(testUrl, {
headers: {
Authorization: 'Basic dGVzdDp0ZXN0'
@@ -97,7 +81,7 @@ describe('Docker Registry Support', () => {
describe('Docker Request Detection', () => {
it('should detect Docker requests by path', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/library/nginx/manifests/latest',
'https://example.com/cr/ghcr/v2/library/nginx/manifests/latest',
{
method: 'GET'
}
@@ -108,28 +92,22 @@ describe('Docker Registry Support', () => {
});
it('should detect Docker requests by Accept header', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/test/repo/manifests/tag',
{
headers: {
Accept: 'application/vnd.docker.distribution.manifest.v2+json'
}
const response = await SELF.fetch('https://example.com/cr/ghcr/v2/test/repo/manifests/tag', {
headers: {
Accept: 'application/vnd.docker.distribution.manifest.v2+json'
}
);
});
// Should not reject with 405 (method not allowed)
expect(response.status).not.toBe(405);
});
it('should detect Docker requests by User-Agent', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/test/repo/manifests/tag',
{
headers: {
'User-Agent': 'docker/20.10.7'
}
const response = await SELF.fetch('https://example.com/cr/ghcr/v2/test/repo/manifests/tag', {
headers: {
'User-Agent': 'docker/20.10.7'
}
);
});
// Should not reject with 405 (method not allowed)
expect(response.status).not.toBe(405);
@@ -139,7 +117,7 @@ describe('Docker Registry Support', () => {
describe('Docker HTTP Methods', () => {
it('should allow GET for manifest requests', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/library/nginx/manifests/latest',
'https://example.com/cr/ghcr/v2/library/nginx/manifests/latest',
{
method: 'GET'
}
@@ -150,7 +128,7 @@ describe('Docker Registry Support', () => {
it('should allow HEAD for manifest requests', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/library/nginx/manifests/latest',
'https://example.com/cr/ghcr/v2/library/nginx/manifests/latest',
{
method: 'HEAD'
}
@@ -160,63 +138,48 @@ describe('Docker Registry Support', () => {
});
it('should allow PUT for manifest uploads', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/test/repo/manifests/tag',
{
method: 'PUT',
headers: {
'Content-Type': 'application/vnd.docker.distribution.manifest.v2+json'
},
body: JSON.stringify({
schemaVersion: 2,
mediaType: 'application/vnd.docker.distribution.manifest.v2+json'
})
}
);
const response = await SELF.fetch('https://example.com/cr/ghcr/v2/test/repo/manifests/tag', {
method: 'PUT',
headers: {
'Content-Type': 'application/vnd.docker.distribution.manifest.v2+json'
},
body: JSON.stringify({
schemaVersion: 2,
mediaType: 'application/vnd.docker.distribution.manifest.v2+json'
})
});
expect(response.status).not.toBe(405);
});
it('should allow POST for blob uploads', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/test/repo/blobs/uploads/',
{
method: 'POST',
headers: {
'Content-Type': 'application/octet-stream'
}
const response = await SELF.fetch('https://example.com/cr/ghcr/v2/test/repo/blobs/uploads/', {
method: 'POST',
headers: {
'Content-Type': 'application/octet-stream'
}
);
});
expect(response.status).not.toBe(405);
});
});
describe('Docker Registry Error Handling', () => {
describe('Container Registry Error Handling', () => {
it('should reject non-cr prefixed Docker requests', async () => {
const response = await SELF.fetch('https://example.com/v2/library/nginx/manifests/latest');
expect(response.status).toBe(400);
expect(await response.text()).toContain('Docker registry requests must use /cr/ prefix');
});
it('should handle Docker Hub blob redirects', async () => {
// This test would verify that 307 redirects from Docker Hub are handled
const testUrl = 'https://example.com/cr/docker/v2/library/nginx/blobs/sha256:abc123';
const response = await SELF.fetch(testUrl);
// The request should be processed (not fail with a redirect error)
expect([200, 301, 302, 307, 404]).toContain(response.status);
expect(await response.text()).toContain('container registry requests must use /cr/ prefix');
});
});
describe('Docker Registry Headers', () => {
it('should preserve Docker-specific headers', async () => {
describe('Container Registry Headers', () => {
it('should preserve container-specific headers', async () => {
const response = await SELF.fetch(
'https://example.com/cr/docker/v2/library/nginx/manifests/latest',
'https://example.com/cr/ghcr/v2/library/nginx/manifests/latest',
{
headers: {
'Docker-Content-Digest': 'sha256:abc123',
'Container-Content-Digest': 'sha256:abc123',
Accept: 'application/vnd.docker.distribution.manifest.v2+json',
Authorization: 'Bearer token123'
}
@@ -227,12 +190,12 @@ describe('Docker Registry Support', () => {
expect(response.status).not.toBe(400);
});
it('should not cache Docker registry responses', async () => {
const testUrl = 'https://example.com/cr/docker/v2/library/nginx/manifests/latest';
it('should not cache container registry responses', async () => {
const testUrl = 'https://example.com/cr/ghcr/v2/library/nginx/manifests/latest';
const response = await SELF.fetch(testUrl);
// Docker registry responses should not be cached
// Container registry responses should not be cached
const cacheControl = response.headers.get('Cache-Control');
if (cacheControl) {
expect(cacheControl).not.toContain('max-age=1800');
@@ -242,7 +205,6 @@ describe('Docker Registry Support', () => {
describe('Container Registry Platform Support', () => {
const containerRegistries = [
{ name: 'Docker Hub', prefix: 'cr/docker', expectedStatus: [200, 301, 302, 401, 404] },
{ name: 'Quay.io', prefix: 'cr/quay', expectedStatus: [200, 301, 302, 401, 404] },
{
name: 'Google Container Registry',
+4 -11
View File
@@ -84,10 +84,6 @@ describe('Platform Configuration', () => {
});
it('should transform container registry paths correctly', () => {
expect(transformPath('/cr/docker/v2/library/nginx/manifests/latest', 'cr-docker')).toBe(
'/v2/library/nginx/manifests/latest'
);
expect(transformPath('/cr/ghcr/v2/microsoft/vscode/manifests/latest', 'cr-ghcr')).toBe(
'/v2/microsoft/vscode/manifests/latest'
);
@@ -129,7 +125,6 @@ describe('Platform Configuration', () => {
});
it('should have correct container registry base URLs', () => {
expect(PLATFORMS['cr-docker']).toBe('https://registry-1.docker.io');
expect(PLATFORMS['cr-ghcr']).toBe('https://ghcr.io');
expect(PLATFORMS['cr-gcr']).toBe('https://gcr.io');
expect(PLATFORMS['cr-mcr']).toBe('https://mcr.microsoft.com');
@@ -181,19 +176,18 @@ describe('Platform Configuration', () => {
});
it('should handle container registry URL construction', () => {
const testPath = '/cr/docker/v2/library/nginx/manifests/latest';
const transformedPath = transformPath(testPath, 'cr-docker');
const fullUrl = PLATFORMS['cr-docker'] + transformedPath;
const testPath = '/cr/ghcr/v2/microsoft/vscode/manifests/latest';
const transformedPath = transformPath(testPath, 'cr-ghcr');
const fullUrl = PLATFORMS['cr-ghcr'] + transformedPath;
expect(() => new URL(fullUrl)).not.toThrow();
expect(fullUrl).toBe('https://registry-1.docker.io/v2/library/nginx/manifests/latest');
expect(fullUrl).toBe('https://ghcr.io/v2/microsoft/vscode/manifests/latest');
});
});
describe('Container Registry Support', () => {
it('should have all major container registries defined', () => {
const containerRegistries = [
'cr-docker',
'cr-quay',
'cr-gcr',
'cr-mcr',
@@ -222,7 +216,6 @@ describe('Platform Configuration', () => {
it('should transform all container registry paths correctly', () => {
const containerRegistries = [
'cr-docker',
'cr-quay',
'cr-gcr',
'cr-mcr',