-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper_update_test.go
99 lines (86 loc) · 3.06 KB
/
mapper_update_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
package wm
import (
"github.com/Hoss-Mobility/wm/internal"
"github.com/stretchr/testify/assert"
"testing"
)
func TestApplyUpdateAdmin(t *testing.T) {
role := "admin"
newSecretItem := internal.SecretItem{
Name: "Updated",
Comment: "Updated",
SecretInfo: "Updated",
TopSecret: "Updated",
CanOnlyBeWrittenTo: "Updated",
}
updated, err := ApplyUpdate(secretItem, newSecretItem, role)
if err != nil {
t.Fatalf("Error creating updated: %v", err)
}
// admin is allowed to write to all fields
assert.Equal(t, newSecretItem.Name, updated.Name)
assert.Equal(t, newSecretItem.Comment, updated.Comment)
assert.Equal(t, newSecretItem.SecretInfo, updated.SecretInfo)
assert.Equal(t, newSecretItem.TopSecret, updated.TopSecret)
assert.Equal(t, newSecretItem.CanOnlyBeWrittenTo, updated.CanOnlyBeWrittenTo)
}
func TestApplyUpdateDeveloper(t *testing.T) {
role := "developer"
newSecretItem := internal.SecretItem{
Name: "Updated",
Comment: "Updated",
SecretInfo: "Updated",
TopSecret: "Updated",
CanOnlyBeWrittenTo: "Updated",
}
updated, err := ApplyUpdate(secretItem, newSecretItem, role)
if err != nil {
t.Fatalf("Error creating updated: %v", err)
}
// developer is not allowed to write to all fields
assert.Equal(t, newSecretItem.Name, updated.Name)
assert.Equal(t, newSecretItem.Comment, updated.Comment)
assert.Equal(t, secretItem.SecretInfo, updated.SecretInfo)
assert.Equal(t, secretItem.TopSecret, updated.TopSecret)
assert.Equal(t, newSecretItem.CanOnlyBeWrittenTo, updated.CanOnlyBeWrittenTo)
}
func TestApplyUpdateStaff(t *testing.T) {
role := "staff"
newSecretItem := internal.SecretItem{
Name: "Updated",
Comment: "Updated",
SecretInfo: "Updated",
TopSecret: "Updated",
CanOnlyBeWrittenTo: "Updated",
}
updated, err := ApplyUpdate(secretItem, newSecretItem, role)
if err != nil {
t.Fatalf("Error creating updated: %v", err)
}
// staff is not allowed to write to all fields
assert.Equal(t, secretItem.Name, updated.Name)
assert.Equal(t, newSecretItem.Comment, updated.Comment)
assert.Equal(t, secretItem.SecretInfo, updated.SecretInfo)
assert.Equal(t, secretItem.TopSecret, updated.TopSecret)
assert.Equal(t, newSecretItem.CanOnlyBeWrittenTo, updated.CanOnlyBeWrittenTo)
}
func TestApplyUpdateUnauthorized(t *testing.T) {
role := "unauthorized"
newSecretItem := internal.SecretItem{
Name: "Updated",
Comment: "Updated",
SecretInfo: "Updated",
TopSecret: "Updated",
CanOnlyBeWrittenTo: "Updated",
}
updated, err := ApplyUpdate(secretItem, newSecretItem, role)
if err != nil {
t.Fatalf("Error creating updated: %v", err)
}
// staff is not allowed to write to all fields
assert.Equal(t, secretItem.Name, updated.Name)
assert.Equal(t, secretItem.Comment, updated.Comment)
assert.Equal(t, secretItem.SecretInfo, updated.SecretInfo)
assert.Equal(t, secretItem.TopSecret, updated.TopSecret)
assert.Equal(t, secretItem.CanOnlyBeWrittenTo, updated.CanOnlyBeWrittenTo)
}