Files
floci/compatibility-tests/sdk-test-node/tests/s3tables.test.ts
T
Priamo Germosen 92a61c2b86 fix(s3tables): check S3 Tables requests under IAM enforcement (#8424)
Under IAM enforcement no S3 Tables request was checked: its model was
not among the vendored REST routes and its namespace's request
resources were not read, so no request mapped to an action and every
call went through, DeleteTableBucket and the policy calls included.

s3tables is now vendored by regen_rest_routes.py and read by the
request-resources, tag-on-create and passed-role generators. A table
bucket call is checked on the bucket its path names. A table's ARN ends
in an id the service mints, which no request carries: a request names
the table by its table bucket's ARN, its namespace and its name. A new
generic rule in the request-resources generator reads such a type,
found by its service by those path labels (or GetTable's query string
members, when tableArn is absent), instead of filling the bucket's name
from the table's name or reading the bucket's ARN as the table's.
S3TablesStoredResourceArns answers it from the stored table, read only.
2026-11-15 10:47:17 -04:00

204 lines
8.7 KiB
TypeScript

import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import {
ConflictException,
CreateNamespaceCommand,
CreateTableBucketCommand,
CreateTableCommand,
DeleteNamespaceCommand,
DeleteTableBucketCommand,
DeleteTableBucketPolicyCommand,
DeleteTableCommand,
DeleteTablePolicyCommand,
GetNamespaceCommand,
GetTableBucketCommand,
GetTableBucketMaintenanceConfigurationCommand,
GetTableBucketPolicyCommand,
GetTableCommand,
GetTableMaintenanceConfigurationCommand,
GetTableMetadataLocationCommand,
GetTablePolicyCommand,
ListNamespacesCommand,
ListTableBucketsCommand,
ListTablesCommand,
NotFoundException,
PutTableBucketMaintenanceConfigurationCommand,
PutTableBucketPolicyCommand,
PutTableMaintenanceConfigurationCommand,
PutTablePolicyCommand,
RenameTableCommand,
S3TablesClient,
UpdateTableMetadataLocationCommand,
} from '@aws-sdk/client-s3tables';
import { makeClient, uniqueName } from './setup';
describe('S3 Tables lifecycle', () => {
let client: S3TablesClient;
let bucketArn: string;
const bucketName = uniqueName('table-bucket');
const namespace = 'analytics';
let tableName = uniqueName('events');
let versionToken: string;
let tableArn: string;
beforeAll(() => {
client = makeClient(S3TablesClient);
});
afterAll(async () => {
if (!bucketArn) return;
await client.send(new DeleteTableCommand({ tableBucketARN: bucketArn, namespace, name: tableName })).catch(() => undefined);
await client.send(new DeleteNamespaceCommand({ tableBucketARN: bucketArn, namespace })).catch(() => undefined);
await client.send(new DeleteTableBucketCommand({ tableBucketARN: bucketArn })).catch(() => undefined);
});
it('creates a table bucket, namespace, and Iceberg table', async () => {
const bucket = await client.send(new CreateTableBucketCommand({
name: bucketName,
tags: { suite: 'sdk-node' },
encryptionConfiguration: { sseAlgorithm: 'AES256' },
storageClassConfiguration: { storageClass: 'STANDARD' },
}));
bucketArn = bucket.arn!;
expect(bucketArn).toContain(`bucket/${bucketName}`);
const createdNamespace = await client.send(new CreateNamespaceCommand({
tableBucketARN: bucketArn,
namespace: [namespace],
}));
expect(createdNamespace.namespace).toEqual([namespace]);
const table = await client.send(new CreateTableCommand({
tableBucketARN: bucketArn,
namespace,
name: tableName,
format: 'ICEBERG',
metadata: { iceberg: { properties: { 'format-version': '2' } } },
encryptionConfiguration: { sseAlgorithm: 'AES256' },
storageClassConfiguration: { storageClass: 'STANDARD' },
tags: { suite: 'sdk-node' },
}));
versionToken = table.versionToken!;
// AWS ends a table's ARN in an id it mints, not the table's name.
tableArn = table.tableARN!;
expect(tableArn.startsWith(`${bucketArn}/table/`)).toBe(true);
expect(tableArn).not.toBe(`${bucketArn}/table/${tableName}`);
});
it('gets resources and applies list prefixes', async () => {
const bucket = await client.send(new GetTableBucketCommand({ tableBucketARN: bucketArn }));
expect(bucket.name).toBe(bucketName);
const buckets = await client.send(new ListTableBucketsCommand({ prefix: 'table-bucket' }));
expect(buckets.tableBuckets?.some((item) => item.name === bucketName)).toBe(true);
const fetchedNamespace = await client.send(new GetNamespaceCommand({ tableBucketARN: bucketArn, namespace }));
expect(fetchedNamespace.namespace).toEqual([namespace]);
const namespaces = await client.send(new ListNamespacesCommand({ tableBucketARN: bucketArn, prefix: 'anal' }));
expect(namespaces.namespaces?.some((item) => item.namespace?.includes(namespace))).toBe(true);
const tables = await client.send(new ListTablesCommand({ tableBucketARN: bucketArn, namespace, prefix: 'events' }));
expect(tables.tables?.some((table) => table.name === tableName)).toBe(true);
const table = await client.send(new GetTableCommand({ tableBucketARN: bucketArn, namespace, name: tableName }));
expect(table.tableARN).toBe(tableArn);
});
it('round-trips policies and metadata version tokens', async () => {
const policy = '{"Version":"2012-10-17","Statement":[]}';
await client.send(new PutTableBucketPolicyCommand({ tableBucketARN: bucketArn, resourcePolicy: policy }));
expect((await client.send(new GetTableBucketPolicyCommand({ tableBucketARN: bucketArn }))).resourcePolicy).toBe(policy);
await client.send(new PutTablePolicyCommand({ tableBucketARN: bucketArn, namespace, name: tableName, resourcePolicy: policy }));
expect((await client.send(new GetTablePolicyCommand({ tableBucketARN: bucketArn, namespace, name: tableName }))).resourcePolicy).toBe(policy);
const updated = await client.send(new UpdateTableMetadataLocationCommand({
tableBucketARN: bucketArn,
namespace,
name: tableName,
metadataLocation: `s3://warehouse/${tableName}/v2.metadata.json`,
versionToken,
}));
expect(updated.versionToken).not.toBe(versionToken);
expect((await client.send(new GetTableMetadataLocationCommand({
tableBucketARN: bucketArn, namespace, name: tableName,
}))).metadataLocation).toBe(updated.metadataLocation);
await expect(client.send(new UpdateTableMetadataLocationCommand({
tableBucketARN: bucketArn,
namespace,
name: tableName,
metadataLocation: `s3://warehouse/${tableName}/stale.metadata.json`,
versionToken,
}))).rejects.toBeInstanceOf(ConflictException);
versionToken = updated.versionToken!;
});
it('round-trips typed maintenance configuration maps', async () => {
await client.send(new PutTableBucketMaintenanceConfigurationCommand({
tableBucketARN: bucketArn,
type: 'icebergUnreferencedFileRemoval',
value: { status: 'enabled' },
}));
const bucketMaintenance = await client.send(new GetTableBucketMaintenanceConfigurationCommand({
tableBucketARN: bucketArn,
}));
expect(bucketMaintenance.configuration?.icebergUnreferencedFileRemoval?.status).toBe('enabled');
await client.send(new PutTableMaintenanceConfigurationCommand({
tableBucketARN: bucketArn,
namespace,
name: tableName,
type: 'icebergCompaction',
value: { status: 'enabled' },
}));
const tableMaintenance = await client.send(new GetTableMaintenanceConfigurationCommand({
tableBucketARN: bucketArn,
namespace,
name: tableName,
}));
expect(tableMaintenance.configuration?.icebergCompaction?.status).toBe('enabled');
});
it('renames a table and rotates its version token', async () => {
const originalToken = versionToken;
const renamedTableName = `${tableName}-renamed`;
await client.send(new RenameTableCommand({
tableBucketARN: bucketArn,
namespace,
name: tableName,
newName: renamedTableName,
versionToken: originalToken,
}));
const renamed = await client.send(new GetTableCommand({
tableBucketARN: bucketArn,
namespace,
name: renamedTableName,
}));
expect(renamed.name).toBe(renamedTableName);
expect(renamed.tableARN).toBe(tableArn);
expect(renamed.versionToken).not.toBe(originalToken);
await expect(client.send(new GetTableCommand({ tableBucketARN: bucketArn, namespace, name: tableName })))
.rejects.toBeInstanceOf(NotFoundException);
tableName = renamedTableName;
versionToken = renamed.versionToken!;
});
it('deletes policies and the resource hierarchy', async () => {
await client.send(new DeleteTablePolicyCommand({ tableBucketARN: bucketArn, namespace, name: tableName }));
await expect(client.send(new GetTablePolicyCommand({ tableBucketARN: bucketArn, namespace, name: tableName })))
.rejects.toBeInstanceOf(NotFoundException);
await client.send(new DeleteTableBucketPolicyCommand({ tableBucketARN: bucketArn }));
await expect(client.send(new GetTableBucketPolicyCommand({ tableBucketARN: bucketArn })))
.rejects.toBeInstanceOf(NotFoundException);
await client.send(new DeleteTableCommand({ tableBucketARN: bucketArn, namespace, name: tableName }));
await expect(client.send(new GetTableCommand({ tableBucketARN: bucketArn, namespace, name: tableName })))
.rejects.toBeInstanceOf(NotFoundException);
await client.send(new DeleteNamespaceCommand({ tableBucketARN: bucketArn, namespace }));
await expect(client.send(new GetNamespaceCommand({ tableBucketARN: bucketArn, namespace })))
.rejects.toBeInstanceOf(NotFoundException);
await client.send(new DeleteTableBucketCommand({ tableBucketARN: bucketArn }));
await expect(client.send(new GetTableBucketCommand({ tableBucketARN: bucketArn })))
.rejects.toBeInstanceOf(NotFoundException);
});
});