feat(core,storage,oci,registry-config): add streaming response support and configurable registry URLs across protocols
This commit is contained in:
@@ -2,6 +2,7 @@ import { tap, expect } from '@git.zone/tstest';
|
||||
import { RegistryStorage } from '../ts/core/classes.registrystorage.js';
|
||||
import { CargoRegistry } from '../ts/cargo/classes.cargoregistry.js';
|
||||
import { AuthManager } from '../ts/core/classes.authmanager.js';
|
||||
import { streamToJson } from '../ts/core/helpers.stream.js';
|
||||
|
||||
// Test index path calculation
|
||||
tap.test('should calculate correct index paths for different crate names', async () => {
|
||||
@@ -123,9 +124,10 @@ tap.test('should return valid config.json', async () => {
|
||||
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.headers['Content-Type']).to.equal('application/json');
|
||||
expect(response.body).to.be.an('object');
|
||||
expect(response.body.dl).to.include('/api/v1/crates/{crate}/{version}/download');
|
||||
expect(response.body.api).to.equal('http://localhost:5000/cargo');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).to.be.an('object');
|
||||
expect(body.dl).to.include('/api/v1/crates/{crate}/{version}/download');
|
||||
expect(body.api).to.equal('http://localhost:5000/cargo');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
||||
@@ -65,7 +65,9 @@ export async function cleanupS3Bucket(prefix?: string): Promise<void> {
|
||||
/**
|
||||
* Create a test SmartRegistry instance with all protocols enabled
|
||||
*/
|
||||
export async function createTestRegistry(): Promise<SmartRegistry> {
|
||||
export async function createTestRegistry(options?: {
|
||||
registryUrl?: string;
|
||||
}): Promise<SmartRegistry> {
|
||||
// Read S3 config from env.json
|
||||
const s3AccessKey = await testQenv.getEnvVarOnDemand('S3_ACCESSKEY');
|
||||
const s3SecretKey = await testQenv.getEnvVarOnDemand('S3_SECRETKEY');
|
||||
@@ -103,30 +105,37 @@ export async function createTestRegistry(): Promise<SmartRegistry> {
|
||||
oci: {
|
||||
enabled: true,
|
||||
basePath: '/oci',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/oci` } : {}),
|
||||
},
|
||||
npm: {
|
||||
enabled: true,
|
||||
basePath: '/npm',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/npm` } : {}),
|
||||
},
|
||||
maven: {
|
||||
enabled: true,
|
||||
basePath: '/maven',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/maven` } : {}),
|
||||
},
|
||||
composer: {
|
||||
enabled: true,
|
||||
basePath: '/composer',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/composer` } : {}),
|
||||
},
|
||||
cargo: {
|
||||
enabled: true,
|
||||
basePath: '/cargo',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/cargo` } : {}),
|
||||
},
|
||||
pypi: {
|
||||
enabled: true,
|
||||
basePath: '/pypi',
|
||||
...(options?.registryUrl ? { registryUrl: options.registryUrl } : {}),
|
||||
},
|
||||
rubygems: {
|
||||
enabled: true,
|
||||
basePath: '/rubygems',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/rubygems` } : {}),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -441,7 +450,7 @@ class TestClass
|
||||
},
|
||||
];
|
||||
|
||||
return zipTools.createZip(entries);
|
||||
return Buffer.from(await zipTools.createZip(entries));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,7 +524,7 @@ def hello():
|
||||
},
|
||||
];
|
||||
|
||||
return zipTools.createZip(entries);
|
||||
return Buffer.from(await zipTools.createZip(entries));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,7 +585,7 @@ def hello():
|
||||
},
|
||||
];
|
||||
|
||||
return tarTools.packFilesToTarGz(entries);
|
||||
return Buffer.from(await tarTools.packFilesToTarGz(entries));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -647,7 +656,7 @@ summary: Test gem for SmartRegistry
|
||||
test_files: []
|
||||
`;
|
||||
|
||||
const metadataGz = await gzipTools.compress(Buffer.from(metadataYaml, 'utf-8'));
|
||||
const metadataGz = Buffer.from(await gzipTools.compress(Buffer.from(metadataYaml, 'utf-8')));
|
||||
|
||||
// Create data.tar.gz content
|
||||
const libContent = `# ${gemName}
|
||||
@@ -668,7 +677,7 @@ end
|
||||
},
|
||||
];
|
||||
|
||||
const dataTarGz = await tarTools.packFilesToTarGz(dataEntries);
|
||||
const dataTarGz = Buffer.from(await tarTools.packFilesToTarGz(dataEntries));
|
||||
|
||||
// Create the outer gem (tar.gz containing metadata.gz and data.tar.gz)
|
||||
const gemEntries: smartarchive.IArchiveEntry[] = [
|
||||
@@ -683,7 +692,7 @@ end
|
||||
];
|
||||
|
||||
// RubyGems .gem files are plain tar archives (NOT gzipped), containing metadata.gz and data.tar.gz
|
||||
return tarTools.packFiles(gemEntries);
|
||||
return Buffer.from(await tarTools.packFiles(gemEntries));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,16 +79,10 @@ async function createHttpServer(
|
||||
res.setHeader(key, value);
|
||||
}
|
||||
|
||||
// Send body
|
||||
// Send body (response.body is always ReadableStream<Uint8Array> or undefined)
|
||||
if (response.body) {
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
res.end(response.body);
|
||||
} else if (typeof response.body === 'string') {
|
||||
res.end(response.body);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(response.body));
|
||||
}
|
||||
const { Readable } = await import('stream');
|
||||
Readable.fromWeb(response.body).pipe(res);
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
@@ -251,8 +245,11 @@ function cleanupTestDir(dir: string): void {
|
||||
// ========================================================================
|
||||
|
||||
tap.test('Cargo CLI: should setup registry and HTTP server', async () => {
|
||||
// Create registry
|
||||
registry = await createTestRegistry();
|
||||
// Use port 5000
|
||||
registryPort = 5000;
|
||||
|
||||
// Create registry with correct registryUrl for CLI tests
|
||||
registry = await createTestRegistry({ registryUrl: `http://localhost:${registryPort}` });
|
||||
const tokens = await createTestTokens(registry);
|
||||
cargoToken = tokens.cargoToken;
|
||||
|
||||
@@ -266,10 +263,6 @@ tap.test('Cargo CLI: should setup registry and HTTP server', async () => {
|
||||
} catch (error) {
|
||||
// Ignore error if operation fails
|
||||
}
|
||||
|
||||
// Use port 5000 (hardcoded in CargoRegistry default config)
|
||||
// TODO: Once registryUrl is configurable, use dynamic port like npm test (35001)
|
||||
registryPort = 5000;
|
||||
const serverSetup = await createHttpServer(registry, registryPort);
|
||||
server = serverSetup.server;
|
||||
registryUrl = serverSetup.url;
|
||||
|
||||
@@ -84,16 +84,10 @@ async function createHttpServer(
|
||||
res.setHeader(key, value);
|
||||
}
|
||||
|
||||
// Send body
|
||||
// Send body (response.body is always ReadableStream<Uint8Array> or undefined)
|
||||
if (response.body) {
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
res.end(response.body);
|
||||
} else if (typeof response.body === 'string') {
|
||||
res.end(response.body);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(response.body));
|
||||
}
|
||||
const { Readable } = await import('stream');
|
||||
Readable.fromWeb(response.body).pipe(res);
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
@@ -249,16 +243,16 @@ tap.test('Composer CLI: should verify composer is installed', async () => {
|
||||
});
|
||||
|
||||
tap.test('Composer CLI: should setup registry and HTTP server', async () => {
|
||||
// Create registry
|
||||
registry = await createTestRegistry();
|
||||
// Use port 38000 (avoids conflicts with other tests)
|
||||
registryPort = 38000;
|
||||
|
||||
// Create registry with correct registryUrl for CLI tests
|
||||
registry = await createTestRegistry({ registryUrl: `http://localhost:${registryPort}` });
|
||||
const tokens = await createTestTokens(registry);
|
||||
composerToken = tokens.composerToken;
|
||||
|
||||
expect(registry).toBeInstanceOf(SmartRegistry);
|
||||
expect(composerToken).toBeTypeOf('string');
|
||||
|
||||
// Use port 38000 (avoids conflicts with other tests)
|
||||
registryPort = 38000;
|
||||
const serverSetup = await createHttpServer(registry, registryPort);
|
||||
server = serverSetup.server;
|
||||
registryUrl = serverSetup.url;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToBuffer, streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import { createTestRegistry, createTestTokens, createComposerZip } from './helpers/registry.js';
|
||||
|
||||
let registry: SmartRegistry;
|
||||
@@ -41,9 +42,10 @@ tap.test('Composer: should return packages.json (GET /packages.json)', async ()
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('metadata-url');
|
||||
expect(response.body).toHaveProperty('available-packages');
|
||||
expect(response.body['available-packages']).toBeInstanceOf(Array);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('metadata-url');
|
||||
expect(body).toHaveProperty('available-packages');
|
||||
expect(body['available-packages']).toBeInstanceOf(Array);
|
||||
});
|
||||
|
||||
tap.test('Composer: should upload a package (PUT /packages/{vendor/package})', async () => {
|
||||
@@ -59,9 +61,10 @@ tap.test('Composer: should upload a package (PUT /packages/{vendor/package})', a
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(201);
|
||||
expect(response.body.status).toEqual('success');
|
||||
expect(response.body.package).toEqual(testPackageName);
|
||||
expect(response.body.version).toEqual(testVersion);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body.status).toEqual('success');
|
||||
expect(body.package).toEqual(testPackageName);
|
||||
expect(body.version).toEqual(testVersion);
|
||||
});
|
||||
|
||||
tap.test('Composer: should retrieve package metadata (GET /p2/{vendor/package}.json)', async () => {
|
||||
@@ -73,11 +76,12 @@ tap.test('Composer: should retrieve package metadata (GET /p2/{vendor/package}.j
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('packages');
|
||||
expect(response.body.packages[testPackageName]).toBeInstanceOf(Array);
|
||||
expect(response.body.packages[testPackageName].length).toEqual(1);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('packages');
|
||||
expect(body.packages[testPackageName]).toBeInstanceOf(Array);
|
||||
expect(body.packages[testPackageName].length).toEqual(1);
|
||||
|
||||
const packageData = response.body.packages[testPackageName][0];
|
||||
const packageData = body.packages[testPackageName][0];
|
||||
expect(packageData.name).toEqual(testPackageName);
|
||||
expect(packageData.version).toEqual(testVersion);
|
||||
expect(packageData.version_normalized).toEqual('1.0.0.0');
|
||||
@@ -97,7 +101,8 @@ tap.test('Composer: should download package ZIP (GET /dists/{vendor/package}/{re
|
||||
query: {},
|
||||
});
|
||||
|
||||
const reference = metadataResponse.body.packages[testPackageName][0].dist.reference;
|
||||
const metaBody = await streamToJson(metadataResponse.body);
|
||||
const reference = metaBody.packages[testPackageName][0].dist.reference;
|
||||
|
||||
const response = await registry.handleRequest({
|
||||
method: 'GET',
|
||||
@@ -107,7 +112,8 @@ tap.test('Composer: should download package ZIP (GET /dists/{vendor/package}/{re
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(response.headers['Content-Type']).toEqual('application/zip');
|
||||
expect(response.headers['Content-Disposition']).toContain('attachment');
|
||||
});
|
||||
@@ -121,9 +127,10 @@ tap.test('Composer: should list packages (GET /packages/list.json)', async () =>
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('packageNames');
|
||||
expect(response.body.packageNames).toBeInstanceOf(Array);
|
||||
expect(response.body.packageNames).toContain(testPackageName);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('packageNames');
|
||||
expect(body.packageNames).toBeInstanceOf(Array);
|
||||
expect(body.packageNames).toContain(testPackageName);
|
||||
});
|
||||
|
||||
tap.test('Composer: should filter package list (GET /packages/list.json?filter=vendor/*)', async () => {
|
||||
@@ -135,8 +142,9 @@ tap.test('Composer: should filter package list (GET /packages/list.json?filter=v
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body.packageNames).toBeInstanceOf(Array);
|
||||
expect(response.body.packageNames).toContain(testPackageName);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body.packageNames).toBeInstanceOf(Array);
|
||||
expect(body.packageNames).toContain(testPackageName);
|
||||
});
|
||||
|
||||
tap.test('Composer: should prevent duplicate version upload', async () => {
|
||||
@@ -152,8 +160,9 @@ tap.test('Composer: should prevent duplicate version upload', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(409);
|
||||
expect(response.body.status).toEqual('error');
|
||||
expect(response.body.message).toContain('already exists');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body.status).toEqual('error');
|
||||
expect(body.message).toContain('already exists');
|
||||
});
|
||||
|
||||
tap.test('Composer: should upload a second version', async () => {
|
||||
@@ -172,8 +181,9 @@ tap.test('Composer: should upload a second version', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(201);
|
||||
expect(response.body.status).toEqual('success');
|
||||
expect(response.body.version).toEqual(testVersion2);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body.status).toEqual('success');
|
||||
expect(body.version).toEqual(testVersion2);
|
||||
});
|
||||
|
||||
tap.test('Composer: should return multiple versions in metadata', async () => {
|
||||
@@ -185,10 +195,11 @@ tap.test('Composer: should return multiple versions in metadata', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body.packages[testPackageName]).toBeInstanceOf(Array);
|
||||
expect(response.body.packages[testPackageName].length).toEqual(2);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body.packages[testPackageName]).toBeInstanceOf(Array);
|
||||
expect(body.packages[testPackageName].length).toEqual(2);
|
||||
|
||||
const versions = response.body.packages[testPackageName].map((p: any) => p.version);
|
||||
const versions = body.packages[testPackageName].map((p: any) => p.version);
|
||||
expect(versions).toContain('1.0.0');
|
||||
expect(versions).toContain('1.1.0');
|
||||
});
|
||||
@@ -213,8 +224,9 @@ tap.test('Composer: should delete a specific version (DELETE /packages/{vendor/p
|
||||
query: {},
|
||||
});
|
||||
|
||||
expect(metadataResponse.body.packages[testPackageName].length).toEqual(1);
|
||||
expect(metadataResponse.body.packages[testPackageName][0].version).toEqual('1.1.0');
|
||||
const metaBody = await streamToJson(metadataResponse.body);
|
||||
expect(metaBody.packages[testPackageName].length).toEqual(1);
|
||||
expect(metaBody.packages[testPackageName][0].version).toEqual('1.1.0');
|
||||
});
|
||||
|
||||
tap.test('Composer: should require auth for package upload', async () => {
|
||||
@@ -231,7 +243,8 @@ tap.test('Composer: should require auth for package upload', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(401);
|
||||
expect(response.body.status).toEqual('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body.status).toEqual('error');
|
||||
});
|
||||
|
||||
tap.test('Composer: should reject invalid ZIP (no composer.json)', async () => {
|
||||
@@ -249,8 +262,9 @@ tap.test('Composer: should reject invalid ZIP (no composer.json)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(400);
|
||||
expect(response.body.status).toEqual('error');
|
||||
expect(response.body.message).toContain('composer.json');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body.status).toEqual('error');
|
||||
expect(body.message).toContain('composer.json');
|
||||
});
|
||||
|
||||
tap.test('Composer: should delete entire package (DELETE /packages/{vendor/package})', async () => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToBuffer, streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import {
|
||||
createTestRegistry,
|
||||
createTestTokens,
|
||||
@@ -79,7 +80,9 @@ tap.test('Integration: should handle /simple path for PyPI', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toStartWith('text/html');
|
||||
expect(response.body).toContain('integration-test-py');
|
||||
const body = await streamToBuffer(response.body);
|
||||
const text = body.toString('utf-8');
|
||||
expect(text).toContain('integration-test-py');
|
||||
});
|
||||
|
||||
tap.test('Integration: should reject PyPI token for RubyGems endpoint', async () => {
|
||||
@@ -135,8 +138,9 @@ tap.test('Integration: should return 404 for unknown paths', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect((response.body as any).error).toEqual('NOT_FOUND');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
expect(body.error).toEqual('NOT_FOUND');
|
||||
});
|
||||
|
||||
tap.test('Integration: should retrieve PyPI registry instance', async () => {
|
||||
|
||||
@@ -1,32 +1,34 @@
|
||||
/**
|
||||
* Integration test for smartregistry with smarts3
|
||||
* Integration test for smartregistry with smartstorage
|
||||
* Verifies that smartregistry works with a local S3-compatible server
|
||||
*/
|
||||
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smarts3Module from '@push.rocks/smarts3';
|
||||
import * as smartstorageModule from '@push.rocks/smartstorage';
|
||||
import { SmartRegistry } from '../ts/classes.smartregistry.js';
|
||||
import type { IRegistryConfig } from '../ts/core/interfaces.core.js';
|
||||
import { streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
let s3Server: smarts3Module.Smarts3;
|
||||
let s3Server: smartstorageModule.SmartStorage;
|
||||
let registry: SmartRegistry;
|
||||
|
||||
/**
|
||||
* Setup: Start smarts3 server
|
||||
* Setup: Start smartstorage server
|
||||
*/
|
||||
tap.test('should start smarts3 server', async () => {
|
||||
s3Server = await smarts3Module.Smarts3.createAndStart({
|
||||
tap.test('should start smartstorage server', async () => {
|
||||
s3Server = await smartstorageModule.SmartStorage.createAndStart({
|
||||
server: {
|
||||
port: 3456, // Use different port to avoid conflicts with other tests
|
||||
host: '0.0.0.0',
|
||||
port: 3456,
|
||||
address: '0.0.0.0',
|
||||
silent: true,
|
||||
},
|
||||
storage: {
|
||||
cleanSlate: true, // Fresh storage for each test run
|
||||
bucketsDir: './.nogit/smarts3-test-buckets',
|
||||
cleanSlate: true,
|
||||
directory: './.nogit/smartstorage-test-buckets',
|
||||
},
|
||||
logging: {
|
||||
silent: true, // Reduce test output noise
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -34,20 +36,10 @@ tap.test('should start smarts3 server', async () => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Setup: Create SmartRegistry with smarts3 configuration
|
||||
* Setup: Create SmartRegistry with smartstorage configuration
|
||||
*/
|
||||
tap.test('should create SmartRegistry instance with smarts3 IS3Descriptor', async () => {
|
||||
// Manually construct IS3Descriptor based on smarts3 configuration
|
||||
// Note: smarts3.getS3Descriptor() returns empty object as of v5.1.0
|
||||
// This is a known limitation - smarts3 doesn't expose its config properly
|
||||
const s3Descriptor = {
|
||||
endpoint: 'localhost',
|
||||
port: 3456,
|
||||
accessKey: 'test', // smarts3 doesn't require real credentials
|
||||
accessSecret: 'test',
|
||||
useSsl: false,
|
||||
region: 'us-east-1',
|
||||
};
|
||||
const s3Descriptor = await s3Server.getStorageDescriptor();
|
||||
|
||||
const config: IRegistryConfig = {
|
||||
storage: {
|
||||
@@ -97,7 +89,7 @@ tap.test('should create SmartRegistry instance with smarts3 IS3Descriptor', asyn
|
||||
});
|
||||
|
||||
/**
|
||||
* Test NPM protocol with smarts3
|
||||
* Test NPM protocol with smartstorage
|
||||
*/
|
||||
tap.test('NPM: should publish package to smarts3', async () => {
|
||||
const authManager = registry.getAuthManager();
|
||||
@@ -139,7 +131,7 @@ tap.test('NPM: should publish package to smarts3', async () => {
|
||||
body: packageData,
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(201); // 201 Created is correct for publishing
|
||||
expect(response.status).toEqual(201);
|
||||
});
|
||||
|
||||
tap.test('NPM: should retrieve package from smarts3', async () => {
|
||||
@@ -151,12 +143,13 @@ tap.test('NPM: should retrieve package from smarts3', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('name');
|
||||
expect(response.body.name).toEqual('test-package-smarts3');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('name');
|
||||
expect(body.name).toEqual('test-package-smarts3');
|
||||
});
|
||||
|
||||
/**
|
||||
* Test OCI protocol with smarts3
|
||||
* Test OCI protocol with smartstorage
|
||||
*/
|
||||
tap.test('OCI: should store blob in smarts3', async () => {
|
||||
const authManager = registry.getAuthManager();
|
||||
@@ -173,7 +166,7 @@ tap.test('OCI: should store blob in smarts3', async () => {
|
||||
// Initiate blob upload
|
||||
const initiateResponse = await registry.handleRequest({
|
||||
method: 'POST',
|
||||
path: '/oci/v2/test-image/blobs/uploads/',
|
||||
path: '/oci/test-image/blobs/uploads/',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
@@ -196,7 +189,7 @@ tap.test('OCI: should store blob in smarts3', async () => {
|
||||
|
||||
const uploadResponse = await registry.handleRequest({
|
||||
method: 'PUT',
|
||||
path: `/oci/v2/test-image/blobs/uploads/${uploadId}`,
|
||||
path: `/oci/test-image/blobs/uploads/${uploadId}`,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/octet-stream',
|
||||
@@ -209,18 +202,9 @@ tap.test('OCI: should store blob in smarts3', async () => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Test PyPI protocol with smarts3
|
||||
* Test PyPI protocol with smartstorage
|
||||
*/
|
||||
tap.test('PyPI: should upload package to smarts3', async () => {
|
||||
const authManager = registry.getAuthManager();
|
||||
const userId = await authManager.authenticate({
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
});
|
||||
const token = await authManager.createPypiToken(userId, false);
|
||||
|
||||
// Note: In a real test, this would be multipart/form-data
|
||||
// For simplicity, we're testing the storage layer
|
||||
const storage = registry.getStorage();
|
||||
|
||||
// Store a test package file
|
||||
@@ -252,7 +236,7 @@ tap.test('PyPI: should upload package to smarts3', async () => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Test Cargo protocol with smarts3
|
||||
* Test Cargo protocol with smartstorage
|
||||
*/
|
||||
tap.test('Cargo: should store crate in smarts3', async () => {
|
||||
const storage = registry.getStorage();
|
||||
@@ -281,11 +265,11 @@ tap.test('Cargo: should store crate in smarts3', async () => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Cleanup: Stop smarts3 server
|
||||
* Cleanup: Stop smartstorage server
|
||||
*/
|
||||
tap.test('should stop smarts3 server', async () => {
|
||||
tap.test('should stop smartstorage server', async () => {
|
||||
await s3Server.stop();
|
||||
expect(true).toEqual(true); // Just verify it completes without error
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
||||
@@ -79,16 +79,10 @@ async function createHttpServer(
|
||||
res.setHeader(key, value);
|
||||
}
|
||||
|
||||
// Send body
|
||||
// Send body (response.body is always ReadableStream<Uint8Array> or undefined)
|
||||
if (response.body) {
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
res.end(response.body);
|
||||
} else if (typeof response.body === 'string') {
|
||||
res.end(response.body);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(response.body));
|
||||
}
|
||||
const { Readable } = await import('stream');
|
||||
Readable.fromWeb(response.body).pipe(res);
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
@@ -282,16 +276,16 @@ tap.test('Maven CLI: should verify mvn is installed', async () => {
|
||||
});
|
||||
|
||||
tap.test('Maven CLI: should setup registry and HTTP server', async () => {
|
||||
// Create registry
|
||||
registry = await createTestRegistry();
|
||||
// Use port 37000 (avoids conflicts with other tests)
|
||||
registryPort = 37000;
|
||||
|
||||
// Create registry with correct registryUrl for CLI tests
|
||||
registry = await createTestRegistry({ registryUrl: `http://localhost:${registryPort}` });
|
||||
const tokens = await createTestTokens(registry);
|
||||
mavenToken = tokens.mavenToken;
|
||||
|
||||
expect(registry).toBeInstanceOf(SmartRegistry);
|
||||
expect(mavenToken).toBeTypeOf('string');
|
||||
|
||||
// Use port 37000 (avoids conflicts with other tests)
|
||||
registryPort = 37000;
|
||||
const serverSetup = await createHttpServer(registry, registryPort);
|
||||
server = serverSetup.server;
|
||||
registryUrl = serverSetup.url;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToBuffer, streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import {
|
||||
createTestRegistry,
|
||||
createTestTokens,
|
||||
@@ -88,10 +89,11 @@ tap.test('Maven: should retrieve uploaded POM file (GET)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).toString('utf-8')).toContain(testGroupId);
|
||||
expect((response.body as Buffer).toString('utf-8')).toContain(testArtifactId);
|
||||
expect((response.body as Buffer).toString('utf-8')).toContain(testVersion);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.toString('utf-8')).toContain(testGroupId);
|
||||
expect(body.toString('utf-8')).toContain(testArtifactId);
|
||||
expect(body.toString('utf-8')).toContain(testVersion);
|
||||
expect(response.headers['Content-Type']).toEqual('application/xml');
|
||||
});
|
||||
|
||||
@@ -107,7 +109,8 @@ tap.test('Maven: should retrieve uploaded JAR file (GET)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(response.headers['Content-Type']).toEqual('application/java-archive');
|
||||
});
|
||||
|
||||
@@ -124,8 +127,9 @@ tap.test('Maven: should retrieve MD5 checksum for JAR (GET *.jar.md5)', async ()
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).toString('utf-8')).toEqual(checksums.md5);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.toString('utf-8')).toEqual(checksums.md5);
|
||||
expect(response.headers['Content-Type']).toEqual('text/plain');
|
||||
});
|
||||
|
||||
@@ -142,8 +146,9 @@ tap.test('Maven: should retrieve SHA1 checksum for JAR (GET *.jar.sha1)', async
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).toString('utf-8')).toEqual(checksums.sha1);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.toString('utf-8')).toEqual(checksums.sha1);
|
||||
expect(response.headers['Content-Type']).toEqual('text/plain');
|
||||
});
|
||||
|
||||
@@ -160,8 +165,9 @@ tap.test('Maven: should retrieve SHA256 checksum for JAR (GET *.jar.sha256)', as
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).toString('utf-8')).toEqual(checksums.sha256);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.toString('utf-8')).toEqual(checksums.sha256);
|
||||
expect(response.headers['Content-Type']).toEqual('text/plain');
|
||||
});
|
||||
|
||||
@@ -178,8 +184,9 @@ tap.test('Maven: should retrieve SHA512 checksum for JAR (GET *.jar.sha512)', as
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).toString('utf-8')).toEqual(checksums.sha512);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.toString('utf-8')).toEqual(checksums.sha512);
|
||||
expect(response.headers['Content-Type']).toEqual('text/plain');
|
||||
});
|
||||
|
||||
@@ -194,8 +201,9 @@ tap.test('Maven: should retrieve maven-metadata.xml (GET)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const xml = (response.body as Buffer).toString('utf-8');
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
const xml = body.toString('utf-8');
|
||||
expect(xml).toContain('<groupId>');
|
||||
expect(xml).toContain('<artifactId>');
|
||||
expect(xml).toContain('<version>1.0.0</version>');
|
||||
@@ -247,7 +255,8 @@ tap.test('Maven: should upload a second version and update metadata', async () =
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
const xml = (response.body as Buffer).toString('utf-8');
|
||||
const metaBody = await streamToBuffer(response.body);
|
||||
const xml = metaBody.toString('utf-8');
|
||||
expect(xml).toContain('<version>1.0.0</version>');
|
||||
expect(xml).toContain('<version>2.0.0</version>');
|
||||
expect(xml).toContain('<latest>2.0.0</latest>');
|
||||
@@ -285,7 +294,8 @@ tap.test('Maven: should return 404 for non-existent artifact', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('Maven: should return 401 for unauthorized upload', async () => {
|
||||
@@ -304,7 +314,8 @@ tap.test('Maven: should return 401 for unauthorized upload', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(401);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('Maven: should reject POM upload with mismatched GAV', async () => {
|
||||
@@ -328,7 +339,8 @@ tap.test('Maven: should reject POM upload with mismatched GAV', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(400);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('Maven: should delete an artifact (DELETE)', async () => {
|
||||
|
||||
@@ -79,16 +79,10 @@ async function createHttpServer(
|
||||
res.setHeader(key, value);
|
||||
}
|
||||
|
||||
// Send body
|
||||
// Send body (response.body is always ReadableStream<Uint8Array> or undefined)
|
||||
if (response.body) {
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
res.end(response.body);
|
||||
} else if (typeof response.body === 'string') {
|
||||
res.end(response.body);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(response.body));
|
||||
}
|
||||
const { Readable } = await import('stream');
|
||||
Readable.fromWeb(response.body).pipe(res);
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
@@ -224,16 +218,16 @@ function cleanupTestDir(dir: string): void {
|
||||
// ========================================================================
|
||||
|
||||
tap.test('NPM CLI: should setup registry and HTTP server', async () => {
|
||||
// Create registry
|
||||
registry = await createTestRegistry();
|
||||
// Find available port
|
||||
registryPort = 35000;
|
||||
|
||||
// Create registry with correct registryUrl for CLI tests
|
||||
registry = await createTestRegistry({ registryUrl: `http://localhost:${registryPort}` });
|
||||
const tokens = await createTestTokens(registry);
|
||||
npmToken = tokens.npmToken;
|
||||
|
||||
expect(registry).toBeInstanceOf(SmartRegistry);
|
||||
expect(npmToken).toBeTypeOf('string');
|
||||
|
||||
// Find available port
|
||||
registryPort = 35000;
|
||||
const serverSetup = await createHttpServer(registry, registryPort);
|
||||
server = serverSetup.server;
|
||||
registryUrl = serverSetup.url;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToBuffer, streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import { createTestRegistry, createTestTokens, createTestPackument } from './helpers/registry.js';
|
||||
|
||||
let registry: SmartRegistry;
|
||||
@@ -34,8 +35,9 @@ tap.test('NPM: should handle user authentication (PUT /-/user/org.couchdb.user:{
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(201);
|
||||
expect(response.body).toHaveProperty('token');
|
||||
expect((response.body as any).token).toBeTypeOf('string');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('token');
|
||||
expect(body.token).toBeTypeOf('string');
|
||||
});
|
||||
|
||||
tap.test('NPM: should publish a package (PUT /{package})', async () => {
|
||||
@@ -53,8 +55,9 @@ tap.test('NPM: should publish a package (PUT /{package})', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(201);
|
||||
expect(response.body).toHaveProperty('ok');
|
||||
expect((response.body as any).ok).toEqual(true);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('ok');
|
||||
expect(body.ok).toEqual(true);
|
||||
});
|
||||
|
||||
tap.test('NPM: should retrieve package metadata (GET /{package})', async () => {
|
||||
@@ -66,10 +69,11 @@ tap.test('NPM: should retrieve package metadata (GET /{package})', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('name');
|
||||
expect((response.body as any).name).toEqual(testPackageName);
|
||||
expect((response.body as any).versions).toHaveProperty(testVersion);
|
||||
expect((response.body as any)['dist-tags'].latest).toEqual(testVersion);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('name');
|
||||
expect(body.name).toEqual(testPackageName);
|
||||
expect(body.versions).toHaveProperty(testVersion);
|
||||
expect(body['dist-tags'].latest).toEqual(testVersion);
|
||||
});
|
||||
|
||||
tap.test('NPM: should retrieve specific version metadata (GET /{package}/{version})', async () => {
|
||||
@@ -81,9 +85,10 @@ tap.test('NPM: should retrieve specific version metadata (GET /{package}/{versio
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('version');
|
||||
expect((response.body as any).version).toEqual(testVersion);
|
||||
expect((response.body as any).name).toEqual(testPackageName);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('version');
|
||||
expect(body.version).toEqual(testVersion);
|
||||
expect(body.name).toEqual(testPackageName);
|
||||
});
|
||||
|
||||
tap.test('NPM: should download tarball (GET /{package}/-/{tarball})', async () => {
|
||||
@@ -95,8 +100,9 @@ tap.test('NPM: should download tarball (GET /{package}/-/{tarball})', async () =
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).toString('utf-8')).toEqual('fake tarball content');
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.toString('utf-8')).toEqual('fake tarball content');
|
||||
expect(response.headers['Content-Type']).toEqual('application/octet-stream');
|
||||
});
|
||||
|
||||
@@ -127,7 +133,8 @@ tap.test('NPM: should publish a new version of the package', async () => {
|
||||
});
|
||||
|
||||
expect(getResponse.status).toEqual(200);
|
||||
expect((getResponse.body as any).versions).toHaveProperty(newVersion);
|
||||
const getBody = await streamToJson(getResponse.body);
|
||||
expect(getBody.versions).toHaveProperty(newVersion);
|
||||
});
|
||||
|
||||
tap.test('NPM: should get dist-tags (GET /-/package/{pkg}/dist-tags)', async () => {
|
||||
@@ -139,8 +146,9 @@ tap.test('NPM: should get dist-tags (GET /-/package/{pkg}/dist-tags)', async ()
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('latest');
|
||||
expect((response.body as any).latest).toBeTypeOf('string');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('latest');
|
||||
expect(body.latest).toBeTypeOf('string');
|
||||
});
|
||||
|
||||
tap.test('NPM: should update dist-tag (PUT /-/package/{pkg}/dist-tags/{tag})', async () => {
|
||||
@@ -165,7 +173,8 @@ tap.test('NPM: should update dist-tag (PUT /-/package/{pkg}/dist-tags/{tag})', a
|
||||
query: {},
|
||||
});
|
||||
|
||||
expect((getResponse.body as any)['dist-tags'].beta).toEqual('1.1.0');
|
||||
const getBody2 = await streamToJson(getResponse.body);
|
||||
expect(getBody2['dist-tags'].beta).toEqual('1.1.0');
|
||||
});
|
||||
|
||||
tap.test('NPM: should delete dist-tag (DELETE /-/package/{pkg}/dist-tags/{tag})', async () => {
|
||||
@@ -188,7 +197,8 @@ tap.test('NPM: should delete dist-tag (DELETE /-/package/{pkg}/dist-tags/{tag})'
|
||||
query: {},
|
||||
});
|
||||
|
||||
expect((getResponse.body as any)['dist-tags']).not.toHaveProperty('beta');
|
||||
const getBody3 = await streamToJson(getResponse.body);
|
||||
expect(getBody3['dist-tags']).not.toHaveProperty('beta');
|
||||
});
|
||||
|
||||
tap.test('NPM: should create a new token (POST /-/npm/v1/tokens)', async () => {
|
||||
@@ -208,8 +218,9 @@ tap.test('NPM: should create a new token (POST /-/npm/v1/tokens)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('token');
|
||||
expect((response.body as any).readonly).toEqual(true);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('token');
|
||||
expect(body.readonly).toEqual(true);
|
||||
});
|
||||
|
||||
tap.test('NPM: should list tokens (GET /-/npm/v1/tokens)', async () => {
|
||||
@@ -223,9 +234,10 @@ tap.test('NPM: should list tokens (GET /-/npm/v1/tokens)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('objects');
|
||||
expect((response.body as any).objects).toBeInstanceOf(Array);
|
||||
expect((response.body as any).objects.length).toBeGreaterThan(0);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('objects');
|
||||
expect(body.objects).toBeInstanceOf(Array);
|
||||
expect(body.objects.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
tap.test('NPM: should search packages (GET /-/v1/search)', async () => {
|
||||
@@ -240,9 +252,10 @@ tap.test('NPM: should search packages (GET /-/v1/search)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('objects');
|
||||
expect((response.body as any).objects).toBeInstanceOf(Array);
|
||||
expect((response.body as any).total).toBeGreaterThan(0);
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('objects');
|
||||
expect(body.objects).toBeInstanceOf(Array);
|
||||
expect(body.total).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
tap.test('NPM: should search packages with specific query', async () => {
|
||||
@@ -256,7 +269,8 @@ tap.test('NPM: should search packages with specific query', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
const results = (response.body as any).objects;
|
||||
const body = await streamToJson(response.body);
|
||||
const results = body.objects;
|
||||
expect(results.length).toBeGreaterThan(0);
|
||||
expect(results[0].package.name).toEqual(testPackageName);
|
||||
});
|
||||
@@ -281,7 +295,8 @@ tap.test('NPM: should unpublish a specific version (DELETE /{package}/-/{version
|
||||
query: {},
|
||||
});
|
||||
|
||||
expect((getResponse.body as any).versions).not.toHaveProperty(testVersion);
|
||||
const getBody4 = await streamToJson(getResponse.body);
|
||||
expect(getBody4.versions).not.toHaveProperty(testVersion);
|
||||
});
|
||||
|
||||
tap.test('NPM: should unpublish entire package (DELETE /{package}/-rev/{rev})', async () => {
|
||||
@@ -316,7 +331,8 @@ tap.test('NPM: should return 404 for non-existent package', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('NPM: should return 401 for unauthorized publish', async () => {
|
||||
@@ -334,7 +350,8 @@ tap.test('NPM: should return 401 for unauthorized publish', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(401);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('NPM: should reject readonly token for write operations', async () => {
|
||||
|
||||
@@ -175,16 +175,10 @@ async function createHttpServer(
|
||||
res.setHeader(key, value);
|
||||
}
|
||||
|
||||
// Send body
|
||||
// Send body (response.body is always ReadableStream<Uint8Array> or undefined)
|
||||
if (response.body) {
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
res.end(response.body);
|
||||
} else if (typeof response.body === 'string') {
|
||||
res.end(response.body);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(response.body));
|
||||
}
|
||||
const { Readable } = await import('stream');
|
||||
Readable.fromWeb(response.body).pipe(res);
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToBuffer, streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import { createTestRegistry, createTestTokens, calculateDigest, createTestManifest } from './helpers/registry.js';
|
||||
|
||||
let registry: SmartRegistry;
|
||||
@@ -113,8 +114,9 @@ tap.test('OCI: should retrieve blob (GET /v2/{name}/blobs/{digest})', async () =
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).toString('utf-8')).toEqual('Hello from OCI test blob!');
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.toString('utf-8')).toEqual('Hello from OCI test blob!');
|
||||
expect(response.headers['Docker-Content-Digest']).toEqual(testBlobDigest);
|
||||
});
|
||||
|
||||
@@ -152,9 +154,10 @@ tap.test('OCI: should retrieve manifest by tag (GET /v2/{name}/manifests/{refere
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
|
||||
const manifest = JSON.parse((response.body as Buffer).toString('utf-8'));
|
||||
const manifest = JSON.parse(body.toString('utf-8'));
|
||||
expect(manifest.schemaVersion).toEqual(2);
|
||||
expect(manifest.config.digest).toEqual(testConfigDigest);
|
||||
expect(manifest.layers[0].digest).toEqual(testBlobDigest);
|
||||
@@ -201,9 +204,9 @@ tap.test('OCI: should list tags (GET /v2/{name}/tags/list)', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('tags');
|
||||
const tagList = await streamToJson(response.body);
|
||||
expect(tagList).toHaveProperty('tags');
|
||||
|
||||
const tagList = response.body as any;
|
||||
expect(tagList.name).toEqual('test-repo');
|
||||
expect(tagList.tags).toBeInstanceOf(Array);
|
||||
expect(tagList.tags).toContain('v1.0.0');
|
||||
@@ -222,7 +225,8 @@ tap.test('OCI: should handle pagination for tag list', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('tags');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('tags');
|
||||
});
|
||||
|
||||
tap.test('OCI: should return 404 for non-existent blob', async () => {
|
||||
@@ -236,7 +240,8 @@ tap.test('OCI: should return 404 for non-existent blob', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('errors');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('errors');
|
||||
});
|
||||
|
||||
tap.test('OCI: should return 404 for non-existent manifest', async () => {
|
||||
@@ -251,7 +256,8 @@ tap.test('OCI: should return 404 for non-existent manifest', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('errors');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('errors');
|
||||
});
|
||||
|
||||
tap.test('OCI: should delete manifest (DELETE /v2/{name}/manifests/{digest})', async () => {
|
||||
|
||||
@@ -89,16 +89,10 @@ async function createHttpServer(
|
||||
res.setHeader(key, value);
|
||||
}
|
||||
|
||||
// Send body
|
||||
// Send body (response.body is always ReadableStream<Uint8Array> or undefined)
|
||||
if (response.body) {
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
res.end(response.body);
|
||||
} else if (typeof response.body === 'string') {
|
||||
res.end(response.body);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(response.body));
|
||||
}
|
||||
const { Readable } = await import('stream');
|
||||
Readable.fromWeb(response.body).pipe(res);
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
@@ -303,16 +297,16 @@ tap.test('PyPI CLI: should verify twine is installed', async () => {
|
||||
});
|
||||
|
||||
tap.test('PyPI CLI: should setup registry and HTTP server', async () => {
|
||||
// Create registry
|
||||
registry = await createTestRegistry();
|
||||
// Use port 39000 (avoids conflicts with other tests)
|
||||
registryPort = 39000;
|
||||
|
||||
// Create registry with correct registryUrl for CLI tests
|
||||
registry = await createTestRegistry({ registryUrl: `http://localhost:${registryPort}` });
|
||||
const tokens = await createTestTokens(registry);
|
||||
pypiToken = tokens.pypiToken;
|
||||
|
||||
expect(registry).toBeInstanceOf(SmartRegistry);
|
||||
expect(pypiToken).toBeTypeOf('string');
|
||||
|
||||
// Use port 39000 (avoids conflicts with other tests)
|
||||
registryPort = 39000;
|
||||
const serverSetup = await createHttpServer(registry, registryPort);
|
||||
server = serverSetup.server;
|
||||
registryUrl = serverSetup.url;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToBuffer, streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import {
|
||||
createTestRegistry,
|
||||
createTestTokens,
|
||||
@@ -101,9 +102,10 @@ tap.test('PyPI: should retrieve Simple API root index HTML (GET /simple/)', asyn
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toStartWith('text/html');
|
||||
expect(response.body).toBeTypeOf('string');
|
||||
const body = await streamToBuffer(response.body);
|
||||
const html = body.toString('utf-8');
|
||||
expect(html).toBeTypeOf('string');
|
||||
|
||||
const html = response.body as string;
|
||||
expect(html).toContain('<!DOCTYPE html>');
|
||||
expect(html).toContain('<title>Simple Index</title>');
|
||||
expect(html).toContain(normalizedPackageName);
|
||||
@@ -121,9 +123,9 @@ tap.test('PyPI: should retrieve Simple API root index JSON (GET /simple/ with Ac
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/vnd.pypi.simple.v1+json');
|
||||
expect(response.body).toBeTypeOf('object');
|
||||
const json = await streamToJson(response.body);
|
||||
expect(json).toBeTypeOf('object');
|
||||
|
||||
const json = response.body as any;
|
||||
expect(json).toHaveProperty('meta');
|
||||
expect(json).toHaveProperty('projects');
|
||||
expect(json.projects).toBeInstanceOf(Array);
|
||||
@@ -144,9 +146,10 @@ tap.test('PyPI: should retrieve Simple API package HTML (GET /simple/{package}/)
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toStartWith('text/html');
|
||||
expect(response.body).toBeTypeOf('string');
|
||||
const body = await streamToBuffer(response.body);
|
||||
const html = body.toString('utf-8');
|
||||
expect(html).toBeTypeOf('string');
|
||||
|
||||
const html = response.body as string;
|
||||
expect(html).toContain('<!DOCTYPE html>');
|
||||
expect(html).toContain(`<title>Links for ${normalizedPackageName}</title>`);
|
||||
expect(html).toContain('.whl');
|
||||
@@ -165,9 +168,9 @@ tap.test('PyPI: should retrieve Simple API package JSON (GET /simple/{package}/
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/vnd.pypi.simple.v1+json');
|
||||
expect(response.body).toBeTypeOf('object');
|
||||
const json = await streamToJson(response.body);
|
||||
expect(json).toBeTypeOf('object');
|
||||
|
||||
const json = response.body as any;
|
||||
expect(json).toHaveProperty('meta');
|
||||
expect(json).toHaveProperty('name');
|
||||
expect(json.name).toEqual(normalizedPackageName);
|
||||
@@ -187,8 +190,9 @@ tap.test('PyPI: should download wheel file (GET /pypi/packages/{package}/{filena
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).length).toEqual(testWheelData.length);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.length).toEqual(testWheelData.length);
|
||||
expect(response.headers['Content-Type']).toEqual('application/octet-stream');
|
||||
});
|
||||
|
||||
@@ -234,7 +238,7 @@ tap.test('PyPI: should list both wheel and sdist in Simple API', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const json = response.body as any;
|
||||
const json = await streamToJson(response.body);
|
||||
// PEP 691: files is an array of file objects
|
||||
expect(json.files.length).toEqual(2);
|
||||
|
||||
@@ -289,7 +293,7 @@ tap.test('PyPI: should list multiple versions in Simple API', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const json = response.body as any;
|
||||
const json = await streamToJson(response.body);
|
||||
// PEP 691: files is an array of file objects
|
||||
expect(json.files.length).toBeGreaterThan(2);
|
||||
|
||||
@@ -323,7 +327,8 @@ tap.test('PyPI: should return 404 for non-existent package', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('PyPI: should return 401 for unauthorized upload', async () => {
|
||||
@@ -353,7 +358,8 @@ tap.test('PyPI: should return 401 for unauthorized upload', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(401);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('PyPI: should reject upload with mismatched hash', async () => {
|
||||
@@ -382,7 +388,8 @@ tap.test('PyPI: should reject upload with mismatched hash', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(400);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('PyPI: should handle package with requires-python metadata', async () => {
|
||||
@@ -425,7 +432,8 @@ tap.test('PyPI: should handle package with requires-python metadata', async () =
|
||||
query: {},
|
||||
});
|
||||
|
||||
const html = getResponse.body as string;
|
||||
const getBody = await streamToBuffer(getResponse.body);
|
||||
const html = getBody.toString('utf-8');
|
||||
expect(html).toContain('data-requires-python');
|
||||
// Note: >= gets HTML-escaped to >= in attribute values
|
||||
expect(html).toContain('>=3.8');
|
||||
@@ -441,9 +449,9 @@ tap.test('PyPI: should support JSON API for package metadata', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/json');
|
||||
expect(response.body).toBeTypeOf('object');
|
||||
const json = await streamToJson(response.body);
|
||||
expect(json).toBeTypeOf('object');
|
||||
|
||||
const json = response.body as any;
|
||||
expect(json).toHaveProperty('info');
|
||||
expect(json.info).toHaveProperty('name');
|
||||
expect(json.info.name).toEqual(normalizedPackageName);
|
||||
@@ -460,9 +468,9 @@ tap.test('PyPI: should support JSON API for specific version', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/json');
|
||||
expect(response.body).toBeTypeOf('object');
|
||||
const json = await streamToJson(response.body);
|
||||
expect(json).toBeTypeOf('object');
|
||||
|
||||
const json = response.body as any;
|
||||
expect(json).toHaveProperty('info');
|
||||
expect(json.info.version).toEqual(testVersion);
|
||||
expect(json).toHaveProperty('urls');
|
||||
|
||||
@@ -79,16 +79,10 @@ async function createHttpServer(
|
||||
res.setHeader(key, value);
|
||||
}
|
||||
|
||||
// Send body
|
||||
// Send body (response.body is always ReadableStream<Uint8Array> or undefined)
|
||||
if (response.body) {
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
res.end(response.body);
|
||||
} else if (typeof response.body === 'string') {
|
||||
res.end(response.body);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(response.body));
|
||||
}
|
||||
const { Readable } = await import('stream');
|
||||
Readable.fromWeb(response.body).pipe(res);
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
@@ -194,16 +188,16 @@ function cleanupTestDir(dir: string): void {
|
||||
// ========================================================================
|
||||
|
||||
tap.test('RubyGems CLI: should setup registry and HTTP server', async () => {
|
||||
// Create registry
|
||||
registry = await createTestRegistry();
|
||||
// Use port 36000 (avoids npm:35000, cargo:5000 conflicts)
|
||||
registryPort = 36000;
|
||||
|
||||
// Create registry with correct registryUrl for CLI tests
|
||||
registry = await createTestRegistry({ registryUrl: `http://localhost:${registryPort}` });
|
||||
const tokens = await createTestTokens(registry);
|
||||
rubygemsToken = tokens.rubygemsToken;
|
||||
|
||||
expect(registry).toBeInstanceOf(SmartRegistry);
|
||||
expect(rubygemsToken).toBeTypeOf('string');
|
||||
|
||||
// Use port 36000 (avoids npm:35000, cargo:5000 conflicts)
|
||||
registryPort = 36000;
|
||||
const serverSetup = await createHttpServer(registry, registryPort);
|
||||
server = serverSetup.server;
|
||||
registryUrl = serverSetup.url;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToBuffer, streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import {
|
||||
createTestRegistry,
|
||||
createTestTokens,
|
||||
@@ -54,7 +55,8 @@ tap.test('RubyGems: should upload gem file (POST /rubygems/api/v1/gems)', async
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(201);
|
||||
expect(response.body).toHaveProperty('message');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('message');
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should retrieve Compact Index versions file (GET /rubygems/versions)', async () => {
|
||||
@@ -67,9 +69,10 @@ tap.test('RubyGems: should retrieve Compact Index versions file (GET /rubygems/v
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('text/plain; charset=utf-8');
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
|
||||
const content = (response.body as Buffer).toString('utf-8');
|
||||
const content = body.toString('utf-8');
|
||||
expect(content).toContain('created_at:');
|
||||
expect(content).toContain('---');
|
||||
expect(content).toContain(testGemName);
|
||||
@@ -86,9 +89,10 @@ tap.test('RubyGems: should retrieve Compact Index info file (GET /rubygems/info/
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('text/plain; charset=utf-8');
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
|
||||
const content = (response.body as Buffer).toString('utf-8');
|
||||
const content = body.toString('utf-8');
|
||||
expect(content).toContain('---');
|
||||
expect(content).toContain(testVersion);
|
||||
expect(content).toContain('checksum:');
|
||||
@@ -104,9 +108,10 @@ tap.test('RubyGems: should retrieve Compact Index names file (GET /rubygems/name
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('text/plain; charset=utf-8');
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
|
||||
const content = (response.body as Buffer).toString('utf-8');
|
||||
const content = body.toString('utf-8');
|
||||
expect(content).toContain('---');
|
||||
expect(content).toContain(testGemName);
|
||||
});
|
||||
@@ -120,8 +125,9 @@ tap.test('RubyGems: should download gem file (GET /rubygems/gems/{gem}-{version}
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
expect((response.body as Buffer).length).toEqual(testGemData.length);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
expect(body.length).toEqual(testGemData.length);
|
||||
expect(response.headers['Content-Type']).toEqual('application/octet-stream');
|
||||
});
|
||||
|
||||
@@ -153,7 +159,8 @@ tap.test('RubyGems: should list multiple versions in Compact Index', async () =>
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const content = (response.body as Buffer).toString('utf-8');
|
||||
const body = await streamToBuffer(response.body);
|
||||
const content = body.toString('utf-8');
|
||||
const lines = content.split('\n');
|
||||
const gemLine = lines.find(l => l.startsWith(`${testGemName} `));
|
||||
|
||||
@@ -172,7 +179,8 @@ tap.test('RubyGems: should list multiple versions in info file', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const content = (response.body as Buffer).toString('utf-8');
|
||||
const body = await streamToBuffer(response.body);
|
||||
const content = body.toString('utf-8');
|
||||
expect(content).toContain('1.0.0');
|
||||
expect(content).toContain('2.0.0');
|
||||
});
|
||||
@@ -203,7 +211,8 @@ tap.test('RubyGems: should support platform-specific gems', async () => {
|
||||
query: {},
|
||||
});
|
||||
|
||||
const content = (versionsResponse.body as Buffer).toString('utf-8');
|
||||
const versionsBody = await streamToBuffer(versionsResponse.body);
|
||||
const content = versionsBody.toString('utf-8');
|
||||
const lines = content.split('\n');
|
||||
const gemLine = lines.find(l => l.startsWith(`${testGemName} `));
|
||||
|
||||
@@ -224,8 +233,9 @@ tap.test('RubyGems: should yank a gem version (DELETE /rubygems/api/v1/gems/yank
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('message');
|
||||
expect((response.body as any).message).toContain('yanked');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('message');
|
||||
expect(body.message).toContain('yanked');
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should mark yanked version in Compact Index', async () => {
|
||||
@@ -238,7 +248,8 @@ tap.test('RubyGems: should mark yanked version in Compact Index', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const content = (response.body as Buffer).toString('utf-8');
|
||||
const body = await streamToBuffer(response.body);
|
||||
const content = body.toString('utf-8');
|
||||
const lines = content.split('\n');
|
||||
const gemLine = lines.find(l => l.startsWith(`${testGemName} `));
|
||||
|
||||
@@ -256,7 +267,8 @@ tap.test('RubyGems: should still allow downloading yanked gem', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should unyank a gem version (PUT /rubygems/api/v1/gems/unyank)', async () => {
|
||||
@@ -273,8 +285,9 @@ tap.test('RubyGems: should unyank a gem version (PUT /rubygems/api/v1/gems/unyan
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('message');
|
||||
expect((response.body as any).message).toContain('unyanked');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('message');
|
||||
expect(body.message).toContain('unyanked');
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should remove yank marker after unyank', async () => {
|
||||
@@ -287,7 +300,8 @@ tap.test('RubyGems: should remove yank marker after unyank', async () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const content = (response.body as Buffer).toString('utf-8');
|
||||
const body = await streamToBuffer(response.body);
|
||||
const content = body.toString('utf-8');
|
||||
const lines = content.split('\n');
|
||||
const gemLine = lines.find(l => l.startsWith(`${testGemName} `));
|
||||
|
||||
@@ -309,9 +323,9 @@ tap.test('RubyGems: should retrieve versions JSON (GET /rubygems/api/v1/versions
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/json');
|
||||
expect(response.body).toBeTypeOf('object');
|
||||
const json = await streamToJson(response.body);
|
||||
expect(json).toBeTypeOf('object');
|
||||
|
||||
const json = response.body as any;
|
||||
expect(json).toHaveProperty('name');
|
||||
expect(json.name).toEqual(testGemName);
|
||||
expect(json).toHaveProperty('versions');
|
||||
@@ -331,9 +345,9 @@ tap.test('RubyGems: should retrieve dependencies JSON (GET /rubygems/api/v1/depe
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/json');
|
||||
expect(response.body).toBeTypeOf('object');
|
||||
const json = await streamToJson(response.body);
|
||||
expect(json).toBeTypeOf('object');
|
||||
|
||||
const json = response.body as any;
|
||||
expect(Array.isArray(json)).toEqual(true);
|
||||
});
|
||||
|
||||
@@ -346,7 +360,8 @@ tap.test('RubyGems: should retrieve gem spec (GET /rubygems/quick/Marshal.4.8/{g
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should support latest specs endpoint (GET /rubygems/latest_specs.4.8.gz)', async () => {
|
||||
@@ -359,7 +374,8 @@ tap.test('RubyGems: should support latest specs endpoint (GET /rubygems/latest_s
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/octet-stream');
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should support specs endpoint (GET /rubygems/specs.4.8.gz)', async () => {
|
||||
@@ -372,7 +388,8 @@ tap.test('RubyGems: should support specs endpoint (GET /rubygems/specs.4.8.gz)',
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['Content-Type']).toEqual('application/octet-stream');
|
||||
expect(response.body).toBeInstanceOf(Buffer);
|
||||
const body = await streamToBuffer(response.body);
|
||||
expect(body).toBeInstanceOf(Buffer);
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should return 404 for non-existent gem', async () => {
|
||||
@@ -384,7 +401,8 @@ tap.test('RubyGems: should return 404 for non-existent gem', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should return 401 for unauthorized upload', async () => {
|
||||
@@ -402,7 +420,8 @@ tap.test('RubyGems: should return 401 for unauthorized upload', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(401);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should return 401 for unauthorized yank', async () => {
|
||||
@@ -419,7 +438,8 @@ tap.test('RubyGems: should return 401 for unauthorized yank', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(401);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
});
|
||||
|
||||
tap.test('RubyGems: should handle gem with dependencies', async () => {
|
||||
@@ -450,7 +470,8 @@ tap.test('RubyGems: should handle gem with dependencies', async () => {
|
||||
|
||||
expect(infoResponse.status).toEqual(200);
|
||||
|
||||
const content = (infoResponse.body as Buffer).toString('utf-8');
|
||||
const infoBody = await streamToBuffer(infoResponse.body);
|
||||
const content = infoBody.toString('utf-8');
|
||||
expect(content).toContain('checksum:');
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRegistry } from '../ts/index.js';
|
||||
import { streamToJson } from '../ts/core/helpers.stream.js';
|
||||
import { createTestRegistry, createTestTokens } from './helpers/registry.js';
|
||||
|
||||
let registry: SmartRegistry;
|
||||
@@ -54,8 +55,9 @@ tap.test('Integration: should return 404 for unknown paths', async () => {
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect((response.body as any).error).toEqual('NOT_FOUND');
|
||||
const body = await streamToJson(response.body);
|
||||
expect(body).toHaveProperty('error');
|
||||
expect(body.error).toEqual('NOT_FOUND');
|
||||
});
|
||||
|
||||
tap.test('Integration: should create and validate tokens', async () => {
|
||||
|
||||
Reference in New Issue
Block a user