Skip to content

Commit

Permalink
Fix: add support to new enforcePrCommenterPermissions policy in the o… (
Browse files Browse the repository at this point in the history
#622)

* Fix: add support to new enforcePrCommenterPermissions policy in the organization policy resource

* updated integration tests
  • Loading branch information
TomerHeber committed Mar 9, 2023
1 parent 990e223 commit a5fddf2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Organization struct {
DoNotReportSkippedStatusChecks bool `json:"doNotReportSkippedStatusChecks"`
DoNotConsiderMergeCommitsForPrPlans bool `json:"doNotConsiderMergeCommitsForPrPlans"`
EnableOidc bool `json:"enableOidc"`
EnforcePrCommenterPermissions bool `json:"enforcePrCommenterPermissions"`
Description string `json:"description"`
PhotoUrl string `json:"photoUrl"`
CreatedBy string `json:"createdBy"`
Expand All @@ -28,6 +29,7 @@ type OrganizationPolicyUpdatePayload struct {
DoNotReportSkippedStatusChecks *bool `json:"doNotReportSkippedStatusChecks,omitempty"`
DoNotConsiderMergeCommitsForPrPlans *bool `json:"doNotConsiderMergeCommitsForPrPlans,omitempty"`
EnableOidc *bool `json:"enableOidc,omitempty"`
EnforcePrCommenterPermissions *bool `json:"enforcePrCommenterPermissions,omitempty"`
}

func (client *ApiClient) Organization() (Organization, error) {
Expand Down
2 changes: 2 additions & 0 deletions client/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var _ = Describe("Organization", func() {
updatedMockOrganization := mockOrganization
updatedMockOrganization.DoNotConsiderMergeCommitsForPrPlans = true
updatedMockOrganization.EnableOidc = true
updatedMockOrganization.EnforcePrCommenterPermissions = true
updatedMockOrganization.DefaultTtl = &hour12

var updatedOrganization *Organization
Expand All @@ -112,6 +113,7 @@ var _ = Describe("Organization", func() {
DefaultTtl: &hour12,
DoNotConsiderMergeCommitsForPrPlans: &t,
EnableOidc: &t,
EnforcePrCommenterPermissions: &t,
}

httpCall = mockHttpClient.EXPECT().
Expand Down
6 changes: 6 additions & 0 deletions env0/resource_organization_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func resourceOrganizationPolicy() *schema.Resource {
Default: false,
Description: "set to 'true' to enable OIDC token (JWT) availability during env0 deployments (defaults to 'false')",
},
"enforce_pr_commenter_permissions": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "set to 'true' to enforce PR commenter permissions during env0 deployments (defaults to 'false')",
},
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions env0/resource_organization_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestUnitOrganizationPolicyResource(t *testing.T) {
DoNotReportSkippedStatusChecks: false,
DoNotConsiderMergeCommitsForPrPlans: true,
EnableOidc: false,
EnforcePrCommenterPermissions: false,
}

organizationUpdated := client.Organization{
Expand All @@ -39,6 +40,7 @@ func TestUnitOrganizationPolicyResource(t *testing.T) {
DoNotReportSkippedStatusChecks: true,
DoNotConsiderMergeCommitsForPrPlans: false,
EnableOidc: true,
EnforcePrCommenterPermissions: true,
}

t.Run("Success", func(t *testing.T) {
Expand All @@ -57,20 +59,23 @@ func TestUnitOrganizationPolicyResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "do_not_report_skipped_status_checks", strconv.FormatBool(organization.DoNotReportSkippedStatusChecks)),
resource.TestCheckResourceAttr(accessor, "do_not_consider_merge_commits_for_pr_plans", strconv.FormatBool(organization.DoNotConsiderMergeCommitsForPrPlans)),
resource.TestCheckResourceAttr(accessor, "enable_oidc", strconv.FormatBool(organization.EnableOidc)),
resource.TestCheckResourceAttr(accessor, "enforce_pr_commenter_permissions", strconv.FormatBool(organization.EnforcePrCommenterPermissions)),
),
},
{
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
"default_ttl": *organizationUpdated.DefaultTtl,
"do_not_report_skipped_status_checks": organizationUpdated.DoNotReportSkippedStatusChecks,
"enable_oidc": organizationUpdated.EnableOidc,
"enforce_pr_commenter_permissions": organizationUpdated.EnforcePrCommenterPermissions,
}),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(accessor, "id", organization.Id),
resource.TestCheckResourceAttr(accessor, "default_ttl", *organizationUpdated.DefaultTtl),
resource.TestCheckResourceAttr(accessor, "do_not_report_skipped_status_checks", strconv.FormatBool(organizationUpdated.DoNotReportSkippedStatusChecks)),
resource.TestCheckResourceAttr(accessor, "do_not_consider_merge_commits_for_pr_plans", strconv.FormatBool(organizationUpdated.DoNotConsiderMergeCommitsForPrPlans)),
resource.TestCheckResourceAttr(accessor, "enable_oidc", strconv.FormatBool(organizationUpdated.EnableOidc)),
resource.TestCheckResourceAttr(accessor, "enforce_pr_commenter_permissions", strconv.FormatBool(organizationUpdated.EnforcePrCommenterPermissions)),
),
},
},
Expand All @@ -84,12 +89,14 @@ func TestUnitOrganizationPolicyResource(t *testing.T) {
DoNotConsiderMergeCommitsForPrPlans: &organization.DoNotConsiderMergeCommitsForPrPlans,
DoNotReportSkippedStatusChecks: boolPtr(false),
EnableOidc: boolPtr(false),
EnforcePrCommenterPermissions: boolPtr(false),
}).Times(1).Return(&organization, nil),
mock.EXPECT().Organization().Times(2).Return(organization, nil),
mock.EXPECT().OrganizationPolicyUpdate(client.OrganizationPolicyUpdatePayload{
DefaultTtl: organizationUpdated.DefaultTtl,
DoNotReportSkippedStatusChecks: &organizationUpdated.DoNotReportSkippedStatusChecks,
EnableOidc: &organizationUpdated.EnableOidc,
EnforcePrCommenterPermissions: &organizationUpdated.EnforcePrCommenterPermissions,
DoNotConsiderMergeCommitsForPrPlans: boolPtr(false),
MaxTtl: stringPtr(""),
}).Times(1).Return(&organizationUpdated, nil),
Expand Down Expand Up @@ -136,6 +143,7 @@ func TestUnitOrganizationPolicyResource(t *testing.T) {
DoNotConsiderMergeCommitsForPrPlans: &organization.DoNotConsiderMergeCommitsForPrPlans,
DoNotReportSkippedStatusChecks: boolPtr(false),
EnableOidc: boolPtr(false),
EnforcePrCommenterPermissions: boolPtr(false),
}).Times(1).Return(nil, errors.New("error"))
})
})
Expand Down
1 change: 1 addition & 0 deletions tests/integration/001_organization/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ resource "env0_organization_policy" "my_organization_policy" {
default_ttl = var.second_run ? "7-h" : "13-h"
do_not_consider_merge_commits_for_pr_plans = var.second_run ? false : true
enable_oidc = var.second_run ? false : true
enforce_pr_commenter_permissions = var.second_run ? false : true
}

0 comments on commit a5fddf2

Please sign in to comment.