Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b339c4c
initial work
ecrupper Feb 28, 2023
746b399
Merge branch 'main' into worker-auth/complete
ecrupper Mar 9, 2023
8bf613c
adding symmetric token handling
ecrupper Mar 14, 2023
c1f1463
incorporating constants
ecrupper Mar 15, 2023
1da6bdd
convert admin register token endpoint to be POST
ecrupper Mar 15, 2023
4d7b735
pulling in types update
ecrupper Mar 21, 2023
e925301
Merge branch 'main' into worker-auth/complete
ecrupper Mar 21, 2023
e620fa3
add server mocks and json tags to check in resp
ecrupper Mar 21, 2023
febb17d
handle symmetric token in worker endpoints
ecrupper Mar 21, 2023
4a12e25
appease linter overlord
ecrupper Mar 21, 2023
25118c9
return properly when met with server worker token
ecrupper Mar 22, 2023
ad7db54
add proper return to update worker too
ecrupper Mar 22, 2023
467b47f
add back actually updating the worker
ecrupper Mar 22, 2023
f6dea85
add comments to create and update worker api func
ecrupper Mar 22, 2023
85c0efd
add new endpoint for refresh, remove plat admin access to worker auth…
ecrupper Mar 23, 2023
75d4c1f
mocks mocks mocks
ecrupper Mar 23, 2023
fa8ba2c
Merge branch 'main' into worker-auth/complete
ecrupper Mar 23, 2023
bbdcfc5
fix mock, fix status returns, move check in update to refresh
ecrupper Mar 23, 2023
2f49e8e
Merge branch 'worker-auth/complete' of github.com:go-vela/server into…
ecrupper Mar 23, 2023
7bc1b5c
update mock validate http method
ecrupper Mar 23, 2023
0014ccd
use authorization not token in mock
ecrupper Mar 23, 2023
077c267
retrieve plat admin for logging in register token + swagger updates
ecrupper Mar 23, 2023
66e3642
change return type of validate token
ecrupper Mar 23, 2023
b140651
getting mocked by mock
ecrupper Mar 23, 2023
05b7cd2
update validate token mock comment
ecrupper Mar 23, 2023
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
mocks mocks mocks
  • Loading branch information
ecrupper committed Mar 23, 2023
commit 75d4c1fcab4e16a7fcbba5a6b48d09c16aefd4c4
1 change: 1 addition & 0 deletions mock/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func FakeHandler() http.Handler {
e.GET("/api/v1/workers/:worker", getWorker)
e.POST("/api/v1/workers", addWorker)
e.PUT("/api/v1/workers/:worker", updateWorker)
e.POST("/api/v1/workers/:worker/refresh", refreshWorkerAuth)
e.DELETE("/api/v1/workers/:worker", removeWorker)

// mock endpoints for authentication calls
Expand Down
33 changes: 26 additions & 7 deletions mock/server/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ const (
],
"active": true,
"last_checked_in": 1602612590
},
"token": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3b3JrZXIiLCJpYXQiOjE1MTYyMzkwMjIsInRva2VuX3R5cGUiOiJXb3JrZXJBdXRoIn0.qeULIimCJlrwsE0JykNpzBmMaHUbvfk0vkyAz2eEo38"
}
}`

Expand Down Expand Up @@ -84,6 +81,11 @@ const (
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3b3JrZXIiLCJpYXQiOjE1MTYyMzkwMjIsInRva2VuX3R5cGUiOiJXb3JrZXJBdXRoIn0.qeULIimCJlrwsE0JykNpzBmMaHUbvfk0vkyAz2eEo38"
}`

// RefreshWorkerAuthResp represents a JSON return for refreshing a worker's authentication.
RefreshWorkerAuthResp = `{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3b3JrZXIiLCJpYXQiOjE1MTYyMzkwMjIsInRva2VuX3R5cGUiOiJXb3JrZXJBdXRoIn0.qeULIimCJlrwsE0JykNpzBmMaHUbvfk0vkyAz2eEo38"
}`

// RegisterTokenResp represents a JSON return for an admin requesting a registration token.
//
//nolint:gosec // not actual credentials
Expand Down Expand Up @@ -148,12 +150,29 @@ func updateWorker(c *gin.Context) {

data := []byte(UpdateWorkerResp)

type WorkerCheckIn struct {
Worker *library.Worker `json:"worker,omitempty"`
Token *library.Token `json:"token,omitempty"`
var body library.Worker
_ = json.Unmarshal(data, &body)

c.JSON(http.StatusOK, body)
}

// refreshWorkerAuth has a param :worker returns mock JSON for a http PUT.
//
// Pass "0" to :worker to test receiving a http 404 response.
func refreshWorkerAuth(c *gin.Context) {
w := c.Param("worker")

if strings.EqualFold(w, "0") {
msg := fmt.Sprintf("Worker %s does not exist", w)

c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})

return
}

var body WorkerCheckIn
data := []byte(RefreshWorkerAuthResp)

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

c.JSON(http.StatusOK, body)
Expand Down