From 37b3af6caf2db82629b3047b0a7c36fc4d34d9ba Mon Sep 17 00:00:00 2001 From: Artem Bogomaz Date: Fri, 30 Jul 2021 18:41:19 +0700 Subject: [PATCH 1/2] :bug: resolving bug with shared files --- code/go/0chain.net/blobbercore/handler/handler.go | 2 +- .../blobbercore/handler/object_operation_handler.go | 6 +----- code/go/0chain.net/blobbercore/readmarker/entity.go | 6 +++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/code/go/0chain.net/blobbercore/handler/handler.go b/code/go/0chain.net/blobbercore/handler/handler.go index c2404b3d6..5e961a1e7 100644 --- a/code/go/0chain.net/blobbercore/handler/handler.go +++ b/code/go/0chain.net/blobbercore/handler/handler.go @@ -37,7 +37,7 @@ func GetMetaDataStore() *datastore.Store { func SetupHandlers(r *mux.Router) { //object operations r.HandleFunc("/v1/file/upload/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(UploadHandler)))) - r.HandleFunc("/v1/file/download/{allocation}", common.UserRateLimit(common.ToByteStream(WithConnection(DownloadHandler)))) + r.HandleFunc("/v1/file/download/{allocation}", common.UserRateLimit(common.ToByteStream(WithConnection(DownloadHandler)))).Methods("POST") r.HandleFunc("/v1/file/rename/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(RenameHandler)))) r.HandleFunc("/v1/file/copy/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CopyHandler)))) r.HandleFunc("/v1/file/attributes/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(UpdateAttributesHandler)))) diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 29f0e499f..a0de2d5fe 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -182,10 +182,6 @@ func (fsh *StorageHandler) DownloadFile( ctx context.Context, r *http.Request, ) (resp interface{}, err error) { - if r.Method == "GET" { - return nil, common.NewError("download_file", - "invalid method used (GET), use POST instead") - } // get client and allocation ids var ( @@ -319,7 +315,7 @@ func (fsh *StorageHandler) DownloadFile( } // we only check content hash if its authticket is referring to a file - if authToken.RefType == zfileref.FILE && authToken.ContentHash != fileref.ContentHash { + if authToken.RefType == zfileref.FILE && authToken.ActualFileHash != fileref.ActualFileHash { return nil, errors.New("content hash does not match the requested file content hash") } diff --git a/code/go/0chain.net/blobbercore/readmarker/entity.go b/code/go/0chain.net/blobbercore/readmarker/entity.go index 0e0dfbc46..dcae8e536 100644 --- a/code/go/0chain.net/blobbercore/readmarker/entity.go +++ b/code/go/0chain.net/blobbercore/readmarker/entity.go @@ -21,18 +21,18 @@ type AuthTicket struct { OwnerID string `json:"owner_id"` AllocationID string `json:"allocation_id"` FilePathHash string `json:"file_path_hash"` - ContentHash string `json:"content_hash"` + ActualFileHash string `json:"actual_file_hash"` FileName string `json:"file_name"` RefType string `json:"reference_type"` Expiration common.Timestamp `json:"expiration"` Timestamp common.Timestamp `json:"timestamp"` ReEncryptionKey string `json:"re_encryption_key"` Signature string `json:"signature"` - Encrypted bool `json:"encrypted"` + Encrypted bool `json:"encrypted"` } func (rm *AuthTicket) GetHashData() string { - hashData := fmt.Sprintf("%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v", rm.AllocationID, rm.ClientID, rm.OwnerID, rm.FilePathHash, rm.FileName, rm.RefType, rm.ReEncryptionKey, rm.Expiration, rm.Timestamp, rm.ContentHash, rm.Encrypted) + hashData := fmt.Sprintf("%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v", rm.AllocationID, rm.ClientID, rm.OwnerID, rm.FilePathHash, rm.FileName, rm.RefType, rm.ReEncryptionKey, rm.Expiration, rm.Timestamp, rm.ActualFileHash, rm.Encrypted) return hashData } From b5c5715fc9a560599f377996840e5c8b8fca5513 Mon Sep 17 00:00:00 2001 From: Artem Bogomaz Date: Mon, 2 Aug 2021 14:40:54 +0700 Subject: [PATCH 2/2] :rotating_light: fixing tests --- code/go/0chain.net/blobbercore/handler/handler_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/handler/handler_test.go b/code/go/0chain.net/blobbercore/handler/handler_test.go index de830a258..68e7053ea 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_test.go +++ b/code/go/0chain.net/blobbercore/handler/handler_test.go @@ -273,7 +273,6 @@ func GetAuthTicketForEncryptedFile(allocationID string, remotePath string, fileH at.ClientID = clientID at.FileName = remotePath at.FilePathHash = fileHash - at.ContentHash = "content_hash" at.RefType = fileref.FILE timestamp := int64(common.Now()) at.Expiration = timestamp + 7776000