File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed
pkg/account/persistence/loader Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -408,4 +408,10 @@ func TestLoad(t *testing.T) {
408408 assert .Error (t , err )
409409 assert .Contains (t , err .Error (), "policy definition is ambiguous" )
410410 })
411+
412+ t .Run ("Loading a group with a missing environment name produces an error" , func (t * testing.T ) {
413+ _ , err := Load (afero .NewOsFs (), "testdata/group-missing-env-name.yaml" )
414+ assert .Error (t , err )
415+ assert .Contains (t , err .Error (), "missing required field 'environment'" )
416+ })
411417}
Original file line number Diff line number Diff line change 1+ groups :
2+ - name : My Group
3+ id : my-group
4+
5+ environments :
6+ # Missing environment name
7+ - permissions :
8+ - View environment
9+ policies :
10+ - View environment
11+ - type : reference
12+ id : my-policy
Original file line number Diff line number Diff line change @@ -202,10 +202,8 @@ func validateGroup(g types.Group) error {
202202 }
203203
204204 for _ , env := range g .Environment {
205- for _ , policyRef := range env .Policies {
206- if err := validatePolicyBinding (policyRef ); err != nil {
207- return err
208- }
205+ if err := validateGroupEnvironment (env , g .ID ); err != nil {
206+ return err
209207 }
210208 }
211209
@@ -221,6 +219,18 @@ func validateGroup(g types.Group) error {
221219 return nil
222220}
223221
222+ func validateGroupEnvironment (env types.Environment , groupID string ) error {
223+ if env .Name == "" {
224+ return fmt .Errorf ("missing required field 'environment' for 'environments' in group '%s'" , groupID )
225+ }
226+ for _ , policyRef := range env .Policies {
227+ if err := validatePolicyBinding (policyRef ); err != nil {
228+ return err
229+ }
230+ }
231+ return nil
232+ }
233+
224234func validateBoundary (b types.Boundary ) error {
225235 if b .ID == "" {
226236 return errors .New ("missing required field 'id' for boundary" )
You can’t perform that action at this time.
0 commit comments