-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathzt_preserve_smb_properties_test.go
339 lines (299 loc) · 11.4 KB
/
zt_preserve_smb_properties_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//go:build windows
// +build windows
package e2etest
import (
"strings"
"testing"
"time"
"github.com/Azure/azure-storage-azcopy/v10/common"
"github.com/Azure/azure-storage-file-go/azfile"
"golang.org/x/sys/windows"
)
const SampleSDDL = "O:<placeholder>G:<placeholder>D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;<placeholder>)(D;;FX;;;SY)S:NO_ACCESS_CONTROL"
const RootSampleSDDL = "O:<placeholder>G:<placeholder>D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;FA;;;<placeholder>)S:NO_ACCESS_CONTROL"
const FolderSampleSDDL = "O:<placeholder>G:<placeholder>D:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;<placeholder>)S:NO_ACCESS_CONTROL"
const SampleSDDLPlaceHolder = "<placeholder>"
func AdjustSDDLToLocal(sample, placeholder string) (sddlOut string, err error) {
nameBuffer := make([]uint16, 50)
bufSize := uint32(len(nameBuffer))
for {
err = windows.GetUserNameEx(windows.NameSamCompatible, &nameBuffer[0], &bufSize)
if err == windows.ERROR_INSUFFICIENT_BUFFER {
// Win32 APIs will adjust our buffer size, we just need to reallocate
nameBuffer = make([]uint16, bufSize)
continue
} else if err != nil {
return "", err
}
break
}
// thankfully the windows package does this for us
sid, _, _, err := windows.LookupSID("", windows.UTF16ToString(nameBuffer))
if err != nil {
return "", err
}
return strings.ReplaceAll(sample, placeholder, sid.String()), nil
}
func TestProperties_SMBPermissionsSDDLPreserved(t *testing.T) {
fileSDDL, err := AdjustSDDLToLocal(SampleSDDL, SampleSDDLPlaceHolder)
if err != nil {
t.Error(err)
}
rootSDDL, err := AdjustSDDLToLocal(RootSampleSDDL, SampleSDDLPlaceHolder)
if err != nil {
t.Error(err)
}
folderSDDL, err := AdjustSDDLToLocal(FolderSampleSDDL, SampleSDDLPlaceHolder)
if err != nil {
t.Error(err)
}
RunScenarios(t, eOperation.Copy(), eTestFromTo.Other(
common.EFromTo.LocalFile(),
common.EFromTo.FileLocal(),
common.EFromTo.FileFile(),
), eValidate.Auto(), anonymousAuthOnly, anonymousAuthOnly, params{
recursive: true,
preserveSMBPermissions: true,
// default, but present for clarity
//preserveSMBInfo: BoolPointer(true),
}, nil, testFiles{
defaultSize: "1K",
shouldTransfer: []interface{}{
folder("", with{smbPermissionsSddl: rootSDDL}),
f("file1", with{smbPermissionsSddl: fileSDDL}),
f("file2.txt", with{smbPermissionsSddl: fileSDDL}),
folder("fldr1", with{smbPermissionsSddl: folderSDDL}),
f("fldr1/file3.txt", with{smbPermissionsSddl: fileSDDL}),
},
}, EAccountType.Standard(), EAccountType.Standard(), "")
}
// TODO: add some tests (or modify the above) to make assertions about case preservation (or not) in metadata
//
// See https://github.com/Azure/azure-storage-azcopy/issues/113 (which incidentally, I'm not observing in the tests above, for reasons unknown)
func TestProperties_SMBDates(t *testing.T) {
RunScenarios(t, eOperation.CopyAndSync(), eTestFromTo.Other(common.EFromTo.LocalFile(), common.EFromTo.FileLocal()), eValidate.Auto(), anonymousAuthOnly, anonymousAuthOnly, params{
recursive: true,
// default, but present for clarity
//preserveSMBInfo: BoolPointer(true),
}, &hooks{
beforeRunJob: func(h hookHelper) {
// Pause then re-write all the files, so that their LastWriteTime is different from their creation time
// So that when validating, our validation can be sure that the right datetime has ended up in the right
// field
time.Sleep(5 * time.Second)
h.CreateFiles(h.GetTestFiles(), true, true, false)
// And pause again, so that that the write times at the destination wont' just _automatically_ match the source times
// (due to there being < 1 sec delay between creation and completion of copy). With this delay, we know they only match
// if AzCopy really did preserve them
time.Sleep(10 * time.Second) // we are assuming here, that the clock skew between source and dest is less than 10 secs
},
}, testFiles{
defaultSize: "1K",
// no need to set specific dates on these. Instead, we just mess with the write times in
// beforeRunJob
// TODO: is that what we really want, or do we want to set write times here?
shouldTransfer: []interface{}{
folder(""),
"filea",
folder("fold1"),
"fold1/fileb",
},
}, EAccountType.Standard(), EAccountType.Standard(), "")
}
func TestProperties_SMBFlags(t *testing.T) {
RunScenarios(t, eOperation.CopyAndSync(), eTestFromTo.Other(common.EFromTo.LocalFile(), common.EFromTo.FileFile(), common.EFromTo.FileLocal()), eValidate.Auto(), anonymousAuthOnly, anonymousAuthOnly, params{
recursive: true,
// default, but present for clarity
//preserveSMBInfo: BoolPointer(true),
}, nil, testFiles{
defaultSize: "1K",
shouldTransfer: []interface{}{
folder("", with{smbAttributes: 2}), // hidden
f("file1.txt", with{smbAttributes: 2}),
folder("fldr1", with{smbAttributes: 2}),
f("fldr1/file2.txt", with{smbAttributes: 2}),
},
}, EAccountType.Standard(), EAccountType.Standard(), "")
}
func TestProperties_SMBPermsAndFlagsWithIncludeAfter(t *testing.T) {
recreateFiles := []interface{}{
folder("", with{smbAttributes: 2}),
f("filea", with{smbAttributes: 2}),
}
skippedFiles := []interface{}{
folder("fold1", with{smbAttributes: 2}),
f("fold1/fileb", with{smbAttributes: 2}),
}
RunScenarios(t, eOperation.Copy(), eTestFromTo.Other(common.EFromTo.FileLocal()), eValidate.Auto(), anonymousAuthOnly, anonymousAuthOnly, params{
recursive: true,
// default, but present for clarity
//preserveSMBInfo: BoolPointer(true),
// includeAfter: SET LATER
}, &hooks{
beforeRunJob: func(h hookHelper) {
// Pause for a includeAfter time
time.Sleep(5 * time.Second)
h.GetModifiableParameters().includeAfter = time.Now().Format(azfile.ISO8601)
// Pause then re-write all the files, so that their LastWriteTime is different from their creation time
// So that when validating, our validation can be sure that the right datetime has ended up in the right
// field
time.Sleep(5 * time.Second)
h.CreateFiles(testFiles{
defaultSize: "1K",
shouldTransfer: recreateFiles,
}, true, true, false)
// And pause again, so that that the write times at the destination wont' just _automatically_ match the source times
// (due to there being < 1 sec delay between creation and completion of copy). With this delay, we know they only match
// if AzCopy really did preserve them
time.Sleep(10 * time.Second) // we are assuming here, that the clock skew between source and dest is less than 10 secs
},
}, testFiles{
defaultSize: "1K",
// no need to set specific dates on these. Instead, we just mess with the write times in
// beforeRunJob
// TODO: is that what we really want, or do we want to set write times here?
shouldTransfer: recreateFiles,
shouldIgnore: skippedFiles,
}, EAccountType.Standard(), EAccountType.Standard(), "")
}
// TODO: Sync test for modern LMT getting
func TestProperties_SMBPermsAndFlagsWithSync(t *testing.T) {
recreateFiles := []interface{}{
folder("", with{smbAttributes: 2}),
f("filea", with{smbAttributes: 2}),
folder("fold2", with{smbAttributes: 2}),
f("fold2/filec", with{smbAttributes: 2}),
}
transferredFiles := []interface{}{
folder("fold1", with{smbAttributes: 2}),
f("fold1/fileb", with{smbAttributes: 2}),
}
RunScenarios(t, eOperation.Sync(), eTestFromTo.Other(common.EFromTo.LocalFile(), common.EFromTo.FileLocal()), eValidate.Auto(), anonymousAuthOnly, anonymousAuthOnly, params{
recursive: true,
// default, but present for clarity
//preserveSMBInfo: BoolPointer(true),
}, &hooks{
beforeRunJob: func(h hookHelper) {
// Pause then re-write all the files, so that their LastWriteTime is different from their creation time
// So that when validating, our validation can be sure that the right datetime has ended up in the right
// field
time.Sleep(5 * time.Second)
h.CreateFiles(testFiles{
defaultSize: "1K",
shouldTransfer: recreateFiles,
}, false, false, true)
// And pause again, so that that the write times at the destination wont' just _automatically_ match the source times
// (due to there being < 1 sec delay between creation and completion of copy). With this delay, we know they only match
// if AzCopy really did preserve them
time.Sleep(10 * time.Second) // we are assuming here, that the clock skew between source and dest is less than 10 secs
},
}, testFiles{
defaultSize: "1K",
// no need to set specific dates on these. Instead, we just mess with the write times in
// beforeRunJob
// TODO: is that what we really want, or do we want to set write times here?
shouldTransfer: transferredFiles,
shouldIgnore: recreateFiles,
}, EAccountType.Standard(), EAccountType.Standard(), "")
}
func TestProperties_SMBWithCopyWithShareRoot(t *testing.T) {
fileSDDL, err := AdjustSDDLToLocal(SampleSDDL, SampleSDDLPlaceHolder)
if err != nil {
t.Error(err)
}
rootSDDL, err := AdjustSDDLToLocal(RootSampleSDDL, SampleSDDLPlaceHolder)
if err != nil {
t.Error(err)
}
folderSDDL, err := AdjustSDDLToLocal(FolderSampleSDDL, SampleSDDLPlaceHolder)
if err != nil {
t.Error(err)
}
RunScenarios(
t,
eOperation.Copy(), // Sync already shares the root by default.
eTestFromTo.Other(common.EFromTo.LocalFile()),
eValidate.Auto(),
anonymousAuthOnly,
anonymousAuthOnly,
params{
recursive: true,
invertedAsSubdir: true,
preserveSMBPermissions: true,
// default, but present for clarity
//preserveSMBInfo: BoolPointer(true),
},
nil,
testFiles{
defaultSize: "1K",
destTarget: "newName",
shouldTransfer: []interface{}{
folder("", with{smbAttributes: 2, smbPermissionsSddl: rootSDDL}),
f("asdf.txt", with{smbAttributes: 2, smbPermissionsSddl: fileSDDL}),
folder("a", with{smbAttributes: 2, smbPermissionsSddl: folderSDDL}),
f("a/asdf.txt", with{smbAttributes: 2, smbPermissionsSddl: fileSDDL}),
folder("a/b", with{smbAttributes: 2, smbPermissionsSddl: folderSDDL}),
f("a/b/asdf.txt", with{smbAttributes: 2, smbPermissionsSddl: fileSDDL}),
},
},
EAccountType.Standard(),
EAccountType.Standard(),
"",
)
}
func TestProperties_SMBTimes(t *testing.T) {
RunScenarios(
t,
eOperation.Sync(),
eTestFromTo.Other(common.EFromTo.FileLocal()),
eValidate.Auto(),
anonymousAuthOnly,
anonymousAuthOnly,
params{
recursive: true,
// default, but present for clarity
//preserveSMBInfo: BoolPointer(true),
},
nil,
testFiles{
defaultSize: "1K",
shouldSkip: []interface{}{
folder("", with{lastWriteTime: time.Now().Add(-time.Hour)}), // If the fix worked, these should not be overwritten.
f("asdf.txt", with{lastWriteTime: time.Now().Add(-time.Hour)}), // If the fix did not work, we'll be relying upon the service's "real" LMT, which is not what we persisted, and an hour ahead of our files.
},
},
EAccountType.Standard(),
EAccountType.Standard(),
"",
)
}
func TestProperties_EnsureContainerBehavior(t *testing.T) {
RunScenarios(
t,
eOperation.Copy(),
eTestFromTo.Other(common.EFromTo.FileFile()),
eValidate.Auto(),
anonymousAuthOnly,
anonymousAuthOnly,
params{
recursive: true,
preserveSMBInfo: BoolPointer(true),
preserveSMBPermissions: true,
},
nil,
testFiles{
defaultSize: "1K",
shouldTransfer: []interface{}{
folder(""),
f("aeiou.txt"),
folder("a"),
f("a/asdf.txt"),
folder("b"),
f("b/1234.txt"),
},
},
EAccountType.Standard(),
EAccountType.Standard(),
"",
)
}