mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
* fix(sts): từ chối AssumeRole khi role không tồn tại trong IAM AssumeRole trước đây cấp credential cho mọi role ARN, kể cả role chưa từng được tạo (iam:GetRole trả NoSuchEntity). Giờ trả AccessDenied như AWS, bất kể enforcement có bật hay không; trust policy vẫn chỉ được đánh giá khi enforcement bật. Các test cũ assume role chưa tạo được sửa để tạo role trước. Closes #4392 * fix(sts): so sánh chính xác role ARN và cập nhật compatibility tests - StsQueryHandler: kiểm tra roleArn khớp chính xác role.getArn() để tránh chấp nhận role cùng tên khác path - StsQueryHandlerTest: đổi tham số helper sang IamRole thay vì Optional, bổ sung test case từ chối role khác path - AssumeRoleTrustPolicyIntegrationTest: sửa Javadoc mô tả đúng hành vi từ chối unknown role - Cập nhật compatibility tests (Java, Node, Python, AWS CLI) để tạo role trước khi assume và kiểm tra lỗi 403 khi role không tồn tại * fix(sts): accept partition-correct role ARNs and strictly catch cleanup exceptions - StsQueryHandler: match role ARN structurally using AwsArnUtils to admit valid noncommercial partition ARNs - StsQueryHandler: preserve caller partition when generating assumedRoleArn - StsTest, test_sts.py, sts.test.ts: only ignore NoSuchEntity/EntityAlreadyExists in cleanup, re-raising unexpected errors per AGENTS.md - StsQueryHandlerTest, AssumeRoleTrustPolicyIntegrationTest: add unit and integration coverage for partition-correct role ARNs * fix(sts): preserve role partition in resolved session caller ARN * fix(sts): preserve stored role partition in assumed identity * fix(sts): validate web identity role ARN * fix(sts): require role existence in AssumeRoleWithWebIdentity and reuse path helpers * fix(sts): keep IAM ARN partition behavior unchanged * fix(sts): derive trust caller account from identity ARN * fix(iam): migrate legacy credential reports by partition * fix(iam): serialize legacy credential report migration * test(iam): make credential report race deterministic * fix(sts): address review feedback * fix(sts): reuse IAM role path normalization
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
/**
|
|
* STS integration tests.
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
import { STSClient, GetCallerIdentityCommand, AssumeRoleCommand } from '@aws-sdk/client-sts';
|
|
import { IAMClient, CreateRoleCommand, DeleteRoleCommand } from '@aws-sdk/client-iam';
|
|
import { makeClient, ACCOUNT } from './setup';
|
|
|
|
describe('STS', () => {
|
|
let sts: STSClient;
|
|
let iam: IAMClient;
|
|
const roleName = 'test-role';
|
|
|
|
beforeAll(async () => {
|
|
sts = makeClient(STSClient);
|
|
iam = makeClient(IAMClient);
|
|
const trustPolicy = JSON.stringify({
|
|
Version: '2012-10-17',
|
|
Statement: [
|
|
{
|
|
Effect: 'Allow',
|
|
Principal: { AWS: '*' },
|
|
Action: 'sts:AssumeRole',
|
|
},
|
|
],
|
|
});
|
|
try {
|
|
await iam.send(
|
|
new CreateRoleCommand({
|
|
RoleName: roleName,
|
|
AssumeRolePolicyDocument: trustPolicy,
|
|
})
|
|
);
|
|
} catch (err: unknown) {
|
|
if ((err as { name?: string })?.name !== 'EntityAlreadyExistsException') {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
afterAll(async () => {
|
|
try {
|
|
await iam.send(new DeleteRoleCommand({ RoleName: roleName }));
|
|
} catch (err: unknown) {
|
|
if ((err as { name?: string })?.name !== 'NoSuchEntityException') {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
it('should get caller identity', async () => {
|
|
const response = await sts.send(new GetCallerIdentityCommand({}));
|
|
expect(response.Account).toBeTruthy();
|
|
expect(response.UserId).toBeTruthy();
|
|
});
|
|
|
|
it('should assume role', async () => {
|
|
const response = await sts.send(
|
|
new AssumeRoleCommand({
|
|
RoleArn: `arn:aws:iam::${ACCOUNT}:role/${roleName}`,
|
|
RoleSessionName: 'test-session',
|
|
})
|
|
);
|
|
expect(response.Credentials?.AccessKeyId).toBeTruthy();
|
|
});
|
|
|
|
it('should deny assume role for nonexistent role', async () => {
|
|
await expect(
|
|
sts.send(
|
|
new AssumeRoleCommand({
|
|
RoleArn: `arn:aws:iam::${ACCOUNT}:role/definitely-nonexistent-role`,
|
|
RoleSessionName: 'test-session',
|
|
})
|
|
)
|
|
).rejects.toThrow();
|
|
});
|
|
});
|