mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-08 14:14:52 +00:00
feat(machine): add validation for machine names to accept only DNS labels
This commit is contained in:
1 parent
11e1200fe8
commit
ce1c6bd05a
12 files changed
+286
-27
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/psviderski/uncloud/api/pb"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func TestAddMachine_InvalidName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ready := make(chan struct{})
|
||||
close(ready)
|
||||
// Invalid names must be rejected before any store access.
|
||||
c := NewCluster(nil, nil, nil, ready)
|
||||
for _, name := range []string{"VPS1", "worker.example", "rr", "nearest", "c337f00600de51ef4375c9a9a267dba5"} {
|
||||
t.Run("add", func(t *testing.T) {
|
||||
resp, err := c.AddMachine(context.Background(), &pb.AddMachineRequest{Name: name})
|
||||
require.Nil(t, resp)
|
||||
require.Equal(t, codes.InvalidArgument, status.Code(err))
|
||||
require.ErrorContains(t, err, "invalid machine name")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user