generated from VLADIMIR/template
fix
This commit is contained in:
@@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"evening_detective_server/internal/modules/file_storage"
|
||||
@@ -113,6 +114,9 @@ func TestUploadFilePutErrorInternal(t *testing.T) {
|
||||
if status.Code(err) != codes.Internal {
|
||||
t.Errorf("code = %v, want Internal", status.Code(err))
|
||||
}
|
||||
if strings.Contains(status.Convert(err).Message(), "s3 недоступен") {
|
||||
t.Fatal("storage error exposed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUploadFileSuccess(t *testing.T) {
|
||||
@@ -160,6 +164,9 @@ func TestDownloadFileInternal(t *testing.T) {
|
||||
if status.Code(err) != codes.Internal {
|
||||
t.Errorf("code = %v, want Internal", status.Code(err))
|
||||
}
|
||||
if strings.Contains(status.Convert(err).Message(), "s3 недоступен") {
|
||||
t.Fatal("storage error exposed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownloadFileSuccess(t *testing.T) {
|
||||
|
||||
@@ -29,14 +29,14 @@ func (s *server) UploadFile(ctx context.Context, req *proto.UploadFileReq) (*pro
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, file_service.ErrFileTooLarge):
|
||||
return nil, status.Errorf(codes.ResourceExhausted, "%v", err)
|
||||
return nil, status.Error(codes.ResourceExhausted, err.Error())
|
||||
case errors.Is(err, file_service.ErrEmptyName),
|
||||
errors.Is(err, file_service.ErrEmptyData),
|
||||
errors.Is(err, file_service.ErrInvalidExtension),
|
||||
errors.Is(err, file_service.ErrInvalidContentType):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
default:
|
||||
return nil, status.Errorf(codes.Internal, "%v", err)
|
||||
return nil, status.Error(codes.Internal, "не удалось загрузить файл")
|
||||
}
|
||||
}
|
||||
return &proto.UploadFileRsp{
|
||||
@@ -50,15 +50,15 @@ func (s *server) DownloadFile(ctx context.Context, req *proto.DownloadFileReq) (
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, file_service.ErrFileNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "%v", err)
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
default:
|
||||
return nil, status.Errorf(codes.Internal, "%v", err)
|
||||
return nil, status.Error(codes.Internal, "не удалось скачать файл")
|
||||
}
|
||||
}
|
||||
// nosniff — при публичном скачивании браузер не должен угадывать
|
||||
// Content-Type по содержимому (защита от stored-XSS при расхождении).
|
||||
if err := grpc.SetHeader(ctx, metadata.Pairs("X-Content-Type-Options", "nosniff")); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to set response header: %v", err)
|
||||
return nil, status.Error(codes.Internal, "не удалось установить заголовки файла")
|
||||
}
|
||||
return &httpbody.HttpBody{
|
||||
Data: file.Data,
|
||||
|
||||
@@ -36,7 +36,7 @@ func (s *server) DownloadTeamQR(ctx context.Context, req *proto.GetGameReq) (*ht
|
||||
case errors.Is(err, team_service.ErrNoCards):
|
||||
return nil, status.Error(codes.FailedPrecondition, err.Error())
|
||||
default:
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
return nil, status.Error(codes.Internal, "не удалось сформировать PDF с QR-кодами")
|
||||
}
|
||||
}
|
||||
if err := grpc.SetHeader(ctx, metadata.Pairs(
|
||||
|
||||
Reference in New Issue
Block a user