Repository navigation
Expand file tree
/
Copy pathminio.test.js
More file actions
99 lines (82 loc) · 3.52 KB
/
Copy pathminio.test.js
File metadata and controls
99 lines (82 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
8000
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
import { createHash } from 'node:crypto';
import { S3mini } from '../dist/index.mjs';
import { beforeRun } from './_shared.test.js';
import * as dotenv from 'dotenv';
dotenv.config();
const name = 'minio';
const bucketName = `BUCKET_ENV_${name.toUpperCase()}`;
const raw = process.env[bucketName] ? process.env[bucketName].split(',') : null;
const minioSpecific = bucket => {
const s3client = new S3mini({
accessKeyId: bucket.accessKeyId,
secretAccessKey: bucket.secretAccessKey,
endpoint: bucket.endpoint,
region: bucket.region,
});
// No resetBucketBeforeAll here: testRunner already registered one on this same describe, so a
// second wipe just repeats it — with a client that has no retryFetch.
it('put object with valid x-amz-checksum-sha1 header', async () => {
const fileContents = Buffer.from('Some file contents.', 'utf-8');
const hasher = createHash('sha1');
hasher.setEncoding('base64');
hasher.write(fileContents);
hasher.end();
const fileHash = hasher.read();
const result = await s3client.putObject('validated-file-one.txt', fileContents, 'text/plain', undefined, {
'x-amz-checksum-sha1': fileHash,
});
expect(result.ok).toBe(true);
expect(result.headers.get('x-amz-checksum-sha1')).toBe(fileHash);
});
it('put object with invalid x-amz-checksum-sha1', async () => {
const fileContents = Buffer.from('Some file contents.', 'utf-8');
const hasher = createHash('sha1');
hasher.setEncoding('base64');
hasher.write(fileContents);
hasher.write('Make the hash faulty.');
hasher.end();
const fileHash = hasher.read();
let caught;
try {
await s3client.putObject('validated-file-two.txt', fileContents, 'text/plain', undefined, {
'x-amz-checksum-sha1': fileHash,
});
} catch (err) {
caught = err;
}
expect(caught).toBeDefined();
expect(caught.code).toBe('XAmzContentChecksumMismatch');
});
/**
* Dedicated MinIO versioning smoke (in addition to shared E2E).
* globalSetup enables versioning on the MinIO bucket — this must not soft-skip.
*/
it('minio versioning is enabled and listObjectVersions returns real versions', async () => {
const status = await s3client.getBucketVersioning();
// setup enables versioning; also accept Off briefly if get is laggy — still require version ids
expect(['Enabled', 'Off', 'Suspended']).toContain(status);
if (status !== 'Enabled') {
const ok = await s3client.setBucketVersioning('Enabled');
expect(ok).toBe(true);
expect(await s3client.getBucketVersioning()).toBe('Enabled');
}
const key = `minio-version-smoke-${Date.now()}.txt`;
const a = await s3client.putObject(key, 'alpha', 'text/plain');
const b = await s3client.putObject(key, 'beta', 'text/plain');
const idA = a.headers.get('x-amz-version-id');
const idB = b.headers.get('x-amz-version-id');
expect(idA).toBeTruthy();
expect(idA).not.toBe('null');
expect(idB).toBeTruthy();
expect(idB).not.toBe('null');
expect(idA).not.toBe(idB);
const versions = await s3client.listObjectVersions(key);
expect(versions.length).toBeGreaterThanOrEqual(2);
expect(versions.filter(v => v.IsLatest).length).toBeGreaterThanOrEqual(1);
expect(await s3client.getObject(key, { versionId: idA })).toBe('alpha');
expect(await s3client.getObject(key, { versionId: idB })).toBe('beta');
await s3client.deleteObjects(versions.map(v => ({ key: v.Key, versionId: v.VersionId })));
});
};
beforeRun(raw, name, minioSpecific);