Remove account IDs in favor of just account names
These were a "security" feature but pre-emptive and just add complications when we can implement secrets later
This commit is contained in:
parent
b3b369f608
commit
7749854eb7
8 changed files with 23 additions and 53 deletions
|
@ -50,7 +50,6 @@ func TestServer_Register(t *testing.T) {
|
|||
r1, err := serv.Register(d1)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r1.Success)
|
||||
assert.NotZero(t, len(r1.Id))
|
||||
|
||||
d2 := rove.RegisterData{
|
||||
Name: uuid.New().String(),
|
||||
|
@ -58,7 +57,6 @@ func TestServer_Register(t *testing.T) {
|
|||
r2, err := serv.Register(d2)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r2.Success)
|
||||
assert.NotZero(t, len(r2.Id))
|
||||
|
||||
r3, err := serv.Register(d1)
|
||||
assert.NoError(t, err)
|
||||
|
@ -72,7 +70,6 @@ func TestServer_Command(t *testing.T) {
|
|||
r1, err := serv.Register(d1)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r1.Success)
|
||||
assert.NotZero(t, len(r1.Id))
|
||||
|
||||
c := rove.CommandData{
|
||||
Commands: []game.Command{
|
||||
|
@ -83,7 +80,7 @@ func TestServer_Command(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
r3, err := serv.Command(r1.Id, c)
|
||||
r3, err := serv.Command(d1.Name, c)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r3.Success)
|
||||
}
|
||||
|
@ -95,9 +92,8 @@ func TestServer_Radar(t *testing.T) {
|
|||
r1, err := serv.Register(d1)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r1.Success)
|
||||
assert.NotZero(t, len(r1.Id))
|
||||
|
||||
r3, err := serv.Radar(r1.Id)
|
||||
r3, err := serv.Radar(d1.Name)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r3.Success)
|
||||
}
|
||||
|
@ -109,9 +105,8 @@ func TestServer_Rover(t *testing.T) {
|
|||
r1, err := serv.Register(d1)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r1.Success)
|
||||
assert.NotZero(t, len(r1.Id))
|
||||
|
||||
r3, err := serv.Rover(r1.Id)
|
||||
r3, err := serv.Rover(d1.Name)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, r3.Success)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/mdiluz/rove/pkg/rove"
|
||||
"github.com/mdiluz/rove/pkg/version"
|
||||
)
|
||||
|
@ -87,7 +86,7 @@ func HandleRegister(s *Server, vars map[string]string, b io.ReadCloser, w io.Wri
|
|||
} else if acc, err := s.accountant.RegisterAccount(data.Name); err != nil {
|
||||
response.Error = err.Error()
|
||||
|
||||
} else if _, _, err := s.SpawnRoverForAccount(acc.Id); err != nil {
|
||||
} else if _, _, err := s.SpawnRoverForAccount(acc.Name); err != nil {
|
||||
response.Error = err.Error()
|
||||
|
||||
} else if err := s.SaveAll(); err != nil {
|
||||
|
@ -95,7 +94,6 @@ func HandleRegister(s *Server, vars map[string]string, b io.ReadCloser, w io.Wri
|
|||
|
||||
} else {
|
||||
// Save out the new accounts
|
||||
response.Id = acc.Id.String()
|
||||
response.Success = true
|
||||
}
|
||||
|
||||
|
@ -120,9 +118,6 @@ func HandleCommand(s *Server, vars map[string]string, b io.ReadCloser, w io.Writ
|
|||
} else if len(id) == 0 {
|
||||
response.Error = "No account ID provided"
|
||||
|
||||
} else if id, err := uuid.Parse(id); err != nil {
|
||||
response.Error = fmt.Sprintf("Provided account ID was invalid: %s", err)
|
||||
|
||||
} else if inst, err := s.accountant.GetRover(id); err != nil {
|
||||
response.Error = fmt.Sprintf("Provided account has no rover: %s", err)
|
||||
|
||||
|
@ -147,9 +142,6 @@ func HandleRadar(s *Server, vars map[string]string, b io.ReadCloser, w io.Writer
|
|||
if len(id) == 0 {
|
||||
response.Error = "No account ID provided"
|
||||
|
||||
} else if id, err := uuid.Parse(id); err != nil {
|
||||
response.Error = fmt.Sprintf("Provided account ID was invalid: %s", err)
|
||||
|
||||
} else if inst, err := s.accountant.GetRover(id); err != nil {
|
||||
response.Error = fmt.Sprintf("Provided account has no rover: %s", err)
|
||||
|
||||
|
@ -179,9 +171,6 @@ func HandleRover(s *Server, vars map[string]string, b io.ReadCloser, w io.Writer
|
|||
if len(id) == 0 {
|
||||
response.Error = "No account ID provided"
|
||||
|
||||
} else if id, err := uuid.Parse(id); err != nil {
|
||||
response.Error = fmt.Sprintf("Provided account ID was invalid: %s", err)
|
||||
|
||||
} else if inst, err := s.accountant.GetRover(id); err != nil {
|
||||
response.Error = fmt.Sprintf("Provided account has no rover: %s", err)
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ func TestHandleCommand(t *testing.T) {
|
|||
assert.NoError(t, err, "Error registering account")
|
||||
|
||||
// Spawn the rover rover for the account
|
||||
_, inst, err := s.SpawnRoverForAccount(a.Id)
|
||||
_, inst, err := s.SpawnRoverForAccount(a.Name)
|
||||
assert.NoError(t, s.world.WarpRover(inst, vector.Vector{}))
|
||||
|
||||
attribs, err := s.world.RoverAttributes(inst)
|
||||
|
@ -85,7 +85,7 @@ func TestHandleCommand(t *testing.T) {
|
|||
b, err := json.Marshal(data)
|
||||
assert.NoError(t, err, "Error marshalling data")
|
||||
|
||||
request, _ := http.NewRequest(http.MethodPost, path.Join("/", a.Id.String(), "/command"), bytes.NewReader(b))
|
||||
request, _ := http.NewRequest(http.MethodPost, path.Join("/", a.Name, "/command"), bytes.NewReader(b))
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
s.router.ServeHTTP(response, request)
|
||||
|
@ -118,7 +118,7 @@ func TestHandleRadar(t *testing.T) {
|
|||
assert.NoError(t, err, "Error registering account")
|
||||
|
||||
// Spawn the rover rover for the account
|
||||
attrib, id, err := s.SpawnRoverForAccount(a.Id)
|
||||
attrib, id, err := s.SpawnRoverForAccount(a.Name)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Warp this rover to 0,0
|
||||
|
@ -134,7 +134,7 @@ func TestHandleRadar(t *testing.T) {
|
|||
assert.NoError(t, s.world.Atlas.SetTile(rockPos, game.TileRock))
|
||||
assert.NoError(t, s.world.Atlas.SetTile(emptyPos, game.TileEmpty))
|
||||
|
||||
request, _ := http.NewRequest(http.MethodGet, path.Join("/", a.Id.String(), "/radar"), nil)
|
||||
request, _ := http.NewRequest(http.MethodGet, path.Join("/", a.Name, "/radar"), nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
s.router.ServeHTTP(response, request)
|
||||
|
@ -172,10 +172,10 @@ func TestHandleRover(t *testing.T) {
|
|||
assert.NoError(t, err, "Error registering account")
|
||||
|
||||
// Spawn one rover for the account
|
||||
attribs, _, err := s.SpawnRoverForAccount(a.Id)
|
||||
attribs, _, err := s.SpawnRoverForAccount(a.Name)
|
||||
assert.NoError(t, err)
|
||||
|
||||
request, _ := http.NewRequest(http.MethodGet, path.Join("/", a.Id.String(), "/rover"), nil)
|
||||
request, _ := http.NewRequest(http.MethodGet, path.Join("/", a.Name, "/rover"), nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
s.router.ServeHTTP(response, request)
|
||||
|
|
|
@ -281,7 +281,7 @@ func (s *Server) wrapHandler(method string, handler Handler) func(w http.Respons
|
|||
}
|
||||
|
||||
// SpawnRoverForAccount spawns the rover rover for an account
|
||||
func (s *Server) SpawnRoverForAccount(accountid uuid.UUID) (game.RoverAttributes, uuid.UUID, error) {
|
||||
func (s *Server) SpawnRoverForAccount(account string) (game.RoverAttributes, uuid.UUID, error) {
|
||||
if inst, err := s.world.SpawnRover(); err != nil {
|
||||
return game.RoverAttributes{}, uuid.UUID{}, err
|
||||
|
||||
|
@ -289,7 +289,7 @@ func (s *Server) SpawnRoverForAccount(accountid uuid.UUID) (game.RoverAttributes
|
|||
return game.RoverAttributes{}, uuid.UUID{}, fmt.Errorf("No attributes found for created rover: %s", err)
|
||||
|
||||
} else {
|
||||
if err := s.accountant.AssignRover(accountid, inst); err != nil {
|
||||
if err := s.accountant.AssignRover(account, inst); err != nil {
|
||||
// Try and clear up the rover
|
||||
if err := s.world.DestroyRover(inst); err != nil {
|
||||
fmt.Printf("Failed to destroy rover after failed rover assign: %s", err)
|
||||
|
|
|
@ -125,8 +125,8 @@ func InnerMain(command string) error {
|
|||
return fmt.Errorf("Server returned failure: %s", response.Error)
|
||||
|
||||
default:
|
||||
fmt.Printf("Registered account with id: %s\n", response.Id)
|
||||
config.Accounts[config.Host] = response.Id
|
||||
fmt.Printf("Registered account with id: %s\n", d.Name)
|
||||
config.Accounts[config.Host] = d.Name
|
||||
}
|
||||
|
||||
case "move":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue