Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate request when handling the request #35

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/cli/iam_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (c *IAMHandleCommand) handleIAM(ctx context.Context) error {
return fmt.Errorf("failed to read %T: %w", req, err)
}

if err := v1alpha1.ValidateIAMRequest(req); err != nil {
return fmt.Errorf("failed to validate %T: %w", req, err)
}

var h iamHandler
if c.testHandler != nil {
// Use testHandler if it is for testing.
Expand Down
15 changes: 15 additions & 0 deletions pkg/cli/iam_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ policies:
- members:
- user:test-project-user@example.com
role: roles/bigquery.dataViewer
`,
"invalid-request.yaml": `
policies:
- resource: organizations/foo
bindings:
- members:
- group:test-org-group@example.com
- user:test-org-userB@example.com
role: roles/cloudkms.cryptoOperator
`,
"invalid.yaml": `bananas`,
}
Expand Down Expand Up @@ -191,6 +200,12 @@ policies:
StartTime: st,
},
},
{
name: "invalid_request",
args: []string{"-path", filepath.Join(dir, "invalid-request.yaml"), "-duration", "2h", "-start-time", st.Format(time.RFC3339)},
handler: &fakeIAMHandler{},
expErr: "failed to validate *v1alpha1.IAMRequest",
},
}

for _, tc := range cases {
Expand Down