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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
import (
"os/exec"
"testing"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
)
func TestCliVersion(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go version`)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
}
func TestCliCreateTeam(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitSystemAdmin()
id := model.NewId()
name := "name" + id
displayName := "Name " + id
cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go team create --name "`+name+`" --display_name "`+displayName+`"`)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
found := th.SystemAdminClient.Must(th.SystemAdminClient.FindTeamByName(name)).Data.(bool)
if !found {
t.Fatal("Failed to create Team")
}
}
func TestCliCreateUserWithTeam(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitSystemAdmin()
id := model.NewId()
email := "success+" + id + "@simulator.amazonses.com"
username := "name" + id
cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go user create --email "`+email+`" --password "mypassword1" --username "`+username+`"`)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
cmd2 := exec.Command("bash", "-c", `go run ../cmd/platform/*.go team add `+th.SystemAdminTeam.Id+" "+email)
output2, err2 := cmd2.CombinedOutput()
if err2 != nil {
t.Log(string(output2))
t.Fatal(err2)
}
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User)
found := false
for _, user := range profiles {
if user.Email == email {
found = true
}
}
if !found {
t.Fatal("Failed to create User")
}
}
func TestCliCreateUserWithoutTeam(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
Setup()
id := model.NewId()
email := "success+" + id + "@simulator.amazonses.com"
username := "name" + id
cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go user create --email "`+email+`" --password "mypassword1" --username "`+username+`"`)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
if result := <-app.Srv.Store.User().GetByEmail(email); result.Err != nil {
t.Fatal()
} else {
user := result.Data.(*model.User)
if user.Email != email {
t.Fatal()
}
}
}
func TestCliAssignRole(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go roles system_admin "+th.BasicUser.Email)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
if result := <-app.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
t.Fatal()
} else {
user := result.Data.(*model.User)
if user.Roles != "system_admin system_user" {
t.Fatal()
}
}
}
func TestCliJoinChannel(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
// These test cannot run since this feature requires an enteprise license
// cmd := exec.Command("bash", "-c", `go run ../*.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`)
// output, err := cmd.CombinedOutput()
// if err != nil {
// t.Log(string(output))
// t.Fatal(err)
// }
// // Joining twice should succeed
// cmd1 := exec.Command("bash", "-c", `go run ../*.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`)
// output1, err1 := cmd1.CombinedOutput()
// if err1 != nil {
// t.Log(string(output1))
// t.Fatal(err1)
// }
// should fail because channel does not exist
cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel add "+th.BasicTeam.Name+":"+channel.Name+"asdf "+th.BasicUser2.Email)
output2, err2 := cmd2.CombinedOutput()
if err2 == nil {
t.Log(string(output2))
t.Fatal()
}
// should fail because channel does not have license
cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel add "+th.BasicTeam.Name+":"+channel.Name+" "+th.BasicUser2.Email)
output3, err3 := cmd3.CombinedOutput()
if err3 == nil {
t.Log(string(output3))
t.Fatal()
}
}
func TestCliRemoveChannel(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
// These test cannot run since this feature requires an enteprise license
// cmd := exec.Command("bash", "-c", `go run ../*.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`)
// output, err := cmd.CombinedOutput()
// if err != nil {
// t.Log(string(output))
// t.Fatal(err)
// }
// cmd0 := exec.Command("bash", "-c", `go run ../*.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`)
// output0, err0 := cmd0.CombinedOutput()
// if err0 != nil {
// t.Log(string(output0))
// t.Fatal(err0)
// }
// // Leaving twice should succeed
// cmd1 := exec.Command("bash", "-c", `go run ../*.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`)
// output1, err1 := cmd1.CombinedOutput()
// if err1 != nil {
// t.Log(string(output1))
// t.Fatal(err1)
// }
// cannot leave town-square
cmd1a := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel remove "+th.BasicTeam.Name+":town-square "+th.BasicUser2.Email)
output1a, err1a := cmd1a.CombinedOutput()
if err1a == nil {
t.Log(string(output1a))
t.Fatal()
}
// should fail because channel does not exist
cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel remove "+th.BasicTeam.Name+":doesnotexist "+th.BasicUser2.Email)
output2, err2 := cmd2.CombinedOutput()
if err2 == nil {
t.Log(string(output2))
t.Fatal()
}
// should fail because channel does not have license
cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel remove "+th.BasicTeam.Name+":"+channel.Name+" "+th.BasicUser2.Email)
output3, err3 := cmd3.CombinedOutput()
if err3 == nil {
t.Log(string(output3))
t.Fatal()
}
}
func TestCliListChannels(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id))
// These test cannot run since this feature requires an enteprise license
// cmd := exec.Command("bash", "-c", `go run ../*.go -list_channels -team_name="`+th.BasicTeam.Name+`"`)
// output, err := cmd.CombinedOutput()
// if err != nil {
// t.Log(string(output))
// t.Fatal(err)
// }
// if !strings.Contains(string(output), "town-square") {
// t.Fatal("should have channels")
// }
// if !strings.Contains(string(output), channel.Name+" (archived)") {
// t.Fatal("should have archived channel")
// }
// should fail because channel does not have license
cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel list "+th.BasicTeam.Name)
output3, err3 := cmd3.CombinedOutput()
if err3 == nil {
t.Log(string(output3))
t.Fatal()
}
}
func TestCliRestoreChannel(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id))
// These test cannot run since this feature requires an enteprise license
// cmd := exec.Command("bash", "-c", `go run ../*.go -restore_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`"`)
// output, err := cmd.CombinedOutput()
// if err != nil {
// t.Log(string(output))
// t.Fatal(err)
// }
// // restoring twice should succeed
// cmd1 := exec.Command("bash", "-c", `go run ../*.go -restore_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`"`)
// output1, err1 := cmd1.CombinedOutput()
// if err1 != nil {
// t.Log(string(output1))
// t.Fatal(err1)
// }
// should fail because channel does not have license
cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel restore "+th.BasicTeam.Name+":"+channel.Name)
output3, err3 := cmd3.CombinedOutput()
if err3 == nil {
t.Log(string(output3))
t.Fatal()
}
}
func TestCliJoinTeam(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitSystemAdmin().InitBasic()
cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go team add "+th.SystemAdminTeam.Name+" "+th.BasicUser.Email)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User)
found := false
for _, user := range profiles {
if user.Email == th.BasicUser.Email {
found = true
}
}
if !found {
t.Fatal("Failed to create User")
}
}
func TestCliLeaveTeam(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go team remove "+th.BasicTeam.Name+" "+th.BasicUser.Email)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
profiles := th.BasicClient.Must(th.BasicClient.GetProfilesInTeam(th.BasicTeam.Id, 0, 1000, "")).Data.(map[string]*model.User)
found := false
for _, user := range profiles {
if user.Email == th.BasicUser.Email {
found = true
}
}
if found {
t.Fatal("profile should not be on team")
}
if result := <-app.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil {
teamMembers := result.Data.([]*model.TeamMember)
if len(teamMembers) > 0 {
t.Fatal("Shouldn't be in team")
}
}
}
func TestCliResetPassword(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go user password "+th.BasicUser.Email+" password2")
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal(err)
}
th.BasicClient.Logout()
th.BasicUser.Password = "password2"
th.LoginBasic()
}
func TestCliCreateChannel(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
id := model.NewId()
name := "name" + id
// should fail because channel does not have license
cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel create --display_name "+name+" --team "+th.BasicTeam.Name+" --name "+name)
output, err := cmd.CombinedOutput()
if err == nil {
t.Log(string(output))
t.Fatal()
}
// should fail because channel does not have license
name = name + "-private"
cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel create --display_name="+name+" --team "+th.BasicTeam.Name+" --private --name "+name)
output2, err2 := cmd2.CombinedOutput()
if err2 == nil {
t.Log(string(output2))
t.Fatal()
}
}
func TestCliMakeUserActiveAndInactive(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
th := Setup().InitBasic()
// first inactivate the user
cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go user deactivate "+th.BasicUser.Email)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal()
}
// activate the inactive user
cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go user activate "+th.BasicUser.Email)
output2, err2 := cmd2.CombinedOutput()
if err2 != nil {
t.Log(string(output2))
t.Fatal()
}
}
|