Skip to content

Commit

Permalink
basic auth on progress route
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Mar 1, 2018
1 parent 2ea45d8 commit 1ec66b7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ func (a *App) getRouter(showProfile bool) *mux.Router {
r.HandleFunc("/scheduler/{schedulerName}/operations/{operationKey}/status", Chain(
NewSchedulerOperationHandler(a),
NewLoggingMiddleware(a),
NewAccessMiddleware(a),
NewBasicAuthMiddleware(a),
NewAuthMiddleware(a),
NewVersionMiddleware(),
).ServeHTTP).Methods("GET").Name("schedulersOperationStatus")

r.HandleFunc("/scheduler/{schedulerName}/operations/{operationKey}/cancel", Chain(
NewSchedulerOperationCancelHandler(a),
NewLoggingMiddleware(a),
NewAccessMiddleware(a),
NewBasicAuthMiddleware(a),
NewAuthMiddleware(a),
NewVersionMiddleware(),
).ServeHTTP).Methods("PUT").Name("schedulersOperationStatus")
Expand Down
9 changes: 6 additions & 3 deletions api/scheduler_diff_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ image: image2`

var response map[string]string
json.Unmarshal(recorder.Body.Bytes(), &response)

Expect(response["version1"]).To(Equal("v1.0"))
Expect(response["version2"]).To(Equal("v0.1"))
Expect(response["diff"]).To(Equal("name: scheduler-name\ngame: \"\"\nshutdownTimeout: 0\nautoscaling: null\naffinity: \"\"\ntoleration: \"\"\noccupiedTimeout: 0\nforwarders: {}\nauthorizedUsers: []\nimage: image\u001b[31m1\u001b[0m\u001b[32m2\u001b[0m\nports: []\nlimits: null\nrequests: null\nenv: []\ncmd: []\ncontainers: []\n"))
Expect(response["diff"]).To(Equal("name: scheduler-name\ngame: \"\"\nshutdownTimeout: 0\nautoscaling: null\naffinity: \"\"\ntoleration: \"\"\noccupiedTimeout: 0\nforwarders: {}\nauthorizedUsers: []\nimage: image\x1b[31m2\x1b[0m\x1b[32m1\x1b[0m\nports: []\nlimits: null\nrequests: null\nenv: []\ncmd: []\ncontainers: []\n"))
})

It("should return schedulers diff between v2 and previous", func() {
Expand All @@ -80,9 +81,10 @@ image: image2`

var response map[string]string
json.Unmarshal(recorder.Body.Bytes(), &response)

Expect(response["version1"]).To(Equal("v2.0"))
Expect(response["version2"]).To(Equal("v1.0"))
Expect(response["diff"]).To(Equal("name: scheduler-name\ngame: \"\"\nshutdownTimeout: 0\nautoscaling: null\naffinity: \"\"\ntoleration: \"\"\noccupiedTimeout: 0\nforwarders: {}\nauthorizedUsers: []\nimage: image\u001b[31m1\u001b[0m\u001b[32m2\u001b[0m\nports: []\nlimits: null\nrequests: null\nenv: []\ncmd: []\ncontainers: []\n"))
Expect(response["diff"]).To(Equal("name: scheduler-name\ngame: \"\"\nshutdownTimeout: 0\nautoscaling: null\naffinity: \"\"\ntoleration: \"\"\noccupiedTimeout: 0\nforwarders: {}\nauthorizedUsers: []\nimage: image\x1b[31m2\x1b[0m\x1b[32m1\x1b[0m\nports: []\nlimits: null\nrequests: null\nenv: []\ncmd: []\ncontainers: []\n"))
})

