Skip to content

Commit

Permalink
NDS 500/531/537/558: API server bugs (#127)
Browse files Browse the repository at this point in the history
* NDS-558: Fixed bug in get account -- expected optional argument

* NDS-531: Check key length on Post/Put spec

* NDS-500: Don't allow delete of admin account

* Remove token on get account

* Remove redacted password

* Check for error state when stopping dependencies
  • Loading branch information
craig-willis authored and bodom0015 committed Sep 16, 2016
1 parent d8f7b44 commit 066d9fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion apiserver/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ func (s *Server) GetAccount(w rest.ResponseWriter, r *rest.Request) {
}
}
account.Password = ""
account.Token = ""
w.WriteJson(account)
}
}
Expand Down Expand Up @@ -879,6 +880,10 @@ func (s *Server) DeleteAccount(w rest.ResponseWriter, r *rest.Request) {
rest.Error(w, "", http.StatusUnauthorized)
return
}
if userId == "admin" {
rest.Error(w, "", http.StatusForbidden)
return
}

if !s.accountExists(userId) {
rest.NotFound(w, r)
Expand Down Expand Up @@ -2100,7 +2105,7 @@ func (s *Server) stopStack(userId string, sid string) (*api.Stack, error) {
for _, dep := range svc.Dependencies {
if dep.DependencyKey == stackService.Service {
numDeps++
if ss.Status == "stopped" || ss.Status == "" {
if ss.Status == "stopped" || ss.Status == "" || ss.Status == "error" {
stoppedDeps++
}
}
Expand Down
7 changes: 5 additions & 2 deletions apiserver/pkg/apictl/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ var getAccountCmd = &cobra.Command{
PreRun: Connect,
Run: func(cmd *cobra.Command, args []string) {

account, err := client.GetAccount(args[0])
userId := apiUser.username
if len(args) == 1 {
userId = args[0]
}
account, err := client.GetAccount(userId)
if err != nil {
fmt.Printf("Get account failed: %s\n", err)
return
}
account.Password = "REDACTED"
data, err := json.MarshalIndent(account, "", " ")
if err != nil {
fmt.Printf("Error marshalling account %s\n", err.Error)
Expand Down
5 changes: 5 additions & 0 deletions apiserver/pkg/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/xeipuuv/gojsonschema"
)

var maxKeyLength = 17

type Validator struct {
schemaLoader gojsonschema.JSONLoader
}
Expand All @@ -28,6 +30,9 @@ func (v *Validator) ValidateSpec(spec *api.ServiceSpec) (bool, error) {
}

if result.Valid() {
if len(spec.Key) > maxKeyLength {
return false, fmt.Errorf("Key must be no longer than 17 characters\n")
}
return true, nil
} else {
msg := ""
Expand Down

0 comments on commit 066d9fa

Please sign in to comment.