From 9027864b68bc1f7d9cd70c469ea854a1adfb6ee5 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Thu, 11 Feb 2021 15:53:33 +0100 Subject: [PATCH 1/3] quickfix for thumbnail generation when using different idp --- .../thumbnails-username-quickfix.md | 7 + ocis/go.mod | 1 + thumbnails/go.mod | 1 + thumbnails/go.sum | 2 + thumbnails/pkg/proto/v0/thumbnails.pb.go | 415 ++++++++++++------ .../pkg/proto/v0/thumbnails.pb.micro.go | 12 +- thumbnails/pkg/proto/v0/thumbnails.proto | 2 + thumbnails/pkg/service/v0/service.go | 28 +- webdav/pkg/dav/thumbnails/thumbnail.go | 2 + webdav/pkg/service/v0/service.go | 1 + 10 files changed, 311 insertions(+), 160 deletions(-) create mode 100644 changelog/unreleased/thumbnails-username-quickfix.md diff --git a/changelog/unreleased/thumbnails-username-quickfix.md b/changelog/unreleased/thumbnails-username-quickfix.md new file mode 100644 index 0000000000..5ec40b22ce --- /dev/null +++ b/changelog/unreleased/thumbnails-username-quickfix.md @@ -0,0 +1,7 @@ +Bugfix: Fix thumbnail generation when using different idp + +The thumbnail service was relying on a konnectd specific field in the access token. +This logic was now replaced by a service parameter for the username. + +https://github.com/owncloud/ocis/issues/1624 +https://github.com/owncloud/ocis/pull/1628 diff --git a/ocis/go.mod b/ocis/go.mod index 22197add2c..2ffbdd3c49 100644 --- a/ocis/go.mod +++ b/ocis/go.mod @@ -31,6 +31,7 @@ require ( github.com/owncloud/ocis/thumbnails v0.1.6 github.com/owncloud/ocis/web v0.0.0-00010101000000-000000000000 github.com/owncloud/ocis/webdav v0.0.0-00010101000000-000000000000 + github.com/refs/pman v0.0.0-20210125101615-7406747552bc github.com/restic/calens v0.2.0 github.com/rs/zerolog v1.20.0 github.com/spf13/cobra v1.0.0 diff --git a/thumbnails/go.mod b/thumbnails/go.mod index 71fd26787f..4df4302910 100644 --- a/thumbnails/go.mod +++ b/thumbnails/go.mod @@ -32,6 +32,7 @@ require ( golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect golang.org/x/image v0.0.0-20190802002840-cff245a6509b google.golang.org/genproto v0.0.0-20200918140846-d0d605568037 // indirect + google.golang.org/protobuf v1.25.0 gopkg.in/square/go-jose.v2 v2.5.1 ) diff --git a/thumbnails/go.sum b/thumbnails/go.sum index 64b3f130dc..84d57d7bab 100644 --- a/thumbnails/go.sum +++ b/thumbnails/go.sum @@ -209,6 +209,8 @@ github.com/cs3org/reva v1.4.1-0.20210111080247-f2b63bfd6825 h1:U6pAVGTjesstz+EXd github.com/cs3org/reva v1.4.1-0.20210111080247-f2b63bfd6825/go.mod h1:abC1Lo0ZKwkKloomTPZWunV/lUJvewkty1pI41zn2Ic= github.com/cs3org/reva v1.5.1 h1:GebunCjhHfA3lFLXjQT+3jOUjEXUubk9sr3otOIDGac= github.com/cs3org/reva v1.5.1/go.mod h1:abC1Lo0ZKwkKloomTPZWunV/lUJvewkty1pI41zn2Ic= +github.com/cs3org/reva v1.5.2-0.20210125114636-0c10b333ee69 h1:HNpnnhoHv/7fUSEuW37clWyPz2x9VqJHuhvWBAHjkEU= +github.com/cs3org/reva v1.5.2-0.20210125114636-0c10b333ee69/go.mod h1:abC1Lo0ZKwkKloomTPZWunV/lUJvewkty1pI41zn2Ic= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/thumbnails/pkg/proto/v0/thumbnails.pb.go b/thumbnails/pkg/proto/v0/thumbnails.pb.go index db7c9109a0..949e9d23bc 100644 --- a/thumbnails/pkg/proto/v0/thumbnails.pb.go +++ b/thumbnails/pkg/proto/v0/thumbnails.pb.go @@ -1,204 +1,351 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: pkg/proto/v0/thumbnails.proto +// versions: +// protoc-gen-go v1.25.0-devel +// protoc v3.14.0 +// source: thumbnails.proto package proto import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - math "math" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) +// The file types to which the thumbnail cna get encoded to. type GetRequest_FileType int32 const ( - GetRequest_PNG GetRequest_FileType = 0 - GetRequest_JPG GetRequest_FileType = 1 + GetRequest_PNG GetRequest_FileType = 0 // Represents PNG type + GetRequest_JPG GetRequest_FileType = 1 // Represents JPG type ) -var GetRequest_FileType_name = map[int32]string{ - 0: "PNG", - 1: "JPG", -} +// Enum value maps for GetRequest_FileType. +var ( + GetRequest_FileType_name = map[int32]string{ + 0: "PNG", + 1: "JPG", + } + GetRequest_FileType_value = map[string]int32{ + "PNG": 0, + "JPG": 1, + } +) -var GetRequest_FileType_value = map[string]int32{ - "PNG": 0, - "JPG": 1, +func (x GetRequest_FileType) Enum() *GetRequest_FileType { + p := new(GetRequest_FileType) + *p = x + return p } func (x GetRequest_FileType) String() string { - return proto.EnumName(GetRequest_FileType_name, int32(x)) + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) } +func (GetRequest_FileType) Descriptor() protoreflect.EnumDescriptor { + return file_thumbnails_proto_enumTypes[0].Descriptor() +} + +func (GetRequest_FileType) Type() protoreflect.EnumType { + return &file_thumbnails_proto_enumTypes[0] +} + +func (x GetRequest_FileType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use GetRequest_FileType.Descriptor instead. func (GetRequest_FileType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_e354cb4f8a62b6c2, []int{0, 0} + return file_thumbnails_proto_rawDescGZIP(), []int{0, 0} } +// A request to retrieve a thumbnail type GetRequest struct { - Filepath string `protobuf:"bytes,1,opt,name=filepath,proto3" json:"filepath,omitempty"` - Filetype GetRequest_FileType `protobuf:"varint,2,opt,name=filetype,proto3,enum=com.owncloud.ocis.thumbnails.v0.GetRequest_FileType" json:"filetype,omitempty"` - Etag string `protobuf:"bytes,3,opt,name=etag,proto3" json:"etag,omitempty"` - Width int32 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"` - Height int32 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"` - Authorization string `protobuf:"bytes,6,opt,name=authorization,proto3" json:"authorization,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The path to the source image + Filepath string `protobuf:"bytes,1,opt,name=filepath,proto3" json:"filepath,omitempty"` + // The type to which the thumbnail should get encoded to. + Filetype GetRequest_FileType `protobuf:"varint,2,opt,name=filetype,proto3,enum=com.owncloud.ocis.thumbnails.v0.GetRequest_FileType" json:"filetype,omitempty"` + // The etag of the source image + Etag string `protobuf:"bytes,3,opt,name=etag,proto3" json:"etag,omitempty"` + // The width of the thumbnail + Width int32 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"` + // The height of the thumbnail + Height int32 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"` + // The authorization token + Authorization string `protobuf:"bytes,6,opt,name=authorization,proto3" json:"authorization,omitempty"` + // The user requesting the resource. + Username string `protobuf:"bytes,7,opt,name=username,proto3" json:"username,omitempty"` } -func (m *GetRequest) Reset() { *m = GetRequest{} } -func (m *GetRequest) String() string { return proto.CompactTextString(m) } -func (*GetRequest) ProtoMessage() {} +func (x *GetRequest) Reset() { + *x = GetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_thumbnails_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetRequest) ProtoMessage() {} + +func (x *GetRequest) ProtoReflect() protoreflect.Message { + mi := &file_thumbnails_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetRequest.ProtoReflect.Descriptor instead. func (*GetRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e354cb4f8a62b6c2, []int{0} + return file_thumbnails_proto_rawDescGZIP(), []int{0} } -func (m *GetRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetRequest.Unmarshal(m, b) -} -func (m *GetRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetRequest.Marshal(b, m, deterministic) -} -func (m *GetRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetRequest.Merge(m, src) -} -func (m *GetRequest) XXX_Size() int { - return xxx_messageInfo_GetRequest.Size(m) -} -func (m *GetRequest) XXX_DiscardUnknown() { - xxx_messageInfo_GetRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_GetRequest proto.InternalMessageInfo - -func (m *GetRequest) GetFilepath() string { - if m != nil { - return m.Filepath +func (x *GetRequest) GetFilepath() string { + if x != nil { + return x.Filepath } return "" } -func (m *GetRequest) GetFiletype() GetRequest_FileType { - if m != nil { - return m.Filetype +func (x *GetRequest) GetFiletype() GetRequest_FileType { + if x != nil { + return x.Filetype } return GetRequest_PNG } -func (m *GetRequest) GetEtag() string { - if m != nil { - return m.Etag +func (x *GetRequest) GetEtag() string { + if x != nil { + return x.Etag } return "" } -func (m *GetRequest) GetWidth() int32 { - if m != nil { - return m.Width +func (x *GetRequest) GetWidth() int32 { + if x != nil { + return x.Width } return 0 } -func (m *GetRequest) GetHeight() int32 { - if m != nil { - return m.Height +func (x *GetRequest) GetHeight() int32 { + if x != nil { + return x.Height } return 0 } -func (m *GetRequest) GetAuthorization() string { - if m != nil { - return m.Authorization +func (x *GetRequest) GetAuthorization() string { + if x != nil { + return x.Authorization } return "" } +func (x *GetRequest) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +// The service response type GetResponse struct { - Thumbnail []byte `protobuf:"bytes,1,opt,name=thumbnail,proto3" json:"thumbnail,omitempty"` - Mimetype string `protobuf:"bytes,2,opt,name=mimetype,proto3" json:"mimetype,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The thumbnail as a binary + Thumbnail []byte `protobuf:"bytes,1,opt,name=thumbnail,proto3" json:"thumbnail,omitempty"` + // The mimetype of the thumbnail + Mimetype string `protobuf:"bytes,2,opt,name=mimetype,proto3" json:"mimetype,omitempty"` } -func (m *GetResponse) Reset() { *m = GetResponse{} } -func (m *GetResponse) String() string { return proto.CompactTextString(m) } -func (*GetResponse) ProtoMessage() {} +func (x *GetResponse) Reset() { + *x = GetResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_thumbnails_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetResponse) ProtoMessage() {} + +func (x *GetResponse) ProtoReflect() protoreflect.Message { + mi := &file_thumbnails_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetResponse.ProtoReflect.Descriptor instead. func (*GetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e354cb4f8a62b6c2, []int{1} + return file_thumbnails_proto_rawDescGZIP(), []int{1} } -func (m *GetResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetResponse.Unmarshal(m, b) -} -func (m *GetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetResponse.Marshal(b, m, deterministic) -} -func (m *GetResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetResponse.Merge(m, src) -} -func (m *GetResponse) XXX_Size() int { - return xxx_messageInfo_GetResponse.Size(m) -} -func (m *GetResponse) XXX_DiscardUnknown() { - xxx_messageInfo_GetResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_GetResponse proto.InternalMessageInfo - -func (m *GetResponse) GetThumbnail() []byte { - if m != nil { - return m.Thumbnail +func (x *GetResponse) GetThumbnail() []byte { + if x != nil { + return x.Thumbnail } return nil } -func (m *GetResponse) GetMimetype() string { - if m != nil { - return m.Mimetype +func (x *GetResponse) GetMimetype() string { + if x != nil { + return x.Mimetype } return "" } -func init() { - proto.RegisterEnum("com.owncloud.ocis.thumbnails.v0.GetRequest_FileType", GetRequest_FileType_name, GetRequest_FileType_value) - proto.RegisterType((*GetRequest)(nil), "com.owncloud.ocis.thumbnails.v0.GetRequest") - proto.RegisterType((*GetResponse)(nil), "com.owncloud.ocis.thumbnails.v0.GetResponse") +var File_thumbnails_proto protoreflect.FileDescriptor + +var file_thumbnails_proto_rawDesc = []byte{ + 0x0a, 0x10, 0x74, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x1f, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x77, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, + 0x2e, 0x6f, 0x63, 0x69, 0x73, 0x2e, 0x74, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x73, + 0x2e, 0x76, 0x30, 0x22, 0x9c, 0x02, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x70, 0x61, 0x74, 0x68, 0x12, 0x50, + 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x34, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x77, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2e, + 0x6f, 0x63, 0x69, 0x73, 0x2e, 0x74, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x73, 0x2e, + 0x76, 0x30, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x46, 0x69, + 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x74, 0x79, 0x70, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x65, 0x74, 0x61, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x65, 0x74, 0x61, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, + 0x69, 0x67, 0x68, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x75, 0x74, 0x68, 0x6f, + 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, + 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x1c, 0x0a, 0x08, 0x46, 0x69, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x07, 0x0a, 0x03, 0x50, 0x4e, 0x47, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4a, 0x50, 0x47, + 0x10, 0x01, 0x22, 0x47, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x74, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x12, + 0x1a, 0x0a, 0x08, 0x6d, 0x69, 0x6d, 0x65, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x6d, 0x69, 0x6d, 0x65, 0x74, 0x79, 0x70, 0x65, 0x32, 0x7d, 0x0a, 0x10, 0x54, + 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x69, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x54, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x12, + 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x77, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2e, 0x6f, + 0x63, 0x69, 0x73, 0x2e, 0x74, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x76, + 0x30, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, + 0x6f, 0x6d, 0x2e, 0x6f, 0x77, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2e, 0x6f, 0x63, 0x69, 0x73, + 0x2e, 0x74, 0x68, 0x75, 0x6d, 0x62, 0x6e, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x47, + 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x07, 0x5a, 0x05, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } -func init() { proto.RegisterFile("pkg/proto/v0/thumbnails.proto", fileDescriptor_e354cb4f8a62b6c2) } +var ( + file_thumbnails_proto_rawDescOnce sync.Once + file_thumbnails_proto_rawDescData = file_thumbnails_proto_rawDesc +) -var fileDescriptor_e354cb4f8a62b6c2 = []byte{ - // 309 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x91, 0x4f, 0x4f, 0xc2, 0x40, - 0x10, 0xc5, 0x2d, 0x50, 0xfe, 0x8c, 0x68, 0xc8, 0xc4, 0x98, 0x86, 0x60, 0x24, 0xc4, 0x03, 0x89, - 0x66, 0x21, 0xe8, 0x27, 0xf0, 0x60, 0x13, 0x0f, 0x86, 0x54, 0x4e, 0xde, 0x4a, 0x19, 0xd9, 0x8d, - 0x6d, 0x77, 0xa5, 0x53, 0x08, 0x26, 0x26, 0x7e, 0x74, 0xc3, 0x22, 0x45, 0x4f, 0xea, 0x69, 0xe7, - 0xfd, 0x76, 0xf2, 0x66, 0xf6, 0x2d, 0x9c, 0x99, 0x97, 0xf9, 0xc0, 0x2c, 0x34, 0xeb, 0xc1, 0x72, - 0x38, 0x60, 0x99, 0x27, 0xd3, 0x34, 0x54, 0x71, 0x26, 0x2c, 0xc3, 0xf3, 0x48, 0x27, 0x42, 0xaf, - 0xd2, 0x28, 0xd6, 0xf9, 0x4c, 0xe8, 0x48, 0x65, 0xe2, 0x5b, 0xcf, 0x72, 0xd8, 0xfb, 0x28, 0x01, - 0xf8, 0xc4, 0x01, 0xbd, 0xe6, 0x94, 0x31, 0xb6, 0xa1, 0xfe, 0xac, 0x62, 0x32, 0x21, 0x4b, 0xcf, - 0xe9, 0x3a, 0xfd, 0x46, 0x50, 0x68, 0x1c, 0x6f, 0xef, 0x78, 0x6d, 0xc8, 0x2b, 0x75, 0x9d, 0xfe, - 0xf1, 0xe8, 0x46, 0xfc, 0x62, 0x2f, 0xf6, 0xd6, 0xe2, 0x4e, 0xc5, 0x34, 0x59, 0x1b, 0x0a, 0x0a, - 0x17, 0x44, 0xa8, 0x10, 0x87, 0x73, 0xaf, 0x6c, 0x27, 0xd9, 0x1a, 0x4f, 0xc0, 0x5d, 0xa9, 0x19, - 0x4b, 0xaf, 0xd2, 0x75, 0xfa, 0x6e, 0xb0, 0x15, 0x78, 0x0a, 0x55, 0x49, 0x6a, 0x2e, 0xd9, 0x73, - 0x2d, 0xfe, 0x52, 0x78, 0x01, 0x47, 0x61, 0xce, 0x52, 0x2f, 0xd4, 0x5b, 0xc8, 0x4a, 0xa7, 0x5e, - 0xd5, 0x5a, 0xfd, 0x84, 0xbd, 0x0e, 0xd4, 0x77, 0xd3, 0xb1, 0x06, 0xe5, 0xf1, 0x83, 0xdf, 0x3a, - 0xd8, 0x14, 0xf7, 0x63, 0xbf, 0xe5, 0xf4, 0x7c, 0x38, 0xb4, 0x6b, 0x66, 0x46, 0xa7, 0x19, 0x61, - 0x07, 0x1a, 0xc5, 0x1b, 0x6c, 0x06, 0xcd, 0x60, 0x0f, 0x36, 0x01, 0x25, 0x2a, 0xd9, 0x87, 0xd0, - 0x08, 0x0a, 0x3d, 0x7a, 0x87, 0xd6, 0x64, 0xd7, 0xf8, 0x48, 0x8b, 0xa5, 0x8a, 0x08, 0x15, 0x34, - 0x7d, 0xe2, 0x02, 0xe3, 0xe5, 0x3f, 0x22, 0x6b, 0x5f, 0xfd, 0xad, 0x79, 0xbb, 0xf8, 0x6d, 0xed, - 0xc9, 0xb5, 0x9f, 0x3e, 0xad, 0xda, 0xe3, 0xfa, 0x33, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x29, 0x25, - 0xcc, 0x1c, 0x02, 0x00, 0x00, +func file_thumbnails_proto_rawDescGZIP() []byte { + file_thumbnails_proto_rawDescOnce.Do(func() { + file_thumbnails_proto_rawDescData = protoimpl.X.CompressGZIP(file_thumbnails_proto_rawDescData) + }) + return file_thumbnails_proto_rawDescData +} + +var file_thumbnails_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_thumbnails_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_thumbnails_proto_goTypes = []interface{}{ + (GetRequest_FileType)(0), // 0: com.owncloud.ocis.thumbnails.v0.GetRequest.FileType + (*GetRequest)(nil), // 1: com.owncloud.ocis.thumbnails.v0.GetRequest + (*GetResponse)(nil), // 2: com.owncloud.ocis.thumbnails.v0.GetResponse +} +var file_thumbnails_proto_depIdxs = []int32{ + 0, // 0: com.owncloud.ocis.thumbnails.v0.GetRequest.filetype:type_name -> com.owncloud.ocis.thumbnails.v0.GetRequest.FileType + 1, // 1: com.owncloud.ocis.thumbnails.v0.ThumbnailService.GetThumbnail:input_type -> com.owncloud.ocis.thumbnails.v0.GetRequest + 2, // 2: com.owncloud.ocis.thumbnails.v0.ThumbnailService.GetThumbnail:output_type -> com.owncloud.ocis.thumbnails.v0.GetResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_thumbnails_proto_init() } +func file_thumbnails_proto_init() { + if File_thumbnails_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_thumbnails_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_thumbnails_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_thumbnails_proto_rawDesc, + NumEnums: 1, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_thumbnails_proto_goTypes, + DependencyIndexes: file_thumbnails_proto_depIdxs, + EnumInfos: file_thumbnails_proto_enumTypes, + MessageInfos: file_thumbnails_proto_msgTypes, + }.Build() + File_thumbnails_proto = out.File + file_thumbnails_proto_rawDesc = nil + file_thumbnails_proto_goTypes = nil + file_thumbnails_proto_depIdxs = nil } diff --git a/thumbnails/pkg/proto/v0/thumbnails.pb.micro.go b/thumbnails/pkg/proto/v0/thumbnails.pb.micro.go index 9533ba8fa0..eb9ad0a91a 100644 --- a/thumbnails/pkg/proto/v0/thumbnails.pb.micro.go +++ b/thumbnails/pkg/proto/v0/thumbnails.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: pkg/proto/v0/thumbnails.proto +// source: thumbnails.proto package proto @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,13 +28,21 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for ThumbnailService service + +func NewThumbnailServiceEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for ThumbnailService service type ThumbnailService interface { + // Generates the thumbnail and returns it. GetThumbnail(ctx context.Context, in *GetRequest, opts ...client.CallOption) (*GetResponse, error) } @@ -62,6 +71,7 @@ func (c *thumbnailService) GetThumbnail(ctx context.Context, in *GetRequest, opt // Server API for ThumbnailService service type ThumbnailServiceHandler interface { + // Generates the thumbnail and returns it. GetThumbnail(context.Context, *GetRequest, *GetResponse) error } diff --git a/thumbnails/pkg/proto/v0/thumbnails.proto b/thumbnails/pkg/proto/v0/thumbnails.proto index 9b1f6476a3..3573456ff2 100644 --- a/thumbnails/pkg/proto/v0/thumbnails.proto +++ b/thumbnails/pkg/proto/v0/thumbnails.proto @@ -28,6 +28,8 @@ message GetRequest { int32 height = 5; // The authorization token string authorization = 6; + // The user requesting the resource. + string username = 7; } // The service response diff --git a/thumbnails/pkg/service/v0/service.go b/thumbnails/pkg/service/v0/service.go index eb8357effe..642a46c431 100644 --- a/thumbnails/pkg/service/v0/service.go +++ b/thumbnails/pkg/service/v0/service.go @@ -4,14 +4,11 @@ import ( "context" "image" - "gopkg.in/square/go-jose.v2/jwt" - merrors "github.com/micro/go-micro/v2/errors" "github.com/owncloud/ocis/ocis-pkg/log" v0proto "github.com/owncloud/ocis/thumbnails/pkg/proto/v0" "github.com/owncloud/ocis/thumbnails/pkg/thumbnail" "github.com/owncloud/ocis/thumbnails/pkg/thumbnail/imgsource" - "github.com/pkg/errors" ) // NewService returns a service implementation for Service. @@ -56,9 +53,9 @@ func (g Thumbnail) GetThumbnail(ctx context.Context, req *v0proto.GetRequest, rs if auth == "" { return merrors.BadRequest(g.serviceID, "authorization is missing") } - username, err := usernameFromAuthorization(auth) - if err != nil { - return merrors.InternalServerError(g.serviceID, "could not get username: %v", err.Error()) + username := req.Username + if username == "" { + return merrors.BadRequest(g.serviceID, "username missing in request") } tr := thumbnail.Request{ @@ -92,22 +89,3 @@ func (g Thumbnail) GetThumbnail(ctx context.Context, req *v0proto.GetRequest, rs rsp.Mimetype = tr.Encoder.MimeType() return nil } - -func usernameFromAuthorization(auth string) (string, error) { - tokenString := auth[len("Bearer "):] // strip the bearer prefix - - var claims map[string]interface{} - token, err := jwt.ParseSigned(tokenString) - if err != nil { - return "", errors.Wrap(err, "could not parse auth token") - } - err = token.UnsafeClaimsWithoutVerification(&claims) - if err != nil { - return "", errors.Wrap(err, "could not get claims from auth token") - } - - identityMap := claims["kc.identity"].(map[string]interface{}) - username := identityMap["kc.i.un"].(string) - - return username, nil -} diff --git a/webdav/pkg/dav/thumbnails/thumbnail.go b/webdav/pkg/dav/thumbnails/thumbnail.go index e8ba4b1348..a42082f951 100644 --- a/webdav/pkg/dav/thumbnails/thumbnail.go +++ b/webdav/pkg/dav/thumbnails/thumbnail.go @@ -25,6 +25,7 @@ type Request struct { Width int Height int Authorization string + Username string } // NewRequest extracts all required parameters from a http request. @@ -54,6 +55,7 @@ func NewRequest(r *http.Request) (Request, error) { Width: width, Height: height, Authorization: authorization, + Username: chi.URLParam(r, "user"), } return tr, nil diff --git a/webdav/pkg/service/v0/service.go b/webdav/pkg/service/v0/service.go index 9955c65288..b7ac0f5d4b 100644 --- a/webdav/pkg/service/v0/service.go +++ b/webdav/pkg/service/v0/service.go @@ -64,6 +64,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { Width: int32(tr.Width), Height: int32(tr.Height), Authorization: tr.Authorization, + Username: tr.Username, }) if err != nil { w.WriteHeader(http.StatusBadRequest) From d7604d8608d03eeadf04fd8f990fe8410281fad2 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Thu, 11 Feb 2021 16:24:02 +0100 Subject: [PATCH 2/3] update thumbnail tests to quickfix --- thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go | 2 ++ thumbnails/pkg/proto/v0/thumbnails.pb_test.go | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go b/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go index 6fcac788f3..874527922d 100644 --- a/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go +++ b/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go @@ -56,6 +56,7 @@ func TestGetThumbnailInvalidImage(t *testing.T) { Etag: "33a64df551425fcc55e4d42a148795d9f25f89d4", Height: 32, Width: 32, + Username: "user1", } client := service.Client() cl := proto.NewThumbnailService("com.owncloud.api.thumbnails", client) @@ -72,6 +73,7 @@ func TestGetThumbnail(t *testing.T) { Height: 32, Width: 32, Authorization: "Bearer eyJhbGciOiJQUzI1NiIsImtpZCI6IiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJwaG9lbml4IiwiZXhwIjoxNTkwNTc1Mzk4LCJqdGkiOiJqUEw5c1A3UUEzY0diYi1yRnhkSjJCWnFPc1BDTDg1ZyIsImlhdCI6MTU5MDU3NDc5OCwiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6OTIwMCIsInN1YiI6Ilh0U2lfbWl5V1NCLXBrdkdueFBvQzVBNGZsaWgwVUNMZ3ZVN2NMd2ptakNLWDdGWW4ySFdrNnJSQ0V1eTJHNXFBeV95TVFjX0ZLOWFORmhVTXJYMnBRQGtvbm5lY3QiLCJrYy5pc0FjY2Vzc1Rva2VuIjp0cnVlLCJrYy5hdXRob3JpemVkU2NvcGVzIjpbIm9wZW5pZCIsInByb2ZpbGUiLCJlbWFpbCJdLCJrYy5pZGVudGl0eSI6eyJrYy5pLmRuIjoiRWluc3RlaW4iLCJrYy5pLmlkIjoiY249ZWluc3RlaW4sb3U9dXNlcnMsZGM9ZXhhbXBsZSxkYz1vcmciLCJrYy5pLnVuIjoiZWluc3RlaW4ifSwia2MucHJvdmlkZXIiOiJpZGVudGlmaWVyLWxkYXAifQ.FSDe4vzwYpHbNfckBON5EI-01MS_dYFxenddqfJPzjlAEMEH2FFn2xQHCsxhC7wSxivhjV7Z5eRoNUR606keA64Tjs8pJBNECSptBMmE_xfAlc6X5IFILgDnR5bBu6Z2hhu-dVj72Hcyvo_X__OeWekYu7oyoXW41Mw3ayiUAwjCAzV3WPOAJ_r0zbW68_m29BgH3BoSxaF6lmjStIIAIyw7IBZ2QXb_FvGouknmfeWlGL9lkFPGL_dYKwjWieG947nY4Kg8IvHByEbw-xlY3L2EdA7Q8ZMbqdX7GzjtEIVYvCT4-TxWRcmB3SmO-Z8CVq27NHlKm3aZ0k2PS8Ga1w", + Username: "user1", } client := service.Client() cl := proto.NewThumbnailService("com.owncloud.api.thumbnails", client) diff --git a/thumbnails/pkg/proto/v0/thumbnails.pb_test.go b/thumbnails/pkg/proto/v0/thumbnails.pb_test.go index 4370ff2b6d..84806b831e 100644 --- a/thumbnails/pkg/proto/v0/thumbnails.pb_test.go +++ b/thumbnails/pkg/proto/v0/thumbnails.pb_test.go @@ -36,7 +36,7 @@ func TestRequestString(t *testing.T) { 24, 24, "Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK", - `filepath:"Foo.jpg" filetype:JPG etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" `, + `filepath:"Foo.jpg" filetype:JPG etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" username:"user1"`, }, { "UTF", @@ -46,7 +46,7 @@ func TestRequestString(t *testing.T) { 24, 24, "Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK", - `filepath:"\340\244\256\340\244\277\340\244\262\340\244\250.jpg" filetype:JPG etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" `, + `filepath:"मिलन.jpg" filetype:JPG etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" username:"user1"`, }, { "PNG", @@ -56,7 +56,7 @@ func TestRequestString(t *testing.T) { 24, 24, "Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK", - `filepath:"Foo.png" etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" `, + `filepath:"Foo.png" etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" username:"user1"`, }, } @@ -69,6 +69,7 @@ func TestRequestString(t *testing.T) { Height: testCase.height, Width: testCase.width, Authorization: testCase.authorization, + Username: "user1", } assert.Equal(t, testCase.expected, req.String()) }) @@ -81,7 +82,7 @@ func TestResponseString(t *testing.T) { "ASCII", []byte("image data"), "image/png", - `thumbnail:"image data" mimetype:"image/png" `, + `thumbnail:"image data" mimetype:"image/png"`, }, } From 8c9a1712fbd83df9e450c7f19d913dcc4feb9c2e Mon Sep 17 00:00:00 2001 From: David Christofas Date: Thu, 11 Feb 2021 16:43:01 +0100 Subject: [PATCH 3/3] delete unnecessary protobuf tests --- thumbnails/pkg/proto/v0/thumbnails.pb_test.go | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100644 thumbnails/pkg/proto/v0/thumbnails.pb_test.go diff --git a/thumbnails/pkg/proto/v0/thumbnails.pb_test.go b/thumbnails/pkg/proto/v0/thumbnails.pb_test.go deleted file mode 100644 index 84806b831e..0000000000 --- a/thumbnails/pkg/proto/v0/thumbnails.pb_test.go +++ /dev/null @@ -1,99 +0,0 @@ -package proto_test - -import ( - "testing" - - "github.com/owncloud/ocis/thumbnails/pkg/proto/v0" - "github.com/stretchr/testify/assert" -) - -type TestRequest struct { - testDataName string - filepath string - filetype proto.GetRequest_FileType - etag string - width int32 - height int32 - authorization string - expected string -} - -type TestResponse struct { - testDataName string - img []byte - mimetype string - expected string -} - -func TestRequestString(t *testing.T) { - - var tests = []TestRequest{ - { - "ASCII", - "Foo.jpg", - proto.GetRequest_JPG, - "33a64df551425fcc55e4d42a148795d9f25f89d4", - 24, - 24, - "Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK", - `filepath:"Foo.jpg" filetype:JPG etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" username:"user1"`, - }, - { - "UTF", - "मिलन.jpg", - proto.GetRequest_JPG, - "33a64df551425fcc55e4d42a148795d9f25f89d4", - 24, - 24, - "Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK", - `filepath:"मिलन.jpg" filetype:JPG etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" username:"user1"`, - }, - { - "PNG", - "Foo.png", - proto.GetRequest_PNG, - "33a64df551425fcc55e4d42a148795d9f25f89d4", - 24, - 24, - "Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK", - `filepath:"Foo.png" etag:"33a64df551425fcc55e4d42a148795d9f25f89d4" width:24 height:24 authorization:"Basic SGVXaG9SZWFkc1RoaXM6SXNTdHVwaWQK" username:"user1"`, - }, - } - - for _, testCase := range tests { - t.Run(testCase.testDataName, func(t *testing.T) { - req := proto.GetRequest{ - Filepath: testCase.filepath, - Filetype: testCase.filetype, - Etag: testCase.etag, - Height: testCase.height, - Width: testCase.width, - Authorization: testCase.authorization, - Username: "user1", - } - assert.Equal(t, testCase.expected, req.String()) - }) - } -} - -func TestResponseString(t *testing.T) { - var tests = []TestResponse{ - { - "ASCII", - []byte("image data"), - "image/png", - `thumbnail:"image data" mimetype:"image/png"`, - }, - } - - for _, testCase := range tests { - t.Run(testCase.testDataName, func(t *testing.T) { - response := proto.GetResponse{ - Thumbnail: testCase.img, - Mimetype: testCase.mimetype, - } - - assert.Equal(t, testCase.expected, response.String()) - }) - } -}