Skip to content

Commit

Permalink
fix: ignore hidden dir files (#459)
Browse files Browse the repository at this point in the history
avoid oss upload fail

> [SignatureDoesNotMatchError]: The request signature we calculated does
not match the signature you provided. Check your key and signing method.
  • Loading branch information
fengmk2 authored May 6, 2023
1 parent 5223e8c commit 637e8ad
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/core/event/SyncPackageVersionFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class SyncPackageVersionFileEvent {

protected async syncPackageVersionFile(fullname: string, version: string) {
if (!this.config.cnpmcore.enableUnpkg) return;
// ignore sync on unittest
if (this.config.env === 'unittest' && fullname !== '@cnpm/unittest-unpkg-demo') return;
const [ scope, name ] = getScopeAndName(fullname);
const { packageVersion } = await this.packageManagerService.showPackageVersionByVersionOrTag(
scope, name, version);
Expand Down
2 changes: 2 additions & 0 deletions app/core/service/PackageVersionFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class PackageVersionFileService extends AbstractService {
onentry: entry => {
if (entry.type !== 'File') return;
if (!entry.path.startsWith('package/')) return;
// ignore hidden dir
if (entry.path.includes('/./')) return;
paths.push(entry.path.replace(/^package\//i, '/'));
},
});
Expand Down
Binary file added test/fixtures/unpkg.com/bovo-ui-0.0.4-36.tgz
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ describe('test/port/controller/PackageVersionFileController/listFiles.test.ts',
assert.equal(res.body.error, '[NOT_FOUND] [email protected]/files/foo not found');
});

it('should auto sync after version publish', async () => {
const pkg = await TestUtil.getFullPackage({
name: '@cnpm/unittest-unpkg-demo',
version: '1.0.0',
versionObject: {
description: 'work with utf8mb4 💩, 𝌆 utf8_unicode_ci, foo𝌆bar 🍻',
},
});
await app.httpRequest()
.put(`/${pkg.name}`)
.set('authorization', publisher.authorization)
.set('user-agent', publisher.ua)
.send(pkg)
.expect(201);
await app.httpRequest()
.get(`/${pkg.name}/1.0.0/files/package.json`)
.expect(200)
.expect('content-type', 'application/json; charset=utf-8');
});

it('should 451 when package block', async () => {
const { pkg } = await TestUtil.createPackage({ isPrivate: false });
let res = await app.httpRequest()
Expand Down
36 changes: 33 additions & 3 deletions test/port/controller/PackageVersionFileController/raw.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { strict as assert } from 'node:assert';
import { setTimeout } from 'node:timers/promises';
import { app, mock } from 'egg-mock/bootstrap';
import { TestUtil } from 'test/TestUtil';
import { calculateIntegrity } from 'app/common/PackageUtil';
Expand Down Expand Up @@ -174,7 +173,6 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () =>
.set('user-agent', publisher.ua)
.send(pkg);
assert.equal(res.status, 201);
await setTimeout(1000);
res = await app.httpRequest()
.get(`/${pkg.name}/1.0.0/files/resource/`);
assert.equal(res.status, 200);
Expand All @@ -190,6 +188,39 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () =>
assert.match(res.text, /ToOneFromχ/);
});

it('should ignore "." hidden dir', async () => {
// https://unpkg.com/browse/[email protected]/
const tarball = await TestUtil.readFixturesFile('unpkg.com/bovo-ui-0.0.4-36.tgz');
const { integrity } = await calculateIntegrity(tarball);
const pkg = await TestUtil.getFullPackage({
name: '@cnpm/bovo-ui',
version: '1.0.0',
versionObject: {
description: 'foo latest description',
},
attachment: {
data: tarball.toString('base64'),
length: tarball.length,
},
dist: {
integrity,
},
main: './lib/index.js',
});
let res = await app.httpRequest()
.put(`/${pkg.name}`)
.set('authorization', publisher.authorization)
.set('user-agent', publisher.ua)
.send(pkg);
assert.equal(res.status, 201);
res = await app.httpRequest()
.get(`/${pkg.name}/1.0.0/files/`);
assert.equal(res.status, 200);
// console.log(res.body);
assert.equal(res.body.files.find(file => file.path === '/.'), undefined);
assert(res.body.files.find(file => file.path === '/dist'));
});

it('should handle big tgz file', async () => {
const tarball = await TestUtil.readFixturesFile('unpkg.com/pouchdb-3.2.1.tgz');
const { integrity } = await calculateIntegrity(tarball);
Expand All @@ -214,7 +245,6 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () =>
.set('user-agent', publisher.ua)
.send(pkg);
assert.equal(res.status, 201);
await setTimeout(5000);
res = await app.httpRequest()
.get(`/${pkg.name}/1.0.0/files/`);
assert.equal(res.status, 200);
Expand Down

0 comments on commit 637e8ad

Please sign in to comment.