Skip to content

Commit

Permalink
Implement a dummy app ssh enabled handler
Browse files Browse the repository at this point in the history
Tools like the MTA rely on this endpoint being available

Co-authored-by: Georgi Sabev <[email protected]>
  • Loading branch information
2 people authored and kieron-dev committed Jul 12, 2023
1 parent 04a09e7 commit 267ae24
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/handlers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
AppEnvVarsPath = "/v3/apps/{guid}/environment_variables"
AppEnvPath = "/v3/apps/{guid}/env"
AppPackagesPath = "/v3/apps/{guid}/packages"
AppSSHEnabledPath = "/v3/apps/{guid}/ssh_enabled"
invalidDropletMsg = "Unable to assign current droplet. Ensure the droplet exists and belongs to this app."

AppStartedState = "STARTED"
Expand Down Expand Up @@ -598,6 +599,13 @@ func (h *App) update(r *http.Request) (*routing.Response, error) {
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForApp(app, h.serverURL)), nil
}

func (h *App) getSSHEnabled(r *http.Request) (*routing.Response, error) {
return routing.NewResponse(http.StatusOK).WithBody(presenter.AppSSHEnabled{
Enabled: false,
Reason: "Disabled globally",
}), nil
}

func (h *App) UnauthenticatedRoutes() []routing.Route {
return nil
}
Expand All @@ -621,5 +629,6 @@ func (h *App) AuthenticatedRoutes() []routing.Route {
{Method: "GET", Pattern: AppEnvPath, Handler: h.getEnvironment},
{Method: "GET", Pattern: AppPackagesPath, Handler: h.getPackages},
{Method: "PATCH", Pattern: AppPath, Handler: h.update},
{Method: "GET", Pattern: AppSSHEnabledPath, Handler: h.getSSHEnabled},
}
}
15 changes: 15 additions & 0 deletions api/handlers/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,21 @@ var _ = Describe("App", func() {
})
})
})

Describe("GET /v3/apps/GUID/ssh_enabled", func() {
BeforeEach(func() {
req = createHttpRequest("GET", "/v3/apps/"+appGUID+"/ssh_enabled", nil)
})

It("returns false", func() {
Expect(rr).To(HaveHTTPStatus(http.StatusOK))
Expect(rr).To(HaveHTTPHeaderWithValue("Content-Type", "application/json"))
Expect(rr).To(HaveHTTPBody(SatisfyAll(
MatchJSONPath("$.enabled", BeFalse()),
MatchJSONPath("$.reason", Equal("Disabled globally")),
)))
})
})
})

func createHttpRequest(method string, url string, body io.Reader) *http.Request {
Expand Down
5 changes: 5 additions & 0 deletions api/presenter/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,8 @@ func emptyMapToAnyIfEmpty(m map[string]any) map[string]any {

return m
}

type AppSSHEnabled struct {
Enabled bool `json:"enabled"`
Reason string `json:"reason"`
}
18 changes: 18 additions & 0 deletions tests/e2e/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,4 +955,22 @@ var _ = Describe("Apps", func() {
Expect(result.Metadata.Annotations).To(HaveKeyWithValue("annkey", "annvalue"))
})
})

Describe("query SSH enabled", func() {
It("always returns false", func() {
var respObj struct {
Enabled bool `json:"enabled"`
Reason string `json:"reason"`
}

resp, err := certClient.R().
SetResult(&respObj).
Get("/v3/apps/any-guid/ssh_enabled")
Expect(err).NotTo(HaveOccurred())

Expect(resp).To(HaveRestyStatusCode(http.StatusOK))
Expect(respObj.Enabled).To(BeFalse())
Expect(respObj.Reason).To(Equal("Disabled globally"))
})
})
})

0 comments on commit 267ae24

Please sign in to comment.