fix: adjust unit tests
This commit is contained in:
@@ -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