

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 测试报告权限
<a name="test-permissions"></a>

 本主题介绍与测试报告相关权限有关的重要信息。

**Topics**
+ [测试报告的 IAM 角色](#test-permissions-required)
+ [测试报告操作的权限](#test-permissions-related-to-reporting)
+ [测试报告权限示例](#test-permissions-examples)

## 测试报告的 IAM 角色
<a name="test-permissions-required"></a>

要运行测试报告，并更新项目以包含测试报告，您的 IAM 角色需要以下权限。这些权限包含在预定义的 AWS 托管策略中。如果要将测试报告添加到现有构建项目，则必须自行添加这些权限。
+ `CreateReportGroup` 
+ `CreateReport` 
+ `UpdateReport` 
+ `BatchPutTestCases` 

要运行代码覆盖率报告，您的 IAM 角色还必须包含 `BatchPutCodeCoverages` 权限。

**注意**  
`BatchPutTestCases`、`CreateReport`、`UpdateReport` 和 `BatchPutCodeCoverages` 不是公共权限。您不能为这些权限调用相应的 AWS CLI 命令或 SDK 方法。

要确保您拥有这些权限，您可以将以下策略附加到您的 IAM 角色：

```
{
    "Effect": "Allow",
    "Resource": [
        "*"
    ],
    "Action": [
        "codebuild:CreateReportGroup",
        "codebuild:CreateReport",
        "codebuild:UpdateReport",
        "codebuild:BatchPutTestCases",
        "codebuild:BatchPutCodeCoverages"
    ]
}
```

我们建议您将此策略仅限定用于您必须使用的报告组。以下内容将权限限制为仅包含两个 ARNs策略的报告组：

```
{
    "Effect": "Allow",
    "Resource": [
        "arn:aws:codebuild:your-region:your-aws-account-id:report-group/report-group-name-1",
        "arn:aws:codebuild:your-region:your-aws-account-id:report-group/report-group-name-2"
    ],
    "Action": [
        "codebuild:CreateReportGroup",
        "codebuild:CreateReport",
        "codebuild:UpdateReport",
        "codebuild:BatchPutTestCases",
        "codebuild:BatchPutCodeCoverages"
    ]
}
```

以下内容将权限仅限定用于通过运行名为 `my-project` 的项目构建而创建的报告组：

```
{
    "Effect": "Allow",
    "Resource": [
        "arn:aws:codebuild:your-region:your-aws-account-id:report-group/my-project-*"
    ],
    "Action": [
        "codebuild:CreateReportGroup",
        "codebuild:CreateReport",
        "codebuild:UpdateReport",
        "codebuild:BatchPutTestCases",
        "codebuild:BatchPutCodeCoverages"
    ]
}
```

**注意**  
项目中指定的 CodeBuild 服务角色用于授予上传到 S3 存储桶的权限。

## 测试报告操作的权限
<a name="test-permissions-related-to-reporting"></a>

 您可以为以下测试报告 CodeBuild API 操作指定权限：
+  `BatchGetReportGroups` 
+  `BatchGetReports` 
+  `CreateReportGroup` 
+  `DeleteReportGroup` 
+  `DeleteReport` 
+  `DescribeTestCases` 
+  `ListReportGroups` 
+  `ListReports` 
+  `ListReportsForReportGroup` 
+  `UpdateReportGroup` 

有关更多信息，请参阅 [AWS CodeBuild 权限参考](auth-and-access-control-permissions-reference.md)。

## 测试报告权限示例
<a name="test-permissions-examples"></a>

 有关测试报告相关示例策略的信息，请参阅以下内容：
+  [允许用户更改报告组](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-change-report-group) 
+  [允许用户创建报告组](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-create-report-group) 
+  [允许用户删除报告](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-delete-report) 
+  [允许用户删除报告组](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-delete-report-group) 
+  [允许用户获取有关报告组的信息](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-get-information-about-report-group) 
+  [允许用户获取有关报告的信息](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-get-information-about-reports) 
+  [允许用户获取报告组列表](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-report-groups) 
+  [允许用户获取报告列表](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-reports) 
+  [允许用户获取报告组的报告列表](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-reports-for-report-group) 
+  [允许用户获取报告的测试用例的列表](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-test-cases-for-report) 