Skip to content

Commit 8cd45e4

Browse files
[TF-18071] Handle unified id for unified resources: project, workspace, org & teams
1 parent f6f1791 commit 8cd45e4

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

policy_set_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func TestPolicySetsCreate(t *testing.T) {
485485

486486
t.Run("with an invalid name provided", func(t *testing.T) {
487487
ps, err := client.PolicySets.Create(ctx, orgTest.Name, PolicySetCreateOptions{
488-
Name: String("nope!"),
488+
Name: String("nope/nope!"),
489489
})
490490
assert.Nil(t, ps)
491491
assert.EqualError(t, err, ErrInvalidName.Error())
@@ -728,7 +728,7 @@ func TestPolicySetsUpdate(t *testing.T) {
728728

729729
t.Run("with invalid attributes", func(t *testing.T) {
730730
ps, err := client.PolicySets.Update(ctx, psTest.ID, PolicySetUpdateOptions{
731-
Name: String("nope!"),
731+
Name: String("nope/nope!"),
732732
})
733733
assert.Nil(t, ps)
734734
assert.EqualError(t, err, ErrInvalidName.Error())

validations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// A regular expression used to validate common string ID patterns.
14-
var reStringID = regexp.MustCompile(`^[a-zA-Z0-9\-._]+$`)
14+
var reStringID = regexp.MustCompile(`^[^/\s]+$`)
1515

1616
// validEmail checks if the given input is a correct email
1717
func validEmail(v string) bool {

validations_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package tfe
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestValidStringID(t *testing.T) {
13+
type testCase struct {
14+
externalID *string
15+
expectedValue bool
16+
}
17+
18+
unifiedTeamID := "iam.group:kmpwhkwf6tkgWzgJKPcP"
19+
unifiedProjectID := "616f63c1-3ef5-46a5-b5e8-6d1d86c3f93f"
20+
nonUnifiedID := "prj-AywVvpbtLQTcwf8K"
21+
invalidID := "test/with-a-slash"
22+
invalidIDWithSpace := "test with-space"
23+
24+
cases := map[string]testCase{
25+
"external-id-is-nil": {externalID: nil, expectedValue: false},
26+
"external-id-is-empty-string": {externalID: new(string), expectedValue: false},
27+
"external-id-is-invalid-with-slash": {externalID: &invalidID, expectedValue: false},
28+
"external-id-is-invalid-with-space": {externalID: &invalidIDWithSpace, expectedValue: false},
29+
"external-id-is-unified-team-id": {externalID: &unifiedTeamID, expectedValue: true},
30+
"external-id-is-unified-project-id": {externalID: &unifiedProjectID, expectedValue: true},
31+
"external-id-is-non-unified": {externalID: &nonUnifiedID, expectedValue: true},
32+
}
33+
34+
for name, tcase := range cases {
35+
t.Run(name, func(tt *testing.T) {
36+
actual := validStringID(tcase.externalID)
37+
assert.Equal(tt, tcase.expectedValue, actual)
38+
})
39+
}
40+
}

0 commit comments

Comments
 (0)