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

[ACM-15010] Added error condition for invalid client id #476

Merged
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
2 changes: 1 addition & 1 deletion controllers/discoveryconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *DiscoveryConfigReconciler) updateDiscoveredClusters(ctx context.Context
}

if err != nil {
if ocm.IsUnrecoverable(err) || ocm.IsUnauthorizedClient(err) {
if ocm.IsUnrecoverable(err) || ocm.IsUnauthorizedClient(err) || ocm.IsInvalidClient(err) {
logf.Info("Error encountered. Cleaning up clusters.", "Error", err.Error())
return r.deleteAllClusters(ctx, config)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ocm/auth/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
AuthProvider IAuthProvider = &authProvider{}

ErrInvalidToken = errors.New("invalid token")
ErrInvalidClient = errors.New("invalid_client")
ErrUnauthorizedClient = errors.New("unauthorized_client")
)

Expand Down
8 changes: 8 additions & 0 deletions pkg/ocm/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func formatCluster(sub subscription.Subscription) (discovery.DiscoveredCluster,
return discoveredCluster, true
}

// IsInvalidClient returns true if the specified error is invalid client side error.
func IsInvalidClient(err error) bool {
if err != nil {
return strings.Contains(err.Error(), auth.ErrInvalidClient.Error())
}
return false
}

// IsUnauthorizedClient returns true if the specified error is unauthorized client side error.
func IsUnauthorizedClient(err error) bool {
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions pkg/ocm/ocm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,38 @@ func Test_IsRecoverable(t *testing.T) {

}

func Test_IsInvalidClient(t *testing.T) {
tests := []struct {
name string
err error
want bool
}{
{
name: "Unrecoverable Invalid Client Error",
err: auth.ErrInvalidClient,
want: true,
},
{
name: "Recoverable Error",
err: errors.New("test error"),
want: false,
},
{
name: "Empty Error",
err: nil,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsInvalidClient(tt.err); got != tt.want {
t.Errorf("IsInvalidClient() = %v, want %v", got, tt.want)
}
})
}

}

// BOOKMARK: This is the test for No ExternalClusterID
func TestFormatCLusterError(t *testing.T) {
tests := []struct {
Expand Down
Loading