Skip to content

Commit

Permalink
chore: check list permissions for replay (#3873)
Browse files Browse the repository at this point in the history
  • Loading branch information
BonapartePC committed Sep 18, 2023
1 parent 2c655f9 commit fddbc0d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
7 changes: 6 additions & 1 deletion warehouse/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,12 @@ func (g *GRPC) validateObjectStorage(ctx context.Context, request validateObject
return fmt.Errorf("unable to create file manager: \n%s", err.Error())
}

it := filemanager.IterateFilesWithPrefix(ctx, fileManager.Prefix(), "", 1, fileManager)
_ = it.Next()
if err = it.Err(); err != nil {
return invalidDestinationCredErr{Base: err, Operation: "list"}
}

tempFilePath, err := validations.CreateTempLoadFile(&backendconfig.DestinationT{
DestinationDefinition: backendconfig.DestinationDefinitionT{
Name: request.Type,
Expand Down Expand Up @@ -757,7 +763,6 @@ func (g *GRPC) validateObjectStorage(ctx context.Context, request validateObject
if err = f.Close(); err != nil {
return fmt.Errorf("unable to close file: \n%w", err)
}

return nil
}

Expand Down
40 changes: 39 additions & 1 deletion warehouse/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,45 @@ func TestGRPC(t *testing.T) {
})
require.NoError(t, err)
require.NotEmpty(t, res)
require.Equal(t, "Invalid destination creds, failed for operation: upload with err: \nEndpoint: does not follow ip address or domain name standards.", res.GetError())
require.Equal(t, "Invalid destination creds, failed for operation: list with err: \nEndpoint: does not follow ip address or domain name standards.", res.GetError())
require.False(t, res.GetIsValid())
})
t.Run("list permissions missing", func(t *testing.T) {
res, err := grpcClient.ValidateObjectStorageDestination(ctx, &proto.ValidateObjectStorageRequest{
Type: whutils.MINIO,
Config: &structpb.Struct{
Fields: map[string]*structpb.Value{
"region": {
Kind: &structpb.Value_StringValue{
StringValue: minioResource.SiteRegion,
},
},
"bucketName": {
Kind: &structpb.Value_StringValue{
StringValue: minioResource.BucketName,
},
},
"secretAccessKey": {
Kind: &structpb.Value_StringValue{
StringValue: "wrongSecretKey",
},
},
"accessKeyID": {
Kind: &structpb.Value_StringValue{
StringValue: "wrongAccessKey",
},
},
"endPoint": {
Kind: &structpb.Value_StringValue{
StringValue: minioResource.Endpoint,
},
},
},
},
})
require.NoError(t, err)
require.NotEmpty(t, res)
require.Equal(t, "Invalid destination creds, failed for operation: list with err: \nThe Access Key Id you provided does not exist in our records.", res.GetError())
require.False(t, res.GetIsValid())
})
t.Run("checkMapForValidKey", func(t *testing.T) {
Expand Down

0 comments on commit fddbc0d

Please sign in to comment.