Refactor request handling and improve Docker detection
Refactored the main request handler in src/index.js for improved readability and error handling. Enhanced Docker request detection in validation.js to include additional Content-Type checks. Updated tests to increase timeouts and expand expected status codes for container registry platforms.
This commit is contained in:
1 parent
b81b3968d9
commit
cb0bb2da2f
5 files changed
+618
-496
No files matched your search
@@ -240,7 +240,7 @@ describe('Security Features', () => {
|
||||
|
||||
it('should provide generic error messages', async () => {
|
||||
const response = await SELF.fetch('https://example.com/gh/test/repo', {
|
||||
method: 'INVALID',
|
||||
method: 'TRACE',
|
||||
redirect: 'manual'
|
||||
});
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Integration Tests', () => {
|
||||
const response = await SELF.fetch(testUrl, { method: 'HEAD' });
|
||||
|
||||
expect([200, 301, 302, 404]).toContain(response.status);
|
||||
});
|
||||
}, 10000);
|
||||
|
||||
it('should handle npm package requests', async () => {
|
||||
const testUrl = 'https://example.com/npm/react';
|
||||
@@ -229,7 +229,7 @@ describe('Integration Tests', () => {
|
||||
});
|
||||
|
||||
// Git requests should not be cached (no cache headers)
|
||||
expect(response.headers.get('Cache-Control')).not.toContain('max-age=1800');
|
||||
expect(response.headers.get('Cache-Control') || '').not.toContain('max-age=1800');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -297,7 +297,7 @@ describe('Integration Tests', () => {
|
||||
const response = await SELF.fetch(url, { method: 'HEAD' });
|
||||
expect(response.headers.get('X-Performance-Metrics')).toBeTruthy();
|
||||
}
|
||||
});
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
describe('Content Type Handling', () => {
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('Container Registry Support', () => {
|
||||
|
||||
// Should attempt to proxy auth requests
|
||||
expect(response.status).not.toBe(400);
|
||||
});
|
||||
}, 15000);
|
||||
|
||||
it('should transform scope parameter correctly for Docker Hub', async () => {
|
||||
// Test that scope parameter removes Xget path prefix
|
||||
@@ -237,24 +237,24 @@ describe('Container 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: 'Docker Hub', prefix: 'cr/docker', expectedStatus: [200, 301, 302, 401, 404, 429] },
|
||||
{ name: 'Quay.io', prefix: 'cr/quay', expectedStatus: [200, 301, 302, 401, 404, 429] },
|
||||
{
|
||||
name: 'Google Container Registry',
|
||||
prefix: 'cr/gcr',
|
||||
expectedStatus: [200, 301, 302, 401, 404]
|
||||
expectedStatus: [200, 301, 302, 401, 404, 429]
|
||||
},
|
||||
{
|
||||
name: 'Microsoft Container Registry',
|
||||
prefix: 'cr/mcr',
|
||||
expectedStatus: [200, 301, 302, 401, 404]
|
||||
expectedStatus: [200, 301, 302, 401, 404, 429]
|
||||
},
|
||||
{
|
||||
name: 'GitHub Container Registry',
|
||||
prefix: 'cr/ghcr',
|
||||
expectedStatus: [200, 301, 302, 401, 404]
|
||||
expectedStatus: [200, 301, 302, 401, 404, 429]
|
||||
},
|
||||
{ name: 'Amazon ECR Public', prefix: 'cr/ecr', expectedStatus: [200, 301, 302, 401, 404] }
|
||||
{ name: 'Amazon ECR Public', prefix: 'cr/ecr', expectedStatus: [200, 301, 302, 401, 404, 429] }
|
||||
];
|
||||
|
||||
containerRegistries.forEach(({ name, prefix, expectedStatus }) => {
|
||||
@@ -263,7 +263,7 @@ describe('Container Registry Support', () => {
|
||||
const response = await SELF.fetch(testUrl, { method: 'HEAD' });
|
||||
|
||||
expect(expectedStatus).toContain(response.status);
|
||||
});
|
||||
}, 10000);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user