Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: worker auth modifications
  • Loading branch information
plyr4 committed Mar 23, 2023
commit a2837d120e39ef700d190df3f91f87bf20278765
2 changes: 1 addition & 1 deletion vela/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (svc *AdminWorkerService) RegisterToken(hostname string) (*library.Token, *
}

// set the API endpoint path we send the request to
url := fmt.Sprintf("/api/v1/workers/%s/register-token", hostname)
url := fmt.Sprintf("/api/v1/admin/workers/%s/register-token", hostname)

// library Token type we want to return
t := new(library.Token)
Expand Down
7 changes: 3 additions & 4 deletions vela/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,13 @@ func TestAdmin_Build_Queue_200(t *testing.T) {
}
}

func TestAdmin_Worker_RegistrationToken_200(t *testing.T) {
func TestAdmin_Worker_RegistrationToken_201(t *testing.T) {
// setup context
gin.SetMode(gin.TestMode)

s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

// needs mocks from server feature
data := []byte(server.RegisterTokenResp)

var want *library.Token
Expand All @@ -352,8 +351,8 @@ func TestAdmin_Worker_RegistrationToken_200(t *testing.T) {
t.Errorf("RegisterToken returned err: %v", err)
}

if resp.StatusCode != http.StatusOK {
t.Errorf("RegisterToken returned %v, want %v", resp.StatusCode, http.StatusOK)
if resp.StatusCode != http.StatusCreated {
t.Errorf("RegisterToken returned %v, want %v", resp.StatusCode, http.StatusCreated)
}

if diff := cmp.Diff(want, got); diff != "" {
Expand Down
7 changes: 6 additions & 1 deletion vela/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestVela_Authentication_ValidateToken_200(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

c.Authentication.SetTokenAuth("foobar")
c.Authentication.SetTokenAuth("foo")

// run test
resp, err := c.Authentication.ValidateToken()
Expand All @@ -221,6 +221,11 @@ func TestVela_Authentication_ValidateToken_200(t *testing.T) {
t.Errorf("ValidateToken returned error %v", err)
}

if resp == nil {
// Fatal so that nil resp is not checked
t.Fatal("ValidateToken returned nil response")
}

if resp.StatusCode != http.StatusOK {
t.Errorf("ValidateToken returned %v, want %v", resp.StatusCode, http.StatusOK)
}
Expand Down
6 changes: 3 additions & 3 deletions vela/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func (svc *WorkerService) GetAll() (*[]library.Worker, *Response, error) {
}

// Add constructs a worker with the provided details.
func (svc *WorkerService) Add(w *library.Worker) (*library.Worker, *Response, error) {
func (svc *WorkerService) Add(w *library.Worker) (*library.Token, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/workers"

// library Worker type we want to return
v := new(library.Worker)
// library Token type we want to return
v := new(library.Token)

// send request using client
resp, err := svc.client.Call("POST", u, w, v)
Expand Down
30 changes: 15 additions & 15 deletions vela/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func TestWorker_Get_200(t *testing.T) {
got, resp, err := c.Worker.Get("worker_1")

if err != nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker get returned err: %v", err)
}

if resp.StatusCode != http.StatusOK {
t.Errorf("Worker returned %v, want %v", resp.StatusCode, http.StatusOK)
t.Errorf("Worker get returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
Expand All @@ -59,11 +59,11 @@ func TestWorker_Get_404(t *testing.T) {
got, resp, err := c.Worker.Get("0")

if err == nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker get returned err: %v", err)
}

if resp.StatusCode != http.StatusNotFound {
t.Errorf("Worker returned %v, want %v", resp.StatusCode, http.StatusOK)
t.Errorf("Worker get returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
Expand All @@ -87,7 +87,7 @@ func TestWorker_GetAll_200(t *testing.T) {
got, resp, err := c.Worker.GetAll()

if err != nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker get all returned err: %v", err)
}

if resp.StatusCode != http.StatusOK {
Expand All @@ -106,9 +106,9 @@ func TestWorker_Add_201(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

data := []byte(server.WorkerResp)
data := []byte(server.AddWorkerResp)

var want library.Worker
var want library.Token
_ = json.Unmarshal(data, &want)

req := library.Worker{
Expand All @@ -128,11 +128,11 @@ func TestWorker_Add_201(t *testing.T) {
got, resp, err := c.Worker.Add(&req)

if err != nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker add returned err: %v", err)
}

if resp.StatusCode != http.StatusCreated {
t.Errorf("Worker returned %v, want %v", resp.StatusCode, http.StatusOK)
t.Errorf("Worker add returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestWorker_Update_200(t *testing.T) {
got, resp, err := c.Worker.Update("worker_1", &req)

if err != nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker update returned err: %v", err)
}

if resp.StatusCode != http.StatusOK {
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestWorker_Update_404(t *testing.T) {
got, resp, err := c.Worker.Update("0", &req)

if err == nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker update returned err: %v", err)
}

if resp.StatusCode != http.StatusNotFound {
Expand All @@ -212,11 +212,11 @@ func TestWorker_Remove_200(t *testing.T) {
_, resp, err := c.Worker.Remove("worker_1")

if err != nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker remove returned err: %v", err)
}

if resp.StatusCode != http.StatusOK {
t.Errorf("Worker returned %v, want %v", resp.StatusCode, http.StatusOK)
t.Errorf("Worker remove returned %v, want %v", resp.StatusCode, http.StatusOK)
}
}

Expand All @@ -231,11 +231,11 @@ func TestWorker_Remove_404(t *testing.T) {
_, resp, err := c.Worker.Remove("0")

if err == nil {
t.Errorf("New returned err: %v", err)
t.Errorf("Worker remove returned err: %v", err)
}

if resp.StatusCode != http.StatusNotFound {
t.Errorf("Worker returned %v, want %v", resp.StatusCode, http.StatusOK)
t.Errorf("Worker remove returned %v, want %v", resp.StatusCode, http.StatusOK)
}
}

Expand Down