Update Service Acct fns based on new ListServiceAccounts type (#2824)

* Update Service Acct fns based on new ListServiceAccounts type
This commit is contained in:
Kaan Kabalak
2023-05-30 10:30:02 -07:00
committed by GitHub
parent 84c5fd58f9
commit 5a77054d6b
4 changed files with 38 additions and 30 deletions

View File

@@ -271,7 +271,7 @@ func getCreateAUserServiceAccountCredsResponse(session *models.Principal, params
return nil, ErrorWithContext(ctx, err)
}
for i := 0; i < len(accounts.Accounts); i++ {
if accounts.Accounts[i] == serviceAccount.AccessKey {
if accounts.Accounts[i].AccessKey == serviceAccount.AccessKey {
return nil, ErrorWithContext(ctx, errors.New("Access Key already in use"))
}
}
@@ -304,7 +304,7 @@ func getCreateServiceAccountCredsResponse(session *models.Principal, params saAp
}
for i := 0; i < len(accounts.Accounts); i++ {
if accounts.Accounts[i] == serviceAccount.AccessKey {
if accounts.Accounts[i].AccessKey == serviceAccount.AccessKey {
return nil, ErrorWithContext(ctx, errors.New("Access Key already in use"))
}
}
@@ -324,7 +324,7 @@ func getUserServiceAccounts(ctx context.Context, userClient MinioAdmin, user str
}
serviceAccounts := models.ServiceAccounts{}
for _, acc := range listServAccs.Accounts {
serviceAccounts = append(serviceAccounts, acc)
serviceAccounts = append(serviceAccounts, acc.AccessKey)
}
return serviceAccounts, nil
}

View File

@@ -87,7 +87,13 @@ func TestListServiceAccounts(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
mockResponse := madmin.ListServiceAccountsResp{
Accounts: []string{"accesskey1", "accesskey2"},
Accounts: []madmin.ServiceAccountInfo{
{
AccessKey: "accesskey1",
}, {
AccessKey: "accesskey2",
},
},
}
minioListServiceAccountsMock = func(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error) {
return mockResponse, nil
@@ -97,7 +103,7 @@ func TestListServiceAccounts(t *testing.T) {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}
for i, sa := range serviceAccounts {
assert.Equal(mockResponse.Accounts[i], sa)
assert.Equal(mockResponse.Accounts[i].AccessKey, sa)
}
// Test-2: getUserServiceAccounts returns an error, handle it properly