mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-20 03:52:32 -05:00
fix: adjust unit tests
This commit is contained in:
@@ -5,8 +5,7 @@ package mocks
|
||||
import (
|
||||
context "context"
|
||||
|
||||
connector "github.com/owncloud/ocis/v2/services/collaboration/pkg/connector"
|
||||
|
||||
fileinfo "github.com/owncloud/ocis/v2/services/collaboration/pkg/connector/fileinfo"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
@@ -24,22 +23,24 @@ func (_m *FileConnectorService) EXPECT() *FileConnectorService_Expecter {
|
||||
}
|
||||
|
||||
// CheckFileInfo provides a mock function with given fields: ctx
|
||||
func (_m *FileConnectorService) CheckFileInfo(ctx context.Context) (connector.FileInfo, error) {
|
||||
func (_m *FileConnectorService) CheckFileInfo(ctx context.Context) (fileinfo.FileInfo, error) {
|
||||
ret := _m.Called(ctx)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CheckFileInfo")
|
||||
}
|
||||
|
||||
var r0 connector.FileInfo
|
||||
var r0 fileinfo.FileInfo
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context) (connector.FileInfo, error)); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context) (fileinfo.FileInfo, error)); ok {
|
||||
return rf(ctx)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context) connector.FileInfo); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context) fileinfo.FileInfo); ok {
|
||||
r0 = rf(ctx)
|
||||
} else {
|
||||
r0 = ret.Get(0).(connector.FileInfo)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(fileinfo.FileInfo)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
|
||||
@@ -69,12 +70,12 @@ func (_c *FileConnectorService_CheckFileInfo_Call) Run(run func(ctx context.Cont
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *FileConnectorService_CheckFileInfo_Call) Return(_a0 connector.FileInfo, _a1 error) *FileConnectorService_CheckFileInfo_Call {
|
||||
func (_c *FileConnectorService_CheckFileInfo_Call) Return(_a0 fileinfo.FileInfo, _a1 error) *FileConnectorService_CheckFileInfo_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *FileConnectorService_CheckFileInfo_Call) RunAndReturn(run func(context.Context) (connector.FileInfo, error)) *FileConnectorService_CheckFileInfo_Call {
|
||||
func (_c *FileConnectorService_CheckFileInfo_Call) RunAndReturn(run func(context.Context) (fileinfo.FileInfo, error)) *FileConnectorService_CheckFileInfo_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
@@ -566,8 +566,8 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (fileinfo.FileInfo, e
|
||||
// nothing special to do here for now
|
||||
|
||||
case appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY:
|
||||
infoMap["DisableExport"] = true
|
||||
infoMap["DisableCopy"] = true
|
||||
infoMap["DisableExport"] = true // only for collabora
|
||||
infoMap["DisableCopy"] = true // only for collabora
|
||||
infoMap["DisablePrint"] = true
|
||||
if !isPublicShare {
|
||||
infoMap["WatermarkText"] = f.watermarkText(wopiContext.User) // only for collabora
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/connector"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/connector/fileinfo"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/middleware"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
@@ -732,7 +733,7 @@ var _ = Describe("FileConnector", func() {
|
||||
ctx := context.Background()
|
||||
newFileInfo, err := fc.CheckFileInfo(ctx)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(newFileInfo).To(Equal(connector.FileInfo{}))
|
||||
Expect(newFileInfo).To(BeNil())
|
||||
})
|
||||
|
||||
It("Stat fails", func() {
|
||||
@@ -746,7 +747,7 @@ var _ = Describe("FileConnector", func() {
|
||||
newFileInfo, err := fc.CheckFileInfo(ctx)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err).To(Equal(targetErr))
|
||||
Expect(newFileInfo).To(Equal(connector.FileInfo{}))
|
||||
Expect(newFileInfo).To(BeNil())
|
||||
})
|
||||
|
||||
It("Stat fails status not ok", func() {
|
||||
@@ -760,7 +761,7 @@ var _ = Describe("FileConnector", func() {
|
||||
Expect(err).To(HaveOccurred())
|
||||
conErr := err.(*connector.ConnectorError)
|
||||
Expect(conErr.HttpCodeOut).To(Equal(500))
|
||||
Expect(newFileInfo).To(Equal(connector.FileInfo{}))
|
||||
Expect(newFileInfo).To(BeNil())
|
||||
})
|
||||
|
||||
It("Stat success", func() {
|
||||
@@ -783,7 +784,7 @@ var _ = Describe("FileConnector", func() {
|
||||
},
|
||||
}, nil)
|
||||
|
||||
expectedFileInfo := connector.FileInfo{
|
||||
expectedFileInfo := &fileinfo.Microsoft{
|
||||
OwnerId: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp
|
||||
Size: int64(998877),
|
||||
Version: "16273849.0",
|
||||
@@ -792,7 +793,6 @@ var _ = Describe("FileConnector", func() {
|
||||
UserCanNotWriteRelative: true,
|
||||
HostViewUrl: "http://test.ex.prv/view",
|
||||
HostEditUrl: "http://test.ex.prv/edit",
|
||||
EnableOwnerTermination: false,
|
||||
SupportsExtendedLockLength: true,
|
||||
SupportsGetLock: true,
|
||||
SupportsLocks: true,
|
||||
@@ -804,7 +804,7 @@ var _ = Describe("FileConnector", func() {
|
||||
|
||||
newFileInfo, err := fc.CheckFileInfo(ctx)
|
||||
Expect(err).To(Succeed())
|
||||
Expect(newFileInfo).To(Equal(expectedFileInfo))
|
||||
Expect(newFileInfo.(*fileinfo.Microsoft)).To(Equal(expectedFileInfo))
|
||||
})
|
||||
|
||||
It("Stat success guests", func() {
|
||||
@@ -839,39 +839,34 @@ var _ = Describe("FileConnector", func() {
|
||||
},
|
||||
}, nil)
|
||||
|
||||
expectedFileInfo := connector.FileInfo{
|
||||
OwnerId: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp
|
||||
Size: int64(998877),
|
||||
Version: "16273849.0",
|
||||
BaseFileName: "test.txt",
|
||||
BreadcrumbDocName: "test.txt",
|
||||
UserCanNotWriteRelative: true,
|
||||
HostViewUrl: "http://test.ex.prv/view",
|
||||
HostEditUrl: "http://test.ex.prv/edit",
|
||||
EnableOwnerTermination: false,
|
||||
SupportsExtendedLockLength: true,
|
||||
SupportsGetLock: true,
|
||||
SupportsLocks: true,
|
||||
DisableExport: true,
|
||||
DisableCopy: true,
|
||||
DisablePrint: true,
|
||||
IsAnonymousUser: true,
|
||||
UserId: "guest-zzz000",
|
||||
UserFriendlyName: "guest zzz000",
|
||||
// change wopi app provider
|
||||
cfg.WopiApp.Provider = "Collabora"
|
||||
|
||||
expectedFileInfo := &fileinfo.Collabora{
|
||||
OwnerId: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp
|
||||
Size: int64(998877),
|
||||
BaseFileName: "test.txt",
|
||||
UserCanNotWriteRelative: true,
|
||||
DisableExport: true,
|
||||
DisableCopy: true,
|
||||
DisablePrint: true,
|
||||
UserId: "guest-zzz000",
|
||||
UserFriendlyName: "guest zzz000",
|
||||
EnableOwnerTermination: true,
|
||||
}
|
||||
|
||||
newFileInfo, err := fc.CheckFileInfo(ctx)
|
||||
|
||||
// UserId and UserFriendlyName have random Ids generated which are impossible to guess
|
||||
// Check both separately
|
||||
Expect(newFileInfo.UserId).To(HavePrefix(hex.EncodeToString([]byte("guest-"))))
|
||||
Expect(newFileInfo.UserFriendlyName).To(HavePrefix("Guest "))
|
||||
Expect(newFileInfo.(*fileinfo.Collabora).UserId).To(HavePrefix(hex.EncodeToString([]byte("guest-"))))
|
||||
Expect(newFileInfo.(*fileinfo.Collabora).UserFriendlyName).To(HavePrefix("Guest "))
|
||||
// overwrite UserId and UserFriendlyName here for easier matching
|
||||
newFileInfo.UserId = "guest-zzz000"
|
||||
newFileInfo.UserFriendlyName = "guest zzz000"
|
||||
newFileInfo.(*fileinfo.Collabora).UserId = "guest-zzz000"
|
||||
newFileInfo.(*fileinfo.Collabora).UserFriendlyName = "guest zzz000"
|
||||
|
||||
Expect(err).To(Succeed())
|
||||
Expect(newFileInfo).To(Equal(expectedFileInfo))
|
||||
Expect(newFileInfo.(*fileinfo.Collabora)).To(Equal(expectedFileInfo))
|
||||
})
|
||||
|
||||
It("Stat success authenticated user", func() {
|
||||
@@ -897,32 +892,27 @@ var _ = Describe("FileConnector", func() {
|
||||
},
|
||||
}, nil)
|
||||
|
||||
expectedFileInfo := connector.FileInfo{
|
||||
OwnerId: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp
|
||||
Size: int64(998877),
|
||||
Version: "16273849.0",
|
||||
BaseFileName: "test.txt",
|
||||
BreadcrumbDocName: "test.txt",
|
||||
UserCanNotWriteRelative: true,
|
||||
HostViewUrl: "http://test.ex.prv/view",
|
||||
HostEditUrl: "http://test.ex.prv/edit",
|
||||
EnableOwnerTermination: false,
|
||||
SupportsExtendedLockLength: true,
|
||||
SupportsGetLock: true,
|
||||
SupportsLocks: true,
|
||||
DisableExport: true,
|
||||
DisableCopy: true,
|
||||
DisablePrint: true,
|
||||
IsAnonymousUser: false,
|
||||
UserId: hex.EncodeToString([]byte("opaqueId@inmemory")),
|
||||
UserFriendlyName: "Pet Shaft",
|
||||
WatermarkText: "Pet Shaft shaft@example.com",
|
||||
// change wopi app provider
|
||||
cfg.WopiApp.Provider = "Collabora"
|
||||
|
||||
expectedFileInfo := &fileinfo.Collabora{
|
||||
OwnerId: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp
|
||||
Size: int64(998877),
|
||||
BaseFileName: "test.txt",
|
||||
UserCanNotWriteRelative: true,
|
||||
DisableExport: true,
|
||||
DisableCopy: true,
|
||||
DisablePrint: true,
|
||||
UserId: hex.EncodeToString([]byte("opaqueId@inmemory")),
|
||||
UserFriendlyName: "Pet Shaft",
|
||||
EnableOwnerTermination: true,
|
||||
WatermarkText: "Pet Shaft shaft@example.com",
|
||||
}
|
||||
|
||||
newFileInfo, err := fc.CheckFileInfo(ctx)
|
||||
|
||||
Expect(err).To(Succeed())
|
||||
Expect(newFileInfo).To(Equal(expectedFileInfo))
|
||||
Expect(newFileInfo.(*fileinfo.Collabora)).To(Equal(expectedFileInfo))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/mocks"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/connector"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/connector/fileinfo"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
@@ -337,7 +338,7 @@ var _ = Describe("HttpAdapter", func() {
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
fc.On("CheckFileInfo", mock.Anything).Times(1).Return(connector.FileInfo{}, errors.New("Something happened"))
|
||||
fc.On("CheckFileInfo", mock.Anything).Times(1).Return(&fileinfo.Microsoft{}, errors.New("Something happened"))
|
||||
|
||||
httpAdapter.CheckFileInfo(w, req)
|
||||
resp := w.Result()
|
||||
@@ -351,7 +352,7 @@ var _ = Describe("HttpAdapter", func() {
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
fc.On("CheckFileInfo", mock.Anything).Times(1).Return(connector.FileInfo{}, connector.NewConnectorError(404, "Not found"))
|
||||
fc.On("CheckFileInfo", mock.Anything).Times(1).Return(&fileinfo.Microsoft{}, connector.NewConnectorError(404, "Not found"))
|
||||
|
||||
httpAdapter.CheckFileInfo(w, req)
|
||||
resp := w.Result()
|
||||
@@ -364,11 +365,11 @@ var _ = Describe("HttpAdapter", func() {
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
// might need more info, but should be enough for the test
|
||||
fileinfo := connector.FileInfo{
|
||||
finfo := &fileinfo.Microsoft{
|
||||
Size: 123456789,
|
||||
BreadcrumbDocName: "testy.docx",
|
||||
}
|
||||
fc.On("CheckFileInfo", mock.Anything).Times(1).Return(fileinfo, nil)
|
||||
fc.On("CheckFileInfo", mock.Anything).Times(1).Return(finfo, nil)
|
||||
|
||||
httpAdapter.CheckFileInfo(w, req)
|
||||
resp := w.Result()
|
||||
@@ -376,9 +377,9 @@ var _ = Describe("HttpAdapter", func() {
|
||||
|
||||
jsonInfo, _ := io.ReadAll(resp.Body)
|
||||
|
||||
var responseInfo connector.FileInfo
|
||||
var responseInfo *fileinfo.Microsoft
|
||||
json.Unmarshal(jsonInfo, &responseInfo)
|
||||
Expect(responseInfo).To(Equal(fileinfo))
|
||||
Expect(responseInfo).To(Equal(finfo))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user