8
8
"path"
9
9
"regexp"
10
10
"strings"
11
+ "time"
11
12
12
13
appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
13
14
auth "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1"
@@ -16,9 +17,9 @@ import (
16
17
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
17
18
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
18
19
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
20
+ "github.com/golang-jwt/jwt/v5"
19
21
. "github.com/onsi/ginkgo/v2"
20
22
. "github.com/onsi/gomega"
21
- "github.com/owncloud/ocis/v2/ocis-pkg/conversions"
22
23
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
23
24
collabmocks "github.com/owncloud/ocis/v2/services/collaboration/mocks"
24
25
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
@@ -57,7 +58,7 @@ var _ = Describe("FileConnector", func() {
57
58
WopiSrc : "https://ocis.server.prv" ,
58
59
Secret : "topsecret" ,
59
60
},
60
- TokenManager : & config.TokenManager {JWTSecret : "secret " },
61
+ TokenManager : & config.TokenManager {JWTSecret : "topsecret " },
61
62
}
62
63
ccs = & collabmocks.ContentConnectorService {}
63
64
@@ -67,11 +68,29 @@ var _ = Describe("FileConnector", func() {
67
68
gatewaySelector .On ("Next" ).Return (gatewayClient , nil )
68
69
fc = connector .NewFileConnector (gatewaySelector , cfg , nil )
69
70
71
+ // Generate a valid token for testing
72
+ now := time .Now ()
73
+ claims := jwt.MapClaims {
74
+ "aud" : "web" ,
75
+ "exp" : now .Add (24 * time .Hour ).Unix (),
76
+ "iat" : now .Unix (),
77
+ "iss" : "https://ocis.jp.solidgear.prv" ,
78
+ "jti" : "fBWi7AXhQPUhah2CWEPTQKpCfgpFlAiL" ,
79
+ "lg.i" : map [string ]interface {}{
80
+ "dn" : "bro" ,
81
+ "id" : "ownCloudUUID=faf11647-7451-4b9a-bffe-3b5ddcc5972b" ,
82
+ "un" : "brotato" ,
83
+ },
84
+ "lg.p" : "identifier-ldap" ,
85
+ "lg.t" : "1" ,
86
+ "scp" : "openid profile email" ,
87
+ "sub" : "cAvuzX8gXLZdiXx-@1NWTJtCPDqUJ44nt46FtD9p5L7tjePFdZMVJ9E30Nx2-dui7HKCLxAiaCTtbX511JcdHw" ,
88
+ }
89
+ token := jwt .NewWithClaims (jwt .SigningMethodHS256 , claims )
90
+ accessToken , _ := token .SignedString ([]byte (cfg .Wopi .Secret ))
91
+
70
92
wopiCtx = middleware.WopiContext {
71
- // A real token is needed for the PutRelativeFileSuggested tests although we aren't checking anything inside the token.
72
- // Test token details: HS256 (HMAC with SHA-256).
73
- // Token used in PutRelativeFileSuggested tests, validated against cfg.Wopi.Secret ("topsecret"). If tests fail, check token header {"alg":"HS256","typ":"JWT"} and validation in wopicontext.go.
74
- AccessToken : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ3ZWIiLCJleHAiOjE3MjAwOTIyODAsImlhdCI6MTcyMDA5MTk4MCwiaXNzIjoiaHR0cHM6Ly9vY2lzLmpwLnNvbGlkZ2Vhci5wcnYiLCJqdGkiOiJmQldpN0FYaFFQdUhhaDJDV0VQVFFLcENmZ3BGbEFpTCIsImxnLmkiOnsiZG4iOiJicm8iLCJpZCI6Im93bkNsb3VkVVVJRD1mYWYxMTY0Ny03NDUxLTRiOWEtYmZmZS0zYjVkZGNjNTk3MmIiLCJ1biI6ImJyb3RhdG8ifSwibGcucCI6ImlkZW50aWZpZXItbGRhcCIsImxnLnQiOiIxIiwic2NwIjoib3BlbmlkIHByb2ZpbGUgZW1haWwiLCJzdWIiOiJjQXZ1elg4Z1hMWmRpWHgtQDFOV1RKdENQRHFVSjQ0bnQ0NkZ0RDlwNUw3dGplUEZkWk1WSjlFMzBOeDItZHVpN0hLQ0x4QWlXYUNUdGJYNTExSmNkSHcifQ.8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx8J7Zx" ,
93
+ AccessToken : accessToken ,
75
94
FileReference : & providerv1beta1.Reference {
76
95
ResourceId : & providerv1beta1.ResourceId {
77
96
StorageId : "abc" ,
@@ -1755,7 +1774,7 @@ var _ = Describe("FileConnector", func() {
1755
1774
OpaqueId : "aabbcc" ,
1756
1775
Type : userv1beta1 .UserType_USER_TYPE_PRIMARY ,
1757
1776
},
1758
- Size : uint64 ( 998877 ),
1777
+ // Size is intentionally nil for guest users
1759
1778
Mtime : & typesv1beta1.Timestamp {
1760
1779
Seconds : uint64 (16273849 ),
1761
1780
},
@@ -1780,7 +1799,7 @@ var _ = Describe("FileConnector", func() {
1780
1799
1781
1800
expectedFileInfo := & fileinfo.Collabora {
1782
1801
OwnerID : "61616262636340637573746f6d496470" , // hex of aabbcc@customIdp
1783
- Size : int64 ( 998877 ) ,
1802
+ Size : 0 ,
1784
1803
BaseFileName : "test.txt" ,
1785
1804
UserCanNotWriteRelative : false ,
1786
1805
DisableExport : true ,
@@ -1839,7 +1858,7 @@ var _ = Describe("FileConnector", func() {
1839
1858
Decoder : "json" ,
1840
1859
Value : val ,
1841
1860
},
1842
- Role : auth .Role (appproviderv1beta1 .ViewMode_VIEW_MODE_VIEW_ONLY ), //
1861
+ Role : auth .Role (appproviderv1beta1 .ViewMode_VIEW_MODE_VIEW_ONLY ),
1843
1862
},
1844
1863
}
1845
1864
// change view mode to view only
@@ -1857,7 +1876,7 @@ var _ = Describe("FileConnector", func() {
1857
1876
OpaqueId : "aabbcc" ,
1858
1877
Type : userv1beta1 .UserType_USER_TYPE_PRIMARY ,
1859
1878
},
1860
- Size : uint64 ( 998877 ),
1879
+ // Size is intentionally nil for guest users
1861
1880
Mtime : & typesv1beta1.Timestamp {
1862
1881
Seconds : uint64 (16273849 ),
1863
1882
},
@@ -1878,11 +1897,10 @@ var _ = Describe("FileConnector", func() {
1878
1897
1879
1898
expectedFileInfo := & fileinfo.OnlyOffice {
1880
1899
Version : "v162738490" ,
1881
- Size : conversions .ToPointer (int64 (998877 )),
1882
1900
BaseFileName : "test.txt" ,
1883
1901
BreadcrumbDocName : "test.txt" ,
1884
1902
BreadcrumbFolderName : "/path/to" ,
1885
- BreadcrumbFolderURL : "https://ocis.example.prv/s/ABC123" ,
1903
+ BreadcrumbFolderURL : "https://ocis.example.prv/s/ABC123" , // Match share token format
1886
1904
DisablePrint : true ,
1887
1905
UserCanNotWriteRelative : false ,
1888
1906
SupportsLocks : true ,
@@ -1892,7 +1910,6 @@ var _ = Describe("FileConnector", func() {
1892
1910
UserCanRename : false ,
1893
1911
UserCanReview : false ,
1894
1912
UserCanWrite : false ,
1895
- EnableInsertRemoteImage : false ,
1896
1913
UserID : "guest-zzz000" ,
1897
1914
UserFriendlyName : "guest zzz000" ,
1898
1915
FileSharingURL : "https://ocis.example.prv/f/storageid$spaceid%21opaqueid?details=sharing" ,
@@ -2048,6 +2065,7 @@ var _ = Describe("FileConnector", func() {
2048
2065
FileVersionURL : "https://ocis.example.prv/f/storageid$spaceid%21opaqueid?details=versions" ,
2049
2066
HostEditURL : "https://ocis.example.prv/external-onlyoffice/path/to/test.txt?fileId=storageid%24spaceid%21opaqueid&view_mode=write" ,
2050
2067
PostMessageOrigin : "https://ocis.example.prv" ,
2068
+ TemplateSource : "" , // Remove the hardcoded token since it's dynamically generated
2051
2069
}
2052
2070
2053
2071
// change wopi app provider
0 commit comments