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

Block desktop-only requests in non-desktop environment #151

Merged
merged 1 commit into from
Jan 17, 2025
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
22 changes: 19 additions & 3 deletions modules/dashboard/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions modules/dashboard/graph/schema.resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/mock"
"k8s.io/utils/ptr"

"github.com/kubetail-org/kubetail/modules/shared/config"
"github.com/kubetail-org/kubetail/modules/shared/graphql/errors"

k8shelpersmock "github.com/kubetail-org/kubetail/modules/dashboard/internal/k8shelpers/mock"
Expand Down Expand Up @@ -134,3 +135,28 @@ func TestAllowedNamespacesListQueries(t *testing.T) {
})
}
}

func TestDesktopOnlyRequests(t *testing.T) {
resolver := &Resolver{environment: config.EnvironmentCluster}

t.Run("kubeConfigGet", func(t *testing.T) {
r := &queryResolver{resolver}
_, err := r.KubeConfigGet(context.Background())
assert.NotNil(t, err)
assert.Equal(t, err, errors.ErrForbidden)
})

t.Run("kubeConfigWatch", func(t *testing.T) {
r := &subscriptionResolver{resolver}
_, err := r.KubeConfigWatch(context.Background())
assert.NotNil(t, err)
assert.Equal(t, err, errors.ErrForbidden)
})

t.Run("kubetailClusterAPIInstall", func(t *testing.T) {
r := &mutationResolver{resolver}
_, err := r.KubetailClusterAPIInstall(context.Background(), nil)
assert.NotNil(t, err)
assert.Equal(t, err, errors.ErrForbidden)
})
}
2 changes: 1 addition & 1 deletion modules/shared/graphql/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
ErrValidationError = NewError("KUBETAIL_VALIDATION_ERROR", "Validation error")
ErrRecordNotFound = NewError("KUBETAIL_RECORD_NOT_FOUND", "Record not found")
ErrUnauthenticated = NewError("KUBETAIL_UNAUTHENTICATED", "Authentication required")
ErrForbidden = NewError("KUBETAIL_FORBIDDEN", "Access forbidden")
ErrForbidden = NewError("KUBETAIL_FORBIDDEN", "Forbidden")
ErrWatchError = NewError("KUBETAIL_WATCH_ERROR", "Watch error")
ErrInternalServerError = NewError("INTERNAL_SERVER_ERROR", "Internal server error")
)
Expand Down
Loading