Skip to content

Commit

Permalink
[CR] Validate nonempty access key ID, secrets in Swagger
Browse files Browse the repository at this point in the history
Also roll back unrelated merged-in change to swagger.yml.
  • Loading branch information
arielshaqed committed Nov 17, 2020
1 parent 25d2bec commit 5976728
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
58 changes: 42 additions & 16 deletions api/api_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,9 @@ func TestHandler_ContinuousExportHandlers(t *testing.T) {
func Test_setupLakeFSHandler(t *testing.T) {
name := "admin"
cases := []struct {
name string
user models.Setup
name string
user models.Setup
expectedStatusCode int
}{
{name: "simple", user: models.Setup{Username: &name}},
{
Expand All @@ -1460,6 +1461,23 @@ func Test_setupLakeFSHandler(t *testing.T) {
},
},
},
{
name: "emptyAccessKeyId",
user: models.Setup{
Username: &name,
Key: &models.SetupKey{SecretAccessKey: swag.String("cetec astronomy")},
},
expectedStatusCode: 422,
},
{
name: "emptySecretKey", user: models.Setup{
Username: &name,
Key: &models.SetupKey{
AccessKeyID: swag.String("IKEAsneakers"),
},
},
expectedStatusCode: 422,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
Expand All @@ -1483,10 +1501,16 @@ func Test_setupLakeFSHandler(t *testing.T) {
_ = res.Body.Close()
}()

const expectedStatusCode = http.StatusOK
expectedStatusCode := http.StatusOK
if c.expectedStatusCode != 0 {
expectedStatusCode = c.expectedStatusCode
}
if res.StatusCode != expectedStatusCode {
t.Fatalf("setup request returned %d status, expected %d", res.StatusCode, expectedStatusCode)
}
if res.StatusCode != http.StatusOK {
return
}

// read response
var credKeys *models.CredentialsWithSecret
Expand Down Expand Up @@ -1520,19 +1544,21 @@ func Test_setupLakeFSHandler(t *testing.T) {
}
})

// now we ask again - should get status conflict
t.Run("existing setup", func(t *testing.T) {
// request to setup
res := mustSetup(t, reqURI, contentType, req)
defer func() {
_ = res.Body.Close()
}()

const expectedStatusCode = http.StatusConflict
if res.StatusCode != expectedStatusCode {
t.Fatalf("setup request returned %d status, expected %d", res.StatusCode, expectedStatusCode)
}
})
if c.expectedStatusCode == 0 {
// now we ask again - should get status conflict
t.Run("existing setup", func(t *testing.T) {
// request to setup
res := mustSetup(t, reqURI, contentType, req)
defer func() {
_ = res.Body.Close()
}()

const expectedStatusCode = http.StatusConflict
if res.StatusCode != expectedStatusCode {
t.Fatalf("setup request returned %d status, expected %d", res.StatusCode, expectedStatusCode)
}
})
}
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions auth/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ func AddAdminUser(authService Service, user *model.SuperuserConfiguration) (*mod
// Generate and return a key pair
creds, err = authService.CreateCredentials(user.Username)
if err != nil {
return nil, fmt.Errorf("create credentials for %s %w", user.Username, err)
return nil, fmt.Errorf("create credentials for %s: %w", user.Username, err)
}
} else {
creds, err = authService.AddCredentials(user.Username, user.AccessKeyID, user.SecretAccessKey)
if err != nil {
return nil, fmt.Errorf("add credentials for %s %w", user.Username, err)
return nil, fmt.Errorf("add credentials for %s: %w", user.Username, err)
}
}
return creds, nil
Expand Down
2 changes: 2 additions & 0 deletions docs/assets/js/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ definitions:
description: access key ID to set for user for use in integration testing.
example: AKIAIOSFODNN7EXAMPLE
type: string
minLength: 1
secret_access_key:
description: secret access key to set for user for use in integration testing.
example: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
type: string
minLength: 1
required:
- access_key_id
- secret_access_key
Expand Down
2 changes: 2 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ definitions:
description: access key ID to set for user for use in integration testing.
example: AKIAIOSFODNN7EXAMPLE
type: string
minLength: 1
secret_access_key:
description: secret access key to set for user for use in integration testing.
example: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
type: string
minLength: 1
required:
- access_key_id
- secret_access_key
Expand Down

0 comments on commit 5976728

Please sign in to comment.