It("should return schedulers diff between v2 and v1", func() {
Expand All @@ -99,9 +101,10 @@ image: image2`

var response map[string]string
json.Unmarshal(recorder.Body.Bytes(), &response)

Expect(response["version1"]).To(Equal("v2.0"))
Expect(response["version2"]).To(Equal("v1.0"))
Expect(response["diff"]).To(Equal("name: scheduler-name\ngame: \"\"\nshutdownTimeout: 0\nautoscaling: null\naffinity: \"\"\ntoleration: \"\"\noccupiedTimeout: 0\nforwarders: {}\nauthorizedUsers: []\nimage: image\u001b[31m1\u001b[0m\u001b[32m2\u001b[0m\nports: []\nlimits: null\nrequests: null\nenv: []\ncmd: []\ncontainers: []\n"))
Expect(response["diff"]).To(Equal("name: scheduler-name\ngame: \"\"\nshutdownTimeout: 0\nautoscaling: null\naffinity: \"\"\ntoleration: \"\"\noccupiedTimeout: 0\nforwarders: {}\nauthorizedUsers: []\nimage: image\x1b[31m2\x1b[0m\x1b[32m1\x1b[0m\nports: []\nlimits: null\nrequests: null\nenv: []\ncmd: []\ncontainers: []\n"))
})

It("should return error if version1 not found", func() {
Expand Down
17 changes: 4 additions & 13 deletions api/scheduler_operation_cancel_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,14 @@ import (
"net/http"
"net/http/httptest"

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/topfreegames/maestro/login"
"github.com/topfreegames/maestro/models"
. "github.com/topfreegames/maestro/testing"
)

var _ = Describe("SchedulerOperationCancelHandler", func() {
BeforeEach(func() {
mockDb.EXPECT().Query(gomock.Any(), `SELECT access_token, refresh_token, expiry, token_type
FROM users
WHERE key_access_token = ?`, gomock.Any()).
Do(func(destToken *login.DestinationToken, query string, modifier string) {
destToken.RefreshToken = "refresh-token"
}).AnyTimes()
mockLogin.EXPECT().Authenticate(gomock.Any(), app.DB).Return("user@example.com", http.StatusOK, nil).AnyTimes()
})

Describe("PUT /scheduler/{schedulerName}/operations/{operationKey}/cancel", func() {
var request *http.Request
var recorder *httptest.ResponseRecorder
Expand All @@ -49,6 +37,7 @@ var _ = Describe("SchedulerOperationCancelHandler", func() {
app.Address, name, opManager.GetOperationKey())

request, _ = http.NewRequest("PUT", url, nil)
request.SetBasicAuth("user", "pass")
})

It("should cancel operation", func() {
Expand All @@ -66,14 +55,15 @@ var _ = Describe("SchedulerOperationCancelHandler", func() {
MockDeleteRedisKey(opManager, mockRedisClient, mockPipeline, errors.New("redis error"))

app.Router.ServeHTTP(recorder, request)
Expect(recorder.Code).To(Equal(http.StatusInternalServerError))

var response map[string]interface{}
json.Unmarshal(recorder.Body.Bytes(), &response)
Expect(response).To(HaveKeyWithValue("success", false))
Expect(response).To(HaveKeyWithValue("error", "error deleting operation key on redis"))
Expect(response).To(HaveKeyWithValue("description", "redis error"))
Expect(response).To(HaveKeyWithValue("code", "MAE-000"))

Expect(recorder.Code).To(Equal(http.StatusInternalServerError))
})

It("should return error if operation key is invalid", func() {
Expand All @@ -82,6 +72,7 @@ var _ = Describe("SchedulerOperationCancelHandler", func() {
app.Address, name, key)

request, _ = http.NewRequest("PUT", url, nil)
request.SetBasicAuth("user", "pass")
app.Router.ServeHTTP(recorder, request)
Expect(recorder.Code).To(Equal(http.StatusInternalServerError))

Expand Down
2 changes: 1 addition & 1 deletion helm/charts/maestro/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: maestro
home: https://github.com/topfreegames/maestro
description: Maestro api and worker
version: 4.9.2
version: 4.9.3
maintainers:
- name: TFGCo
email: backend@tfgco.com
2 changes: 1 addition & 1 deletion metadata/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package metadata

//Version of Maestro
var Version = "4.9.2"
var Version = "4.9.3"

//KubeVersion is the desired Kubernetes version
var KubeVersion = "v1.7.5"

0 comments on commit 1ec66b7

Please sign in to comment.