fix(oci): remove /v2/ from internal route patterns and make upstream apiPrefix configurable
The OCI handler had /v2/ baked into all regex patterns and Location headers. When basePath was set to /v2 (as in stack.gallery), stripping it removed the prefix that patterns expected, causing all OCI endpoints to 404. Now patterns match on bare paths after basePath stripping, working correctly regardless of the basePath value. Also adds configurable apiPrefix to OCI upstream class (default /v2) for registries behind reverse proxies with custom path prefixes.
This commit is contained in:
@@ -48,7 +48,7 @@ async function createDockerTestRegistry(port: number): Promise<SmartRegistry> {
|
||||
},
|
||||
oci: {
|
||||
enabled: true,
|
||||
basePath: '/oci',
|
||||
basePath: '/v2',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -95,8 +95,7 @@ let testImageName: string;
|
||||
* Create HTTP server wrapper around SmartRegistry
|
||||
* CRITICAL: Always passes rawBody for content-addressable operations (OCI manifests/blobs)
|
||||
*
|
||||
* Docker expects registry at /v2/ but SmartRegistry serves at /oci/v2/
|
||||
* This wrapper rewrites paths for Docker compatibility
|
||||
* SmartRegistry OCI is configured with basePath '/v2' matching Docker's native /v2/ prefix.
|
||||
*
|
||||
* Also implements a simple /v2/token endpoint for Docker Bearer auth flow
|
||||
*/
|
||||
@@ -130,10 +129,7 @@ async function createHttpServer(
|
||||
// Log all requests for debugging
|
||||
console.log(`[Registry] ${req.method} ${pathname}`);
|
||||
|
||||
// Docker expects /v2/ but SmartRegistry serves at /oci/v2/
|
||||
if (pathname.startsWith('/v2')) {
|
||||
pathname = '/oci' + pathname;
|
||||
}
|
||||
// basePath is /v2 which matches Docker's native /v2/ prefix — no rewrite needed
|
||||
|
||||
// Read raw body - ALWAYS preserve exact bytes for OCI
|
||||
const chunks: Buffer[] = [];
|
||||
@@ -313,7 +309,7 @@ tap.test('Docker CLI: should verify server is responding', async () => {
|
||||
// Give the server a moment to fully initialize
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
const response = await fetch(`${registryUrl}/oci/v2/`);
|
||||
const response = await fetch(`${registryUrl}/v2/`);
|
||||
expect(response.status).toEqual(200);
|
||||
console.log('OCI v2 response:', await response.json());
|
||||
});
|
||||
@@ -352,7 +348,7 @@ tap.test('Docker CLI: should push image to registry', async () => {
|
||||
});
|
||||
|
||||
tap.test('Docker CLI: should verify manifest in registry via API', async () => {
|
||||
const response = await fetch(`${registryUrl}/oci/v2/test-image/tags/list`, {
|
||||
const response = await fetch(`${registryUrl}/v2/test-image/tags/list`, {
|
||||
headers: { Authorization: `Bearer ${ociToken}` },
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ tap.test('OCI: should create registry instance', async () => {
|
||||
tap.test('OCI: should handle version check (GET /v2/)', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: '/oci/v2/',
|
||||
path: '/oci/',
|
||||
headers: {},
|
||||
query: {},
|
||||
});
|
||||
@@ -36,7 +36,7 @@ tap.test('OCI: should handle version check (GET /v2/)', async () => {
|
||||
tap.test('OCI: should initiate blob upload (POST /v2/{name}/blobs/uploads/)', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'POST',
|
||||
path: '/oci/v2/test-repo/blobs/uploads/',
|
||||
path: '/oci/test-repo/blobs/uploads/',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -53,7 +53,7 @@ tap.test('OCI: should upload blob in single PUT', async () => {
|
||||
|
||||
const response = await registry.handleRequest({
|
||||
method: 'POST',
|
||||
path: '/oci/v2/test-repo/blobs/uploads/',
|
||||
path: '/oci/test-repo/blobs/uploads/',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -73,7 +73,7 @@ tap.test('OCI: should upload config blob', async () => {
|
||||
|
||||
const response = await registry.handleRequest({
|
||||
method: 'POST',
|
||||
path: '/oci/v2/test-repo/blobs/uploads/',
|
||||
path: '/oci/test-repo/blobs/uploads/',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -90,7 +90,7 @@ tap.test('OCI: should upload config blob', async () => {
|
||||
tap.test('OCI: should check if blob exists (HEAD /v2/{name}/blobs/{digest})', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'HEAD',
|
||||
path: `/oci/v2/test-repo/blobs/${testBlobDigest}`,
|
||||
path: `/oci/test-repo/blobs/${testBlobDigest}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -105,7 +105,7 @@ tap.test('OCI: should check if blob exists (HEAD /v2/{name}/blobs/{digest})', as
|
||||
tap.test('OCI: should retrieve blob (GET /v2/{name}/blobs/{digest})', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: `/oci/v2/test-repo/blobs/${testBlobDigest}`,
|
||||
path: `/oci/test-repo/blobs/${testBlobDigest}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -126,7 +126,7 @@ tap.test('OCI: should upload manifest (PUT /v2/{name}/manifests/{reference})', a
|
||||
|
||||
const response = await registry.handleRequest({
|
||||
method: 'PUT',
|
||||
path: '/oci/v2/test-repo/manifests/v1.0.0',
|
||||
path: '/oci/test-repo/manifests/v1.0.0',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
'Content-Type': 'application/vnd.oci.image.manifest.v1+json',
|
||||
@@ -143,7 +143,7 @@ tap.test('OCI: should upload manifest (PUT /v2/{name}/manifests/{reference})', a
|
||||
tap.test('OCI: should retrieve manifest by tag (GET /v2/{name}/manifests/{reference})', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: '/oci/v2/test-repo/manifests/v1.0.0',
|
||||
path: '/oci/test-repo/manifests/v1.0.0',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
Accept: 'application/vnd.oci.image.manifest.v1+json',
|
||||
@@ -163,7 +163,7 @@ tap.test('OCI: should retrieve manifest by tag (GET /v2/{name}/manifests/{refere
|
||||
tap.test('OCI: should retrieve manifest by digest (GET /v2/{name}/manifests/{digest})', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: `/oci/v2/test-repo/manifests/${testManifestDigest}`,
|
||||
path: `/oci/test-repo/manifests/${testManifestDigest}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
Accept: 'application/vnd.oci.image.manifest.v1+json',
|
||||
@@ -178,7 +178,7 @@ tap.test('OCI: should retrieve manifest by digest (GET /v2/{name}/manifests/{dig
|
||||
tap.test('OCI: should check if manifest exists (HEAD /v2/{name}/manifests/{reference})', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'HEAD',
|
||||
path: '/oci/v2/test-repo/manifests/v1.0.0',
|
||||
path: '/oci/test-repo/manifests/v1.0.0',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
Accept: 'application/vnd.oci.image.manifest.v1+json',
|
||||
@@ -193,7 +193,7 @@ tap.test('OCI: should check if manifest exists (HEAD /v2/{name}/manifests/{refer
|
||||
tap.test('OCI: should list tags (GET /v2/{name}/tags/list)', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: '/oci/v2/test-repo/tags/list',
|
||||
path: '/oci/test-repo/tags/list',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -212,7 +212,7 @@ tap.test('OCI: should list tags (GET /v2/{name}/tags/list)', async () => {
|
||||
tap.test('OCI: should handle pagination for tag list', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: '/oci/v2/test-repo/tags/list',
|
||||
path: '/oci/test-repo/tags/list',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -228,7 +228,7 @@ tap.test('OCI: should handle pagination for tag list', async () => {
|
||||
tap.test('OCI: should return 404 for non-existent blob', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: '/oci/v2/test-repo/blobs/sha256:0000000000000000000000000000000000000000000000000000000000000000',
|
||||
path: '/oci/test-repo/blobs/sha256:0000000000000000000000000000000000000000000000000000000000000000',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -242,7 +242,7 @@ tap.test('OCI: should return 404 for non-existent blob', async () => {
|
||||
tap.test('OCI: should return 404 for non-existent manifest', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: '/oci/v2/test-repo/manifests/non-existent-tag',
|
||||
path: '/oci/test-repo/manifests/non-existent-tag',
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
Accept: 'application/vnd.oci.image.manifest.v1+json',
|
||||
@@ -257,7 +257,7 @@ tap.test('OCI: should return 404 for non-existent manifest', async () => {
|
||||
tap.test('OCI: should delete manifest (DELETE /v2/{name}/manifests/{digest})', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'DELETE',
|
||||
path: `/oci/v2/test-repo/manifests/${testManifestDigest}`,
|
||||
path: `/oci/test-repo/manifests/${testManifestDigest}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -270,7 +270,7 @@ tap.test('OCI: should delete manifest (DELETE /v2/{name}/manifests/{digest})', a
|
||||
tap.test('OCI: should delete blob (DELETE /v2/{name}/blobs/{digest})', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'DELETE',
|
||||
path: `/oci/v2/test-repo/blobs/${testBlobDigest}`,
|
||||
path: `/oci/test-repo/blobs/${testBlobDigest}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ociToken}`,
|
||||
},
|
||||
@@ -283,7 +283,7 @@ tap.test('OCI: should delete blob (DELETE /v2/{name}/blobs/{digest})', async ()
|
||||
tap.test('OCI: should handle unauthorized requests', async () => {
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
path: '/oci/v2/test-repo/manifests/v1.0.0',
|
||||
path: '/oci/test-repo/manifests/v1.0.0',
|
||||
headers: {
|
||||
// No authorization header
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user