Newer
Older
/*
* Copyright (C) 2023-2024
* Das Land Schleswig-Holstein vertreten durch den
* Ministerpräsidenten des Landes Schleswig-Holstein
* Staatskanzlei
* Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
*
* Lizenziert unter der EUPL, Version 1.2 oder - sobald
* diese von der Europäischen Kommission genehmigt wurden -
* Folgeversionen der EUPL ("Lizenz");
* Sie dürfen dieses Werk ausschließlich gemäß
* dieser Lizenz nutzen.
* Eine Kopie der Lizenz finden Sie hier:
*
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
*
* Sofern nicht durch anwendbare Rechtsvorschriften
* gefordert oder in schriftlicher Form vereinbart, wird
* die unter der Lizenz verbreitete Software "so wie sie
* ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
* ausdrücklich oder stillschweigend - verbreitet.
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import (
"context"
pb "fachstellen-proxy/gen/go"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

OZGCloud
committed
"io"

OZGCloud
committed
"os"
"testing"

OZGCloud
committed
const (
GrpcMockPort = 50052
defaultFilePath = "internal/mock/testdata/dummy.pdf"
testFilePath = "testdata/dummy.pdf"
)
pb.UnimplementedFachstelleRegistrationServiceServer
}

OZGCloud
committed
func (s *registrationServer) Register(_ context.Context, in *pb.GrpcFachstelleRegistrationRequest) (*pb.GrpcFachstelleRegistrationResponse, error) {
return nil, status.Error(codes.InvalidArgument, "fachstelle is missing")
return nil, status.Error(codes.AlreadyExists, "conflict MukId")
return nil, status.Error(codes.Unavailable, "unavailable MukId")
return nil, status.Error(codes.Internal, "erroneous MukId")
return &pb.GrpcFachstelleRegistrationResponse{}, nil
}
type collaborationServer struct {
pb.UnimplementedCollaborationServiceServer
}

OZGCloud
committed
func (s *collaborationServer) FindVorgang(_ context.Context, in *pb.GrpcFindVorgangRequest) (*pb.GrpcFindVorgangResponse, error) {
return nil, status.Error(codes.InvalidArgument, "vorgangId is missing")
return nil, status.Error(codes.InvalidArgument, "samlToken is missing")
return &pb.GrpcFindVorgangResponse{Vorgang: &pb.GrpcVorgang{Id: "testVorgangId"}}, nil

OZGCloud
committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
func (s *collaborationServer) GetFileContent(in *pb.GrpcGetFileContentRequest, stream pb.CollaborationService_GetFileContentServer) error {
if in.Id == "" {
return status.Error(codes.InvalidArgument, "fileId is missing")
}
if in.SamlToken == "" {
return status.Error(codes.InvalidArgument, "samlToken is missing")
}
fp := defaultFilePath
if testing.Testing() {
fp = testFilePath
}
file, err := os.Open(fp)
if err != nil {
return err
}
defer file.Close()
buffer := make([]byte, 1024*1024)
for {
bytesRead, err := file.Read(buffer)
if err == io.EOF {
break
}
if err != nil {
return err
}
chunk := &pb.GrpcGetFileContentResponse{FileContent: buffer[:bytesRead]}
if err := stream.Send(chunk); err != nil {
return err
}
}
return nil
}
func StartGrpcServer() *grpc.Server {
s := grpc.NewServer()
pb.RegisterFachstelleRegistrationServiceServer(s, ®istrationServer{})
pb.RegisterCollaborationServiceServer(s, &collaborationServer{})
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", GrpcMockPort))
logger.Info("gRPC server listening on port %d", GrpcMockPort)